Auto merge of #86827 - camsteffen:hash-lint-resolved, r=oli-obk

Fix internal `default_hash_types` lint to use resolved path

I run into false positives now and then (mostly in Clippy) when I want to name some util after HashMap.
This commit is contained in:
bors 2021-07-13 15:06:10 +00:00
commit 3e1c75c6e2
8 changed files with 72 additions and 71 deletions

View file

@ -1,22 +1,29 @@
// compile-flags: -Z unstable-options
#![feature(rustc_private)]
#![deny(rustc::default_hash_types)]
extern crate rustc_data_structures;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use std::collections::{HashMap, HashSet};
#[deny(rustc::default_hash_types)]
mod foo {
pub struct HashMap;
}
fn main() {
let _map: HashMap<String, String> = HashMap::default();
//~^ ERROR Prefer FxHashMap over HashMap, it has better performance
//~^^ ERROR Prefer FxHashMap over HashMap, it has better performance
//~^ ERROR prefer `FxHashMap` over `HashMap`, it has better performance
//~^^ ERROR prefer `FxHashMap` over `HashMap`, it has better performance
let _set: HashSet<String> = HashSet::default();
//~^ ERROR Prefer FxHashSet over HashSet, it has better performance
//~^^ ERROR Prefer FxHashSet over HashSet, it has better performance
//~^ ERROR prefer `FxHashSet` over `HashSet`, it has better performance
//~^^ ERROR prefer `FxHashSet` over `HashSet`, it has better performance
// test that the lint doesn't also match the Fx variants themselves
let _fx_map: FxHashMap<String, String> = FxHashMap::default();
let _fx_set: FxHashSet<String> = FxHashSet::default();
// test another struct of the same name
let _ = foo::HashMap;
}

View file

@ -1,37 +1,37 @@
error: Prefer FxHashMap over HashMap, it has better performance
--> $DIR/default_hash_types.rs:12:15
error: prefer `FxHashMap` over `HashMap`, it has better performance
--> $DIR/default_hash_types.rs:16:41
|
LL | let _map: HashMap<String, String> = HashMap::default();
| ^^^^^^^ help: use: `FxHashMap`
| ^^^^^^^
|
note: the lint level is defined here
--> $DIR/default_hash_types.rs:10:8
--> $DIR/default_hash_types.rs:4:9
|
LL | #[deny(rustc::default_hash_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
LL | #![deny(rustc::default_hash_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
error: Prefer FxHashMap over HashMap, it has better performance
--> $DIR/default_hash_types.rs:12:41
error: prefer `FxHashMap` over `HashMap`, it has better performance
--> $DIR/default_hash_types.rs:16:15
|
LL | let _map: HashMap<String, String> = HashMap::default();
| ^^^^^^^ help: use: `FxHashMap`
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= note: a `use rustc_data_structures::fx::FxHashMap` may be necessary
error: Prefer FxHashSet over HashSet, it has better performance
--> $DIR/default_hash_types.rs:15:15
error: prefer `FxHashSet` over `HashSet`, it has better performance
--> $DIR/default_hash_types.rs:19:33
|
LL | let _set: HashSet<String> = HashSet::default();
| ^^^^^^^ help: use: `FxHashSet`
| ^^^^^^^
|
= note: a `use rustc_data_structures::fx::FxHashSet` may be necessary
error: Prefer FxHashSet over HashSet, it has better performance
--> $DIR/default_hash_types.rs:15:33
error: prefer `FxHashSet` over `HashSet`, it has better performance
--> $DIR/default_hash_types.rs:19:15
|
LL | let _set: HashSet<String> = HashSet::default();
| ^^^^^^^ help: use: `FxHashSet`
| ^^^^^^^^^^^^^^^
|
= note: a `use rustc_data_structures::fx::FxHashSet` may be necessary

View file

@ -12,6 +12,5 @@
//~| SUGGESTION rustc::default_hash_types
fn main() {
let _ = std::collections::HashMap::<String, String>::new();
//~^ WARN Prefer FxHashMap over HashMap, it has better performance
//~| HELP use
//~^ WARN prefer `FxHashMap` over `HashMap`, it has better performance
}

View file

@ -12,11 +12,11 @@ warning: unknown lint: `rustc::foo::default_hash_types`
LL | #[allow(rustc::foo::default_hash_types)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `rustc::default_hash_types`
warning: Prefer FxHashMap over HashMap, it has better performance
--> $DIR/issue-83477.rs:14:31
warning: prefer `FxHashMap` over `HashMap`, it has better performance
--> $DIR/issue-83477.rs:14:13
|
LL | let _ = std::collections::HashMap::<String, String>::new();
| ^^^^^^^ help: use: `FxHashMap`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/issue-83477.rs:3:9