rust-lang / rust-lang/rust-clippy
Print_* family of lints fail to match on `async_trait` functions with a return value
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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");
}
}
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the print_stdout, print_stderr, and print_literal lint entry points, then reproduce the supplied async_trait example. Compare diagnostics for baz and qux in the trait and impl; done means the print macros and format literal are detected consistently for both return-value and unit-returning async functions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100