-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
unnecessary closure constraint propagation #148289
Copy link
Copy link
Closed
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsC-bugCategory: This is a bug.Category: This is a bug.T-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.
should compile but results in the following error
What's going on is that the closure has the signature
for<'a> fn(Inv<'a>, OutlivedBy<'a, 'b>, OutlivedBy<'a, 'c>, Inv<'d>)where'b,'c, and'dare external regions.We have assumptions
'b: 'aand'c: 'a.Borrow checking the closure results in requirements
'b: 'a,'c: 'a,'d: 'b.rust/compiler/rustc_borrowck/src/region_infer/mod.rs
Lines 1222 to 1227 in 72fe2ff
fn check_universal_regionthen checks for every universal region in the closure, whether it transitively outlives any other regions. We check'b: 'a,'c: 'a,'d: 'bAND'd: 'a(transitive)'b: 'aand'c: 'aare implied by our assumptions. We can propagate'd: 'bto the parent without issues.Propagating
'd: 'ais scuffed. Figuring out how to propagate this looks at upper bounds on'a:'band'cand simply requires'dto outlive both. This is unnecessary and results in the incorrect outlives error in the parent.