Skip to content

Commit aca8f94

Browse files
committed
submodules: update clippy from a416c5e to fc24fce
Fixes clippy tool state Changes: ```` FIXME > TODO rustup rust-lang/rust#56992 Document map_clone known problems rust-lang#498 Remove header link test: panic at map_unit_fn.rs:202 for map() without args rm unused file map_unit_fn.stderr panic at map_unit_fn.rs:202 for map() without args Change contrib.md hierarchy, link to it from readme Workaround rust-lang/rust#43081 Teach `suspicious_else_formatting` about `if .. {..} {..}` Link to `rustc_driver` crate in plugin mutex_atomic: Correct location of AtomicBool and friends Update README local run command to specify syspath Do not mark as_ref as useless if it's followed by a method call Changes lint sugg to bitwise and operator `&` Run update_lints after renaming Rename lint to MODULE_NAME_REPETITIONS Add renaming tests Move renaming to the right place Implements lint for order comparisons against bool fix(module_name_repeat): Try to register renamed lint, not valid yet Fix an endless loop in the tests. Fix `implicit_return` false positives. chore(moduel_name_repeat): Rename stutter lint to module_name_repeat to avoid ableist language Make integration tests fail on 'E0463' base tests: make sure cargo-clippy binary can be called directly Revert "Merge pull request rust-lang#3257 from o01eg/remove-sysroot" ````
1 parent 9d15aaf commit aca8f94

33 files changed

+552
-417
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,6 +760,7 @@ All notable changes to this project will be documented in this file.
760760
[`mistyped_literal_suffixes`]: https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes
761761
[`mixed_case_hex_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_case_hex_literals
762762
[`module_inception`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_inception
763+
[`module_name_repetitions`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions
763764
[`modulo_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_one
764765
[`multiple_crate_versions`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions
765766
[`multiple_inherent_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#multiple_inherent_impl
@@ -850,7 +851,6 @@ All notable changes to this project will be documented in this file.
850851
[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars
851852
[`string_lit_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
852853
[`string_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_to_string
853-
[`stutter`]: https://rust-lang.github.io/rust-clippy/master/index.html#stutter
854854
[`suspicious_arithmetic_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_arithmetic_impl
855855
[`suspicious_assignment_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_assignment_formatting
856856
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ All contributors are expected to follow the [Rust Code of Conduct](http://www.ru
1919
* [Running test suite](#running-test-suite)
2020
* [Running rustfmt](#running-rustfmt)
2121
* [Testing manually](#testing-manually)
22-
* [How Clippy works](#how-clippy-works)
23-
* [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
22+
* [How Clippy works](#how-clippy-works)
23+
* [Fixing nightly build failures](#fixing-build-failures-caused-by-rust)
2424
* [Issue and PR Triage](#issue-and-pr-triage)
2525
* [Bors and Homu](#bors-and-homu)
2626
* [Contributions](#contributions)
@@ -168,7 +168,7 @@ Manually testing against an example file is useful if you have added some
168168
local modifications, run `env CLIPPY_TESTS=true cargo run --bin clippy-driver -- -L ./target/debug input.rs`
169169
from the working copy root.
170170

171-
### How Clippy works
171+
## How Clippy works
172172

173173
Clippy is a [rustc compiler plugin][compiler_plugin]. The main entry point is at [`src/lib.rs`][main_entry]. In there, the lint registration is delegated to the [`clippy_lints`][lint_crate] crate.
174174

@@ -218,7 +218,7 @@ The difference between `EarlyLintPass` and `LateLintPass` is that the methods of
218218

219219
That's why the `else_if_without_else` example uses the `register_early_lint_pass` function. Because the [actual lint logic][else_if_without_else] does not depend on any type information.
220220

221-
### Fixing build failures caused by Rust
221+
## Fixing build failures caused by Rust
222222

223223
Clippy will sometimes fail to build from source because building it depends on unstable internal Rust features. Most of the times we have to adapt to the changes and only very rarely there's an actual bug in Rust. Fixing build failures caused by Rust updates, can be a good way to learn about Rust internals.
224224

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ To have cargo compile your crate with Clippy without Clippy installation
7979
in your code, you can use:
8080

8181
```terminal
82-
cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
82+
RUSTFLAGS=--sysroot=`rustc --print sysroot` cargo run --bin cargo-clippy --manifest-path=path_to_clippys_Cargo.toml
8383
```
8484

8585
*[Note](https://github.com/rust-lang/rust-clippy/wiki#a-word-of-warning):*
@@ -151,6 +151,10 @@ Note: `deny` produces errors instead of warnings.
151151

152152
If you do not want to include your lint levels in your code, you can globally enable/disable lints by passing extra flags to Clippy during the run: `cargo clippy -- -A clippy::lint_name` will run Clippy with `lint_name` disabled and `cargo clippy -- -W clippy::lint_name` will run it with that enabled. This also works with lint groups. For example you can run Clippy with warnings for all lints enabled: `cargo clippy -- -W clippy::pedantic`
153153

154+
## Contributing
155+
156+
If you want to contribute to Clippy, you can find more information in [CONTRIBUTING.md](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md).
157+
154158
## License
155159

156160
Copyright 2014-2018 The Rust Project Developers

ci/base-tests.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ cd clippy_lints && cargo test && cd ..
2626
cd rustc_tools_util && cargo test && cd ..
2727
cd clippy_dev && cargo test && cd ..
2828

29+
# make sure clippy can be called via ./path/to/cargo-clippy
30+
cd clippy_workspace_tests
31+
../target/debug/cargo-clippy
32+
cd ..
33+
2934
# Perform various checks for lint registration
3035
./util/dev update_lints --check
3136
cargo +nightly fmt --all -- --check

ci/integration-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function check() {
2121
# run clippy on a project, try to be verbose and trigger as many warnings as possible for greater coverage
2222
RUST_BACKTRACE=full cargo clippy --all-targets --all-features -- --cap-lints warn -W clippy::pedantic -W clippy::nursery &> clippy_output
2323
cat clippy_output
24-
! cat clippy_output | grep -q "internal compiler error\|query stack during panic"
24+
! cat clippy_output | grep -q "internal compiler error\|query stack during panic\|E0463"
2525
if [[ $? != 0 ]]; then
2626
return 1
2727
fi

clippy_lints/src/attrs.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
337337
&name_lower,
338338
Some(tool_name.as_str())
339339
) {
340-
CheckLintNameResult::NoLint => (),
340+
// FIXME: can we suggest similar lint names here?
341+
// https://github.com/rust-lang/rust/pull/56992
342+
CheckLintNameResult::NoLint(None) => (),
341343
_ => {
342344
db.span_suggestion(lint.span,
343345
"lowercase the lint name",

clippy_lints/src/enum_variants.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ declare_clippy_lint! {
7575
/// }
7676
/// ```
7777
declare_clippy_lint! {
78-
pub STUTTER,
78+
pub MODULE_NAME_REPETITIONS,
7979
pedantic,
8080
"type names prefixed/postfixed with their containing module's name"
8181
}
@@ -126,7 +126,12 @@ impl EnumVariantNames {
126126

127127
impl LintPass for EnumVariantNames {
128128
fn get_lints(&self) -> LintArray {
129-
lint_array!(ENUM_VARIANT_NAMES, PUB_ENUM_VARIANT_NAMES, STUTTER, MODULE_INCEPTION)
129+
lint_array!(
130+
ENUM_VARIANT_NAMES,
131+
PUB_ENUM_VARIANT_NAMES,
132+
MODULE_NAME_REPETITIONS,
133+
MODULE_INCEPTION
134+
)
130135
}
131136
}
132137

@@ -277,7 +282,7 @@ impl EarlyLintPass for EnumVariantNames {
277282
match item_camel.chars().nth(nchars) {
278283
Some(c) if is_word_beginning(c) => span_lint(
279284
cx,
280-
STUTTER,
285+
MODULE_NAME_REPETITIONS,
281286
item.span,
282287
"item name starts with its containing module's name",
283288
),
@@ -287,7 +292,7 @@ impl EarlyLintPass for EnumVariantNames {
287292
if rmatching == nchars {
288293
span_lint(
289294
cx,
290-
STUTTER,
295+
MODULE_NAME_REPETITIONS,
291296
item.span,
292297
"item name ends with its containing module's name",
293298
);

clippy_lints/src/formatting.rs

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ declare_clippy_lint! {
3131
"suspicious formatting of `*=`, `-=` or `!=`"
3232
}
3333

34-
/// **What it does:** Checks for formatting of `else if`. It lints if the `else`
35-
/// and `if` are not on the same line or the `else` seems to be missing.
34+
/// **What it does:** Checks for formatting of `else`. It lints if the `else`
35+
/// is followed immediately by a newline or the `else` seems to be missing.
3636
///
3737
/// **Why is this bad?** This is probably some refactoring remnant, even if the
3838
/// code is correct, it might look confusing.
@@ -42,19 +42,29 @@ declare_clippy_lint! {
4242
/// **Example:**
4343
/// ```rust,ignore
4444
/// if foo {
45+
/// } { // looks like an `else` is missing here
46+
/// }
47+
///
48+
/// if foo {
4549
/// } if bar { // looks like an `else` is missing here
4650
/// }
4751
///
4852
/// if foo {
4953
/// } else
5054
///
55+
/// { // this is the `else` block of the previous `if`, but should it be?
56+
/// }
57+
///
58+
/// if foo {
59+
/// } else
60+
///
5161
/// if bar { // this is the `else` block of the previous `if`, but should it be?
5262
/// }
5363
/// ```
5464
declare_clippy_lint! {
5565
pub SUSPICIOUS_ELSE_FORMATTING,
5666
style,
57-
"suspicious formatting of `else if`"
67+
"suspicious formatting of `else`"
5868
}
5969

6070
/// **What it does:** Checks for possible missing comma in an array. It lints if
@@ -96,7 +106,7 @@ impl EarlyLintPass for Formatting {
96106
match (&w[0].node, &w[1].node) {
97107
(&ast::StmtKind::Expr(ref first), &ast::StmtKind::Expr(ref second))
98108
| (&ast::StmtKind::Expr(ref first), &ast::StmtKind::Semi(ref second)) => {
99-
check_consecutive_ifs(cx, first, second);
109+
check_missing_else(cx, first, second);
100110
},
101111
_ => (),
102112
}
@@ -105,7 +115,7 @@ impl EarlyLintPass for Formatting {
105115

106116
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
107117
check_assign(cx, expr);
108-
check_else_if(cx, expr);
118+
check_else(cx, expr);
109119
check_array(cx, expr);
110120
}
111121
}
@@ -139,10 +149,18 @@ fn check_assign(cx: &EarlyContext<'_>, expr: &ast::Expr) {
139149
}
140150
}
141151

142-
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else if`.
143-
fn check_else_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
152+
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for weird `else`.
153+
fn check_else(cx: &EarlyContext<'_>, expr: &ast::Expr) {
144154
if let Some((then, &Some(ref else_))) = unsugar_if(expr) {
145-
if unsugar_if(else_).is_some() && !differing_macro_contexts(then.span, else_.span) && !in_macro(then.span) {
155+
if (is_block(else_) || unsugar_if(else_).is_some())
156+
&& !differing_macro_contexts(then.span, else_.span)
157+
&& !in_macro(then.span)
158+
{
159+
// workaround for rust-lang/rust#43081
160+
if expr.span.lo().0 == 0 && expr.span.hi().0 == 0 {
161+
return;
162+
}
163+
146164
// this will be a span from the closing ‘}’ of the “then” block (excluding) to
147165
// the
148166
// “if” of the “else if” block (excluding)
@@ -154,14 +172,19 @@ fn check_else_if(cx: &EarlyContext<'_>, expr: &ast::Expr) {
154172
let else_pos = else_snippet.find("else").expect("there must be a `else` here");
155173

156174
if else_snippet[else_pos..].contains('\n') {
175+
let else_desc = if unsugar_if(else_).is_some() { "if" } else { "{..}" };
176+
157177
span_note_and_lint(
158178
cx,
159179
SUSPICIOUS_ELSE_FORMATTING,
160180
else_span,
161-
"this is an `else if` but the formatting might hide it",
181+
&format!("this is an `else {}` but the formatting might hide it", else_desc),
162182
else_span,
163-
"to remove this lint, remove the `else` or remove the new line between `else` \
164-
and `if`",
183+
&format!(
184+
"to remove this lint, remove the `else` or remove the new line between \
185+
`else` and `{}`",
186+
else_desc,
187+
),
165188
);
166189
}
167190
}
@@ -200,32 +223,47 @@ fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) {
200223
}
201224
}
202225

203-
/// Implementation of the `SUSPICIOUS_ELSE_FORMATTING` lint for consecutive ifs.
204-
fn check_consecutive_ifs(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Expr) {
226+
fn check_missing_else(cx: &EarlyContext<'_>, first: &ast::Expr, second: &ast::Expr) {
205227
if !differing_macro_contexts(first.span, second.span)
206228
&& !in_macro(first.span)
207229
&& unsugar_if(first).is_some()
208-
&& unsugar_if(second).is_some()
230+
&& (is_block(second) || unsugar_if(second).is_some())
209231
{
210232
// where the else would be
211233
let else_span = first.span.between(second.span);
212234

213235
if let Some(else_snippet) = snippet_opt(cx, else_span) {
214236
if !else_snippet.contains('\n') {
237+
let (looks_like, next_thing) = if unsugar_if(second).is_some() {
238+
("an `else if`", "the second `if`")
239+
} else {
240+
("an `else {..}`", "the next block")
241+
};
242+
215243
span_note_and_lint(
216244
cx,
217245
SUSPICIOUS_ELSE_FORMATTING,
218246
else_span,
219-
"this looks like an `else if` but the `else` is missing",
247+
&format!("this looks like {} but the `else` is missing", looks_like),
220248
else_span,
221-
"to remove this lint, add the missing `else` or add a new line before the second \
222-
`if`",
249+
&format!(
250+
"to remove this lint, add the missing `else` or add a new line before {}",
251+
next_thing,
252+
),
223253
);
224254
}
225255
}
226256
}
227257
}
228258

259+
fn is_block(expr: &ast::Expr) -> bool {
260+
if let ast::ExprKind::Block(..) = expr.node {
261+
true
262+
} else {
263+
false
264+
}
265+
}
266+
229267
/// Match `if` or `if let` expressions and return the `then` and `else` block.
230268
fn unsugar_if(expr: &ast::Expr) -> Option<(&P<ast::Block>, &Option<P<ast::Expr>>)> {
231269
match expr.node {

clippy_lints/src/implicit_return.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,19 @@ declare_clippy_lint! {
4545
pub struct Pass;
4646

4747
impl Pass {
48+
fn lint(cx: &LateContext<'_, '_>, outer_span: syntax_pos::Span, inner_span: syntax_pos::Span, msg: &str) {
49+
span_lint_and_then(cx, IMPLICIT_RETURN, outer_span, "missing return statement", |db| {
50+
if let Some(snippet) = snippet_opt(cx, inner_span) {
51+
db.span_suggestion_with_applicability(
52+
outer_span,
53+
msg,
54+
format!("return {}", snippet),
55+
Applicability::MachineApplicable,
56+
);
57+
}
58+
});
59+
}
60+
4861
fn expr_match(cx: &LateContext<'_, '_>, expr: &rustc::hir::Expr) {
4962
match &expr.node {
5063
// loops could be using `break` instead of `return`
@@ -55,23 +68,19 @@ impl Pass {
5568
// only needed in the case of `break` with `;` at the end
5669
else if let Some(stmt) = block.stmts.last() {
5770
if let rustc::hir::StmtKind::Semi(expr, ..) = &stmt.node {
58-
Self::expr_match(cx, expr);
71+
// make sure it's a break, otherwise we want to skip
72+
if let ExprKind::Break(.., break_expr) = &expr.node {
73+
if let Some(break_expr) = break_expr {
74+
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
75+
}
76+
}
5977
}
6078
}
6179
},
6280
// use `return` instead of `break`
6381
ExprKind::Break(.., break_expr) => {
6482
if let Some(break_expr) = break_expr {
65-
span_lint_and_then(cx, IMPLICIT_RETURN, expr.span, "missing return statement", |db| {
66-
if let Some(snippet) = snippet_opt(cx, break_expr.span) {
67-
db.span_suggestion_with_applicability(
68-
expr.span,
69-
"change `break` to `return` as shown",
70-
format!("return {}", snippet),
71-
Applicability::MachineApplicable,
72-
);
73-
}
74-
});
83+
Self::lint(cx, expr.span, break_expr.span, "change `break` to `return` as shown");
7584
}
7685
},
7786
ExprKind::If(.., if_expr, else_expr) => {
@@ -89,16 +98,7 @@ impl Pass {
8998
// skip if it already has a return statement
9099
ExprKind::Ret(..) => (),
91100
// everything else is missing `return`
92-
_ => span_lint_and_then(cx, IMPLICIT_RETURN, expr.span, "missing return statement", |db| {
93-
if let Some(snippet) = snippet_opt(cx, expr.span) {
94-
db.span_suggestion_with_applicability(
95-
expr.span,
96-
"add `return` as shown",
97-
format!("return {}", snippet),
98-
Applicability::MachineApplicable,
99-
);
100-
}
101-
}),
101+
_ => Self::lint(cx, expr.span, expr.span, "add `return` as shown"),
102102
}
103103
}
104104
}

clippy_lints/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
517517
doc::DOC_MARKDOWN,
518518
empty_enum::EMPTY_ENUM,
519519
enum_glob_use::ENUM_GLOB_USE,
520+
enum_variants::MODULE_NAME_REPETITIONS,
520521
enum_variants::PUB_ENUM_VARIANT_NAMES,
521-
enum_variants::STUTTER,
522522
if_not_else::IF_NOT_ELSE,
523523
infinite_iter::MAYBE_INFINITE_ITER,
524524
items_after_statements::ITEMS_AFTER_STATEMENTS,
@@ -1030,6 +1030,10 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry<'_>, conf: &Conf) {
10301030
]);
10311031
}
10321032

1033+
pub fn register_renamed(ls: &mut rustc::lint::LintStore) {
1034+
ls.register_renamed("clippy::stutter", "clippy::module_name_repetitions");
1035+
}
1036+
10331037
// only exists to let the dogfood integration test works.
10341038
// Don't run clippy as an executable directly
10351039
#[allow(dead_code)]

clippy_lints/src/map_clone.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ pub struct Pass;
2727
///
2828
/// **Why is this bad?** Readability, this can be written more concisely
2929
///
30-
/// **Known problems:** None.
30+
/// **Known problems:** Sometimes `.cloned()` requires stricter trait
31+
/// bound than `.map(|e| e.clone())` (which works because of the coercion).
32+
/// See [#498](https://github.com/rust-lang-nursery/rust-clippy/issues/498).
3133
///
3234
/// **Example:**
3335
///

0 commit comments

Comments
 (0)