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

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

Closed
kentfredric opened this issue May 5, 2019 · 0 comments · Fixed by #96833
Closed
Assignees
Labels
A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kentfredric
Copy link

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)
@Centril Centril added A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2019
gadomski added a commit to stac-utils/stac-rs that referenced this issue Feb 7, 2022
Requires allowing `single_use_lifetimes` due to
rust-lang/rust#60554
gadomski added a commit to stac-utils/stac-rs that referenced this issue Feb 7, 2022
Requires allowing `single_use_lifetimes` due to
rust-lang/rust#60554
gadomski added a commit to stac-utils/stac-rs that referenced this issue Feb 7, 2022
Requires allowing `single_use_lifetimes` due to
rust-lang/rust#60554
@jackh726 jackh726 added the F-lint-single_use_lifetimes `single_use_lifetimes` lint label Mar 18, 2022
@cjgillot cjgillot self-assigned this May 8, 2022
@bors bors closed this as completed in b5caa5a May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: lifetime related A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-lint-single_use_lifetimes `single_use_lifetimes` lint T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants