Skip to content

let_with_type_underscore false positive with '_ lifetime and tracing::instrument #10498

Closed
@sciguy16

Description

@sciguy16

Summary

The new let_with_type_underscore lint is reported when an anonymous lifetime is required in a function return type when the function is instrumented with tracing::instrument, as in the below example. Without the #[tracing::instrument] clippy correctly produces no warnings. Following clippy's suggestion to remove the '_ results in a compilation error.

Lint Name

let_with_type_underscore

Reproducer

I tried this code (playground):

#[derive(Debug)]
struct Wrapper(Vec<i32>);

impl Wrapper {
    #[tracing::instrument]
    fn items(&self) -> impl Iterator<Item = i32> + '_ {
        self.0.iter().cloned()
    }
}

fn main() {
    let a = Wrapper(vec![1, 2, 3]);
    let _ = a.items();
}

I saw this happen:

warning: variable declared with type underscore
 --> src/main.rs:6:24
  |
6 |     fn items(&self) -> impl Iterator<Item = i32> + '_ {
  |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
help: remove the explicit type `_` declaration
 --> src/main.rs:6:54
  |
6 |     fn items(&self) -> impl Iterator<Item = i32> + '_ {
  |                                                      ^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_with_type_underscore
  = note: `#[warn(clippy::let_with_type_underscore)]` on by default

I expected to see this happen:
[no clippy warning]

Version

rustc 1.70.0-nightly (7b4f48927 2023-03-12)
binary: rustc
commit-hash: 7b4f48927dce585f747a58083b45ab62b9d73a53
commit-date: 2023-03-12
host: x86_64-unknown-linux-gnu
release: 1.70.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions