Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: The 2018 editionArea: Lifetimes / regionsArea: Lints (warnings about flaws in source code) such as unused_mut.Area: Suggestions generated by the compiler applied by `cargo fix`Category: This is a bug.Lint: elided_lifetimes_in_pathsRelevant to the compiler team, which will review and decide on the PR/issue.