-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Unused generic in struct definition is allowed when used in invariant position #152884
Copy link
Copy link
Open
Labels
A-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-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.
Metadata
Metadata
Assignees
Labels
A-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-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.
Type
Fields
Give feedbackNo fields configured for issues without a type.
I'm not sure if this is a bug or not.
The following code compiles:
I expected the above code to not compile, since the generic parameter
Tis used only in a recursive position. There isn't an "actual"Tusage anywhere in the struct.Note that changing the
*mutto*constmakes the code stop compiling. It seems that the recursion must be in an invariant position for the code to compile.Code and error with *const
This also has some strange behavior with auto traits. For example, the following code compiles:
Discovered in #152857
cc @lcnr
Meta
Reproducible on the playground with version
1.95.0-nightly (2026-02-19 7f99507f57e6c4aa0dce)