Skip to content
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

Update Clippy #81038

Merged
merged 77 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c06793b
Add Roadmap for 2021
flip1995 Dec 15, 2020
469281c
Check if never type feature is enabled by TyCtxt before suggesting em…
nahuakang Dec 28, 2020
83a458a
Enable never type in empty enum ui test; run cargo dev bless
nahuakang Dec 28, 2020
275988c
Add additional lint doc to known problems section
nahuakang Dec 28, 2020
af480a6
Ensure `Copy` exception in trait definition for `wrong_self_conventio…
ThibsG Dec 30, 2020
0afe2db
Update CHANGELOG for Rust 1.50
phansch Dec 30, 2020
b81111b
Address review comments
phansch Dec 30, 2020
6b37932
Fix blessing of test output in subdirectories
phansch Dec 31, 2020
6909055
s/test_dir/test_suite_dir
phansch Dec 31, 2020
5d48b91
field_reassign_with_default: don't expand macros in suggestion
matthiaskrgr Jan 1, 2021
ba4bf4f
Merge commit '1fcc74cc9e03bc91eaa80ecf92976b0b14b3aeb6' into clippyup
flip1995 Jan 2, 2021
1853f8b
Add lint
Jarcho Jan 2, 2021
78f6009
Auto merge of #6520 - phansch:update-changelog, r=flip1995
bors Jan 2, 2021
053afe4
Use bootstrap rustc for versioncheck in Clippy
flip1995 Jan 2, 2021
9427e03
Fix clone_on_copy test
Jarcho Jan 2, 2021
d37ee6f
Fix lint errors
Jarcho Jan 2, 2021
592f7eb
Auto merge of #6531 - matthiaskrgr:6522, r=ebroto
bors Jan 2, 2021
a02806e
Auto merge of #6518 - ThibsG:CopyException, r=ebroto
bors Jan 2, 2021
7b5f549
Fix docs: use type inference
Jarcho Jan 3, 2021
8951916
Auto merge of #6525 - phansch:fix-bless-in-subdirs, r=flip1995
bors Jan 4, 2021
d141cdc
Add prioritization chapter and remove unresolved questions
flip1995 Jan 4, 2021
6dcec6a
collapsible_if: split collapsible_else_if into its own lint so we can…
matthiaskrgr Jan 4, 2021
dd1929e
Auto merge of #6544 - matthiaskrgr:else_if, r=flip1995
bors Jan 4, 2021
ba87acb
Implemented needless question mark lint
bengsparks Dec 26, 2020
ae9ae97
Auto merge of #6507 - bengsparks:lint/issue6410, r=flip1995
bors Jan 4, 2021
7acfa44
Add ui-internal to cargo dev bless
camsteffen Dec 31, 2020
cbbb188
Bless only updated since clippy build
camsteffen Dec 31, 2020
445eb99
Auto merge of #6548 - camsteffen:bless-internal, r=flip1995
bors Jan 4, 2021
bc97f5d
Address flip1995's review comments
nahuakang Jan 4, 2021
a8d47b4
Run cargo dev fmt
nahuakang Jan 4, 2021
976850b
Auto merge of #6538 - Jarcho:vec_init_then_push, r=llogiq
bors Jan 4, 2021
4b478a5
Add a new lint `ptr_as_ptr`,
rail-rain Jan 3, 2021
dfa5d7e
Fix the MSRV and add the tests for MSRV
rail-rain Jan 4, 2021
dd52066
Auto merge of #6547 - camsteffen:curse-outdated, r=phansch
bors Jan 5, 2021
311186b
Auto merge of #6513 - nahuakang:fix/empty_enum_lint_never_type, r=fli…
bors Jan 5, 2021
a6b72d3
Auto merge of #6542 - rail-rain:ptr_as_ptr, r=flip1995
bors Jan 5, 2021
ea885d9
Tiny Symbol cleanup
phansch Jan 5, 2021
42b9e92
Auto merge of #6551 - phansch:tiny-symbol-cleanup, r=flip1995
bors Jan 5, 2021
a8825e9
Use existing 'is_automatically_derived' helper
phansch Jan 5, 2021
92f2bbb
Fix macro issues with field_reassign_with_default
phansch Jan 5, 2021
efccfe8
Auto merge of #6553 - phansch:field-reassign-with-default-macros, r=f…
bors Jan 6, 2021
8a45ffa
Fix typo: `which which can be` -> `which can be`
sozysozbot Jan 6, 2021
8e5c5a6
Auto merge of #6554 - sozysozbot:master, r=flip1995
bors Jan 6, 2021
f50ded0
Catch `pointer::cast` too in `cast_ptr_alignment`
rail-rain Jan 7, 2021
547ce0d
Change env var used for testing Clippy
flip1995 Jan 7, 2021
2b3c0ad
Fix typo: `irrevelent` -> `irrelevant`
stanislav-tkach Jan 7, 2021
e15bef9
Auto merge of #6558 - stanislav-tkach:patch-2, r=flip1995
bors Jan 7, 2021
7d42172
Reintroduce hir::ExprKind::If
c410-f3r Jan 1, 2021
aa9adbf
Small fixes of doc in `needless_question_mark`
giraffate Jan 7, 2021
0e14a75
Reduce the span in `from_over_into` to impl header
giraffate Jan 7, 2021
ee9b47d
Move `is_hir_ty_cfg_dependant` to `util`,
rail-rain Jan 8, 2021
2950c8e
Auto merge of #6566 - giraffate:reduce_the_span_in_from_over_into, r=…
bors Jan 8, 2021
24c700b
Use DefId in interning defined symbol lint
camsteffen Dec 30, 2020
121c65f
Add keywords to interning defined symbol lint
camsteffen Dec 29, 2020
76ccfb4
Fix unnecessary keyword intern dogfood
camsteffen Dec 29, 2020
cc26919
Add unnecessary symbol string lint
camsteffen Dec 30, 2020
7871eba
Fix symbol string comparison dogfood
camsteffen Dec 29, 2020
68bcd20
Auto merge of #6569 - camsteffen:symbol-comparison, r=Manishearth
bors Jan 8, 2021
8a6fea4
Fix FP for `boxed_local` lint in default trait fn impl
ThibsG Jan 9, 2021
ee0598e
Auto merge of #6571 - ThibsG:BoxedLocalTrait, r=phansch
bors Jan 9, 2021
583715f
Auto merge of #6565 - giraffate:small_fixes_of_doc_in_needless_questi…
bors Jan 9, 2021
9e45a23
ast: Remove some indirection layers from values in key-value attributes
petrochenkov Dec 19, 2020
2c6dc88
Rework diagnostics for wrong number of generic args
Patryk27 Jan 2, 2021
1eed27f
Auto merge of #6575 - flip1995:stop_linting_deps, r=Manishearth
bors Jan 11, 2021
53f8731
Simplify `cast_ptr_alignment` `pointer::casr` case
rail-rain Jan 11, 2021
7f4599a
Auto merge of #6557 - rail-rain:extending_cast_ptr_alignment, r=phansch
bors Jan 11, 2021
13ca5c8
Auto merge of #6462 - flip1995:roadmap, r=flip1995,llogiq,killercup,M…
bors Jan 12, 2021
ea02849
Make a reference a link in doc
giraffate Jan 13, 2021
dfb41f4
Separate out a `hir::Impl` struct
jyn514 Nov 22, 2020
00586df
Auto merge of #6584 - giraffate:make_references_to_issues_links, r=ll…
bors Jan 13, 2021
dcd8c8e
Auto merge of #77524 - Patryk27:fixes/66228, r=estebank
bors Jan 13, 2021
7b3af41
Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasper
bors Jan 14, 2021
9bd037d
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jan 15, 2021
0c5ba9a
Bump nightly version to 2021-01-15
flip1995 Jan 15, 2021
f18cf82
Don't trigger needless_return lint in macros
flip1995 Jan 15, 2021
953f024
Auto merge of #6586 - flip1995:rustup, r=flip1995
bors Jan 15, 2021
3e236b3
Merge commit '953f024793dab92745fee9cd2c4dee6a60451771' into clippyup
flip1995 Jan 15, 2021
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
137 changes: 134 additions & 3 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,138 @@ document.

## Unreleased / In Rust Nightly

[b20d4c1...master](https://github.com/rust-lang/rust-clippy/compare/b20d4c1...master)
[4911ab1...master](https://github.com/rust-lang/rust-clippy/compare/4911ab1...master)

## Rust 1.50

Current beta, release 2021-02-11

[b20d4c1...4911ab1](https://github.com/rust-lang/rust-clippy/compare/b20d4c1...4911ab1)

### New Lints

* [`suspicious_operation_groupings`] [#6086](https://github.com/rust-lang/rust-clippy/pull/6086)
* [`size_of_in_element_count`] [#6394](https://github.com/rust-lang/rust-clippy/pull/6394)
* [`unnecessary_wraps`] [#6070](https://github.com/rust-lang/rust-clippy/pull/6070)
* [`let_underscore_drop`] [#6305](https://github.com/rust-lang/rust-clippy/pull/6305)
* [`collapsible_match`] [#6402](https://github.com/rust-lang/rust-clippy/pull/6402)
* [`redundant_else`] [#6330](https://github.com/rust-lang/rust-clippy/pull/6330)
* [`zero_sized_map_values`] [#6218](https://github.com/rust-lang/rust-clippy/pull/6218)
* [`print_stderr`] [#6367](https://github.com/rust-lang/rust-clippy/pull/6367)
* [`string_from_utf8_as_bytes`] [#6134](https://github.com/rust-lang/rust-clippy/pull/6134)

### Moves and Deprecations

* Previously deprecated [`str_to_string`] and [`string_to_string`] have been un-deprecated
as `restriction` lints [#6333](https://github.com/rust-lang/rust-clippy/pull/6333)
* Deprecate [`panic_params`] lint. This is now available in rustc as `panic_fmt`
[#6351](https://github.com/rust-lang/rust-clippy/pull/6351)
* Move [`map_err_ignore`] to `restriction`
[#6416](https://github.com/rust-lang/rust-clippy/pull/6416)
* Move [`await_holding_refcell_ref`] to `pedantic`
[#6354](https://github.com/rust-lang/rust-clippy/pull/6354)
* Move [`await_holding_lock`] to `pedantic`
[#6354](https://github.com/rust-lang/rust-clippy/pull/6354)

### Enhancements

* Add the `unreadable-literal-lint-fractions` configuration to disable
the `unreadable_literal` lint for fractions
[#6421](https://github.com/rust-lang/rust-clippy/pull/6421)
* [`clone_on_copy`]: Now shows the type in the lint message
[#6443](https://github.com/rust-lang/rust-clippy/pull/6443)
* [`redundant_pattern_matching`]: Now also lints on `std::task::Poll`
[#6339](https://github.com/rust-lang/rust-clippy/pull/6339)
* [`redundant_pattern_matching`]: Additionally also lints on `std::net::IpAddr`
[#6377](https://github.com/rust-lang/rust-clippy/pull/6377)
* [`search_is_some`]: Now suggests `contains` instead of `find(foo).is_some()`
[#6119](https://github.com/rust-lang/rust-clippy/pull/6119)
* [`clone_double_ref`]: Now prints the reference type in the lint message
[#6442](https://github.com/rust-lang/rust-clippy/pull/6442)
* [`modulo_one`]: Now also lints on -1.
[#6360](https://github.com/rust-lang/rust-clippy/pull/6360)
* [`empty_loop`]: Now lints no_std crates, too
[#6205](https://github.com/rust-lang/rust-clippy/pull/6205)
* [`or_fun_call`]: Now also lints when indexing `HashMap` or `BTreeMap`
[#6267](https://github.com/rust-lang/rust-clippy/pull/6267)
* [`wrong_self_convention`]: Now also lints in trait definitions
[#6316](https://github.com/rust-lang/rust-clippy/pull/6316)
* [`needless_borrow`]: Print the type in the lint message
[#6449](https://github.com/rust-lang/rust-clippy/pull/6449)

[msrv_readme]: https://github.com/rust-lang/rust-clippy#specifying-the-minimum-supported-rust-version

### False Positive Fixes

* [`manual_range_contains`]: No longer lints in `const fn`
[#6382](https://github.com/rust-lang/rust-clippy/pull/6382)
* [`unnecessary_lazy_evaluations`]: No longer lints if closure argument is used
[#6370](https://github.com/rust-lang/rust-clippy/pull/6370)
* [`match_single_binding`]: Now ignores cases with `#[cfg()]` macros
[#6435](https://github.com/rust-lang/rust-clippy/pull/6435)
* [`match_like_matches_macro`]: No longer lints on arms with attributes
[#6290](https://github.com/rust-lang/rust-clippy/pull/6290)
* [`map_clone`]: No longer lints with deref and clone
[#6269](https://github.com/rust-lang/rust-clippy/pull/6269)
* [`map_clone`]: No longer lints in the case of &mut
[#6301](https://github.com/rust-lang/rust-clippy/pull/6301)
* [`needless_update`]: Now ignores `non_exhaustive` structs
[#6464](https://github.com/rust-lang/rust-clippy/pull/6464)
* [`needless_collect`]: No longer lints when a collect is needed multiple times
[#6313](https://github.com/rust-lang/rust-clippy/pull/6313)
* [`unnecessary_cast`] No longer lints cfg-dependent types
[#6369](https://github.com/rust-lang/rust-clippy/pull/6369)
* [`declare_interior_mutable_const`] and [`borrow_interior_mutable_const`]:
Both now ignore enums with frozen variants
[#6110](https://github.com/rust-lang/rust-clippy/pull/6110)


### Suggestion Fixes/Improvements

* [`vec_box`]: Provide correct type scope suggestion
[#6271](https://github.com/rust-lang/rust-clippy/pull/6271)
* [`manual_range_contains`]: Give correct suggestion when using floats
[#6320](https://github.com/rust-lang/rust-clippy/pull/6320)
* [`unnecessary_lazy_evaluations`]: Don't always mark suggestion as MachineApplicable
[#6272](https://github.com/rust-lang/rust-clippy/pull/6272)
* [`manual_async_fn`]: Improve suggestion formatting
[#6294](https://github.com/rust-lang/rust-clippy/pull/6294)
* [`unnecessary_cast`]: Fix incorrectly formatted float literal suggestion
[#6362](https://github.com/rust-lang/rust-clippy/pull/6362)

### ICE Fixes

* Fix a crash in [`from_iter_instead_of_collect`]
[#6304](https://github.com/rust-lang/rust-clippy/pull/6304)
* Fix a silent crash when parsing doc comments in [`needless_doctest_main`]
[#6458](https://github.com/rust-lang/rust-clippy/pull/6458)

### Documentation Improvements

* The lint website search has been improved ([#6477](https://github.com/rust-lang/rust-clippy/pull/6477)):
* Searching for lints with dashes and spaces is possible now. For example
`missing-errors-doc` and `missing errors doc` are now valid aliases for lint names
* Improved fuzzy search in lint descriptions
* Various README improvements
[#6287](https://github.com/rust-lang/rust-clippy/pull/6287)
* Add known problems to [`comparison_chain`] documentation
[#6390](https://github.com/rust-lang/rust-clippy/pull/6390)
* Fix example used in [`cargo_common_metadata`]
[#6293](https://github.com/rust-lang/rust-clippy/pull/6293)
* Improve [`map_clone`] documentation
[#6340](https://github.com/rust-lang/rust-clippy/pull/6340)

### Others

* You can now tell Clippy about the MSRV your project supports. Please refer to
the specific README section to learn more about MSRV support [here][msrv_readme]
[#6201](https://github.com/rust-lang/rust-clippy/pull/6201)
* Add `--no-deps` option to avoid running on path dependencies in workspaces
[#6188](https://github.com/rust-lang/rust-clippy/pull/6188)

## Rust 1.49

Current beta, release 2020-12-31
Current stable, released 2020-12-31

[e636b88...b20d4c1](https://github.com/rust-lang/rust-clippy/compare/e636b88...b20d4c1)

Expand Down Expand Up @@ -116,7 +243,7 @@ Current beta, release 2020-12-31

## Rust 1.48

Current stable, released 2020-11-19
Released 2020-11-19

[09bd400...e636b88](https://github.com/rust-lang/rust-clippy/compare/09bd400...e636b88)

Expand Down Expand Up @@ -1769,6 +1896,7 @@ Released 2018-09-13
[`cmp_null`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_null
[`cmp_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#cmp_owned
[`cognitive_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#cognitive_complexity
[`collapsible_else_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if
[`collapsible_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if
[`collapsible_match`]: https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_match
[`comparison_chain`]: https://rust-lang.github.io/rust-clippy/master/index.html#comparison_chain
Expand Down Expand Up @@ -1973,6 +2101,7 @@ Released 2018-09-13
[`needless_doctest_main`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_doctest_main
[`needless_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes
[`needless_pass_by_value`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_pass_by_value
[`needless_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark
[`needless_range_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_range_loop
[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
Expand Down Expand Up @@ -2012,6 +2141,7 @@ Released 2018-09-13
[`print_with_newline`]: https://rust-lang.github.io/rust-clippy/master/index.html#print_with_newline
[`println_empty_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#println_empty_string
[`ptr_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_arg
[`ptr_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr
[`ptr_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_eq
[`ptr_offset_with_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#ptr_offset_with_cast
[`pub_enum_variant_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#pub_enum_variant_names
Expand Down Expand Up @@ -2152,6 +2282,7 @@ Released 2018-09-13
[`useless_transmute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute
[`useless_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_vec
[`vec_box`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_box
[`vec_init_then_push`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_init_then_push
[`vec_resize_to_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#vec_resize_to_zero
[`verbose_bit_mask`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_bit_mask
[`verbose_file_reads`]: https://rust-lang.github.io/rust-clippy/master/index.html#verbose_file_reads
Expand Down
45 changes: 35 additions & 10 deletions src/tools/clippy/clippy_dev/src/bless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::env;
use std::ffi::OsStr;
use std::fs;
use std::lazy::SyncLazy;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;

use crate::clippy_project_root;
Expand All @@ -16,27 +16,41 @@ pub static CARGO_TARGET_DIR: SyncLazy<PathBuf> = SyncLazy::new(|| match env::var
None => env::current_dir().unwrap().join("target"),
});

pub fn bless() {
let test_dirs = [
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::new(|| {
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
let mut path = PathBuf::from(&**CARGO_TARGET_DIR);
path.push(profile);
path.push("cargo-clippy");
fs::metadata(path).ok()?.modified().ok()
});

pub fn bless(ignore_timestamp: bool) {
let test_suite_dirs = [
clippy_project_root().join("tests").join("ui"),
clippy_project_root().join("tests").join("ui-internal"),
clippy_project_root().join("tests").join("ui-toml"),
clippy_project_root().join("tests").join("ui-cargo"),
];
for test_dir in &test_dirs {
WalkDir::new(test_dir)
for test_suite_dir in &test_suite_dirs {
WalkDir::new(test_suite_dir)
.into_iter()
.filter_map(Result::ok)
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
.for_each(|f| {
update_reference_file(f.path().with_extension("stdout"));
update_reference_file(f.path().with_extension("stderr"));
update_reference_file(f.path().with_extension("fixed"));
let test_name = f.path().strip_prefix(test_suite_dir).unwrap();
for &ext in &["stdout", "stderr", "fixed"] {
update_reference_file(
f.path().with_extension(ext),
test_name.with_extension(ext),
ignore_timestamp,
);
}
});
}
}

fn update_reference_file(reference_file_path: PathBuf) {
let test_output_path = build_dir().join(PathBuf::from(reference_file_path.file_name().unwrap()));
fn update_reference_file(reference_file_path: PathBuf, test_name: PathBuf, ignore_timestamp: bool) {
let test_output_path = build_dir().join(test_name);
let relative_reference_file_path = reference_file_path.strip_prefix(clippy_project_root()).unwrap();

// If compiletest did not write any changes during the test run,
Expand All @@ -45,6 +59,11 @@ fn update_reference_file(reference_file_path: PathBuf) {
return;
}

// If the test output was not updated since the last clippy build, it may be outdated
if !ignore_timestamp && !updated_since_clippy_build(&test_output_path).unwrap_or(true) {
return;
}

let test_output_file = fs::read(&test_output_path).expect("Unable to read test output file");
let reference_file = fs::read(&reference_file_path).unwrap_or_default();

Expand All @@ -64,6 +83,12 @@ fn update_reference_file(reference_file_path: PathBuf) {
}
}

fn updated_since_clippy_build(path: &Path) -> Option<bool> {
let clippy_build_time = (*CLIPPY_BUILD_TIME)?;
let modified = fs::metadata(path).ok()?.modified().ok()?;
Some(modified >= clippy_build_time)
}

fn build_dir() -> PathBuf {
let profile = env::var("PROFILE").unwrap_or_else(|_| "debug".to_string());
let mut path = PathBuf::new();
Expand Down
14 changes: 11 additions & 3 deletions src/tools/clippy/clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ fn main() {
let matches = get_clap_config();

match matches.subcommand() {
("bless", Some(_)) => {
bless::bless();
("bless", Some(matches)) => {
bless::bless(matches.is_present("ignore-timestamp"));
},
("fmt", Some(matches)) => {
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
Expand Down Expand Up @@ -47,7 +47,15 @@ fn main() {

fn get_clap_config<'a>() -> ArgMatches<'a> {
App::new("Clippy developer tooling")
.subcommand(SubCommand::with_name("bless").about("bless the test output changes"))
.subcommand(
SubCommand::with_name("bless")
.about("bless the test output changes")
.arg(
Arg::with_name("ignore-timestamp")
.long("ignore-timestamp")
.help("Include files updated before clippy was built"),
),
)
.subcommand(
SubCommand::with_name("fmt")
.about("Run rustfmt on all projects and tests")
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
if let Some(meta_item) = lint.meta_item();
if meta_item.path.segments.len() > 1;
if let tool_name = meta_item.path.segments[0].ident;
if tool_name.as_str() == "clippy";
if tool_name.name == sym::clippy;
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
then {
return Some(lint_name.as_str());
Expand Down
44 changes: 30 additions & 14 deletions src/tools/clippy/clippy_lints/src/collapsible_if.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ use rustc_errors::Applicability;

declare_clippy_lint! {
/// **What it does:** Checks for nested `if` statements which can be collapsed
/// by `&&`-combining their conditions and for `else { if ... }` expressions
/// that
/// can be collapsed to `else if ...`.
/// by `&&`-combining their conditions.
///
/// **Why is this bad?** Each `if`-statement adds one level of nesting, which
/// makes code look more complex than it really is.
Expand All @@ -40,7 +38,31 @@ declare_clippy_lint! {
/// }
/// }
///
/// // or
/// ```
///
/// Should be written:
///
/// ```rust.ignore
/// if x && y {
/// …
/// }
/// ```
pub COLLAPSIBLE_IF,
style,
"nested `if`s that can be collapsed (e.g., `if x { if y { ... } }`"
}

declare_clippy_lint! {
/// **What it does:** Checks for collapsible `else { if ... }` expressions
/// that can be collapsed to `else if ...`.
///
/// **Why is this bad?** Each `if`-statement adds one level of nesting, which
/// makes code look more complex than it really is.
///
/// **Known problems:** None.
///
/// **Example:**
/// ```rust,ignore
///
/// if x {
/// …
Expand All @@ -54,24 +76,18 @@ declare_clippy_lint! {
/// Should be written:
///
/// ```rust.ignore
/// if x && y {
/// …
/// }
///
/// // or
///
/// if x {
/// …
/// } else if y {
/// …
/// }
/// ```
pub COLLAPSIBLE_IF,
pub COLLAPSIBLE_ELSE_IF,
style,
"`if`s that can be collapsed (e.g., `if x { if y { ... } }` and `else { if x { ... } }`)"
"nested `else`-`if` expressions that can be collapsed (e.g., `else { if x { ... } }`)"
}

declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF]);
declare_lint_pass!(CollapsibleIf => [COLLAPSIBLE_IF, COLLAPSIBLE_ELSE_IF]);

impl EarlyLintPass for CollapsibleIf {
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &ast::Expr) {
Expand Down Expand Up @@ -112,7 +128,7 @@ fn check_collapsible_maybe_if_let(cx: &EarlyContext<'_>, else_: &ast::Expr) {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
cx,
COLLAPSIBLE_IF,
COLLAPSIBLE_ELSE_IF,
block.span,
"this `else { if .. }` block can be collapsed",
"collapse nested if block",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/comparison_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ declare_clippy_lint! {
/// repetitive
///
/// **Known problems:** The match statement may be slower due to the compiler
/// not inlining the call to cmp. See issue #5354
/// not inlining the call to cmp. See issue [#5354](https://github.com/rust-lang/rust-clippy/issues/5354)
///
/// **Example:**
/// ```rust,ignore
Expand Down
Loading