Skip to content

single-use-lifetime warning not satisifiable with '_ , " '_ is a reserved lifetime name "Β #60554

Closed
@kentfredric

Description

@kentfredric

Minimal Proof:

use std::borrow::Cow;
#[warn(single_use_lifetimes)]
pub fn good<'a,S>( value: S ) -> String 
    where S: Into<Cow<'a,str>>
{
    value.into().into_owned()
}

fn main() -> () {
    println!("{}",good("pass"));
}
rustc -v mcve.rs 
warning: lifetime parameter `'a` only used once
 --> mcve.rs:3:13
  |
3 | pub fn good<'a,S>( value: S ) -> String 
  |             ^^ this lifetime...
4 |     where S: Into<Cow<'a,str>>
  |                       -- ...is used only here
  |
note: lint level defined here
 --> mcve.rs:2:8
  |
2 | #[warn(single_use_lifetimes)]
  |        ^^^^^^^^^^^^^^^^^^^^

Alas, doing what is natural ( and what people will tell you to do on IRC channels, only to find that it doesn't work, and writing:

use std::borrow::Cow;
#[warn(single_use_lifetimes)]
pub fn good<S>( value: S ) -> String 
    where S: Into<Cow<'_,str>>
{
    value.into().into_owned()
}

fn main() -> () {
    println!("{}",good("pass"));
}

Trips up E0637

error[E0637]: `'_` cannot be used here
 --> mcve.rs:4:23
  |
4 |     where S: Into<Cow<'_,str>>
  |                       ^^ `'_` is a reserved lifetime name

error: aborting due to previous error

I looked at all the other open bugs in this area and I saw several that looked similar( #55057 was closest ), but none were close enough to this, in particular, the error about using a reserved lifetime is particularly odd.

Other examples I saw of this understandably complained about an inferred lifetime in a return value, but having problems with it in input values is very curious.

So apologies if this is "a dupe"

rustc -V
# rustc 1.36.0-nightly (a3404557c 2019-05-03)

Metadata

Metadata

Assignees

Labels

A-lifetimesArea: Lifetimes / regionsA-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.C-bugCategory: This is a bug.F-lint-single_use_lifetimes`single_use_lifetimes` lintT-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