Skip to content

Commit f8308c8

Browse files
committed
Auto merge of rust-lang#5438 - flip1995:rollup-pi762oy, r=flip1995
Rollup of 11 pull requests Successful merges: - rust-lang#5406 (Fix update_lints) - rust-lang#5409 (Downgrade let_unit_value to pedantic) - rust-lang#5410 (Downgrade trivially_copy_pass_by_ref to pedantic) - rust-lang#5412 (Downgrade inefficient_to_string to pedantic) - rust-lang#5415 (Add new lint for `Result<T, E>.map_or(None, Some(T))`) - rust-lang#5417 (Update doc links and mentioned names in docs) - rust-lang#5419 (Downgrade unreadable_literal to pedantic) - rust-lang#5420 (Downgrade new_ret_no_self to pedantic) - rust-lang#5422 (CONTRIBUTING.md: fix broken triage link) - rust-lang#5424 (Incorrect suspicious_op_assign_impl) - rust-lang#5425 (Ehance opt_as_ref_deref lint.) Failed merges: - rust-lang#5345 (Add lint for float in array comparison) - rust-lang#5411 (Downgrade implicit_hasher to pedantic) - rust-lang#5428 (Move cognitive_complexity to nursery) r? @ghost changelog: rollup
2 parents 0b40983 + 381f9cb commit f8308c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+687
-532
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,7 @@ Released 2018-09-13
14481448
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
14491449
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
14501450
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
1451+
[`result_map_or_into_option`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_or_into_option
14511452
[`result_map_unit_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unit_fn
14521453
[`result_map_unwrap_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_map_unwrap_or_else
14531454
[`result_unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_unwrap_used

CONTRIBUTING.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ High level approach:
3636

3737
### Finding something to fix/improve
3838

39-
All issues on Clippy are mentored, if you want help with a bug just ask @Manishearth, @llogiq, @mcarton or @oli-obk.
39+
All issues on Clippy are mentored, if you want help with a bug just ask
40+
@Manishearth, @flip1995, @phansch or @yaahc.
4041

4142
Some issues are easier than others. The [`good first issue`] label can be used to find the easy issues.
4243
If you want to work on an issue, please leave a comment so that we can assign it to you!
@@ -70,24 +71,22 @@ an AST expression). `match_def_path()` in Clippy's `utils` module can also be us
7071
[`T-AST`]: https://github.com/rust-lang/rust-clippy/labels/T-AST
7172
[`T-middle`]: https://github.com/rust-lang/rust-clippy/labels/T-middle
7273
[`E-medium`]: https://github.com/rust-lang/rust-clippy/labels/E-medium
73-
[`ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty
74+
[`ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty
7475
[nodes in the AST docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/
7576
[deep-nesting]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/mem_forget.rs#L29-L43
7677
[if_chain]: https://docs.rs/if_chain/*/if_chain
7778
[nest-less]: https://github.com/rust-lang/rust-clippy/blob/557f6848bd5b7183f55c1e1522a326e9e1df6030/clippy_lints/src/bit_mask.rs#L124-L150
7879

7980
## Writing code
8081

81-
Have a look at the [docs for writing lints][adding_lints] for more details. [Llogiq's blog post on lints]
82-
is also a nice primer to lint-writing, though it does get into advanced stuff and may be a bit outdated.
82+
Have a look at the [docs for writing lints][adding_lints] for more details.
8383

8484
If you want to add a new lint or change existing ones apart from bugfixing, it's
8585
also a good idea to give the [stability guarantees][rfc_stability] and
8686
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
8787
quick read.
8888

8989
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/doc/adding_lints.md
90-
[Llogiq's blog post on lints]: https://llogiq.github.io/2015/06/04/workflows.html
9190
[clippy_rfc]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md
9291
[rfc_stability]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#stability-guarantees
9392
[rfc_lint_cats]: https://github.com/rust-lang/rfcs/blob/master/text/2476-clippy-uno.md#lint-audit-and-categories
@@ -223,7 +222,7 @@ You can find the Clippy bors queue [here][homu_queue].
223222
If you have @bors permissions, you can find an overview of the available
224223
commands [here][homu_instructions].
225224

226-
[triage]: https://forge.rust-lang.org/triage-procedure.html
225+
[triage]: https://forge.rust-lang.org/release/triage-procedure.html
227226
[l-crash]: https://github.com/rust-lang/rust-clippy/labels/L-crash%20%3Aboom%3A
228227
[l-bug]: https://github.com/rust-lang/rust-clippy/labels/L-bug%20%3Abeetle%3A
229228
[homu]: https://github.com/rust-lang/homu

clippy_dev/src/lib.rs

+53-75
Original file line numberDiff line numberDiff line change
@@ -62,110 +62,89 @@ impl Lint {
6262
}
6363

6464
/// Returns all non-deprecated lints and non-internal lints
65-
pub fn usable_lints(lints: impl Iterator<Item = Self>) -> impl Iterator<Item = Self> {
66-
lints.filter(|l| l.deprecation.is_none() && !l.is_internal())
65+
#[must_use]
66+
pub fn usable_lints(lints: &[Self]) -> Vec<Self> {
67+
lints
68+
.iter()
69+
.filter(|l| l.deprecation.is_none() && !l.group.starts_with("internal"))
70+
.cloned()
71+
.collect()
6772
}
6873

6974
/// Returns all internal lints (not `internal_warn` lints)
70-
pub fn internal_lints(lints: impl Iterator<Item = Self>) -> impl Iterator<Item = Self> {
71-
lints.filter(|l| l.group == "internal")
75+
#[must_use]
76+
pub fn internal_lints(lints: &[Self]) -> Vec<Self> {
77+
lints.iter().filter(|l| l.group == "internal").cloned().collect()
7278
}
7379

74-
/// Returns the lints in a `HashMap`, grouped by the different lint groups
80+
/// Returns all deprecated lints
7581
#[must_use]
76-
pub fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
77-
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
82+
pub fn deprecated_lints(lints: &[Self]) -> Vec<Self> {
83+
lints.iter().filter(|l| l.deprecation.is_some()).cloned().collect()
7884
}
7985

86+
/// Returns the lints in a `HashMap`, grouped by the different lint groups
8087
#[must_use]
81-
pub fn is_internal(&self) -> bool {
82-
self.group.starts_with("internal")
88+
pub fn by_lint_group(lints: impl Iterator<Item = Self>) -> HashMap<String, Vec<Self>> {
89+
lints.map(|lint| (lint.group.to_string(), lint)).into_group_map()
8390
}
8491
}
8592

8693
/// Generates the Vec items for `register_lint_group` calls in `clippy_lints/src/lib.rs`.
8794
#[must_use]
88-
pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
95+
pub fn gen_lint_group_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
8996
lints
90-
.into_iter()
91-
.filter_map(|l| {
92-
if l.deprecation.is_some() {
93-
None
94-
} else {
95-
Some(format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
96-
}
97-
})
97+
.map(|l| format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
9898
.sorted()
9999
.collect::<Vec<String>>()
100100
}
101101

102102
/// Generates the `pub mod module_name` list in `clippy_lints/src/lib.rs`.
103103
#[must_use]
104-
pub fn gen_modules_list(lints: Vec<Lint>) -> Vec<String> {
104+
pub fn gen_modules_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
105105
lints
106-
.into_iter()
107-
.filter_map(|l| {
108-
if l.is_internal() || l.deprecation.is_some() {
109-
None
110-
} else {
111-
Some(l.module)
112-
}
113-
})
106+
.map(|l| &l.module)
114107
.unique()
115-
.map(|module| format!("pub mod {};", module))
108+
.map(|module| format!("mod {};", module))
116109
.sorted()
117110
.collect::<Vec<String>>()
118111
}
119112

120113
/// Generates the list of lint links at the bottom of the README
121114
#[must_use]
122-
pub fn gen_changelog_lint_list(lints: Vec<Lint>) -> Vec<String> {
123-
let mut lint_list_sorted: Vec<Lint> = lints;
124-
lint_list_sorted.sort_by_key(|l| l.name.clone());
125-
lint_list_sorted
126-
.iter()
127-
.filter_map(|l| {
128-
if l.is_internal() {
129-
None
130-
} else {
131-
Some(format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
132-
}
133-
})
115+
pub fn gen_changelog_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
116+
lints
117+
.sorted_by_key(|l| &l.name)
118+
.map(|l| format!("[`{}`]: {}#{}", l.name, DOCS_LINK, l.name))
134119
.collect()
135120
}
136121

137122
/// Generates the `register_removed` code in `./clippy_lints/src/lib.rs`.
138123
#[must_use]
139-
pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
124+
pub fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
140125
lints
141-
.iter()
142-
.filter_map(|l| {
143-
l.clone().deprecation.map(|depr_text| {
144-
vec![
145-
" store.register_removed(".to_string(),
146-
format!(" \"clippy::{}\",", l.name),
147-
format!(" \"{}\",", depr_text),
148-
" );".to_string(),
149-
]
150-
})
126+
.flat_map(|l| {
127+
l.deprecation
128+
.clone()
129+
.map(|depr_text| {
130+
vec![
131+
" store.register_removed(".to_string(),
132+
format!(" \"clippy::{}\",", l.name),
133+
format!(" \"{}\",", depr_text),
134+
" );".to_string(),
135+
]
136+
})
137+
.expect("only deprecated lints should be passed")
151138
})
152-
.flatten()
153139
.collect::<Vec<String>>()
154140
}
155141

156142
#[must_use]
157-
pub fn gen_register_lint_list(lints: &[Lint]) -> Vec<String> {
143+
pub fn gen_register_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
158144
let pre = " store.register_lints(&[".to_string();
159145
let post = " ]);".to_string();
160146
let mut inner = lints
161-
.iter()
162-
.filter_map(|l| {
163-
if !l.is_internal() && l.deprecation.is_none() {
164-
Some(format!(" &{}::{},", l.module, l.name.to_uppercase()))
165-
} else {
166-
None
167-
}
168-
})
147+
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
169148
.sorted()
170149
.collect::<Vec<String>>();
171150
inner.insert(0, pre);
@@ -439,7 +418,7 @@ fn test_usable_lints() {
439418
None,
440419
"module_name",
441420
)];
442-
assert_eq!(expected, Lint::usable_lints(lints.into_iter()).collect::<Vec<Lint>>());
421+
assert_eq!(expected, Lint::usable_lints(&lints));
443422
}
444423

445424
#[test]
@@ -469,13 +448,12 @@ fn test_gen_changelog_lint_list() {
469448
let lints = vec![
470449
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
471450
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
472-
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
473451
];
474452
let expected = vec![
475453
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
476454
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
477455
];
478-
assert_eq!(expected, gen_changelog_lint_list(lints));
456+
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
479457
}
480458

481459
#[test]
@@ -495,7 +473,6 @@ fn test_gen_deprecated() {
495473
Some("will be removed"),
496474
"module_name",
497475
),
498-
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
499476
];
500477
let expected: Vec<String> = vec![
501478
" store.register_removed(",
@@ -510,36 +487,37 @@ fn test_gen_deprecated() {
510487
.into_iter()
511488
.map(String::from)
512489
.collect();
513-
assert_eq!(expected, gen_deprecated(&lints));
490+
assert_eq!(expected, gen_deprecated(lints.iter()));
491+
}
492+
493+
#[test]
494+
#[should_panic]
495+
fn test_gen_deprecated_fail() {
496+
let lints = vec![Lint::new("should_assert_eq2", "group2", "abc", None, "module_name")];
497+
let _ = gen_deprecated(lints.iter());
514498
}
515499

516500
#[test]
517501
fn test_gen_modules_list() {
518502
let lints = vec![
519503
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
520-
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
521504
Lint::new("incorrect_stuff", "group3", "abc", None, "another_module"),
522-
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
523-
];
524-
let expected = vec![
525-
"pub mod another_module;".to_string(),
526-
"pub mod module_name;".to_string(),
527505
];
528-
assert_eq!(expected, gen_modules_list(lints));
506+
let expected = vec!["mod another_module;".to_string(), "mod module_name;".to_string()];
507+
assert_eq!(expected, gen_modules_list(lints.iter()));
529508
}
530509

531510
#[test]
532511
fn test_gen_lint_group_list() {
533512
let lints = vec![
534513
Lint::new("abc", "group1", "abc", None, "module_name"),
535514
Lint::new("should_assert_eq", "group1", "abc", None, "module_name"),
536-
Lint::new("should_assert_eq2", "group2", "abc", Some("abc"), "deprecated"),
537515
Lint::new("internal", "internal_style", "abc", None, "module_name"),
538516
];
539517
let expected = vec![
540518
" LintId::of(&module_name::ABC),".to_string(),
541519
" LintId::of(&module_name::INTERNAL),".to_string(),
542520
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
543521
];
544-
assert_eq!(expected, gen_lint_group_list(lints));
522+
assert_eq!(expected, gen_lint_group_list(lints.iter()));
545523
}

clippy_dev/src/update_lints.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ pub enum UpdateMode {
1414
pub fn run(update_mode: UpdateMode) {
1515
let lint_list: Vec<Lint> = gather_all().collect();
1616

17-
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
18-
19-
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
20-
let usable_lint_count = round_to_fifty(usable_lints.len());
21-
17+
let internal_lints = Lint::internal_lints(&lint_list);
18+
let deprecated_lints = Lint::deprecated_lints(&lint_list);
19+
let usable_lints = Lint::usable_lints(&lint_list);
2220
let mut sorted_usable_lints = usable_lints.clone();
2321
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
2422

23+
let usable_lint_count = round_to_fifty(usable_lints.len());
24+
2525
let mut file_change = replace_region_in_file(
2626
Path::new("src/lintlist/mod.rs"),
2727
"begin lint list",
@@ -61,7 +61,7 @@ pub fn run(update_mode: UpdateMode) {
6161
"<!-- end autogenerated links to lint list -->",
6262
false,
6363
update_mode == UpdateMode::Change,
64-
|| gen_changelog_lint_list(lint_list.clone()),
64+
|| gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())),
6565
)
6666
.changed;
6767

@@ -71,7 +71,7 @@ pub fn run(update_mode: UpdateMode) {
7171
"end deprecated lints",
7272
false,
7373
update_mode == UpdateMode::Change,
74-
|| gen_deprecated(&lint_list),
74+
|| gen_deprecated(deprecated_lints.iter()),
7575
)
7676
.changed;
7777

@@ -81,7 +81,7 @@ pub fn run(update_mode: UpdateMode) {
8181
"end register lints",
8282
false,
8383
update_mode == UpdateMode::Change,
84-
|| gen_register_lint_list(&lint_list),
84+
|| gen_register_lint_list(usable_lints.iter().chain(internal_lints.iter())),
8585
)
8686
.changed;
8787

@@ -91,7 +91,7 @@ pub fn run(update_mode: UpdateMode) {
9191
"end lints modules",
9292
false,
9393
update_mode == UpdateMode::Change,
94-
|| gen_modules_list(lint_list.clone()),
94+
|| gen_modules_list(usable_lints.iter()),
9595
)
9696
.changed;
9797

@@ -104,13 +104,9 @@ pub fn run(update_mode: UpdateMode) {
104104
update_mode == UpdateMode::Change,
105105
|| {
106106
// clippy::all should only include the following lint groups:
107-
let all_group_lints = usable_lints
108-
.clone()
109-
.into_iter()
110-
.filter(|l| {
111-
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
112-
})
113-
.collect();
107+
let all_group_lints = usable_lints.iter().filter(|l| {
108+
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
109+
});
114110

115111
gen_lint_group_list(all_group_lints)
116112
},
@@ -125,7 +121,7 @@ pub fn run(update_mode: UpdateMode) {
125121
r#"\]\);"#,
126122
false,
127123
update_mode == UpdateMode::Change,
128-
|| gen_lint_group_list(lints.clone()),
124+
|| gen_lint_group_list(lints.iter()),
129125
)
130126
.changed;
131127
}
@@ -140,8 +136,8 @@ pub fn run(update_mode: UpdateMode) {
140136
}
141137

142138
pub fn print_lints() {
143-
let lint_list = gather_all();
144-
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
139+
let lint_list: Vec<Lint> = gather_all().collect();
140+
let usable_lints = Lint::usable_lints(&lint_list);
145141
let usable_lint_count = usable_lints.len();
146142
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
147143

0 commit comments

Comments
 (0)