Closed
Description
Given
trait Foo {
fn dummy(&self) { }
}
struct A;
impl Foo for A {}
struct B<'a>(&'a (Foo+'a));
fn foo<'a>(a: &Foo) -> B<'a> {
B(a)
}
The output is
error[E0621]: explicit lifetime required in the type of `a`
--> $DIR/issue-14285.rs:22:5
|
LL | fn foo<'a>(a: &Foo) -> B<'a> {
| - consider changing the type of `a` to `&'a (dyn Foo + 'a)`
LL | B(a) //~ ERROR 22:5: 22:9: explicit lifetime required in the type of `a` [E0621]
| ^^^^ lifetime `'a` required
The label suggesting changing the type of a
should be a span_suggestion
instead of a span_label
.
Another case:
use std::any::Any;
fn foo<T: Any>(value: &T) -> Box<Any> {
Box::new(value) as Box<Any>
}
error[E0621]: explicit lifetime required in the type of `value`
--> $DIR/issue-16922.rs:14:5
|
LL | fn foo<T: Any>(value: &T) -> Box<Any> {
| ----- consider changing the type of `value` to `&'static T`
LL | Box::new(value) as Box<Any>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required