Skip to content

Missing implied bound raises misleading error message #127900

Closed as duplicate of#89236
@x4exr

Description

@x4exr

I tried this code:

struct Foo<'a, T>(&'a T);

impl<'a, T> Foo<'a, T> {
    const X: usize = 100;
    
    fn what() {
        let a = [0; Self::X];
    }
}

I expected to see this happen: There should not be an error, the constant should have been evaluated as a literal. Using a literal does not raise the error.

Instead, this happened: Compile time error stating there is a lifetime issue. It requests a bound that shouldn't be neccessary. The error is misleading.

Meta

The bug occurs in my version and the latest stable.

rustc --version --verbose:

rustc 1.81.0-nightly (bcf94dec5 2024-06-23)
binary: rustc
commit-hash: bcf94dec5ba6838e435902120c0384c360126a26
commit-date: 2024-06-23
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsD-confusingDiagnostics: Confusing error or lint that should be reworked.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