about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndreas Liljeqvist <bonega@gmail.com>2021-08-23 15:05:40 +0200
committerAndreas Liljeqvist <bonega@gmail.com>2021-08-23 15:05:40 +0200
commitd230b92ba7a2a32000be5e207860aa27d1a11113 (patch)
treedffa0271c91f9f030d20910111088715752606f4
parente8e6d9bd86c9cf685666718ca99e016275e1751b (diff)
downloadrust-d230b92ba7a2a32000be5e207860aa27d1a11113.tar.gz
rust-d230b92ba7a2a32000be5e207860aa27d1a11113.zip
implement debug in similar way to RangeInclusive
-rw-r--r--compiler/rustc_target/src/abi/mod.rs9
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr2
-rw-r--r--src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr2
-rw-r--r--src/test/ui/layout/debug.stderr45
-rw-r--r--src/test/ui/layout/hexagon-enum.stderr75
-rw-r--r--src/test/ui/layout/thumb-enum.stderr75
6 files changed, 49 insertions, 159 deletions
diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs
index d29b731e4f1..c9d0b12e739 100644
--- a/compiler/rustc_target/src/abi/mod.rs
+++ b/compiler/rustc_target/src/abi/mod.rs
@@ -688,7 +688,7 @@ impl Primitive {
 ///
 /// 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 @@ 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)]
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
index 01403a61e5e..e44f3249454 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-nonnull.32bit.stderr
@@ -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) {
diff --git a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
index 41de900f164..1ce87bc7c1c 100644
--- a/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
+++ b/src/test/ui/consts/const-eval/ub-nonnull.64bit.stderr
@@ -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) {
diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr
index cbe9b6400c3..1a371c6b170 100644
--- a/src/test/ui/layout/debug.stderr
+++ b/src/test/ui/layout/debug.stderr
@@ -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,
diff --git a/src/test/ui/layout/hexagon-enum.stderr b/src/test/ui/layout/hexagon-enum.stderr
index 520ba12c39f..d4676a5afb2 100644
--- a/src/test/ui/layout/hexagon-enum.stderr
+++ b/src/test/ui/layout/hexagon-enum.stderr
@@ -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,
             },
         },
     ),
diff --git a/src/test/ui/layout/thumb-enum.stderr b/src/test/ui/layout/thumb-enum.stderr
index 50e37c54116..898a61b904d 100644
--- a/src/test/ui/layout/thumb-enum.stderr
+++ b/src/test/ui/layout/thumb-enum.stderr
@@ -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,
             },
         },
     ),