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

Function monomorphization site that causes post-monomorphization errors is never shown #73961

Closed
oli-cosmian opened this issue Jul 2, 2020 · 1 comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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 does not highlight the foo::<u32>() call, even though removing it will remove the error.

#[warn(const_err)]

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)
warning: any use of this value will cause an error
 --> src/main.rs:4:24
  |
4 |     const ASSERT: () = [()][(std::mem::size_of::<Self>() != 0) as usize];
  |     -------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
  |                        |
  |                        index out of bounds: the len is 1 but the index is 1
  |
note: the lint level is defined here
 --> src/main.rs:1:8
  |
1 | #[warn(const_err)]
  |        ^^^^^^^^^

error: erroneous constant encountered
  --> src/main.rs:12:9
   |
12 |         T::ASSERT
   |         ^^^^^^^^^

error: aborting due to previous error; 1 warning emitted

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 (MIR interpretation) 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
@oli-obk
Copy link
Contributor

oli-obk commented May 13, 2021

closing in favour of the more detailed #85155

@oli-obk oli-obk closed this as completed May 13, 2021
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-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

3 participants