Skip to content

A lint to detect explicitly-annotated lifetimes which can be inferred #18853

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

Closed
bstrie opened this issue Nov 10, 2014 · 3 comments
Closed

A lint to detect explicitly-annotated lifetimes which can be inferred #18853

bstrie opened this issue Nov 10, 2014 · 3 comments
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.

Comments

@bstrie
Copy link
Contributor

bstrie commented Nov 10, 2014

I think a lint for code of the following form would be useful:

fn foo<'a>(x: &'a str) -> &'a str {
    x
}

This function signature contains explicit lifetimes which can be inferred by the compiler. I imagine that the lint would emit something like the following:

warning: unnecesary lifetime annotations
fn foo<'a>(x: &'a str) -> &'a str {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: signature can be written as follows:
fn foo(x: &str) -> &str {

Perhaps the suggested signature bit would be tricky. I also have no opinion regarding whether or not this lint would be on or off by default.

@bstrie bstrie added the A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. label Nov 10, 2014
@steveklabnik
Copy link
Member

/cc @Manishearth does clippy have something like this?

@Manishearth
Copy link
Member

@steveklabnik
Copy link
Member

Nice. Giving this a close, then.

lnicola added a commit to lnicola/rust that referenced this issue Jan 7, 2025
Fix case where completion inside macro that expands to `#[test]` was unavailable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut.
Projects
None yet
Development

No branches or pull requests

3 participants