Skip to content

Provide structured suggestion instead of label #52413

Closed
@estebank

Description

@estebank

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions