Skip to content

"Consider adding an explicit lifetime bound" doesn't take into account existing bounds #65286

Closed
@varkor

Description

@varkor
trait X { fn foo(&self) {} }

fn p3<'a, 'b, T: 'b>(v: T) -> Box<dyn X + 'a> where T: X {
    Box::new(v)
}

produces:

error[E0309]: the parameter type `T` may not live long enough
 --> src/lib.rs:4:5
  |
3 | fn p3<'a, 'b, T: 'b>(v: T) -> Box<dyn X + 'a> where T: X {
  |               -- help: consider adding an explicit lifetime bound `T: 'a`...
4 |     Box::new(v)
  |     ^^^^^^^^^^^
  |

It should suggest T: 'a + 'b (or similar), ideally in the same format as E0599.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions