]> git.lizzy.rs Git - rust.git/commitdiff
implement debug in similar way to RangeInclusive
authorAndreas Liljeqvist <bonega@gmail.com>
Mon, 23 Aug 2021 13:05:40 +0000 (15:05 +0200)
committerAndreas Liljeqvist <bonega@gmail.com>
Mon, 23 Aug 2021 13:05:40 +0000 (15:05 +0200)
compiler/rustc_target/src/abi/mod.rs
src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
src/test/ui/layout/debug.stderr
src/test/ui/layout/hexagon-enum.stderr
src/test/ui/layout/thumb-enum.stderr

index d29b731e4f1291f06d3f6ea2e159169c2dec3cee..c9d0b12e7396f0bac4815b20e57d81c63f596e26 100644 (file)
@@ -688,7 +688,7 @@ pub fn is_int(self) -> bool {
 ///
 /// This is intended specifically to mirror LLVM’s `!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 @@ pub fn contains_zero(&self) -> bool {
     }
 }
 
+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)]
index 01403a61e5e24d10c90b33390829477a77ad0ae1..e44f324945481e2f84cc695315d701aecd25078e 100644 (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) {
index 41de900f1640a3afaf4494c7e8d2d697bef028f8..1ce87bc7c1ce87a4e22b3c66578373ff1b11703e 100644 (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) {
index cbe9b6400c35fad07cb6bab1aa9437969b2c5547..1a371c6b17000b6c93d2a491f88321ba4ee95230 100644 (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,
index 520ba12c39fb1058256e4f99a16443101ab85bef..d4676a5afb25e227f19eb6a3867692e635ddda8c 100644 (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,
             },
         },
     ),
index 50e37c5411632e9c54c1091ed957fd284d1816ba..898a61b904db50bd0dbf1fa8f6feb492d2878290 100644 (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,
             },
         },
     ),