implement debug in similar way to RangeInclusive

This commit is contained in:
Andreas Liljeqvist 2021-08-23 15:05:40 +02:00
parent e8e6d9bd86
commit d230b92ba7
6 changed files with 49 additions and 159 deletions

View File

@ -688,7 +688,7 @@ impl Primitive {
///
/// This is intended specifically to mirror LLVMs `!range` metadata,
/// semantics.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(Clone, PartialEq, Eq, Hash)]
#[derive(HashStable_Generic)]
pub struct WrappingRange {
pub start: u128,
@ -714,6 +714,13 @@ impl WrappingRange {
}
}
impl fmt::Debug for WrappingRange {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(fmt, "{}..={}", self.start, self.end)?;
Ok(())
}
}
/// Information about one scalar component of a Rust type.
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
#[derive(HashStable_Generic)]

View File

@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:41:1
|
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
|
= 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.
= note: the raw bytes of the constant (size: 4, align: 4) {

View File

@ -52,7 +52,7 @@ error[E0080]: it is undefined behavior to use this value
--> $DIR/ub-nonnull.rs:41:1
|
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range AllocationRange { start: 10, end: 30 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
|
= 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.
= note: the raw bytes of the constant (size: 4, align: 4) {

View File

@ -15,10 +15,7 @@ error: layout_of(E) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
@ -94,10 +91,7 @@ error: layout_of(E) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
},
),
@ -144,20 +138,14 @@ error: layout_of(S) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 0,
end: 4294967295,
},
valid_range: 0..=4294967295,
},
Scalar {
value: Int(
I32,
true,
),
valid_range: AllocationRange {
start: 0,
end: 4294967295,
},
valid_range: 0..=4294967295,
},
),
largest_niche: None,
@ -219,10 +207,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 0,
end: 1,
},
valid_range: 0..=1,
},
tag_encoding: Direct,
tag_field: 0,
@ -291,20 +276,14 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 0,
end: 1,
},
valid_range: 0..=1,
},
Scalar {
value: Int(
I32,
true,
),
valid_range: AllocationRange {
start: 0,
end: 4294967295,
},
valid_range: 0..=4294967295,
},
),
largest_niche: Some(
@ -317,10 +296,7 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 0,
end: 1,
},
valid_range: 0..=1,
},
},
),
@ -350,10 +326,7 @@ error: layout_of(i32) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 0,
end: 4294967295,
},
valid_range: 0..=4294967295,
},
),
largest_niche: None,

View File

@ -15,10 +15,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
@ -55,10 +52,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
),
largest_niche: Some(
@ -71,10 +65,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
},
),
@ -112,10 +103,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
tag_encoding: Direct,
tag_field: 0,
@ -152,10 +140,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
),
largest_niche: Some(
@ -168,10 +153,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
},
),
@ -209,10 +191,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
tag_encoding: Direct,
tag_field: 0,
@ -249,10 +228,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
),
largest_niche: Some(
@ -265,10 +241,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
},
),
@ -306,10 +279,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
tag_encoding: Direct,
tag_field: 0,
@ -346,10 +316,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
),
largest_niche: Some(
@ -362,10 +329,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
},
),
@ -403,10 +367,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
tag_encoding: Direct,
tag_field: 0,
@ -443,10 +404,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
),
largest_niche: Some(
@ -459,10 +417,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
},
),

View File

@ -15,10 +15,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
tag_encoding: Direct,
tag_field: 0,
@ -55,10 +52,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
),
largest_niche: Some(
@ -71,10 +65,7 @@ error: layout_of(A) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 0,
end: 0,
},
valid_range: 0..=0,
},
},
),
@ -112,10 +103,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
tag_encoding: Direct,
tag_field: 0,
@ -152,10 +140,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
),
largest_niche: Some(
@ -168,10 +153,7 @@ error: layout_of(B) = Layout {
I8,
false,
),
valid_range: AllocationRange {
start: 255,
end: 255,
},
valid_range: 255..=255,
},
},
),
@ -209,10 +191,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
tag_encoding: Direct,
tag_field: 0,
@ -249,10 +228,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
),
largest_niche: Some(
@ -265,10 +241,7 @@ error: layout_of(C) = Layout {
I16,
false,
),
valid_range: AllocationRange {
start: 256,
end: 256,
},
valid_range: 256..=256,
},
},
),
@ -306,10 +279,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
tag_encoding: Direct,
tag_field: 0,
@ -346,10 +316,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
),
largest_niche: Some(
@ -362,10 +329,7 @@ error: layout_of(P) = Layout {
I32,
false,
),
valid_range: AllocationRange {
start: 268435456,
end: 268435456,
},
valid_range: 268435456..=268435456,
},
},
),
@ -403,10 +367,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
tag_encoding: Direct,
tag_field: 0,
@ -443,10 +404,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
),
largest_niche: Some(
@ -459,10 +417,7 @@ error: layout_of(T) = Layout {
I32,
true,
),
valid_range: AllocationRange {
start: 2164260864,
end: 2164260864,
},
valid_range: 2164260864..=2164260864,
},
},
),