Repository navigation
Associated constants inside array repeat expression don't use implied bounds from impl header during well-formedness checking #89236
Copy link
Copy link
Open
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Activity
- changed the title
[-]Confusing diagnostic when mixing generics, lifetimes and associated consts[/-][+]Incorrect diagnostic when mixing generics, lifetimes and associated consts[/+]on Sep 24, 2021 - addedT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsand removed
on Jan 24, 2024 - addedA-trait-systemArea: Trait systemArea: Trait systemA-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)
on Dec 29, 2024 Revisiting this, I think this is a duplicate of #105495. For struct
Iand subsequently{impl#0}we have the implied boundRS: 'ibut it's not used when trying to checkI::gofor well-formedness.Actually I'm not sure if it's a duplicate of that issue. This probably a separate issue.
So, interestingly the following code compiles successfully:
struct S<'a, T>(&'a T); impl<'a, T> S<'a, T> { const K: usize = 0; fn f() { let _ = Self::K; } }
However, once you place the
Self::Kinto the array repeat expr, it fails:struct S<'a, T>(&'a T); impl<'a, T> S<'a, T> { const K: usize = 0; fn f() { let _ = [(); Self::K]; } //~ ERROR type parameter `T` may not live long enough }
- addedS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issue
on Dec 29, 2024 - changed the title
[-]Incorrect diagnostic when mixing generics, lifetimes and associated consts[/-][+]Associated constants inside array repeat expression don't use implied bounds from impl header during well-formedness checking[/+]on Dec 29, 2024 - marked Missing implied bound raises misleading error message #127900 as a duplicate of this issue
on Dec 29, 2024 Note: I wrote "well-formedness checking" but haven't actually double-checked if this is true or if this obligation failure stems from some other system in the compiler.
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueStatus: A Minimal Complete and Verifiable Example has been found for this issueT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
I tried this code: (try it in a playground)
I expect this code to either compile fine or provide a warning similar to #76200.
However, I see an error:
I don't understand why
RS: 'iis needed for accessing a constant off ofSelf. As one might expect, replacingSelf::CHUNK_SIZEwithVeryVeryLongTypeName::CHUNK_SIZEworks around the issue.Tested with stable
1.55.0and1.57.0-nightly (2021-09-23 2b862bed9889808b6962).