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

give some context in error messages #1250

Merged
merged 4 commits into from
Mar 22, 2020
Merged

Conversation

RalfJung
Copy link
Member

Some examples for how different errors look now

Unsupported operation:

error: unsupported operation: Miri does not support threading
  --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/sys/unix/thread.rs:68:19
   |
68 |         let ret = libc::pthread_create(&mut native, &attr, thread_start, &*p as *const _ as *mut _);
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Miri does not support threading
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support

Unsupported operation that works without isolation:

error: unsupported operation: `clock_gettime` not available when isolation is enabled
   --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/sys/unix/time.rs:349:22
    |
349 |         cvt(unsafe { libc::clock_gettime(clock, &mut t.t) }).unwrap();
    |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `clock_gettime` not available when isolation is enabled
    |
    = help: pass the flag `-Zmiri-disable-isolation` to disable isolation

Program abort:

error: program stopped: the evaluated program aborted execution
   --> /home/r/.rustup/toolchains/miri/lib/rustlib/src/rust/src/libstd/panicking.rs:530:18
    |
530 |         unsafe { intrinsics::abort() }
    |                  ^^^^^^^^^^^^^^^^^^^ the evaluated program aborted execution
    |

UB:

error: Undefined Behavior: type validation failed: encountered 2, but expected a boolean
 --> tests/compile-fail/validity/invalid_bool.rs:2:23
  |
2 |     let _b = unsafe { std::mem::transmute::<u8, bool>(2) }; //~ ERROR encountered 2, but expected a boolean
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 2, but expected a boolean
  |
  = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior

Experimental UB:

error: Undefined Behavior: not granting access to tag <1562> because incompatible item is protected: [Unique for <1567> (call 1189)]
  --> tests/compile-fail/stacked_borrows/aliasing_mut1.rs:3:1
   |
3  | pub fn safe(_x: &mut i32, _y: &mut i32) {} //~ ERROR protect
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <1562> because incompatible item is protected: [Unique for <1567> (call 1189)]
   |
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental

Fixes #417

@RalfJung RalfJung requested a review from oli-obk March 22, 2020 18:50
@oli-obk
Copy link
Contributor

oli-obk commented Mar 22, 2020

PR lgtm, just a general question, if we are explaining things to users, should we link them to appropriate issues or so where they can get more info?

@RalfJung
Copy link
Member Author

I mean long-term it would be really cool for every "this is UB" message to link to the part of the Reference that says why this, specifically, is UB -- but that will need some more work I think.

Right now, I am not sure what things we could specifically link to?

@oli-obk
Copy link
Contributor

oli-obk commented Mar 22, 2020

Maybe the ucg repo?

@RalfJung
Copy link
Member Author

For most UB, that doesn't really have a lot to say, I feel. But we could link to the general reference UB page:

error: Undefined Behavior: type validation failed: encountered 2, but expected a boolean
 --> tests/compile-fail/validity/invalid_bool.rs:2:23
  |
2 |     let _b = unsafe { std::mem::transmute::<u8, bool>(2) }; //~ ERROR encountered 2, but expected a boolean
  |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 2, but expected a boolean
  |
  = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
  = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information

And for Stacked Borrows:

error: Undefined Behavior: not granting access to tag <1562> because incompatible item is protected: [Unique for <1567> (call 1189)]
  --> tests/compile-fail/stacked_borrows/aliasing_mut1.rs:3:1
   |
3  | pub fn safe(_x: &mut i32, _y: &mut i32) {} //~ ERROR protect
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not granting access to tag <1562> because incompatible item is protected: [Unique for <1567> (call 1189)]
   |
   = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental
   = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information

@oli-obk
Copy link
Contributor

oli-obk commented Mar 22, 2020

@bors r+

@bors
Copy link
Contributor

bors commented Mar 22, 2020

📌 Commit 6e302b8 has been approved by oli-obk

@bors
Copy link
Contributor

bors commented Mar 22, 2020

⌛ Testing commit 6e302b8 with merge 9fe39ba...

@bors
Copy link
Contributor

bors commented Mar 22, 2020

☀️ Test successful - checks-travis, status-appveyor
Approved by: oli-obk
Pushing 9fe39ba to master...

@bors bors merged commit 9fe39ba into rust-lang:master Mar 22, 2020
@RalfJung RalfJung deleted the error-context branch March 23, 2020 08:08
Centril added a commit to Centril/rust that referenced this pull request Mar 23, 2020
…nkov

Miri error type: remove UbExperimental variant

In rust-lang/miri#1250, I will move Miri away from that variant, and use a custom `MachineStop` exception instead.
@shepmaster
Copy link
Member

Those messages are great!

@RalfJung
Copy link
Member Author

It took almost 2 years but finally we are there. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve error message: Unsupported operation vs. undefined behavior
4 participants