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

extra_unused_type_parameters should not warn external macros #10318

Closed
taiki-e opened this issue Feb 11, 2023 · 2 comments · Fixed by #10321
Closed

extra_unused_type_parameters should not warn external macros #10318

taiki-e opened this issue Feb 11, 2023 · 2 comments · Fixed by #10321
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

Comments

@taiki-e
Copy link
Member

taiki-e commented Feb 11, 2023

Summary

extra_unused_type_parameters currently warns of code generated by external macros, but it should not. (there is no way for the user to fix it.)

Mentioning @mkrasnitski who implemented this lint in #10028.

Lint Name

extra_unused_type_parameters

Reproducer

I tried this code:

# Cargo.toml
[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[dependencies]
static_assertions = "=1.1.0"
// src/lib.rs
#![warn(clippy::extra_unused_type_parameters)]

#[allow(dead_code)]
struct S(());

static_assertions::assert_impl_all!(S: Send);

I saw this happen:

warning: type parameter goes unused in function definition
 --> src/lib.rs:6:1
  |
6 | static_assertions::assert_impl_all!(S: Send);
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: consider removing the parameter
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::extra_unused_type_parameters)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this warning originates in the macro `static_assertions::assert_impl_all` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen: no warnings

Version

rustc 1.69.0-nightly (2773383a3 2023-02-10)
binary: rustc
commit-hash: 2773383a314a4b8f481ce2bed12c32de794ffbe9
commit-date: 2023-02-10
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

@chorman0773
Copy link

chorman0773 commented Feb 23, 2023

This is still triggering on the latest nightly (I did rustup update and rebuild to check), with a derive macro.

The linted-on code is

#[repr(C)]
#[derive(Zeroable, Pod, Clone, Copy)]
pub struct O65FixedHeader {
    id1: [u8; 2],
    magic: [u8; 3],
    ver: u8,
    mode: u16,
}

Which triggers this output

error: type parameter goes unused in function definition
 --> binfmt/src/o65.rs:1:1
  |
1 | / #[repr(C)]
2 | | #[derive(Zeroable, Pod, Clone, Copy)]
3 | | pub struct O65FixedHeader {
4 | |     id1: [u8; 2],
... |
7 | |     mode: u16,
8 | | }
  | |_^
  |
  = help: consider removing the parameter
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters

IMO, I'm suspicious this should trigger on macro-expanded tokens at all, given that a common technique to typecheck some type against a trait is to define pub fn __check<T: MyTrait>(){} then call it with turbofish.

@mkrasnitski
Copy link
Contributor

That's because the changes haven't made it into nightly rust yet. Nightly pulls from clippy's HEAD on a biweekly basis, and the next time it does this is tomorrow, the 23rd. So, #10321 should make it in then, as well as hopefully #10392, if it gets merged in time.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants