Type parameter change and type change are now in a multispan suggestion
This commit is contained in:
parent
a4f45e85b1
commit
eea30777dd
@ -1453,8 +1453,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidUpcastComparisons {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// **What it does:** Checks for public `impl` or `fn` missing generalization over
|
/// **What it does:** Checks for public `impl` or `fn` missing generalization
|
||||||
/// different hashers and implicitly defaulting to the default hashing
|
/// over different hashers and implicitly defaulting to the default hashing
|
||||||
/// algorithm (SipHash).
|
/// algorithm (SipHash).
|
||||||
///
|
///
|
||||||
/// **Why is this bad?** `HashMap` or `HashSet` with custom hashers cannot be
|
/// **Why is this bad?** `HashMap` or `HashSet` with custom hashers cannot be
|
||||||
@ -1505,26 +1505,29 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
|
|||||||
&generics_snip[1..generics_snip.len() - 1]
|
&generics_snip[1..generics_snip.len() - 1]
|
||||||
};
|
};
|
||||||
|
|
||||||
db.span_suggestion(
|
multispan_sugg(
|
||||||
generics_suggestion_span,
|
db,
|
||||||
"consider adding a type parameter",
|
"consider adding a type parameter".to_string(),
|
||||||
format!(
|
vec![
|
||||||
"<{}{}S: ::std::hash::BuildHasher{}>",
|
(
|
||||||
generics_snip,
|
generics_suggestion_span,
|
||||||
if generics_snip.is_empty() { "" } else { ", " },
|
format!(
|
||||||
if vis.suggestions.is_empty() {
|
"<{}{}S: ::std::hash::BuildHasher{}>",
|
||||||
""
|
generics_snip,
|
||||||
} else {
|
if generics_snip.is_empty() { "" } else { ", " },
|
||||||
// request users to add `Default` bound so that generic constructors can be used
|
if vis.suggestions.is_empty() {
|
||||||
" + Default"
|
""
|
||||||
},
|
} else {
|
||||||
),
|
// request users to add `Default` bound so that generic constructors can be used
|
||||||
);
|
" + Default"
|
||||||
|
},
|
||||||
db.span_suggestion(
|
),
|
||||||
target.span(),
|
),
|
||||||
"...and change the type to",
|
(
|
||||||
format!("{}<{}, S>", target.type_name(), target.type_arguments(),),
|
target.span(),
|
||||||
|
format!("{}<{}, S>", target.type_name(), target.type_arguments(),),
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
if !vis.suggestions.is_empty() {
|
if !vis.suggestions.is_empty() {
|
||||||
|
@ -7,12 +7,8 @@ error: impl for `HashMap` should be generarized over different hashers
|
|||||||
= note: `-D implicit-hasher` implied by `-D warnings`
|
= note: `-D implicit-hasher` implied by `-D warnings`
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
11 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V> {
|
11 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashMap<K, V, S> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
11 | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V, S> {
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
17 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
17 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||||
@ -26,12 +22,8 @@ error: impl for `HashMap` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
20 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for (HashMap<K, V>,) {
|
20 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<i8> for (HashMap<K, V, S>,) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
20 | impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V, S>,) {
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
22 | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),))
|
22 | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Default::default()),))
|
||||||
@ -45,12 +37,8 @@ error: impl for `HashMap` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
25 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashMap<String, String> {
|
25 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashMap<String, String, S> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
25 | impl Foo<i16> for HashMap<String, String, S> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
27 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
27 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||||
@ -64,12 +52,8 @@ error: impl for `HashSet` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
43 | impl<T: Hash + Eq, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashSet<T> {
|
43 | impl<T: Hash + Eq, S: ::std::hash::BuildHasher + Default> Foo<i8> for HashSet<T, S> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
43 | impl<T: Hash + Eq> Foo<i8> for HashSet<T, S> {
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
45 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
45 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
||||||
@ -83,12 +67,8 @@ error: impl for `HashSet` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
48 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashSet<String> {
|
48 | impl<S: ::std::hash::BuildHasher + Default> Foo<i16> for HashSet<String, S> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
48 | impl Foo<i16> for HashSet<String, S> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
50 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
50 | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default::default()))
|
||||||
@ -102,12 +82,8 @@ error: parameter of type `HashMap` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
|
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
65 | pub fn foo(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: parameter of type `HashSet` should be generarized over different hashers
|
error: parameter of type `HashSet` should be generarized over different hashers
|
||||||
--> $DIR/implicit_hasher.rs:65:53
|
--> $DIR/implicit_hasher.rs:65:53
|
||||||
@ -117,12 +93,8 @@ error: parameter of type `HashSet` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
|
65 | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
65 | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
|
||||||
| ^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: impl for `HashMap` should be generarized over different hashers
|
error: impl for `HashMap` should be generarized over different hashers
|
||||||
--> $DIR/implicit_hasher.rs:70:43
|
--> $DIR/implicit_hasher.rs:70:43
|
||||||
@ -135,12 +107,8 @@ error: impl for `HashMap` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
70 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u8> for HashMap<K, V> {
|
70 | impl<K: Hash + Eq, V, S: ::std::hash::BuildHasher + Default> Foo<u8> for HashMap<K, V, S> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
70 | impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V, S> {
|
|
||||||
| ^^^^^^^^^^^^^^^^
|
|
||||||
help: ...and use generic constructor
|
help: ...and use generic constructor
|
||||||
|
|
|
|
||||||
72 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
72 | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default::default()))
|
||||||
@ -157,12 +125,8 @@ error: parameter of type `HashMap` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
|
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
78 | pub fn $name(_map: &mut HashMap<i32, i32, S>, _set: &mut HashSet<i32>) {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: parameter of type `HashSet` should be generarized over different hashers
|
error: parameter of type `HashSet` should be generarized over different hashers
|
||||||
--> $DIR/implicit_hasher.rs:78:63
|
--> $DIR/implicit_hasher.rs:78:63
|
||||||
@ -175,10 +139,6 @@ error: parameter of type `HashSet` should be generarized over different hashers
|
|||||||
|
|
|
|
||||||
help: consider adding a type parameter
|
help: consider adding a type parameter
|
||||||
|
|
|
|
||||||
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {
|
78 | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
help: ...and change the type to
|
|
||||||
|
|
|
||||||
78 | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32, S>) {
|
|
||||||
| ^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user