-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing
Description
Summary
implicit_haser wrongly unmangled macros
Reproducer
Code:
use std::collections::HashMap;
use std::hash::Hash;
pub trait Foo<T>: Sized {
fn make() -> (Self, Self);
}
impl<K: Hash + Eq, V> Foo<u64> for HashMap<K, V> {
fn make() -> (Self, Self) {
macro_rules! times_by_ten {
($num:expr) => {
$num * 10
};
}
(HashMap::new(), HashMap::with_capacity(times_by_ten!(5)))
}
}Current output:
warning: impl for `HashMap` should be generalized over different hashers
--> src/main.rs:11:36
|
11 | impl<K: Hash + Eq, V> Foo<u64> for HashMap<K, V> {
| ^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
note: the lint level is defined here
--> src/main.rs:2:9
|
2 | #![warn(clippy::implicit_hasher)]
| ^^^^^^^^^^^^^^^^^^^^^^^
help: add a type parameter for `BuildHasher`
|
11 ~ impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u64> for HashMap<K, V, S> {
12 | fn make() -> (Self, Self) {
...
18 |
19 ~ (HashMap::default(), HashMap::with_capacity_and_hasher($num * 10, Default::default()))
|
Desired output:
warning: impl for `HashMap` should be generalized over different hashers
--> src/main.rs:11:36
|
11 | impl<K: Hash + Eq, V> Foo<u64> for HashMap<K, V> {
| ^^^^^^^^^^^^^
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher
note: the lint level is defined here
--> src/main.rs:2:9
|
2 | #![warn(clippy::implicit_hasher)]
| ^^^^^^^^^^^^^^^^^^^^^^^
help: add a type parameter for `BuildHasher`
|
11 ~ impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u64> for HashMap<K, V, S> {
12 | fn make() -> (Self, Self) {
...
18 |
19 ~ (HashMap::default(), HashMap::with_capacity_and_hasher(times_by_ten!(5), Default::default()))
|
Version
rustc 1.93.0-nightly (2286e5d22 2025-11-13)
binary: rustc
commit-hash: 2286e5d224b3413484cf4f398a9f078487e7b49d
commit-date: 2025-11-13
host: x86_64-unknown-linux-gnu
release: 1.93.0-nightly
LLVM version: 21.1.5
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thing