Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad diagnostic for bad lifetime syntax #36179

Closed
steveklabnik opened this issue Aug 31, 2016 · 1 comment
Closed

Bad diagnostic for bad lifetime syntax #36179

steveklabnik opened this issue Aug 31, 2016 · 1 comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@steveklabnik
Copy link
Member

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.

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Aug 31, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@estebank
Copy link
Contributor

estebank commented Nov 7, 2018

Current output (since #55173) suggests the appropriate syntax:

error[E0106]: missing lifetime specifier
 --> src/lib.rs:1:15
  |
1 | fn hello() -> &str {
  |               ^ help: consider giving it a 'static lifetime: `&'static`
  |
  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from

@estebank estebank closed this as completed Nov 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants