-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Confusing error message when trying to use a lifetime on an Any
trait object
#83325
Comments
I have the same problem, and it's really hard to solve it even with Google. ChatGPT suggest: To resolve this error, you need to either increase the lifetime of the lifetime parameter or change the static reference to a reference with a shorter lifetime. Here are some strategies you can use: Decrease the lifetime thanks to a reference.
Increase the lifetime:
I am still new to Rust but lifetime and Arc,Box.. Is hard to get. |
``` error[E0478]: lifetime bound not satisfied --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:4:21 | 4 | broken: Box<dyn Any + 'a> | ^^^ ^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:3:18 | 3 | struct Something<'a> { | ^^ = note: but lifetime parameter must outlive the static lifetime note: unmet `'static` obligations introduced here --> rust/library/core/src/any.rs:115:16 | 115 | pub trait Any: 'static { | ^^^^^^^ ``` Fix rust-lang#83325.
``` error[E0478]: lifetime bound not satisfied --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:4:21 | 4 | broken: Box<dyn Any + 'a> | ^^^ ^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:3:18 | 3 | struct Something<'a> { | ^^ = note: but lifetime parameter must outlive the static lifetime note: unmet `'static` obligations introduced here --> rust/library/core/src/any.rs:115:16 | 115 | pub trait Any: 'static { | ^^^^^^^ ``` Fix rust-lang#83325.
``` error[E0478]: lifetime bound not satisfied --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:4:21 | 4 | broken: Box<dyn Any + 'a> | ^^^ ^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> tests/ui/lifetimes/point-at-lifetime-obligation-from-trait-in-trait-object.rs:3:18 | 3 | struct Something<'a> { | ^^ = note: but lifetime parameter must outlive the static lifetime note: unmet `'static` obligations introduced here --> rust/library/core/src/any.rs:115:16 | 115 | pub trait Any: 'static { | ^^^^^^^ ``` Fix rust-lang#83325.
The following code playground link
Outputs an error message related to lifetime issues that is not clear what the issue exactly is.
This error is caused by
trait Any: 'static
, however this error message is not clear as to why the lifetime needs to outlive the static lifetime. Ideally the error message would say where the requirement comes from, like other lifetime-related errors.cc @estebank who was looking for weird and unintuitive errors. This wasn't caused by a crate specifically, but it still isn't a good error.
The text was updated successfully, but these errors were encountered: