forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#114729 - flip1995:clippyup, r=Manishearth
Update Clippy r? `@Manishearth` cc `@Centri3` This reinstates the `filter_map_bool_then` lint rust-lang#114715, since I think you fixed the ICE in rust-lang@beb57f0 which is included in this sync.
- Loading branch information
Showing
72 changed files
with
1,543 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/tools/clippy/clippy_lints/src/ignored_unit_patterns.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use clippy_utils::diagnostics::span_lint_and_sugg; | ||
use hir::PatKind; | ||
use rustc_errors::Applicability; | ||
use rustc_hir as hir; | ||
use rustc_lint::{LateContext, LateLintPass}; | ||
use rustc_session::{declare_lint_pass, declare_tool_lint}; | ||
|
||
declare_clippy_lint! { | ||
/// ### What it does | ||
/// Checks for usage of `_` in patterns of type `()`. | ||
/// | ||
/// ### Why is this bad? | ||
/// Matching with `()` explicitly instead of `_` outlines | ||
/// the fact that the pattern contains no data. Also it | ||
/// would detect a type change that `_` would ignore. | ||
/// | ||
/// ### Example | ||
/// ```rust | ||
/// match std::fs::create_dir("tmp-work-dir") { | ||
/// Ok(_) => println!("Working directory created"), | ||
/// Err(s) => eprintln!("Could not create directory: {s}"), | ||
/// } | ||
/// ``` | ||
/// Use instead: | ||
/// ```rust | ||
/// match std::fs::create_dir("tmp-work-dir") { | ||
/// Ok(()) => println!("Working directory created"), | ||
/// Err(s) => eprintln!("Could not create directory: {s}"), | ||
/// } | ||
/// ``` | ||
#[clippy::version = "1.73.0"] | ||
pub IGNORED_UNIT_PATTERNS, | ||
pedantic, | ||
"suggest replacing `_` by `()` in patterns where appropriate" | ||
} | ||
declare_lint_pass!(IgnoredUnitPatterns => [IGNORED_UNIT_PATTERNS]); | ||
|
||
impl<'tcx> LateLintPass<'tcx> for IgnoredUnitPatterns { | ||
fn check_pat(&mut self, cx: &LateContext<'tcx>, pat: &'tcx hir::Pat<'tcx>) { | ||
if matches!(pat.kind, PatKind::Wild) && cx.typeck_results().pat_ty(pat).is_unit() { | ||
span_lint_and_sugg( | ||
cx, | ||
IGNORED_UNIT_PATTERNS, | ||
pat.span, | ||
"matching over `()` is more explicit", | ||
"use `()` instead of `_`", | ||
String::from("()"), | ||
Applicability::MachineApplicable, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.