Skip to content

Commit 94146d5

Browse files
committed
Auto merge of #4270 - flip1995:rollup-piifrj5, r=flip1995
Rollup of 2 pull requests Successful merges: - #4229 (don't strip blank lines in lint documentation) - #4268 (Fix bug in `implicit_hasher` causing crashes) Failed merges: r? @ghost
2 parents b029042 + a21c00c commit 94146d5

File tree

5 files changed

+35
-22
lines changed

5 files changed

+35
-22
lines changed

clippy_lints/src/types.rs

+3
Original file line numberDiff line numberDiff line change
@@ -2038,6 +2038,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ImplicitHasher {
20382038
vis.visit_ty(ty);
20392039

20402040
for target in &vis.found {
2041+
if in_external_macro(cx.sess(), generics.span) {
2042+
continue;
2043+
}
20412044
let generics_suggestion_span = generics.span.substitute_dummy({
20422045
let pos = snippet_opt(cx, item.span.until(body.arguments[0].pat.span))
20432046
.and_then(|snip| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[macro_export]
2+
macro_rules! implicit_hasher_fn {
3+
() => {
4+
pub fn f(input: &HashMap<u32, u32>) {}
5+
};
6+
}

tests/ui/implicit_hasher.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
// aux-build:implicit_hasher_macros.rs
12
#![allow(unused)]
23

4+
#[macro_use]
5+
extern crate implicit_hasher_macros;
6+
37
use std::cmp::Eq;
48
use std::collections::{HashMap, HashSet};
59
use std::hash::{BuildHasher, Hash};
@@ -88,4 +92,7 @@ gen!(fn bar);
8892
pub mod test_macro;
8993
__implicit_hasher_test_macro!(impl<K, V> for HashMap<K, V> where V: test_macro::A);
9094

95+
// #4260
96+
implicit_hasher_fn!();
97+
9198
fn main() {}

tests/ui/implicit_hasher.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: impl for `HashMap` should be generalized over different hashers
2-
--> $DIR/implicit_hasher.rs:11:35
2+
--> $DIR/implicit_hasher.rs:15:35
33
|
44
LL | impl<K: Hash + Eq, V> Foo<i8> for HashMap<K, V> {
55
| ^^^^^^^^^^^^^
@@ -15,7 +15,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
1515
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1616

1717
error: impl for `HashMap` should be generalized over different hashers
18-
--> $DIR/implicit_hasher.rs:20:36
18+
--> $DIR/implicit_hasher.rs:24:36
1919
|
2020
LL | impl<K: Hash + Eq, V> Foo<i8> for (HashMap<K, V>,) {
2121
| ^^^^^^^^^^^^^
@@ -29,7 +29,7 @@ LL | ((HashMap::default(),), (HashMap::with_capacity_and_hasher(10, Defa
2929
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error: impl for `HashMap` should be generalized over different hashers
32-
--> $DIR/implicit_hasher.rs:25:19
32+
--> $DIR/implicit_hasher.rs:29:19
3333
|
3434
LL | impl Foo<i16> for HashMap<String, String> {
3535
| ^^^^^^^^^^^^^^^^^^^^^^^
@@ -43,7 +43,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10, Default:
4343
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

4545
error: impl for `HashSet` should be generalized over different hashers
46-
--> $DIR/implicit_hasher.rs:42:32
46+
--> $DIR/implicit_hasher.rs:46:32
4747
|
4848
LL | impl<T: Hash + Eq> Foo<i8> for HashSet<T> {
4949
| ^^^^^^^^^^
@@ -57,7 +57,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
5757
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5858

5959
error: impl for `HashSet` should be generalized over different hashers
60-
--> $DIR/implicit_hasher.rs:47:19
60+
--> $DIR/implicit_hasher.rs:51:19
6161
|
6262
LL | impl Foo<i16> for HashSet<String> {
6363
| ^^^^^^^^^^^^^^^
@@ -71,7 +71,7 @@ LL | (HashSet::default(), HashSet::with_capacity_and_hasher(10, Default:
7171
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7272

7373
error: parameter of type `HashMap` should be generalized over different hashers
74-
--> $DIR/implicit_hasher.rs:64:23
74+
--> $DIR/implicit_hasher.rs:68:23
7575
|
7676
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
7777
| ^^^^^^^^^^^^^^^^^
@@ -81,7 +81,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32, S>, _s
8181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
8282

8383
error: parameter of type `HashSet` should be generalized over different hashers
84-
--> $DIR/implicit_hasher.rs:64:53
84+
--> $DIR/implicit_hasher.rs:68:53
8585
|
8686
LL | pub fn foo(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
8787
| ^^^^^^^^^^^^
@@ -91,7 +91,7 @@ LL | pub fn foo<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i32>, _set:
9191
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
9292

9393
error: impl for `HashMap` should be generalized over different hashers
94-
--> $DIR/implicit_hasher.rs:68:43
94+
--> $DIR/implicit_hasher.rs:72:43
9595
|
9696
LL | impl<K: Hash + Eq, V> Foo<u8> for HashMap<K, V> {
9797
| ^^^^^^^^^^^^^
@@ -108,7 +108,7 @@ LL | (HashMap::default(), HashMap::with_capacity_and_hasher(10,
108108
| ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109

110110
error: parameter of type `HashMap` should be generalized over different hashers
111-
--> $DIR/implicit_hasher.rs:76:33
111+
--> $DIR/implicit_hasher.rs:80:33
112112
|
113113
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
114114
| ^^^^^^^^^^^^^^^^^
@@ -121,7 +121,7 @@ LL | pub fn $name<S: ::std::hash::BuildHasher>(_map: &mut HashMap<i32, i
121121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^
122122

123123
error: parameter of type `HashSet` should be generalized over different hashers
124-
--> $DIR/implicit_hasher.rs:76:63
124+
--> $DIR/implicit_hasher.rs:80:63
125125
|
126126
LL | pub fn $name(_map: &mut HashMap<i32, i32>, _set: &mut HashSet<i32>) {}
127127
| ^^^^^^^^^^^^

util/export.py

+9-12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
# Build the gh-pages
44

5+
from collections import OrderedDict
56
import re
67
import sys
78
import json
@@ -21,33 +22,29 @@ def parse_lint_def(lint):
2122
lint_dict['id'] = lint.name
2223
lint_dict['group'] = lint.group
2324
lint_dict['level'] = lint.level
24-
lint_dict['docs'] = {}
25+
lint_dict['docs'] = OrderedDict()
2526

2627
last_section = None
2728

2829
for line in lint.doc:
29-
if len(line.strip()) == 0 and not last_section.startswith("Example"):
30-
continue
31-
3230
match = re.match(lint_subheadline, line)
3331
if match:
3432
last_section = match.groups()[0]
35-
if match:
3633
text = match.groups()[1]
3734
else:
3835
text = line
3936

4037
if not last_section:
41-
log.warn("Skipping comment line as it was not preceded by a heading")
38+
log.warning("Skipping comment line as it was not preceded by a heading")
4239
log.debug("in lint `%s`, line `%s`", lint.name, line)
4340

44-
fragment = lint_dict['docs'].get(last_section, "")
45-
if text == "\n":
46-
line = fragment + text
47-
else:
48-
line = (fragment + "\n" + text).strip()
41+
if last_section not in lint_dict['docs']:
42+
lint_dict['docs'][last_section] = ""
43+
44+
lint_dict['docs'][last_section] += text + "\n"
4945

50-
lint_dict['docs'][last_section] = line
46+
for section in lint_dict['docs']:
47+
lint_dict['docs'][section] = lint_dict['docs'][section].strip()
5148

5249
return lint_dict
5350

0 commit comments

Comments
 (0)