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

Incompatibility between axum_macros::debug_handler and Clippy #8683

Closed
decryphe opened this issue Apr 11, 2022 · 0 comments · Fixed by #8694
Closed

Incompatibility between axum_macros::debug_handler and Clippy #8683

decryphe opened this issue Apr 11, 2022 · 0 comments · Fixed by #8694
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion

Comments

@decryphe
Copy link
Contributor

Summary

We try to use as many lints as possible on our project, so that issues are caught as early as possible. That's why we use Clippy for many extra lints that are useful.

There is one lint that fails when using #[axum_macros::debug_handler] on any axum handler: clippy::missing-docs-in-private-items

Removing the #[axum_macros::debug_handler] attribute makes the error go away.

Presumably, axum_macros generates some functions that are not documented during generation and as such get caught by Clippy. It's not possible to fix the lint rule requirements as a user of the lint or the macro. I'm not familiar with how Clippy normally deals with generated code that is never seen or accessed directly by a developer.

Lint Name

clippy::missing-docs-in-private-items

Reproducer

Cargo.toml:

[package]
name = "axum-clippy"
version = "0.0.0"
edition = "2021"
publish = false

[dependencies]
axum = { version="0.5.1" }
axum-macros = "0.2.0"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0.79"
tokio = { version = "1.16.1", features = ["full"] }
tokio-stream = { version = "0.1.8" }

src/main.rs:

//! Sample application showing axum/clippy incompatibility

use axum::{routing::get, Router};

#[tokio::main]
async fn main() {
    let app = Router::new().route("/", get(root));

    // run our app with hyper
    // `axum::Server` is a re-export of `hyper::Server`
    let addr = std::net::SocketAddr::from(([127, 0, 0, 1], 3000));
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();
}

/// GET Response Body for `/`
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub struct Sample {
    /// Put whatever in here.
    pub something: String,
}

/// Handler for GET `/`
#[axum_macros::debug_handler]
pub async fn root() -> axum::Json<Sample> {
    let response = Sample {
        something: "Hello World".into(),
    };

    axum::Json(response)
}

How to enable the additional lints:
RUSTFLAGS="-D warnings -D missing_docs -D clippy::doc_markdown -D clippy::missing_docs_in_private_items" cargo clippy

The error output from running cargo clippy:

error: missing documentation for a function
  --> src/main.rs:27:24
   |
27 | pub async fn root() -> axum::Json<Sample> {
   |                        ^^^^
   |
   = note: requested on the command line with `-D clippy::missing-docs-in-private-items`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items

error: missing documentation for a function
  --> src/main.rs:25:1
   |
25 | /// Handler for GET `/`
   | ^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#missing_docs_in_private_items

error: could not compile `axum-clippy` due to 2 previous errors

Version

rustc 1.60.0 (7737e0b5c 2022-04-04)
binary: rustc
commit-hash: 7737e0b5c4103216d6fd8cf941b7ab9bdbaace7c
commit-date: 2022-04-04
host: x86_64-unknown-linux-gnu
release: 1.60.0
LLVM version: 14.0.0

Additional Labels

No response

@decryphe decryphe added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Apr 11, 2022
@xFrednet xFrednet added the T-macros Type: Issues with macros and macro expansion label Apr 11, 2022
bors added a commit that referenced this issue Aug 8, 2022
More proc-macro detection

fixes #6514
fixes #8683
fixes #6858
fixes #6594

This is a more general way of checking if an expression comes from a macro and could be trivially applied to other lints. Ideally this would be fixed in rustc's proc-macro api, but I don't see that happening any time soon.

changelog: Don't lint `unit_arg` when generated by a proc-macro.
@bors bors closed this as completed in 10853f7 Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have T-macros Type: Issues with macros and macro expansion
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants