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

With allow(const_err), diagnostics are not very helpful #65597

Closed
RalfJung opened this issue Oct 19, 2019 · 5 comments
Closed

With allow(const_err), diagnostics are not very helpful #65597

RalfJung opened this issue Oct 19, 2019 · 5 comments
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

Consider:

#![allow(const_err)]

union Trans { i: usize, o: &'static u32 }

const C: () = unsafe { let _val = *Trans { i: 4 }.o; () };

fn main() {
    println!("{:?}", C);
}

This deref's a dangling pointer, but due to allow(const_err) the only diagnostic we get is

error[E0080]: evaluation of constant expression failed
 --> src/main.rs:8:22
  |
8 |     println!("{:?}", C);
  |                      ^ referenced constant has errors

error: aborting due to previous error

Making this an allowable lint is not very helpful when later follow-on errors are hard errors.

@jonas-schievink jonas-schievink added A-const-eval Area: constant evaluation (mir interpretation) 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. labels Oct 19, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Oct 19, 2019

We could add a Silenced variant to ErrorHandled and use it in

ErrorHandled::Reported
if the lint has not been emitted.

Then we can add a note to the referenced constant has errors error stating that some errors have been hidden due to allow(const_err)

@luojia65
Copy link
Contributor

luojia65 commented Nov 23, 2019

I met this issue when I try to write for embedded devices, for example we need to generate PLL configurations from frequencies set and there could be no solution in some situations where a panic should be fired. After this issue being solved we can write more abstract in embedded rust crates.
I may need a 'note: panic happens here' plus code snapshot in this situation if possible.

@RalfJung
Copy link
Member Author

@luojia65 the issue only applies when you do allow(const_err), so I don't understand how you can say "there could be no solution in some situations". Just don't allow(const_err)?

@RalfJung
Copy link
Member Author

RalfJung commented May 3, 2020

The "hard error" option in #71800 would solve this.

@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@estebank
Copy link
Contributor

estebank commented Aug 3, 2023

Current output:

warning: lint `const_err` has been removed: converted into hard error, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> for more information
 --> src/main.rs:1:10
  |
1 | #![allow(const_err)]
  |          ^^^^^^^^^
  |
  = note: `#[warn(renamed_and_removed_lints)]` on by default

error[E0080]: evaluation of constant value failed
 --> src/main.rs:5:35
  |
5 | const C: () = unsafe { let _val = *Trans { i: 4 }.o; () };
  |                                   ^^^^^^^^^^^^^^^^^ dereferencing pointer failed: 0x4[noalloc] is a dangling pointer (it has no provenance)

note: erroneous constant used
 --> src/main.rs:8:22
  |
8 |     println!("{:?}", C);
  |                      ^

note: erroneous constant used
 --> src/main.rs:8:22
  |
8 |     println!("{:?}", C);
  |                      ^
  |
  = note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

@estebank estebank closed this as completed Aug 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants