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

Multiple anonymous lifetimes bounds upset compiler #60199

Closed
imp opened this issue Apr 23, 2019 · 0 comments · Fixed by #90446
Closed

Multiple anonymous lifetimes bounds upset compiler #60199

imp opened this issue Apr 23, 2019 · 0 comments · Fixed by #90446
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@imp
Copy link

imp commented Apr 23, 2019

TL;DR Rust is unable to compile its own hint with anonymous lifetimes
(Playground)

#![warn(rust_2018_idioms)]

use clap::{App, SubCommand};

fn app() -> App {
    SubCommand::with_name("app")
}

fn main () {
    let _matches = app().get_matches();
}

Rust doesn't like it as App is defined with two lifetimes - App<'a, 'b>
and indeed the hint is dead on:

   Compiling playground v0.0.1 (/playground)
warning: hidden lifetime parameters in types are deprecated
 --> src/lib.rs:5:13
  |
5 | fn app() -> App {
  |             ^^^- help: indicate the anonymous lifetimes: `<'_, '_>`
  |
note: lint level defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(rust_2018_idioms)]
  |         ^^^^^^^^^^^^^^^^
  = note: #[warn(elided_lifetimes_in_paths)] implied by #[warn(rust_2018_idioms)]

So we do as suggested and add two anonymous lifetimes to App<'_, '_>

#![warn(rust_2018_idioms)]

use clap::{App, SubCommand};

fn app() -> App<'_, '_> {
    SubCommand::with_name("app")
}

fn main () {
    let _matches = app().get_matches();
}

This time it is even worth as now compiler coudn't tell these two lifetimes apart

   Compiling playground v0.0.1 (/playground)
error[E0106]: missing lifetime specifiers
 --> src/lib.rs:5:17
  |
5 | fn app() -> App<'_, '_> {
  |                 ^^ expected 2 lifetime parameters

error: aborting due to previous error

So it is either anonymous liftime logic should be fixed to work similar to the type hints, or the help message should avoid suggesting incorrect syntax.

@jonas-schievink jonas-schievink added A-edition-2018-lints Area: Lints supporting the 2018 edition A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 23, 2019
@bors bors closed this as completed in 76938d6 Dec 2, 2021
@jieyouxu jieyouxu added the L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-edition-2018-lints Area: Lints supporting the 2018 edition A-lifetimes Area: Lifetimes / regions A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix` C-bug Category: This is a bug. L-elided_lifetimes_in_paths Lint: elided_lifetimes_in_paths 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.

3 participants