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

instrument macro sometimes triggers clippy::let_with_type_underscore #2503

Open
jplatte opened this issue Mar 11, 2023 · 4 comments
Open

instrument macro sometimes triggers clippy::let_with_type_underscore #2503

jplatte opened this issue Mar 11, 2023 · 4 comments

Comments

@jplatte
Copy link
Member

jplatte commented Mar 11, 2023

Bug Report

Version

v0.1.37

Platform

Linux 6.2.2-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 03 Mar 2023 15:58:31 +0000 x86_64 GNU/Linux

Description

Clippy introduced a new lint let_with_type_underscore that triggers on let pattern: _ = expression; in rust-lang/rust-clippy#10463. It seems to trigger on #[instrument]ed function that return impl Trait + 'lt, for instance one function I saw it was the function

#[instrument(name = "sync_stream", skip_all, parent = &self.inner.client.inner.root_span)]
pub fn stream(&self) -> impl Stream<Item = Result<UpdateSummary, crate::Error>> + '_ {
    // ...
}

(and naming the lifetime didn't help)

@BBaoVanC
Copy link

I got this issue with a function in my axum app:

#[instrument(skip(headers), fields(if_none_match = ?headers.get(header::IF_NONE_MATCH)))]
pub async fn handler(uri: Uri, headers: HeaderMap) -> impl IntoResponse {

In the macro expansion, a bit down I see:

            let __tracing_attr_fake_return: _ = ::core::panicking::panic_fmt(format_args!(
                "internal error: entered unreachable code: {0}",
                format_args!("this is just for type inference, and is unreachable code")
            ));
            return __tracing_attr_fake_return;

@mrnossiom
Copy link

mrnossiom commented Mar 18, 2023

This only happens with impl Trait because impl in return types removed as it is used later in a let binding. This happens because impl Trait in let bindings RFC is accepted but not implemented nor stable. It means that let foo: impl Trait = ... is not valid syntax yet. (See PR)

let (return_type, return_span) = if let ReturnType::Type(_, return_type) = &output {
(erase_impl_trait(return_type), return_type.span())

Here, the return type is completely empty, so it equals _
let __tracing_attr_fake_return: #return_type =
unreachable!("this is just for type inference, and is unreachable code");

I would love to make a PR, but I don't know if we should silence the warning with a allow(clippy::let_with_type_underscore) or in the expansion itself, not emitting to an underscore but rather nothing.

Thanks

@ranile
Copy link

ranile commented Jun 2, 2023

Min repro on playground. This only happens if there's an impl Trait return type from my testing

This lint bug is triggered on stable now and breaks CI

@mrnossiom
Copy link

I made a PR two months ago. And yes, the lint is now warn by default on rust v1.70.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants