Skip to content

Invalid suggestion of -> [u8] #159491

Description

@estebank

Code

fn values() -> &[i32] {
    let values = vec![1, 2];
    &values
}

Current output

error[E0106]: missing lifetime specifier
 --> src/lib.rs:1:16
  |
1 | fn values() -> &[i32] {
  |                ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
  |
1 | fn values() -> &'static [i32] {
  |                 +++++++
help: instead, you are more likely to want to return an owned value
  |
1 - fn values() -> &[i32] {
1 + fn values() -> [i32] {
  |

Desired output

error[E0106]: missing lifetime specifier
 --> src/lib.rs:1:16
  |
1 | fn values() -> &[i32] {
  |                ^ expected named lifetime parameter
  |
  = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
  |
1 | fn values() -> &'static [i32] {
  |                 +++++++
help: instead, you are more likely to want to return an owned value
  |
1 - fn values() -> &[i32] {
1 + fn values() -> Vec<i32> {
  |

Rationale and extra context

No response

Other cases

Rust Version

1.97

Anything else?

No response

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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