diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-08-12 22:57:14 +0000 | 
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-08-21 16:40:15 +0000 | 
| commit | f5bae722be1f81f70d92e30cec1930f7cefc6313 (patch) | |
| tree | 42a4ddc047523fae41d3e1323d09750a86c5adaa /tests/ui/regions/explicit-static-bound-on-trait.stderr | |
| parent | 4d5b3b196284aded6ae99d12bcf149ffdc8ef379 (diff) | |
| download | rust-f5bae722be1f81f70d92e30cec1930f7cefc6313.tar.gz rust-f5bae722be1f81f70d92e30cec1930f7cefc6313.zip  | |
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.
Diffstat (limited to 'tests/ui/regions/explicit-static-bound-on-trait.stderr')
| -rw-r--r-- | tests/ui/regions/explicit-static-bound-on-trait.stderr | 32 | 
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/ui/regions/explicit-static-bound-on-trait.stderr b/tests/ui/regions/explicit-static-bound-on-trait.stderr new file mode 100644 index 00000000000..30d39c6e86e --- /dev/null +++ b/tests/ui/regions/explicit-static-bound-on-trait.stderr @@ -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`.  | 
