Skip to content

const &str now requires explicit lifetime #1838

@rsofaer

Description

@rsofaer

Minimal example: Permalink to the playground

use vstd::prelude::*;

verus! {
  const C: &str = "str";
}

Gives error message:

error[[E0106]](https://doc.rust-lang.org/stable/error_codes/E0106.html): missing lifetime specifier
 --> /playground/src/main.rs:4:10
  |
4 | const C: &str = "str";
  |          ^ 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`
  |
4 | const C: &'static str = "str";
  |           +++++++
help: instead, you are more likely to want to return an owned value
  |
4 - const C: &str = "str";
4 + const C: String = "str";
  |

error: aborting due to 1 previous error

This is irritating because when annotated with 'static, the code gives a warning in rustc for an unneeded lifetime specifier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions