rust-lang / rust-lang/rust-clippy

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

Open
#13,228 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
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");
    }
}

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.