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

const_err spans not rendered when rust-src not installed #97699

Closed
RalfJung opened this issue Jun 3, 2022 · 8 comments · Fixed by #104449
Closed

const_err spans not rendered when rust-src not installed #97699

RalfJung opened this issue Jun 3, 2022 · 8 comments · Fixed by #104449
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 3, 2022

This code causes a const_err somewhere in the standard library:

#![feature(const_swap)]
#![feature(const_mut_refs)]
use std::{
    mem::{self, MaybeUninit},
    ptr,
};

const X: () = {
    let mut ptr1 = &1;
    let mut ptr2 = &2;

    // Swap them, bytewise.
    unsafe {
        ptr::swap_nonoverlapping(
            &mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
            &mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
            mem::size_of::<&i32>(),
        );
    }
};

When the rust-src package is not installed, the error is pretty unreadable:

error: any use of this value will cause an error
   |
  ::: src/lib.rs:8:1
   |
8  | / const X: () = {
9  | |     let mut ptr1 = &1;
10 | |     let mut ptr2 = &2;
11 | |
...  |
19 | |     }
20 | | };
   | |__-
   |
   = note: `#[deny(const_err)]` on by default
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, [see issue #71800 <https://github.com/rust-lang/rust/issues/71800>](https://github.com/rust-lang/rust/issues/71800)

This is missing the key information of what goes wrong! With rust-src, the following is added, making it much clearer:

    --> /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1151:9
     |
1151 |           copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |           |
     |           unable to turn pointer into raw bytes
     |           inside `std::ptr::read::<MaybeUninit<u8>>` at /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1151:9
     |           inside `mem::swap_simple::<MaybeUninit<u8>>` at /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/mem/mod.rs:768:17
     |           inside `ptr::swap_nonoverlapping_simple::<MaybeUninit<u8>>` at /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:968:9
     |           inside `swap_nonoverlapping::<MaybeUninit<u8>>` at /home/r/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:949:14
     |           inside `X` at test.rs:14:9

If the sources are missing, we should probably still show the error, even if we cannot attach it to any code.
Cc @rust-lang/wg-const-eval

@RalfJung
Copy link
Member Author

RalfJung commented Jun 6, 2022

Cc @rust-lang/wg-diagnostics : IMO it is a bug in the rustc diagnostic printing that it entirely omits information attached to spans where the source is missing. Is there anything we can do about that?

@estebank
Copy link
Contributor

estebank commented Jun 6, 2022

We could emit the information as a note instead of a label, but the wording would likely refer to "this blah", making it seem like it's referring to whatever is being pointed at in the main window. That might cause things to be misinterpreted. Another option would be to emit a note when rustc-src isn't present asking the user to install it when we encounter cases like this one.

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Jun 6, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Nov 13, 2022

Has this been resolved by #103970 ?

@albertlarsan68
Copy link
Member

The error message is

error[E0080]: evaluation of constant value failed
   |
  ::: src\main.rs:14:9
   |
14 | /         ptr::swap_nonoverlapping(
15 | |             &mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
16 | |             &mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
17 | |             mem::size_of::<&i32>(),
18 | |         );
   | |_________- inside `X` at src\main.rs:14:9
   |
   = help: this code performed an operation that depends on the underlying bytes representing a pointer
   = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported

without rust-src installed, and

error[E0080]: evaluation of constant value failed
    --> $HOME\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ptr\mod.rs:1139:9
     |
929  |       unsafe { swap_nonoverlapping_simple_untyped(x, y, count) }
     |                ----------------------------------------------- inside `swap_nonoverlapping::<MaybeUninit<u8>>` at $HOME\.rustup\toolchains\nightly-x86948  |           mem::swap_simple::<MaybeUninit<T>>(x, y);
     |           ---------------------------------------- inside `ptr::swap_nonoverlapping_simple_untyped::<MaybeUninit<u8>>` at $HOME\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ptr\mod.rs:948:9
...
1139 |           copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |           |
     |           unable to copy parts of a pointer from memory at alloc6+0x1
     |           inside `std::ptr::read::<MaybeUninit<MaybeUninit<u8>>>` at $HOME\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ptr\mod.rs:1139:9
     |
    ::: $HOME\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\mem\mod.rs:776:17
     |
776  |           let a = ptr::read(x);
     |                   ------------ inside `mem::swap_simple::<MaybeUninit<MaybeUninit<u8>>>` at $HOME\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\mem\mod.rs:776:17
     |
    ::: src\main.rs:14:9
     |
14   | /         ptr::swap_nonoverlapping(
15   | |             &mut ptr1 as *mut _ as *mut MaybeUninit<u8>,
16   | |             &mut ptr2 as *mut _ as *mut MaybeUninit<u8>,
17   | |             mem::size_of::<&i32>(),
18   | |         );
     | |_________- inside `X` at src\main.rs:14:9
     |
     = help: this code performed an operation that depends on the underlying bytes representing a pointer
     = help: the absolute address of a pointer is not known at compile-time, so such operations are not supported

with the rust-src component installed with rustc 1.67.0-nightly (6284998a2 2022-11-12) on x86_64-pc-windows-msvc

@oli-obk oli-obk self-assigned this Nov 13, 2022
@RalfJung
Copy link
Member Author

So it does not seem entirely resolved -- the 'unable to copy parts of a pointer from memory at alloc6+0x1' is still missing completely when rust-src is not installed.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 15, 2022

ugh... I'm slowly wondering if we should enable -Z simulate-remapped-rust-src-base=/rustc/xyz -Z translate-remapped-path-to-local-path=no for all ui tests just to actually see the way diagnostics are shown to users normally

@RalfJung
Copy link
Member Author

Yeah if that is possible that would probably be good.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 15, 2022

Well... either way, I found a way to fix this specific diagnostic, so once that is landed I'll experiment with unconditionally setting that flag on all ui tests.

@bors bors closed this as completed in badd6a5 Dec 9, 2022
Aaron1011 pushed a commit to Aaron1011/rust that referenced this issue Jan 6, 2023
…bank,RalfJung

Start emitting labels even if their pointed to file is not available locally

r? `@estebank`

cc `@RalfJung`

fixes rust-lang#97699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-confusing Diagnostics: Confusing error or lint that should be reworked. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants