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

Error spans into the standard library are missing because rust-src is not installed #808

Open
RalfJung opened this issue Jun 3, 2022 · 3 comments
Labels
enhancement Something new the playground could do

Comments

@RalfJung
Copy link
Member

RalfJung commented Jun 3, 2022

Consider this code:

#![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>(),
        );
    }
};

Locally, this renders an error like this:

error: any use of this value will cause an error
    --> /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
     |
    ::: test.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>

However, on the playground, it looks like this:

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)

In particular, the actual message of what went wrong ("unable to turn pointer into raw bytes") and the span of where that happened are missing!

@RalfJung RalfJung changed the title Errors on the playground are missing some spans Some errors on the playground are missing some spans Jun 3, 2022
@shepmaster
Copy link
Member

shepmaster commented Jun 3, 2022

This is because there's no source files for the compiler to point to:

% rustup component remove rust-src --toolchain nightly
info: removing component 'rust-src'

% cargo +nightly build
   Compiling rr v0.1.0 (/private/tmp/rr)
warning: constant is never used: `X`
  --> src/lib.rs:8:1
   |
8  | / const X: () = {
9  | |     let mut ptr1 = &1;
10 | |     let mut ptr2 = &2;
11 | |
...  |
19 | |     }
20 | | };
   | |__^
   |
   = note: `#[warn(dead_code)]` on by default

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>

warning: `rr` (lib) generated 1 warning
error: could not compile `rr` due to previous error; 1 warning emitted

If we install them, they reappear:

% rustup component add rust-src --toolchain nightly
info: downloading component 'rust-src'
info: installing component 'rust-src'

% cargo +nightly build
   Compiling rr v0.1.0 (/private/tmp/rr)
warning: constant is never used: `X`
  --> src/lib.rs:8:1
   |
8  | / const X: () = {
9  | |     let mut ptr1 = &1;
10 | |     let mut ptr2 = &2;
11 | |
...  |
19 | |     }
20 | | };
   | |__^
   |
   = note: `#[warn(dead_code)]` on by default

error: any use of this value will cause an error
    --> /Users/shep/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1104:9
     |
1104 |           copy_nonoverlapping(src, tmp.as_mut_ptr(), 1);
     |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |           |
     |           unable to turn pointer into raw bytes
     |           inside `std::ptr::read::<MaybeUninit<u8>>` at /Users/shep/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:1104:9
     |           inside `mem::swap_simple::<MaybeUninit<u8>>` at /Users/shep/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:768:17
     |           inside `ptr::swap_nonoverlapping_simple::<MaybeUninit<u8>>` at /Users/shep/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:921:9
     |           inside `swap_nonoverlapping::<MaybeUninit<u8>>` at /Users/shep/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:902:14
     |           inside `X` at src/lib.rs:14:9
     |
    ::: 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>

warning: `rr` (lib) generated 1 warning
error: could not compile `rr` due to previous error; 1 warning emitted

@shepmaster shepmaster added the enhancement Something new the playground could do label Jun 3, 2022
@shepmaster shepmaster changed the title Some errors on the playground are missing some spans Error spans into the standard library are missing because rust-src is not installed Jun 3, 2022
@shepmaster
Copy link
Member

the actual message of what went wrong ("unable to turn pointer into raw bytes")

I think that this should be reported separately as an upstream Rust bug.

@RalfJung
Copy link
Member Author

RalfJung commented Jun 3, 2022

Ah, good catch about the rust-src package! Reported as rust-lang/rust#97699.

Would it be an option for the playground to have rust-src installed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Something new the playground could do
Projects
None yet
Development

No branches or pull requests

2 participants