Skip to content

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

Open
@oli-cosmian

Description

@oli-cosmian

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions