-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lifetime inference inconsistency with borrowed pointer fields #8845
Comments
Interestingly, the issue seems to persist through multiple levels of borrowed pointers. This fails to compile as well:
With
But works fine either removing the box around the |
I believe that the compiler is acting correctly. The Unfortunately, as #3598 has not been fixed, all types are currently |
This code appears to compile today: struct Foo<'a> {
f: 'a ||
}
struct Bar<'a> {
f: &'a Foo<'a>
}
struct Baz<'a> {
b: &'a Bar<'a>
}
impl<'a> Foo<'a> {
fn foo(&'a self) -> Bar<'a> {
Bar { f: self }
}
}
impl<'a> Bar<'a> {
fn bar<'a>(&'a self) -> Baz<'a> {
Baz { b: self }
}
} It doesn't have the use std::cell::RefCell;
struct Foo<'a> {
f: RefCell<&'a 'a ||>
}
struct Bar<'a> {
f: &'a Foo<'a>
}
impl<'a> Foo<'a> {
fn foo<'a>(&'a self) -> Bar<'a> {
Bar { f: self }
}
} while this code does use std::cell::RefCell;
struct Foo<'a> {
f: RefCell<&'a 'a ||>
}
struct Bar<'a> {
f: &'a Foo<'a>
}
impl<'a> Foo<'a> {
fn foo(&'a self) -> Bar<'a> {
Bar { f: self }
}
} (note the missing I'm tempted to close this as working, but I'm not sure I understand whow #3598 interacts here. |
…ts, r=Alexendoo Fix `[use_self]` false negative with on struct and tuple struct patterns fixes rust-lang#8845 changelog: Triggered the warning for ``[`use_self`]`` on `TupleStruct` and `Struct` patterns, whereas currently it's only triggered for `Path` patterns
fails to compile with
but removing the
Cell
compiles correctly:It turns out that using
'self
instead of'a
fixes the problem:I would think that all three examples should compile, since the lifetime bounds of
'a
and'self
should intersect properly.cc @nikomatsakis
The text was updated successfully, but these errors were encountered: