-
Notifications
You must be signed in to change notification settings - Fork 13.3k
"non-defining opaque type use" with equal bound regions due to closure #112841
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I think the issue is that the closure erases regions in its signature and does not have any user type, so its generic params for the opaque aren't really sensible. I feel like maybe closures should return their opaque constraints via https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.BorrowCheckResult.html#structfield.closure_requirements instead of dealing with them itself? |
why does this fail even if a closure is just defined in-scope? 🤔 #![feature(type_alias_impl_trait)]
trait Trait<'a, 'b> {}
impl Trait<'_, '_> for () {}
type Tait<'a, 'b> = impl Trait<'a, 'b>;
fn fail<'a: 'b, 'b: 'a>() -> Tait<'a, 'b> {
let x = || {};
()
}
fn main() {} |
idk, maybe pinging @aliemjay who knows more about borrowck + closures 🤣 |
I disagree that the OP's code should pass. Even more, I think it is a bug that we accept this: #![feature(type_alias_impl_trait)]
trait Trait<'a, 'b> {}
impl Trait<'_, '_> for () {}
type Tait<'a, 'b> = impl Trait<'a, 'b>;
fn fail<'a: 'b, 'b: 'a>() -> Tait<'a, 'b> {
()
} because it is in no way different than writing The reason we accept these illegal defining uses of TAIT is due to a bug in
which evaluates lifetime equality based on the constraint graph alone, ignoring the the environment bounds. This is why this trivial change triggers the error: fn fail<'a: 'b, 'b: 'a>() -> Tait<'a, 'b> {
+ let _ = None::<&'a &'b &'a ()>; // Now 'a and 'b are equal in the constraint graph
()
+ //~^ ERROR non-defining opaque type use in defining scope
} and this explains why using closures anywhere in the body triggers the error, because it somehow adds the environmet bounds (on early-bound lifetimes exclusively) to the constraint graph. |
…2, r=<try> rework opaque type region inference fixes rust-lang#113971 Pass -> Error fixes rust-lang#111906 ICE -> Pass fixes rust-lang#110623 == fixes rust-lang#109059 == fixes rust-lang#112841 Pass -> Error fixes rust-lang#110726 ICE->Error r? `@ghost`
…2, r=<try> rework opaque type region inference fixes rust-lang#113971 Pass -> Error fixes rust-lang#111906 ICE -> Pass fixes rust-lang#110623 == fixes rust-lang#109059 == fixes rust-lang#112841 Pass -> Error fixes rust-lang#110726 ICE->Error r? `@ghost`
…2, r=<try> rework opaque type region inference fixes rust-lang#113971 Pass -> Error fixes rust-lang#111906 ICE -> Pass fixes rust-lang#110623 == fixes rust-lang#109059 == fixes rust-lang#112841 Pass -> Error fixes rust-lang#110726 ICE->Error fixes rust-lang#111935 Pass -> Error fixes rust-lang#113916 == r? `@ghost`
results in the following but should ideally compile.
The text was updated successfully, but these errors were encountered: