-
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
Trait object with non-static lifetime is accepted where static lifetime is expected and required #72315
Comments
Seems to be an issue with type inference. Giving |
Maybe fixed by #71896 ? |
Wow, nice catch! |
Would be nice to find and mcve ... @rustbot ping cleanup |
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke |
Assigning |
We should try to find out if this is a duplicate of #71550 or not. |
I can confirm that the example code with #71896 applied gives ...
|
Knows anybody a version of rust where this example (from thread start) compiles & do not crash? So either my script-fu has an bug our there is no working rust version 🤔 |
Well, it is not supposed to compile. It's a broken app which is supposed to be rejected by compiler. |
Discussed with @spastorino . This is probably a duplicate of #71550, but since it is P-critical and we have not 100% confirmed that these are exactly the same bug (in part because we do not have an MCVE for #72315). Since @spastorino has confirmed that their PR #71896 does fix both issues, I'm going to assign this bug to them, just like #71550. |
…riance, r=nikomatsakis Relate existential associated types with variance Invariant Fixes rust-lang#71550 rust-lang#72315 r? @nikomatsakis The test case reported in that issue now errors with the following message ... ``` error[E0495]: cannot infer an appropriate lifetime for lifetime parameter 'a in function call due to conflicting requirements --> /tmp/test.rs:25:5 | 25 | bad(&Bar(PhantomData), x) | ^^^^^^^^^^^^^^^^^^^^^^^^^ | note: first, the lifetime cannot outlive the lifetime `'a` as defined on the function body at 24:11... --> /tmp/test.rs:24:11 | 24 | fn extend<'a, T>(x: &'a T) -> &'static T { | ^^ note: ...so that reference does not outlive borrowed content --> /tmp/test.rs:25:28 | 25 | bad(&Bar(PhantomData), x) | ^ = note: but, the lifetime must be valid for the static lifetime... note: ...so that the types are compatible --> /tmp/test.rs:25:9 | 25 | bad(&Bar(PhantomData), x) | ^^^^^^^^^^^^^^^^^ = note: expected `&'static T` found `&T` error: aborting due to previous error For more information about this error, try `rustc --explain E0495`. ``` I could also add that test case if we want to have a weaponized one too.
Should be closed by #71896 |
Problem: function is explicitly defined as accepting
Box<dyn Fn + 'static>
and yet it acceptsBox<dyn Fn + 'a>
where'a
is definitely less than'static
.It allows to keep reference to an object past object lifetime and therefore cause a crash.
Sorry for an extremely long example, but issue in question is very fragile and I couldn't reproduce it with smaller code.
I expected this error to happen (and it actually does happen if you change the example even a little bit):
Instead this code is silently accepted and causes a segmentation error when executed.
Meta
I tried it both on stable and nightly rust:
The text was updated successfully, but these errors were encountered: