Skip to content

Update Clippy #78774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 107 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
32e2021
Lint items after statements in macro expansions
achris Oct 15, 2020
de5a6d3
Initial implementation of comparison_to_empty
Urcra Oct 25, 2020
7f7faa1
Move implementation into len_zero.rs
Urcra Oct 25, 2020
4417af8
Revert changes to Cargo.toml file
Urcra Oct 25, 2020
deecfb5
Add description to lint
Urcra Oct 26, 2020
4cf5b5f
Run update lints
Urcra Oct 26, 2020
4532dd9
run cargo fmt
Urcra Oct 26, 2020
45aa3ef
Remove unnecesary format
Urcra Oct 26, 2020
f0cf3bd
Add lint for replacing `.map().collect()` with `.try_for_each()`
HMPerson1 Oct 26, 2020
bab3386
No lint in external macro for `toplevel_ref_arg`
ThibsG Oct 24, 2020
2911d9c
Use better placeholders for some methods lint messages
ThibsG Oct 18, 2020
3fec6f5
Improve some suggestions for `filter_map_next`, `filter_next` and `ma…
ThibsG Oct 19, 2020
2a3ae11
Move fixable `map_unwrap_or` cases to rustfixed test
ThibsG Oct 23, 2020
e2d86b5
Move fixable `filter_next` and `filter_map_next` cases to rustfixed t…
ThibsG Oct 23, 2020
c0dd1f9
Fix tests for `map_unwrap_or*`
ThibsG Oct 26, 2020
213dbf7
clippy_lint: Add 'ref_option_ref'
dvermd Oct 12, 2020
d1baa25
clippy_lint: Add 'ref_option_ref' refactor code
dvermd Oct 13, 2020
469b2fc
clippy_lint: Add 'ref_option_ref' move to check_ty and add type alias…
dvermd Oct 13, 2020
c1f3bab
clippy_lint: Add 'ref_option_ref' remove unused import
dvermd Oct 13, 2020
bdd76a9
clippy_lint: Allow 'ref_option_ref' for 'option_if_let_else'
dvermd Oct 13, 2020
b41b38c
clippy_lint: Refactor 'ref_option_ref'
dvermd Oct 13, 2020
2270ff4
clippy_lint: Add test cases
dvermd Oct 15, 2020
8e26004
Update clippy_lints/src/ref_option_ref.rs doctest
dvermd Oct 19, 2020
1566db7
Update clippy_lints/src/ref_option_ref.rs
dvermd Oct 19, 2020
7fd74c6
clippy_lint: Add Known Problems message
dvermd Oct 19, 2020
db40a07
Update clippy_lints/src/ref_option_ref.rs
dvermd Oct 19, 2020
ffddb66
clippy_lint: run after changing category to pendantic
dvermd Oct 20, 2020
8337c46
Change Applicability to MaybeIncorrect
dvermd Oct 26, 2020
6212950
Explain why 'run-rustfix' is not defined
dvermd Oct 26, 2020
e568a32
fix the error-causing suggestion of 'borrowed_box'
rail-rain Oct 20, 2020
111b902
add manual_ok_or lint
tnielens Oct 27, 2020
8bd1e23
Replace `E-easy` with `good first issue` in `CONTRIBUTING.md`
giraffate Oct 27, 2020
4c58860
Fix suggestion to add unneeded space in `unused_unit`
giraffate Oct 27, 2020
0d6eed1
use diff -u in driver.sh test
matthiaskrgr Oct 28, 2020
4f1240f
Auto merge of #6263 - matthiaskrgr:diff_u, r=ebroto
bors Oct 28, 2020
abd64d7
add a couple of ICE testcases
matthiaskrgr Oct 28, 2020
5041911
Merge commit '645ef505da378b6f810b1567806d1bcc2856395f' into clippyup
ebroto Oct 28, 2020
7f3462a
cargo dev ra-setup: don't inject deps multiple times if we have alrea…
matthiaskrgr Oct 29, 2020
6d5cd6e
Auto merge of #6264 - matthiaskrgr:ra_setup_no_twice, r=llogiq
bors Oct 29, 2020
e97602e
Update existing arithmetic lint and add new tests related to it.
henil Oct 26, 2020
e8de57c
Auto merge of #6212 - ThibsG:MacroTopLevelRefArg, r=flip1995
bors Oct 29, 2020
e3de544
Remove empty lines in doc comment
Urcra Oct 29, 2020
ee9da9a
Auto merge of #6176 - achris:issues/578, r=phansch
bors Oct 29, 2020
e1a2845
Auto merge of #6226 - Urcra:master, r=flip1995
bors Oct 29, 2020
38ec920
Update CONTRIBUTING.md to describe `E-medium` in detail
giraffate Oct 29, 2020
c57d8ae
Auto merge of #6227 - HMPerson1:collect_map, r=phansch
bors Oct 29, 2020
e01d487
Auto merge of #6248 - giraffate:replace_e_easy_with_good_first_issue,…
bors Oct 29, 2020
230d9cb
Update clippy_lints/src/ref_option_ref.rs
dvermd Oct 29, 2020
7b065db
clippy: update reference file to match suggested change
dvermd Oct 29, 2020
d780f61
add manual_ok_or / pr remarks
tnielens Oct 29, 2020
74d8fbb
Auto merge of #6200 - rail-rain:borrowed_box_invalid_sugg, r=phansch
bors Oct 30, 2020
fa79cc4
TypeVisitor: use `ControlFlow` in clippy
LeSeulArtichaut Oct 21, 2020
4a06145
Use `ControlFlow::is{break,continue}`
LeSeulArtichaut Oct 22, 2020
1c8c3d1
Remove implicit `Continue` type
LeSeulArtichaut Oct 25, 2020
fa0a78b
removed lint for division/modulo for literal `0`
henil Oct 30, 2020
0be6544
Auto merge of #6229 - henil:improve-integer-division-lint, r=phansch
bors Oct 30, 2020
9f402c9
Clarify allow/warn/deny. Remove enable/disable.
ClashTheBunny Oct 30, 2020
7387b87
Auto merge of #6197 - ThibsG:ImproveFilterNext, r=ebroto
bors Oct 30, 2020
084b203
Auto merge of #6260 - matthiaskrgr:ices, r=ebroto
bors Oct 30, 2020
2350ee7
single_char_push_str lint using insert_str() on single-char literals …
matthiaskrgr Sep 13, 2020
c6412ae
handle macros returning Strings in single_char_push_str and single_ch…
matthiaskrgr Sep 14, 2020
c1eb8ce
get_hint_if_single_char_arg: fix bug where multi-char letters are not…
matthiaskrgr Sep 24, 2020
d958269
Rename single_char_push_str to single_char_add_str
ebroto Oct 7, 2020
f8ac1f9
Address suggestions in PR review
ebroto Oct 30, 2020
4bbc771
Update Clippy path to `Lint`
Aaron1011 Oct 31, 2020
9d73371
Merge remote-tracking branch 'upstream/master' into rustup
ebroto Oct 31, 2020
2eb248d
Fix formatting
ebroto Oct 31, 2020
a6b3a40
Auto merge of #6277 - ebroto:rustup, r=ebroto
bors Oct 31, 2020
edfa13d
Fix typo in adding_lints.md
dp304 Oct 31, 2020
e298c83
Auto merge of #6276 - dp304:patch-1, r=llogiq
bors Oct 31, 2020
7b203f3
Implement field_reassign_with_default
Oct 31, 2019
8a18963
Auto merge of #75534 - Aaron1011:feature/new-future-breakage, r=pnkfelix
bors Nov 1, 2020
4a3a249
Merge remote-tracking branch 'upstream/master' into sync-from-rust
giraffate Nov 2, 2020
5f97326
Provide diagnostic suggestion in ExprUseVisitor Delegate
null-sleep Nov 1, 2020
c45255b
Auto merge of #6282 - giraffate:sync-from-rust, r=ebroto
bors Nov 2, 2020
22cc77a
Use const rustc sym where possible
camsteffen Nov 2, 2020
b2332a7
Change lint to use const sym
camsteffen Nov 2, 2020
3ee9c2e
Auto merge of #6037 - matthiaskrgr:single_char_insert, r=flip1995
bors Nov 3, 2020
315bab0
Add `from_iter_instead_of_collect` lint implementation
pitiK3U Sep 10, 2020
9d6eedf
Run `cargo dev update_lints`
pitiK3U Sep 10, 2020
1b117f4
Add tests for `from_iter_instead_of_collect`
pitiK3U Sep 10, 2020
8a5d78b
Fix `from_iter_instead_of_collect` lint crashing on exprs without pat…
pitiK3U Sep 11, 2020
a856706
Update: stderr message format
pitiK3U Oct 1, 2020
8906040
Improvements from PR feedback
pitiK3U Oct 1, 2020
0ab96ba
Allow lint
pitiK3U Oct 1, 2020
e320dd3
Improve: error message
pitiK3U Oct 1, 2020
854f2ce
Run `cargo dev fmt`
pitiK3U Oct 1, 2020
abdb7ae
Remove backticks
pitiK3U Oct 1, 2020
f359fb8
Improve error message
pitiK3U Oct 1, 2020
52d1ea3
Fix: Don't show lint for types that doesn't implement Iterator
pitiK3U Oct 12, 2020
ddf23d6
Fix: Use `.collect()` instead of `::fromIterator()`
pitiK3U Oct 24, 2020
a2bf404
Auto merge of #6101 - pitiK3U:from_iter_instead_of_collect, r=flip1995
bors Nov 3, 2020
2fe87a8
Auto merge of #6165 - dvermd:ref_option_ref, r=flip1995
bors Nov 3, 2020
225ce5f
Auto merge of #6233 - montrivo:manual_ok_or, r=flip1995
bors Nov 3, 2020
cf2043d
Update wording to avoid code having "lint" metaphor
ClashTheBunny Nov 3, 2020
3a34bc0
Auto merge of #6270 - ClashTheBunny:clarify_allow_deny_enable_disable…
bors Nov 4, 2020
c2cf40c
Auto merge of #6284 - camsteffen:rustc-sym, r=flip1995
bors Nov 4, 2020
6fdbde5
Split the "raw integer bytes" part out of `Scalar`
oli-obk Sep 26, 2020
83edb2f
s/Scalar::Raw/Scalar::Int
oli-obk Nov 1, 2020
834ad5c
Merge remote-tracking branch 'upstream/master' into rustup
ebroto Nov 4, 2020
f5166e8
Run cargo dev fmt
ebroto Nov 4, 2020
62c0d29
Auto merge of #6292 - ebroto:rustup, r=ebroto
bors Nov 4, 2020
5b52474
Auto merge of #5911 - hegza:issue-568, r=ebroto
bors Nov 4, 2020
0d2f1ae
Auto merge of #6247 - giraffate:fix_suggestion_to_add_space_in_unused…
bors Nov 4, 2020
0c1531a
Auto merge of #78662 - sexxi-goose:add_expr_id_to_delegate, r=nikomat…
bors Nov 4, 2020
b20d4c1
Auto merge of #6296 - flip1995:rustup, r=flip1995
bors Nov 5, 2020
46c714f
Merge commit 'b20d4c155d2fe3a8391f86dcf9a8c49e17188703' into clippyup
flip1995 Nov 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/tools/clippy/.github/driver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ unset CARGO_MANIFEST_DIR
# FIXME: How to match the clippy invocation in compile-test.rs?
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/double_neg.rs 2>double_neg.stderr && exit 1
sed -e "s,tests/ui,\$DIR," -e "/= help/d" double_neg.stderr >normalized.stderr
diff normalized.stderr tests/ui/double_neg.stderr
diff -u normalized.stderr tests/ui/double_neg.stderr

# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
SYSROOT=$(rustc --print sysroot)
diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)
diff -u <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)

echo "fn main() {}" >target/driver_test.rs
# we can't run 2 rustcs on the same file at the same time
CLIPPY=$(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc)
RUSTC=$(rustc ./target/driver_test.rs)
diff <($CLIPPY) <($RUSTC)
diff -u <($CLIPPY) <($RUSTC)

# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR
10 changes: 8 additions & 2 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Current beta, release 2020-11-19
* [`map_err_ignore`] [#5998](https://github.com/rust-lang/rust-clippy/pull/5998)
* [`rc_buffer`] [#6044](https://github.com/rust-lang/rust-clippy/pull/6044)
* [`to_string_in_display`] [#5831](https://github.com/rust-lang/rust-clippy/pull/5831)
* [`single_char_push_str`] [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)
* `single_char_push_str` [#5881](https://github.com/rust-lang/rust-clippy/pull/5881)

### Moves and Deprecations

Expand Down Expand Up @@ -1665,6 +1665,7 @@ Released 2018-09-13
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
[`comparison_to_empty`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_to_empty
[`copy_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#copy_iterator
[`create_dir`]: https://rust-lang.github.io/rust-clippy/master/index.html#create_dir
[`crosspointer_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#crosspointer_transmute
Expand Down Expand Up @@ -1713,6 +1714,7 @@ Released 2018-09-13
[`extend_from_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#extend_from_slice
[`extra_unused_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
Expand All @@ -1731,6 +1733,7 @@ Released 2018-09-13
[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
[`future_not_send`]: https://rust-lang.github.io/rust-clippy/master/index.html#future_not_send
[`get_last_with_len`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_last_with_len
[`get_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#get_unwrap
Expand Down Expand Up @@ -1795,13 +1798,15 @@ Released 2018-09-13
[`manual_async_fn`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_async_fn
[`manual_memcpy`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_memcpy
[`manual_non_exhaustive`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
[`manual_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_unwrap_or
[`many_single_char_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#many_single_char_names
[`map_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_clone
[`map_collect_result_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_collect_result_unit
[`map_entry`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_entry
[`map_err_ignore`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_err_ignore
[`map_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
Expand Down Expand Up @@ -1917,6 +1922,7 @@ Released 2018-09-13
[`redundant_pub_crate`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
Expand All @@ -1937,8 +1943,8 @@ Released 2018-09-13
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
[`single_char_add_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_add_str
[`single_char_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_pattern
[`single_char_push_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_char_push_str
[`single_component_path_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_component_path_imports
[`single_element_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_element_loop
[`single_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#single_match
Expand Down
7 changes: 4 additions & 3 deletions src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ To figure out how this syntax structure is encoded in the AST, it is recommended
Usually the lint will end up to be a nested series of matches and ifs, [like so][deep-nesting].
But we can make it nest-less by using [if_chain] macro, [like this][nest-less].

[`E-medium`] issues are generally pretty easy too, though it's recommended you work on an E-easy issue first.
They are mostly classified as [`E-medium`], since they might be somewhat involved code wise,
but not difficult per-se.
[`E-medium`] issues are generally pretty easy too, though it's recommended you work on an [`good first issue`]
first. Sometimes they are only somewhat involved code wise, but not difficult per-se.
Note that [`E-medium`] issues may require some knowledge of Clippy internals or some
debugging to find the actual problem behind the issue.

[`T-middle`] issues can be more involved and require verifying types. The [`ty`] module contains a
lot of methods that are useful, though one of the most useful would be `expr_ty` (gives the type of
Expand Down
15 changes: 9 additions & 6 deletions src/tools/clippy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,21 @@ You can add options to your code to `allow`/`warn`/`deny` Clippy lints:

* `allow`/`warn`/`deny` can be limited to a single function or module using `#[allow(...)]`, etc.

Note: `deny` produces errors instead of warnings.
Note: `allow` means to suppress the lint for your code. With `warn` the lint
will only emit a warning, while with `deny` the lint will emit an error, when
triggering for your code. An error causes clippy to exit with an error code, so
is useful in scripts like CI/CD.

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:
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:

To disable `lint_name`, run
To allow `lint_name`, run

```terminal
cargo clippy -- -A clippy::lint_name
```

And to enable `lint_name`, run
And to warn on `lint_name`, run

```terminal
cargo clippy -- -W clippy::lint_name
Expand All @@ -190,7 +193,7 @@ can run Clippy with warnings for all lints enabled:
cargo clippy -- -W clippy::pedantic
```

If you care only about a single lint, you can allow all others and then explicitly reenable
If you care only about a single lint, you can allow all others and then explicitly warn on
the lint(s) you are interested in:
```terminal
cargo clippy -- -A clippy::all -W clippy::useless_format -W clippy::...
Expand Down
11 changes: 10 additions & 1 deletion src/tools/clippy/clippy_dev/src/ra_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::path::PathBuf;
// code. See https://github.com/rust-analyzer/rust-analyzer/issues/3517 and https://github.com/rust-lang/rust-clippy/issues/5514 for details

pub fn run(rustc_path: Option<&str>) {
// we can unwrap here because the arg is required here
// we can unwrap here because the arg is required by clap
let rustc_path = PathBuf::from(rustc_path.unwrap());
assert!(rustc_path.is_dir(), "path is not a directory");
let rustc_source_basedir = rustc_path.join("compiler");
Expand Down Expand Up @@ -49,6 +49,15 @@ fn inject_deps_into_manifest(
cargo_toml: &str,
lib_rs: &str,
) -> std::io::Result<()> {
// do not inject deps if we have aleady done so
if cargo_toml.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") {
eprintln!(
"cargo dev ra-setup: warning: deps already found inside {}, doing nothing.",
manifest_path
);
return Ok(());
}

let extern_crates = lib_rs
.lines()
// get the deps
Expand Down
25 changes: 22 additions & 3 deletions src/tools/clippy/clippy_lints/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,28 @@ impl<'tcx> LateLintPass<'tcx> for Arithmetic {

let (l_ty, r_ty) = (cx.typeck_results().expr_ty(l), cx.typeck_results().expr_ty(r));
if l_ty.peel_refs().is_integral() && r_ty.peel_refs().is_integral() {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
} else if l_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
match op.node {
hir::BinOpKind::Div | hir::BinOpKind::Rem => match &r.kind {
hir::ExprKind::Lit(_lit) => (),
hir::ExprKind::Unary(hir::UnOp::UnNeg, expr) => {
if let hir::ExprKind::Lit(lit) = &expr.kind {
if let rustc_ast::ast::LitKind::Int(1, _) = lit.node {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
}
}
},
_ => {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
},
},
_ => {
span_lint(cx, INTEGER_ARITHMETIC, expr.span, "integer arithmetic detected");
self.expr_span = Some(expr.span);
},
}
} else if r_ty.peel_refs().is_floating_point() && r_ty.peel_refs().is_floating_point() {
span_lint(cx, FLOAT_ARITHMETIC, expr.span, "floating-point arithmetic detected");
self.expr_span = Some(expr.span);
}
Expand Down
22 changes: 11 additions & 11 deletions src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use rustc_middle::lint::in_external_macro;
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::sym;
use rustc_span::symbol::{Symbol, SymbolStr};
use semver::Version;

Expand Down Expand Up @@ -286,14 +287,14 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
},
_ => {},
}
if items.is_empty() || !attr.has_name(sym!(deprecated)) {
if items.is_empty() || !attr.has_name(sym::deprecated) {
return;
}
for item in items {
if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.kind;
if mi.has_name(sym!(since));
if mi.has_name(sym::since);
then {
check_semver(cx, item.span(), lit);
}
Expand All @@ -309,7 +310,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
}
match item.kind {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym!(macro_use)));
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym::macro_use));

for attr in item.attrs {
if in_external_macro(cx.sess(), attr.span) {
Expand All @@ -326,7 +327,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
match item.kind {
ItemKind::Use(..) => {
if is_word(lint, sym!(unused_imports))
|| is_word(lint, sym!(deprecated))
|| is_word(lint, sym::deprecated)
|| is_word(lint, sym!(unreachable_pub))
|| is_word(lint, sym!(unused))
|| extract_clippy_lint(lint)
Expand Down Expand Up @@ -411,8 +412,7 @@ fn check_clippy_lint_names(cx: &LateContext<'_>, ident: &str, items: &[NestedMet
let lint_store = cx.lints();
for lint in items {
if let Some(lint_name) = extract_clippy_lint(lint) {
if let CheckLintNameResult::Tool(Err((None, _))) =
lint_store.check_lint_name(&lint_name, Some(sym!(clippy)))
if let CheckLintNameResult::Tool(Err((None, _))) = lint_store.check_lint_name(&lint_name, Some(sym::clippy))
{
span_lint_and_then(
cx,
Expand Down Expand Up @@ -529,10 +529,10 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut

for attr in attrs {
if let Some(values) = attr.meta_item_list() {
if values.len() != 1 || !attr.has_name(sym!(inline)) {
if values.len() != 1 || !attr.has_name(sym::inline) {
continue;
}
if is_word(&values[0], sym!(always)) {
if is_word(&values[0], sym::always) {
span_lint(
cx,
INLINE_ALWAYS,
Expand Down Expand Up @@ -623,12 +623,12 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! {
// check cfg_attr
if attr.has_name(sym!(cfg_attr));
if attr.has_name(sym::cfg_attr);
if let Some(items) = attr.meta_item_list();
if items.len() == 2;
// check for `rustfmt`
if let Some(feature_item) = items[0].meta_item();
if feature_item.has_name(sym!(rustfmt));
if feature_item.has_name(sym::rustfmt);
// check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item();
if skip_item.has_name(sym!(rustfmt_skip)) ||
Expand Down Expand Up @@ -690,7 +690,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
}

if_chain! {
if attr.has_name(sym!(cfg));
if attr.has_name(sym::cfg);
if let Some(list) = attr.meta_item_list();
let mismatched = find_mismatched_target_os(&list);
if !mismatched.is_empty();
Expand Down
5 changes: 3 additions & 2 deletions src/tools/clippy/clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::sym;

declare_clippy_lint! {
/// **What it does:** Checks for boolean expressions that can be written more
Expand Down Expand Up @@ -253,8 +254,8 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
},
ExprKind::MethodCall(path, _, args, _) if args.len() == 1 => {
let type_of_receiver = cx.typeck_results().expr_ty(&args[0]);
if !is_type_diagnostic_item(cx, type_of_receiver, sym!(option_type))
&& !is_type_diagnostic_item(cx, type_of_receiver, sym!(result_type))
if !is_type_diagnostic_item(cx, type_of_receiver, sym::option_type)
&& !is_type_diagnostic_item(cx, type_of_receiver, sym::result_type)
{
return None;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::sym;
use rustc_span::Symbol;

declare_clippy_lint! {
Expand Down Expand Up @@ -68,7 +69,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
let haystack = if let ExprKind::MethodCall(ref path, _, ref args, _) =
filter_args[0].kind {
let p = path.ident.name;
if (p == sym!(iter) || p == sym!(iter_mut)) && args.len() == 1 {
if (p == sym::iter || p == sym!(iter_mut)) && args.len() == 1 {
&args[0]
} else {
&filter_args[0]
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::map::Map;
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
use rustc_span::BytePos;
use rustc_span::{sym, BytePos};

use crate::utils::{is_type_diagnostic_item, snippet_opt, span_lint_and_help, LimitStack};

Expand Down Expand Up @@ -61,7 +61,7 @@ impl CognitiveComplexity {
helper.visit_expr(expr);
let CCHelper { cc, returns } = helper;
let ret_ty = cx.typeck_results().node_type(expr.hir_id);
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym!(result_type)) {
let ret_adjust = if is_type_diagnostic_item(cx, ret_ty, sym::result_type) {
returns
} else {
#[allow(clippy::integer_division)]
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
hir_id: HirId,
) {
let def_id = cx.tcx.hir().local_def_id(hir_id);
if !cx.tcx.has_attr(def_id.to_def_id(), sym!(test)) {
if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) {
self.check(cx, kind, decl, body, span);
}
}
Expand Down
Loading