-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #129070 - estebank:static-trait, r=davidtwco
Point at explicit `'static` obligations on a trait Given `trait Any: 'static` and a `struct` with a `Box<dyn Any + 'a>` field, point at the `'static` bound in `Any` to explain why `'a: 'static`. ``` error[E0478]: lifetime bound not satisfied --> f202.rs:2:12 | 2 | value: Box<dyn std::any::Any + 'a>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: lifetime parameter instantiated with the lifetime `'a` as defined here --> f202.rs:1:14 | 1 | struct Hello<'a> { | ^^ note: but lifetime parameter must outlive the static lifetime --> /home/gh-estebank/rust/library/core/src/any.rs:113:16 | 113 | pub trait Any: 'static { | ^^^^^^^ ``` Partially address #33652.
- Loading branch information
Showing
8 changed files
with
80 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
struct Hello<'a> { | ||
value: Box<dyn std::any::Any + 'a>, | ||
//~^ ERROR lifetime bound not satisfied | ||
} | ||
|
||
impl<'a> Hello<'a> { | ||
fn new<T: 'a>(value: T) -> Self { | ||
Self { value: Box::new(value) } | ||
//~^ ERROR the parameter type `T` may not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/explicit-static-bound-on-trait.rs:2:12 | ||
| | ||
LL | value: Box<dyn std::any::Any + 'a>, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined here | ||
--> $DIR/explicit-static-bound-on-trait.rs:1:14 | ||
| | ||
LL | struct Hello<'a> { | ||
| ^^ | ||
note: but lifetime parameter must outlive the static lifetime | ||
--> $SRC_DIR/core/src/any.rs:LL:COL | ||
|
||
error[E0310]: the parameter type `T` may not live long enough | ||
--> $DIR/explicit-static-bound-on-trait.rs:8:23 | ||
| | ||
LL | Self { value: Box::new(value) } | ||
| ^^^^^^^^^^^^^^^ | ||
| | | ||
| the parameter type `T` must be valid for the static lifetime... | ||
| ...so that the type `T` will meet its required lifetime bounds | ||
| | ||
help: consider adding an explicit lifetime bound | ||
| | ||
LL | fn new<T: 'a + 'static>(value: T) -> Self { | ||
| +++++++++ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0310, E0478. | ||
For more information about an error, try `rustc --explain E0310`. |