Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trim paths when printing const eval frame #100144

Closed

Conversation

compiler-errors
Copy link
Member

Fixes #100114

Some UI test output is more verbose now, but it's not immediately clear that we should've been trimming those paths anyways. Verbosity in this case is useful, I think.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 4, 2022
@rustbot
Copy link
Collaborator

rustbot commented Aug 4, 2022

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 4, 2022
@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

I don't think this will fix #100114. It makes very little sense that changing the way the path is rendered would affect that regression test. My prediction is that if you undo the compiler/ changes in this PR, the new regression test you added will still pass.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Ah no the reason it passes now is that you get a "Future incompatibility report". But this does not fix the ICE for rustc invocations that don't print these reports. Note that there still is no regular diagnostic being printed, only the future-incompat-report. That basically circumvents the allow(const_err) and hence circumvents the ICE.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Ah, the original ICE does mention something about path trimming?

error: trimmed_def_paths constructed

The error doesn't even say why that is an error though. Pretty useless. :(

Still I am not convinced that we want the verbose paths here.

@compiler-errors
Copy link
Member Author

compiler-errors commented Aug 4, 2022

My prediction is that if you undo the compiler/ changes in this PR, the new regression test you added will still pass.

I verified that this UI tests fails locally without the compiler changes, and passes with them applied.

Ah, the original ICE does mention something about path trimming?

Yes, the ICE is because we format a string that uses the trimmed path (e.g. Vec) but then never emit a diagnostic related to it. That's considered a "good path bug", since we should only be constructing a trimmed path (which I'm guessing is a relatively expensive operation) if we're actually going to be using it.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Is "good path bug" the same thing as delay_span_bug? "delay_bug" makes a lot more sense as a name, I am very confused by "good_path_bug"^^

@compiler-errors
Copy link
Member Author

@RalfJung I actually didn't even notice that "Future incompatibility report" being printed. We can probably use the fact that that's printed to defuse the trimmed paths bug.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Ah no "good_path_bug" is something else, a new thing I haven't encountered yet.

@compiler-errors
Copy link
Member Author

Good path bugs are the opposite of span bugs, they trigger when no diagnostic is emitted (as opposed to triggering when no error is emitted). I can probably just fix the good path bug to consider the fact that a future incompatibility warning is emitted.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Yes, the ICE is because we format a string that uses the trimmed path (e.g. Vec) but then never emit a diagnostic related to it. That's considered a "good path bug", since we should only be constructing a trimmed path (which I'm guessing is a relatively expensive operation) if we're actually going to be using it.

Okay so the proper fix then would be to only do this work when the lint is actually going to be emitted.

Your patch as-is will also affect diagnostics we want, and it will affect Miri, so I don't think this is the right patch.

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Good path bugs are the opposite of span bugs

So they panic! if any error is omitted? ;) (delay_span_bug panics if no error is omitted so that's what I would expect the opposite to be)

From the docs, seems like it's like a less aggressive version of delay_span_bug that is also "happy" with just a warning having been emitted.

@compiler-errors
Copy link
Member Author

compiler-errors commented Aug 4, 2022

@RalfJung, so I'm actually not sure if I agree that the diagnostic changes are regressions.

We're already being pretty verbose in this Display impl by printing the file/line/etc., so I'm not sure why printing the full path of the instance is bad?

that is, I don't see why

within `std::intrinsics::unreachable_unchecked` at $FILE:LL:LL

is worse than

within `unreachable_unchecked` at $FILE:LL:LL

The fact that we're currently trimming these paths seems like it was a side-effect of the printing logic having this behavior by default, and not done intentionally? 🤔

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Why is printing the full path ever bad in any diagnostic? The same reason applies here.

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-12 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
diff of 32bit.stderr:

105    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106    |                  |
107    |                  out-of-bounds offset_from: null pointer is a dangling pointer (it has no provenance)
-    |                  inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
110   ::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
111    |


112 LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
-    |                                          ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+    |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
115   ::: $DIR/forbidden_slices.rs:46:34
116    |

124    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
124    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125    |         |
126    |         the evaluated program panicked at 'assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize', $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
-    |         inside `ptr::const_ptr::<impl *const ()>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |         inside `std::ptr::const_ptr::<impl *const ()>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
129   ::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
130    |


131 LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
-    |                                          ------------------------------ inside `from_ptr_range::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=i686-unknown-linux-gnu
+    |                                          ------------------------------ inside `std::slice::from_ptr_range::<()>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
134   ::: $DIR/forbidden_slices.rs:47:33
135    |

145    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
145    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
146    |                  |
147    |                  out-of-bounds pointer arithmetic: ALLOC_ID has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
-    |                  inside `ptr::const_ptr::<impl *const u32>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  inside `std::ptr::const_ptr::<impl *const u32>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
149 ...
150 LL |         unsafe { self.offset(count as isize) }
-    |                  --------------------------- inside `ptr::const_ptr::<impl *const u32>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  --------------------------- inside `std::ptr::const_ptr::<impl *const u32>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
153   ::: $DIR/forbidden_slices.rs:50:25
154    |

206    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
206    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
207    |                  |
208    |                  out-of-bounds pointer arithmetic: ALLOC_ID has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
-    |                  inside `ptr::const_ptr::<impl *const u64>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  inside `std::ptr::const_ptr::<impl *const u64>::offset` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
210 ...
211 LL |         unsafe { self.offset(count as isize) }
-    |                  --------------------------- inside `ptr::const_ptr::<impl *const u64>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  --------------------------- inside `std::ptr::const_ptr::<impl *const u64>::add` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
214   ::: $DIR/forbidden_slices.rs:74:25
215    |

223    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
223    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224    |                  |
225    |                  `ptr_offset_from_unsigned` called on pointers into different allocations
-    |                  inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
228   ::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
229    |


230 LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
-    |                                          ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+    |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
233   ::: $DIR/forbidden_slices.rs:79:34
234    |

242    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
242    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
243    |                  |
244    |                  `ptr_offset_from_unsigned` called on pointers into different allocations
-    |                  inside `ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
+    |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
247   ::: $SRC_DIR/core/src/slice/raw.rs:LL:COL
248    |


249 LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
-    |                                          ------------------------------ inside `from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
+    |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at $SRC_DIR/core/src/slice/raw.rs:LL:COL
252   ::: $DIR/forbidden_slices.rs:80:35
253    |



The actual 32bit.stderr differed from the expected 32bit.stderr.
Actual 32bit.stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-ptr/forbidden_slices/forbidden_slices.32bit.stderr
To only update this specific test, also pass `--test-args const-ptr/forbidden_slices.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/const-ptr/forbidden_slices.rs" "-Zthreads=1" "--target=i686-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-ptr/forbidden_slices" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/i686-unknown-linux-gnu/native/rust-test-helpers" "-Clinker=x86_64-linux-gnu-gcc" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-ptr/forbidden_slices/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0080]: could not evaluate static initializer
   |
   |
LL |         &*ptr::slice_from_raw_parts(data, len)
   |         |
   |         dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
   |         inside `std::slice::from_raw_parts::<u32>` at /checkout/library/core/src/slice/raw.rs:97:9
   |
   |
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:18:34
   |
LL | pub static S0: &[u32] = unsafe { from_raw_parts(ptr::null(), 0) };
   |                                  ------------------------------ inside `S0` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:18:34
error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/slice/raw.rs:97:9
   |
   |
LL |         &*ptr::slice_from_raw_parts(data, len)
   |         |
   |         dereferencing pointer failed: null pointer is a dangling pointer (it has no provenance)
   |         inside `std::slice::from_raw_parts::<()>` at /checkout/library/core/src/slice/raw.rs:97:9
   |
   |
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:19:33
   |
LL | pub static S1: &[()] = unsafe { from_raw_parts(ptr::null(), 0) };
   |                                 ------------------------------ inside `S1` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:19:33
error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/slice/raw.rs:97:9
   |
   |
LL |         &*ptr::slice_from_raw_parts(data, len)
   |         |
   |         |
   |         dereferencing pointer failed: alloc24 has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
   |         inside `std::slice::from_raw_parts::<u32>` at /checkout/library/core/src/slice/raw.rs:97:9
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:22:34
   |
   |
LL | pub static S2: &[u32] = unsafe { from_raw_parts(&D0, 2) };
   |                                  ---------------------- inside `S2` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:22:34
error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:25:1
   |
   |
LL | pub static S4: &[u8] = unsafe { from_raw_parts((&D1) as *const _ as _, 1) }; //~ ERROR: it is undefined behavior to use this value
   | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized bytes
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:27:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:27:1
   |
LL | pub static S5: &[u8] = unsafe { from_raw_parts((&D3) as *const _ as _, size_of::<&u32>()) }; //~ ERROR: it is undefined behavior to use t...
   | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered a pointer, but expected plain (non-pointer) bytes
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:29:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:29:1
   |
LL | pub static S6: &[bool] = unsafe { from_raw_parts((&D0) as *const _ as _, 4) }; //~ ERROR: it is undefined behavior to use this value
   | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:32:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:32:1
   |
LL | pub static S7: &[u16] = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
   |
   = 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: 8, align: 4) {
               ╾─a68+0x1─╼ 04 00 00 00                         │ ╾──╼....

error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/slice/raw.rs:97:9
   |
   |
LL |         &*ptr::slice_from_raw_parts(data, len)
   |         |
   |         |
   |         dereferencing pointer failed: alloc82 has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
   |         inside `std::slice::from_raw_parts::<u64>` at /checkout/library/core/src/slice/raw.rs:97:9
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:43:5
   |
LL |     from_raw_parts(ptr, 1)
   |     ---------------------- inside `S8` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:43:5
   |     ---------------------- inside `S8` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:43:5

error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
LL |         unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
   |                  |
   |                  out-of-bounds offset_from: null pointer is a dangling pointer (it has no provenance)
   |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
   |
  ::: /checkout/library/core/src/slice/raw.rs:219:42
   |
LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
   |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at /checkout/library/core/src/slice/raw.rs:219:42
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:46:34
   |
   |
LL | pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
   |                                  ---------------------------------------- inside `R0` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:46:34
error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:748:9
   |
   |
LL |         assert!(0 < pointee_size && pointee_size <= isize::MAX as usize);
   |         |
   |         |
   |         the evaluated program panicked at 'assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize', /checkout/library/core/src/ptr/const_ptr.rs:748:9
   |         inside `std::ptr::const_ptr::<impl *const ()>::sub_ptr` at /checkout/library/core/src/ptr/const_ptr.rs:748:9
  ::: /checkout/library/core/src/slice/raw.rs:219:42
   |
   |
LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
   |                                          ------------------------------ inside `std::slice::from_ptr_range::<()>` at /checkout/library/core/src/slice/raw.rs:219:42
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:47:33
   |
   |
LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) };
   |                                 ---------------------------------------- inside `R1` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:47:33
   = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:458:18
  --> /checkout/library/core/src/ptr/const_ptr.rs:458:18
   |
LL |         unsafe { intrinsics::offset(self, count) }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                  |
   |                  out-of-bounds pointer arithmetic: alloc137 has size 4, so pointer to 8 bytes starting at offset 0 is out-of-bounds
   |                  inside `std::ptr::const_ptr::<impl *const u32>::offset` at /checkout/library/core/src/ptr/const_ptr.rs:458:18
...
LL |         unsafe { self.offset(count as isize) }
   |                  --------------------------- inside `std::ptr::const_ptr::<impl *const u32>::add` at /checkout/library/core/src/ptr/const_ptr.rs:876:18
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:50:25
   |
   |
LL |     from_ptr_range(ptr..ptr.add(2))
   |                         ---------- inside `R2` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:50:25
error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:52:1
   |
   |
LL | pub static R4: &[u8] = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered uninitialized bytes
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:57:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:57:1
   |
LL | pub static R5: &[u8] = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>: encountered a pointer, but expected plain (non-pointer) bytes
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:62:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:62:1
   |
LL | pub static R6: &[bool] = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value at .<deref>[0]: encountered 0x11, but expected a boolean
   |
   = 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: 8, align: 4) {
           }

error[E0080]: it is undefined behavior to use this value
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:67:1
  --> /checkout/src/test/ui/const-ptr/forbidden_slices.rs:67:1
   |
LL | pub static R7: &[u16] = unsafe {
   | ^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered an unaligned reference (required 2 byte alignment but found 1)
   |
   = 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: 8, align: 4) {
               ╾a182+0x1─╼ 04 00 00 00                         │ ╾──╼....

error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:458:18
   |
   |
LL |         unsafe { intrinsics::offset(self, count) }
   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |                  |
   |                  out-of-bounds pointer arithmetic: alloc199 has size 8, so pointer to 8 bytes starting at offset 1 is out-of-bounds
   |                  inside `std::ptr::const_ptr::<impl *const u64>::offset` at /checkout/library/core/src/ptr/const_ptr.rs:458:18
...
LL |         unsafe { self.offset(count as isize) }
   |                  --------------------------- inside `std::ptr::const_ptr::<impl *const u64>::add` at /checkout/library/core/src/ptr/const_ptr.rs:876:18
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:74:25
   |
   |
LL |     from_ptr_range(ptr..ptr.add(1))
   |                         ---------- inside `R8` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:74:25
error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
   |
LL |         unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
   |                  |
   |                  `ptr_offset_from_unsigned` called on pointers into different allocations
   |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
   |
  ::: /checkout/library/core/src/slice/raw.rs:219:42
   |
LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
   |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at /checkout/library/core/src/slice/raw.rs:219:42
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:79:34
   |
   |
LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
   |                                  ----------------------------------------------- inside `R9` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:79:34
error[E0080]: could not evaluate static initializer
  --> /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
   |
LL |         unsafe { intrinsics::ptr_offset_from_unsigned(self, origin) }
   |                  |
   |                  `ptr_offset_from_unsigned` called on pointers into different allocations
   |                  inside `std::ptr::const_ptr::<impl *const u32>::sub_ptr` at /checkout/library/core/src/ptr/const_ptr.rs:750:18
   |
   |
  ::: /checkout/library/core/src/slice/raw.rs:219:42
   |
LL |     unsafe { from_raw_parts(range.start, range.end.sub_ptr(range.start)) }
   |                                          ------------------------------ inside `std::slice::from_ptr_range::<u32>` at /checkout/library/core/src/slice/raw.rs:219:42
  ::: /checkout/src/test/ui/const-ptr/forbidden_slices.rs:80:35
   |
   |
LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
   |                                   ------------------------ inside `R10` at /checkout/src/test/ui/const-ptr/forbidden_slices.rs:80:35
error: aborting due to 18 previous errors

For more information about this error, try `rustc --explain E0080`.
------------------------------------------

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

To put it differently -- yes, our messages are quite verbose. We have been working on reducing that (more in the Miri side than the CTFE side). So I'd appreciate if we didn't make them even more verbose than they already are. :)

@compiler-errors
Copy link
Member Author

So they panic! if any error is omitted? ;)

@RalfJung whoops, sorry, yeah I didn't mean opposite. Your understanding is correct and what I meant, didn't know why that wording came to me.

The diagnostics concerns w/ miri makes sense, let me try an alternative approach to suppressing this ICE. I have a few options...

@RalfJung
Copy link
Member

RalfJung commented Aug 4, 2022

Thanks!

Fundamentally the problem is that this code

let mut stacktrace = ecx.generate_stacktrace();

gets executed even if the lint is allowed. But that file is a mess and refactoring it to delay this work is not worth it, since in a few weeks const_err will become a hard error anyway...

@compiler-errors
Copy link
Member Author

Yeah, I'm aware of the problem... but if you say it'll be hard error soon, then maybe I won't bother 😄

@petrochenkov
Copy link
Contributor

constructing a trimmed path (which I'm guessing is a relatively expensive operation)

It's a really expensive operation, like +10-50% to whole compile time, that's why there's a special compiler mechanism for preventing it from slipping through.

@petrochenkov
Copy link
Contributor

r? @RalfJung

@compiler-errors compiler-errors deleted the issue-100114 branch August 11, 2023 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants