-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Trait objects can be created with lifetime bounds that ignore input lifetimes #18055
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
Comments
A more self-contained example that shouldn't type-check: fn f(v: &[u8]) -> Box<Clone + 'static> {
box v
}
fn main() { } |
Box<BufReader<'a>>
coerces to Box<Reader+'static>
It seems that this has been possible since generalized lifetime bounds went in. |
Huh. This was supposed to be fixed. I'll take a look. |
P-backcompat-lang, 1.0 |
OK, simple oversight. PR coming soon. Amazing we have no test for this. It occurs only with coercions. (In general, this code path could be cleaned up, and will be as part of implementing generalized where clauses, making these kinds of oversights harder to do.) |
Check object lifetime bounds in coercions, not just trait bounds. Fixes #18055. r? @pcwalton This is a [breaking change]. Change code like this: fn foo(v: &[u8]) -> Box<Clone+'static> { ... } to make the lifetimes agree: // either... fn foo(v: &'static[u8]) -> Box<Clone+'static> { box v } // or ... fn foo<'a>(v: &'a [u8]) -> Box<Clone+'a> { box v }
This should not compile, since
v
is&'a [u8]
for some non-'static
'a
and thusBufReader<'a>
will contain&'a [u8]
as well. It compiles fine however and results in the varying output depending on the optimization level (which shows that this is an UB out of the "safe" code).Tested with
rustc 0.13.0-nightly (1c3ddd297 2014-10-13 23:27:46 +0000)
and playpen.The text was updated successfully, but these errors were encountered: