rust-clippy icon indicating copy to clipboard operation
rust-clippy copied to clipboard

Print_* family of lints fail to match on `async_trait` functions with a return value

Open wfchandler opened this issue 1 year ago • 0 comments

Summary

The print_ lint group, e.g. print_stdout, print_literal, fail to detect usage inside async_trait functions with a return type other than (). This occurs both in impl blocks for types implementing the trait and in default implementation provided in the trait definition.

Reproducer

I tried this code:

#![deny(clippy::print_stdout, clippy::print_stderr)]

use async_trait::async_trait;

#[async_trait]
pub trait Bar {
    async fn baz(&self) -> i32;
    async fn qux(&self);
}

pub struct Foo {}

#[async_trait]
impl Bar for Foo {
    async fn baz(&self) -> i32 {
        println!("{}", "hi");
        eprintln!("bye");
        1
    }
    
    async fn qux(&self) {
        println!("{}", "hi");
        eprintln!("bye");
    }
}

Playground link

I expected to see this happen:

Clippy reports the use of println, eprintln, and a literal in format string in both baz and qux.

Instead, this happened:

Clippy fails to detect the print macros in baz, an async_trait function with a return value. An async_trait function without a return value works as expected.

Version

rustc 1.80.0 (051478957 2024-07-21)
binary: rustc
commit-hash: 051478957371ee0084a7c0913941d2a8c4757bb9
commit-date: 2024-07-21
host: aarch64-apple-darwin
release: 1.80.0
LLVM version: 18.1.7

Additional Labels

No response

wfchandler avatar Aug 06 '24 20:08 wfchandler