Skip to content

Bad diagnostic for bad lifetime syntax #36179

Closed
@steveklabnik

Description

@steveklabnik

Consider this function:

fn hello() -> &str {
    "hello"
}

This gives a help note:

help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider giving it a 'static lifetime

This doesn't demonstrate how to do the syntax. So, if you screw it up:

fn hello() -> '&str {
    "hello"
}

(which you are likely to do if you are new because the lifetime syntax is foreign...)

Rust will give a very confusing diagnostic:

error: character literal may only contain one codepoint: '&
 --> <anon>:1:15
  |>
1 |> fn hello() -> '&str {
  |>               ^^

This seems like something we could improve.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions