Skip to content

Commit eaeac1a

Browse files
committed
submodules: update clippy from fc24fce to f7bdf50
Fixes clippy toolstate Changes: ```` Match on ast/hir::ExprKind::Err Update *.stderr files Use -Zui-testing flag Mention S-inactive-closed PRs in the CONTRIBUTING.md tests: fix formatting and update test output base tests: make sure to fail CI if tests need formatting base tests: switch to nightly toolchain before checking formatting of tests with rustfmt rustup rust-lang/rust#57069 Rustfmt. fix breakage from rust-lang/rust#57088 fix a couple of ftrivial typos (NFC). update CARGO_CLIPPY_HELP string to suggest tool lints. rustc_tools_util: add readme rustc_tool_utils: expand Cargo.toml with a few keywords in preparation for crates.io release Fix macro detection in `empty_loop`. Changed `macro_backtrace()` to `in_macro()`. Fix lint detection on macro expansion. ````
1 parent aca8f94 commit eaeac1a

File tree

247 files changed

+4864
-4759
lines changed

Some content is hidden

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

247 files changed

+4864
-4759
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ Some issues are easier than others. The [`good first issue`](https://github.com/
4242
label can be used to find the easy issues. If you want to work on an issue, please leave a comment
4343
so that we can assign it to you!
4444

45+
There are also some abandoned PRs, marked with
46+
[`S-inactive-closed`](https://github.com/rust-lang/rust-clippy/pulls?q=is%3Aclosed+label%3AS-inactive-closed).
47+
Pretty often these PRs are nearly completed and just need some extra steps
48+
(formatting, addressing review comments, ...) to be merged. If you want to
49+
complete such a PR, please leave a comment in the PR and open a new one based
50+
on it.
51+
4552
Issues marked [`T-AST`](https://github.com/rust-lang/rust-clippy/labels/T-AST) involve simple
4653
matching of the syntax tree structure, and are generally easier than
4754
[`T-middle`](https://github.com/rust-lang/rust-clippy/labels/T-middle) issues, which involve types

ci/base-tests.sh

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,29 @@ cd ..
3535
./util/dev update_lints --check
3636
cargo +nightly fmt --all -- --check
3737

38-
39-
#avoid loop spam
40-
set +x
4138
# make sure tests are formatted
4239

4340
# some lints are sensitive to formatting, exclude some files
44-
needs_formatting=false
41+
tests_need_reformatting="false"
42+
# switch to nightly
43+
rustup default nightly
44+
# avoid loop spam and allow cmds with exit status != 0
45+
set +ex
46+
4547
for file in `find tests -not -path "tests/ui/methods.rs" -not -path "tests/ui/format.rs" -not -path "tests/ui/formatting.rs" -not -path "tests/ui/empty_line_after_outer_attribute.rs" -not -path "tests/ui/double_parens.rs" -not -path "tests/ui/doc.rs" -not -path "tests/ui/unused_unit.rs" | grep "\.rs$"` ; do
46-
rustfmt ${file} --check || echo "${file} needs reformatting!" ; needs_formatting=true
48+
rustfmt ${file} --check
49+
if [ $? -ne 0 ]; then
50+
echo "${file} needs reformatting!"
51+
tests_need_reformatting="true"
52+
fi
4753
done
4854

49-
if [ "${needs_reformatting}" = true ] ; then
55+
set -ex # reset
56+
57+
if [ "${tests_need_reformatting}" == "true" ] ; then
5058
echo "Tests need reformatting!"
5159
exit 2
5260
fi
53-
set -x
61+
62+
# switch back to master
63+
rustup default master

clippy_dev/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn test_gen_deprecated() {
432432
"should_assert_eq",
433433
"group1",
434434
"abc",
435-
Some("has been superseeded by should_assert_eq2"),
435+
Some("has been superseded by should_assert_eq2"),
436436
"module_name",
437437
),
438438
Lint::new(
@@ -447,7 +447,7 @@ fn test_gen_deprecated() {
447447
let expected: Vec<String> = vec![
448448
" store.register_removed(",
449449
" \"should_assert_eq\",",
450-
" \"has been superseeded by should_assert_eq2\",",
450+
" \"has been superseded by should_assert_eq2\",",
451451
" );",
452452
" store.register_removed(",
453453
" \"another_deprecated\",",

clippy_lints/src/double_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::syntax::source_map::Span;
1717

1818
use crate::utils::{snippet_with_applicability, span_lint_and_sugg, SpanlessEq};
1919

20-
/// **What it does:** Checks for double comparions that could be simpified to a single expression.
20+
/// **What it does:** Checks for double comparions that could be simplified to a single expression.
2121
///
2222
///
2323
/// **Why is this bad?** Readability.

clippy_lints/src/implicit_return.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
1212
use crate::rustc::{declare_tool_lint, lint_array};
1313
use crate::rustc_errors::Applicability;
1414
use crate::syntax::{ast::NodeId, source_map::Span};
15-
use crate::utils::{snippet_opt, span_lint_and_then};
15+
use crate::utils::{in_macro, snippet_opt, span_lint_and_then};
1616

1717
/// **What it does:** Checks for missing return statements at the end of a block.
1818
///
@@ -116,14 +116,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
116116
_: FnKind<'tcx>,
117117
_: &'tcx FnDecl,
118118
body: &'tcx Body,
119-
_: Span,
119+
span: Span,
120120
_: NodeId,
121121
) {
122122
let def_id = cx.tcx.hir().body_owner_def_id(body.id());
123123
let mir = cx.tcx.optimized_mir(def_id);
124124

125125
// checking return type through MIR, HIR is not able to determine inferred closure return types
126-
if !mir.return_ty().is_unit() {
126+
// make sure it's not a macro
127+
if !mir.return_ty().is_unit() && !in_macro(span) {
127128
Self::expr_match(cx, &body.value);
128129
}
129130
}

clippy_lints/src/loops.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,11 @@ impl LintPass for Pass {
478478

479479
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
480480
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
481+
// we don't want to check expanded macros
482+
if in_macro(expr.span) {
483+
return;
484+
}
485+
481486
if let Some((pat, arg, body)) = higher::for_loop(expr) {
482487
check_for_loop(cx, pat, arg, body, expr);
483488
}
@@ -751,7 +756,8 @@ fn never_loop_expr(expr: &Expr, main_loop_id: NodeId) -> NeverLoopResult {
751756
| ExprKind::Closure(_, _, _, _, _)
752757
| ExprKind::InlineAsm(_, _, _)
753758
| ExprKind::Path(_)
754-
| ExprKind::Lit(_) => NeverLoopResult::Otherwise,
759+
| ExprKind::Lit(_)
760+
| ExprKind::Err => NeverLoopResult::Otherwise,
755761
}
756762
}
757763

clippy_lints/src/utils/author.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,9 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor {
504504
self.current = value_pat;
505505
self.visit_expr(value);
506506
},
507+
ExprKind::Err => {
508+
println!("Err = {}", current);
509+
},
507510
}
508511
}
509512

clippy_lints/src/utils/hir_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
615615
self.hash_name(l.ident.name);
616616
}
617617
},
618+
ExprKind::Err => {},
618619
}
619620
}
620621

clippy_lints/src/utils/inspector.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) {
347347
println!("{}repeat count:", ind);
348348
print_expr(cx, &cx.tcx.hir().body(anon_const.body).value, indent + 1);
349349
},
350+
hir::ExprKind::Err => {
351+
println!("{}Err", ind);
352+
},
350353
}
351354
}
352355

clippy_lints/src/utils/sugg.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ impl<'a> Sugg<'a> {
7979
| hir::ExprKind::Ret(..)
8080
| hir::ExprKind::Struct(..)
8181
| hir::ExprKind::Tup(..)
82-
| hir::ExprKind::While(..) => Sugg::NonParen(snippet),
82+
| hir::ExprKind::While(..)
83+
| hir::ExprKind::Err => Sugg::NonParen(snippet),
8384
hir::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),
8485
hir::ExprKind::AssignOp(op, ..) => Sugg::BinOp(hirbinop2assignop(op), snippet),
8586
hir::ExprKind::Binary(op, ..) => Sugg::BinOp(AssocOp::from_ast_binop(higher::binop(op.node)), snippet),
@@ -158,7 +159,8 @@ impl<'a> Sugg<'a> {
158159
| ast::ExprKind::Tup(..)
159160
| ast::ExprKind::Array(..)
160161
| ast::ExprKind::While(..)
161-
| ast::ExprKind::WhileLet(..) => Sugg::NonParen(snippet),
162+
| ast::ExprKind::WhileLet(..)
163+
| ast::ExprKind::Err => Sugg::NonParen(snippet),
162164
ast::ExprKind::Range(.., RangeLimits::HalfOpen) => Sugg::BinOp(AssocOp::DotDot, snippet),
163165
ast::ExprKind::Range(.., RangeLimits::Closed) => Sugg::BinOp(AssocOp::DotDotEq, snippet),
164166
ast::ExprKind::Assign(..) => Sugg::BinOp(AssocOp::Assign, snippet),

clippy_lints/src/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl EarlyLintPass for Pass {
257257
}
258258

259259
/// Checks the arguments of `print[ln]!` and `write[ln]!` calls. It will return a tuple of two
260-
/// options. The first part of the tuple is `format_str` of the macros. The secund part of the tuple
260+
/// options. The first part of the tuple is `format_str` of the macros. The second part of the tuple
261261
/// is in the `write[ln]!` case the expression the `format_str` should be written to.
262262
///
263263
/// Example:
@@ -292,7 +292,7 @@ fn check_tts<'a>(cx: &EarlyContext<'a>, tts: &ThinTokenStream, is_write: bool) -
292292
};
293293
let tmp = fmtstr.clone();
294294
let mut args = vec![];
295-
let mut fmt_parser = Parser::new(&tmp, None);
295+
let mut fmt_parser = Parser::new(&tmp, None, Vec::new(), false);
296296
while let Some(piece) = fmt_parser.next() {
297297
if !fmt_parser.errors.is_empty() {
298298
return (None, expr);

rustc_tools_util/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,11 @@
22
name = "rustc_tools_util"
33
version = "0.1.0"
44
authors = ["Matthias Krüger <[email protected]>"]
5+
description = "small helper to generate version information for git packages"
6+
repository = "https://github.com/rust-lang/rust-clippy"
7+
readme = "README.md"
8+
license = "MIT/Apache-2.0"
9+
keywords = ["rustc", "tool", "git", "version", "hash"]
10+
categories = ["development-tools"]
511
edition = "2018"
612
[dependencies]

rustc_tools_util/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# rustc_tools_util
2+
3+
A small tool to help you generate version information
4+
for packages installed from a git repo
5+
6+
## Usage
7+
8+
Add a `build.rs` file to your repo and list it in `Cargo.toml`
9+
````
10+
build = "build.rs"
11+
````
12+
13+
List rustc_tools_util as regular AND build dependency.
14+
````
15+
[dependencies]
16+
rustc_tools_util = "0.1"
17+
18+
[build-dependencies]
19+
rustc_tools_util = "0.1"
20+
````
21+
22+
In `build.rs`, generate the data in your `main()`
23+
````rust
24+
fn main() {
25+
println!(
26+
"cargo:rustc-env=GIT_HASH={}",
27+
rustc_tools_util::get_commit_hash().unwrap_or_default()
28+
);
29+
println!(
30+
"cargo:rustc-env=COMMIT_DATE={}",
31+
rustc_tools_util::get_commit_date().unwrap_or_default()
32+
);
33+
}
34+
35+
````
36+
37+
Use the version information in your main.rs
38+
````rust
39+
use rustc_tools_util::*;
40+
41+
fn show_version() {
42+
let version_info = rustc_tools_util::get_version_info!();
43+
println!("{}", version_info);
44+
}
45+
````
46+
This gives the following output in clippy:
47+
`clippy 0.0.212 (a416c5e 2018-12-14)`
48+
49+
50+
## License
51+
52+
Copyright 2014-2018 The Rust Project Developers
53+
54+
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
55+
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
56+
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
57+
option. All files in the project carrying such notice may not be
58+
copied, modified, or distributed except according to those terms.

src/main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ with:
3333
-D --deny OPT Set lint denied
3434
-F --forbid OPT Set lint forbidden
3535
36-
The feature `cargo-clippy` is automatically defined for convenience. You can use
37-
it to allow or deny lints from the code, eg.:
36+
You can use tool lints to allow or deny lints from your code, eg.:
3837
39-
#[cfg_attr(feature = "cargo-clippy", allow(needless_lifetimes))]
38+
#[allow(clippy::needless_lifetimes)]
4039
"#;
4140

4241
fn show_help() {

tests/compile-test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ fn config(mode: &str, dir: PathBuf) -> compiletest::Config {
5555
config.run_lib_path = rustc_lib_path();
5656
config.compile_lib_path = rustc_lib_path();
5757
}
58-
config.target_rustcflags = Some(format!("-L {0} -L {0}/deps -Dwarnings", host_libs().display()));
58+
config.target_rustcflags = Some(format!(
59+
"-L {0} -L {0}/deps -Dwarnings -Zui-testing",
60+
host_libs().display()
61+
));
5962

6063
config.mode = cfg_mode;
6164
config.build_base = if rustc_test_suite().is_some() {

tests/ui-toml/toml_blacklist/conf_french_blacklisted_name.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
error: use of a blacklisted/placeholder name `toto`
22
--> $DIR/conf_french_blacklisted_name.rs:15:9
33
|
4-
15 | fn test(toto: ()) {}
4+
LL | fn test(toto: ()) {}
55
| ^^^^
66
|
77
= note: `-D clippy::blacklisted-name` implied by `-D warnings`
88

99
error: use of a blacklisted/placeholder name `toto`
1010
--> $DIR/conf_french_blacklisted_name.rs:18:9
1111
|
12-
18 | let toto = 42;
12+
LL | let toto = 42;
1313
| ^^^^
1414

1515
error: use of a blacklisted/placeholder name `tata`
1616
--> $DIR/conf_french_blacklisted_name.rs:19:9
1717
|
18-
19 | let tata = 42;
18+
LL | let tata = 42;
1919
| ^^^^
2020

2121
error: use of a blacklisted/placeholder name `titi`
2222
--> $DIR/conf_french_blacklisted_name.rs:20:9
2323
|
24-
20 | let titi = 42;
24+
LL | let titi = 42;
2525
| ^^^^
2626

2727
error: use of a blacklisted/placeholder name `toto`
2828
--> $DIR/conf_french_blacklisted_name.rs:26:10
2929
|
30-
26 | (toto, Some(tata), titi @ Some(_)) => (),
30+
LL | (toto, Some(tata), titi @ Some(_)) => (),
3131
| ^^^^
3232

3333
error: use of a blacklisted/placeholder name `tata`
3434
--> $DIR/conf_french_blacklisted_name.rs:26:21
3535
|
36-
26 | (toto, Some(tata), titi @ Some(_)) => (),
36+
LL | (toto, Some(tata), titi @ Some(_)) => (),
3737
| ^^^^
3838

3939
error: use of a blacklisted/placeholder name `titi`
4040
--> $DIR/conf_french_blacklisted_name.rs:26:28
4141
|
42-
26 | (toto, Some(tata), titi @ Some(_)) => (),
42+
LL | (toto, Some(tata), titi @ Some(_)) => (),
4343
| ^^^^
4444

4545
error: aborting due to 7 previous errors

tests/ui-toml/toml_trivially_copy/test.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
error: this argument is passed by reference, but would be more efficient if passed by value
22
--> $DIR/test.rs:20:11
33
|
4-
20 | fn bad(x: &u16, y: &Foo) {}
4+
LL | fn bad(x: &u16, y: &Foo) {}
55
| ^^^^ help: consider passing by value instead: `u16`
66
|
77
= note: `-D clippy::trivially-copy-pass-by-ref` implied by `-D warnings`
88

99
error: this argument is passed by reference, but would be more efficient if passed by value
1010
--> $DIR/test.rs:20:20
1111
|
12-
20 | fn bad(x: &u16, y: &Foo) {}
12+
LL | fn bad(x: &u16, y: &Foo) {}
1313
| ^^^^ help: consider passing by value instead: `Foo`
1414

1515
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)