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

Denying a const_err lint can hide the root cause site #73960

Open
oli-cosmian opened this issue Jul 2, 2020 · 3 comments
Open

Denying a const_err lint can hide the root cause site #73960

oli-cosmian opened this issue Jul 2, 2020 · 3 comments
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@oli-cosmian
Copy link

The following code snippet does not show the T::ASSERT site unless the const_err lint is allowed or set to warn only.
I'm guessing the error on T::ASSERT is happening during codegen.

trait ZstAssert: Sized {
    const ASSERT: () = [()][(std::mem::size_of::<Self>() != 0) as usize];
}

impl<T> ZstAssert for T {}

fn foo<T>() {
    #[allow(path_statements)]
    {
        T::ASSERT
    }
}

fn main() {
    foo::<u32>();
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: any use of this value will cause an error
 --> src/main.rs:2:24
  |
2 |     const ASSERT: () = [()][(std::mem::size_of::<Self>() != 0) as usize];
  |     -------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                        |
  |                        index out of bounds: the len is 1 but the index is 1
  |
  = note: `#[deny(const_err)]` on by default

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 2, 2020
@RalfJung
Copy link
Member

Cc #71800

@oli-obk
Copy link
Contributor

oli-obk commented Jul 12, 2020

Turning that lint into a hard error won't help here, as the T::ASSERT error still won't be shown.

@RalfJung
Copy link
Member

Yeah but once that is not a user-controlled variable any more, it is much easier to ensure that we always show something reasonable.

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, covers all const contexts (static, const fn, ...) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. 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

4 participants