-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.
Description
A common mistake for beginners writing lifetime annotations is to write something like this:
pub fn min<'a: 'c, 'b: 'c, 'c, T: Ord>(a: &'a T, b: &'b T) -> &'c T {
if b < a { b } else { a }
}which while it's not wrong, is rather more complex than necessary.
It would be nice for the compiler to use its own knowledge of subtyping to suggest that the signature change to
pub fn min<'c, T: Ord>(a: &'c T, b: &'c T) -> &'c T {
if b < a { b } else { a }
}since that's equivalent.
theemathas and lukaslueg
Metadata
Metadata
Assignees
Labels
A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Lints (warnings about flaws in source code) such as unused_mut.C-feature-requestCategory: A feature request, i.e: not implemented / a PR.Category: A feature request, i.e: not implemented / a PR.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.