Skip to content

Commit d230b92

Browse files
committed
implement debug in similar way to RangeInclusive
1 parent e8e6d9b commit d230b92

File tree

6 files changed

+49
-159
lines changed

6 files changed

+49
-159
lines changed

compiler/rustc_target/src/abi/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl Primitive {
688688
///
689689
/// This is intended specifically to mirror LLVM’s `!range` metadata,
690690
/// semantics.
691-
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
691+
#[derive(Clone, PartialEq, Eq, Hash)]
692692
#[derive(HashStable_Generic)]
693693
pub struct WrappingRange {
694694
pub start: u128,
@@ -714,6 +714,13 @@ impl WrappingRange {
714714
}
715715
}
716716

717+
impl fmt::Debug for WrappingRange {
718+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
719+
write!(fmt, "{}..={}", self.start, self.end)?;
720+
Ok(())
721+
}
722+
}
723+
717724
/// Information about one scalar component of a Rust type.
718725
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
719726
#[derive(HashStable_Generic)]

src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value
5252
--> $DIR/ub-nonnull.rs:41:1
5353
|
5454
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 }
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
5656
|
5757
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
5858
= note: the raw bytes of the constant (size: 4, align: 4) {

src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value
5252
--> $DIR/ub-nonnull.rs:41:1
5353
|
5454
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
55-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 }
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
5656
|
5757
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
5858
= note: the raw bytes of the constant (size: 4, align: 4) {

src/test/ui/layout/debug.stderr

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ error: layout_of(E) = Layout {
1515
I32,
1616
false,
1717
),
18-
valid_range: AllocationRange {
19-
start: 0,
20-
end: 0,
21-
},
18+
valid_range: 0..=0,
2219
},
2320
tag_encoding: Direct,
2421
tag_field: 0,
@@ -94,10 +91,7 @@ error: layout_of(E) = Layout {
9491
I32,
9592
false,
9693
),
97-
valid_range: AllocationRange {
98-
start: 0,
99-
end: 0,
100-
},
94+
valid_range: 0..=0,
10195
},
10296
},
10397
),
@@ -144,20 +138,14 @@ error: layout_of(S) = Layout {
144138
I32,
145139
true,
146140
),
147-
valid_range: AllocationRange {
148-
start: 0,
149-
end: 4294967295,
150-
},
141+
valid_range: 0..=4294967295,
151142
},
152143
Scalar {
153144
value: Int(
154145
I32,
155146
true,
156147
),
157-
valid_range: AllocationRange {
158-
start: 0,
159-
end: 4294967295,
160-
},
148+
valid_range: 0..=4294967295,
161149
},
162150
),
163151
largest_niche: None,
@@ -219,10 +207,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
219207
I32,
220208
false,
221209
),
222-
valid_range: AllocationRange {
223-
start: 0,
224-
end: 1,
225-
},
210+
valid_range: 0..=1,
226211
},
227212
tag_encoding: Direct,
228213
tag_field: 0,
@@ -291,20 +276,14 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
291276
I32,
292277
false,
293278
),
294-
valid_range: AllocationRange {
295-
start: 0,
296-
end: 1,
297-
},
279+
valid_range: 0..=1,
298280
},
299281
Scalar {
300282
value: Int(
301283
I32,
302284
true,
303285
),
304-
valid_range: AllocationRange {
305-
start: 0,
306-
end: 4294967295,
307-
},
286+
valid_range: 0..=4294967295,
308287
},
309288
),
310289
largest_niche: Some(
@@ -317,10 +296,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
317296
I32,
318297
false,
319298
),
320-
valid_range: AllocationRange {
321-
start: 0,
322-
end: 1,
323-
},
299+
valid_range: 0..=1,
324300
},
325301
},
326302
),
@@ -350,10 +326,7 @@ error: layout_of(i32) = Layout {
350326
I32,
351327
true,
352328
),
353-
valid_range: AllocationRange {
354-
start: 0,
355-
end: 4294967295,
356-
},
329+
valid_range: 0..=4294967295,
357330
},
358331
),
359332
largest_niche: None,

src/test/ui/layout/hexagon-enum.stderr

Lines changed: 15 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ error: layout_of(A) = Layout {
1515
I8,
1616
false,
1717
),
18-
valid_range: AllocationRange {
19-
start: 0,
20-
end: 0,
21-
},
18+
valid_range: 0..=0,
2219
},
2320
tag_encoding: Direct,
2421
tag_field: 0,
@@ -55,10 +52,7 @@ error: layout_of(A) = Layout {
5552
I8,
5653
false,
5754
),
58-
valid_range: AllocationRange {
59-
start: 0,
60-
end: 0,
61-
},
55+
valid_range: 0..=0,
6256
},
6357
),
6458
largest_niche: Some(
@@ -71,10 +65,7 @@ error: layout_of(A) = Layout {
7165
I8,
7266
false,
7367
),
74-
valid_range: AllocationRange {
75-
start: 0,
76-
end: 0,
77-
},
68+
valid_range: 0..=0,
7869
},
7970
},
8071
),
@@ -112,10 +103,7 @@ error: layout_of(B) = Layout {
112103
I8,
113104
false,
114105
),
115-
valid_range: AllocationRange {
116-
start: 255,
117-
end: 255,
118-
},
106+
valid_range: 255..=255,
119107
},
120108
tag_encoding: Direct,
121109
tag_field: 0,
@@ -152,10 +140,7 @@ error: layout_of(B) = Layout {
152140
I8,
153141
false,
154142
),
155-
valid_range: AllocationRange {
156-
start: 255,
157-
end: 255,
158-
},
143+
valid_range: 255..=255,
159144
},
160145
),
161146
largest_niche: Some(
@@ -168,10 +153,7 @@ error: layout_of(B) = Layout {
168153
I8,
169154
false,
170155
),
171-
valid_range: AllocationRange {
172-
start: 255,
173-
end: 255,
174-
},
156+
valid_range: 255..=255,
175157
},
176158
},
177159
),
@@ -209,10 +191,7 @@ error: layout_of(C) = Layout {
209191
I16,
210192
false,
211193
),
212-
valid_range: AllocationRange {
213-
start: 256,
214-
end: 256,
215-
},
194+
valid_range: 256..=256,
216195
},
217196
tag_encoding: Direct,
218197
tag_field: 0,
@@ -249,10 +228,7 @@ error: layout_of(C) = Layout {
249228
I16,
250229
false,
251230
),
252-
valid_range: AllocationRange {
253-
start: 256,
254-
end: 256,
255-
},
231+
valid_range: 256..=256,
256232
},
257233
),
258234
largest_niche: Some(
@@ -265,10 +241,7 @@ error: layout_of(C) = Layout {
265241
I16,
266242
false,
267243
),
268-
valid_range: AllocationRange {
269-
start: 256,
270-
end: 256,
271-
},
244+
valid_range: 256..=256,
272245
},
273246
},
274247
),
@@ -306,10 +279,7 @@ error: layout_of(P) = Layout {
306279
I32,
307280
false,
308281
),
309-
valid_range: AllocationRange {
310-
start: 268435456,
311-
end: 268435456,
312-
},
282+
valid_range: 268435456..=268435456,
313283
},
314284
tag_encoding: Direct,
315285
tag_field: 0,
@@ -346,10 +316,7 @@ error: layout_of(P) = Layout {
346316
I32,
347317
false,
348318
),
349-
valid_range: AllocationRange {
350-
start: 268435456,
351-
end: 268435456,
352-
},
319+
valid_range: 268435456..=268435456,
353320
},
354321
),
355322
largest_niche: Some(
@@ -362,10 +329,7 @@ error: layout_of(P) = Layout {
362329
I32,
363330
false,
364331
),
365-
valid_range: AllocationRange {
366-
start: 268435456,
367-
end: 268435456,
368-
},
332+
valid_range: 268435456..=268435456,
369333
},
370334
},
371335
),
@@ -403,10 +367,7 @@ error: layout_of(T) = Layout {
403367
I32,
404368
true,
405369
),
406-
valid_range: AllocationRange {
407-
start: 2164260864,
408-
end: 2164260864,
409-
},
370+
valid_range: 2164260864..=2164260864,
410371
},
411372
tag_encoding: Direct,
412373
tag_field: 0,
@@ -443,10 +404,7 @@ error: layout_of(T) = Layout {
443404
I32,
444405
true,
445406
),
446-
valid_range: AllocationRange {
447-
start: 2164260864,
448-
end: 2164260864,
449-
},
407+
valid_range: 2164260864..=2164260864,
450408
},
451409
),
452410
largest_niche: Some(
@@ -459,10 +417,7 @@ error: layout_of(T) = Layout {
459417
I32,
460418
true,
461419
),
462-
valid_range: AllocationRange {
463-
start: 2164260864,
464-
end: 2164260864,
465-
},
420+
valid_range: 2164260864..=2164260864,
466421
},
467422
},
468423
),

0 commit comments

Comments
 (0)