From 05e05eaed7f512bf2a1f7f236fc4b484d4a52aa5 Mon Sep 17 00:00:00 2001 From: Max Baumann Date: Fri, 18 Mar 2022 01:04:33 +0100 Subject: [PATCH] refactor: rename lint to or_then_unwrap --- CHANGELOG.md | 2 +- clippy_lints/src/lib.register_all.rs | 2 +- clippy_lints/src/lib.register_complexity.rs | 2 +- clippy_lints/src/lib.register_lints.rs | 2 +- clippy_lints/src/lib.rs | 4 ++-- clippy_lints/src/{use_unwrap_or.rs => or_then_unwrap.rs} | 8 ++++---- tests/ui/{use_unwrap_or.rs => or_then_unwrap.rs} | 2 +- tests/ui/{use_unwrap_or.stderr => or_then_unwrap.stderr} | 6 +++--- 8 files changed, 14 insertions(+), 14 deletions(-) rename clippy_lints/src/{use_unwrap_or.rs => or_then_unwrap.rs} (95%) rename tests/ui/{use_unwrap_or.rs => or_then_unwrap.rs} (97%) rename tests/ui/{use_unwrap_or.stderr => or_then_unwrap.stderr} (78%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9475c674983..b45be38bf4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3538,7 +3538,7 @@ Released 2018-09-13 [`upper_case_acronyms`]: https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms [`use_debug`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_debug [`use_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_self -[`use_unwrap_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#use_unwrap_or +[`or_then_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#or_then_unwrap [`used_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#used_underscore_binding [`useless_asref`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_asref [`useless_attribute`]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_attribute diff --git a/clippy_lints/src/lib.register_all.rs b/clippy_lints/src/lib.register_all.rs index a42f4cb6d70..5c3e352d09f 100644 --- a/clippy_lints/src/lib.register_all.rs +++ b/clippy_lints/src/lib.register_all.rs @@ -310,7 +310,7 @@ LintId::of(unwrap::PANICKING_UNWRAP), LintId::of(unwrap::UNNECESSARY_UNWRAP), LintId::of(upper_case_acronyms::UPPER_CASE_ACRONYMS), - LintId::of(use_unwrap_or::USE_UNWRAP_OR), + LintId::of(or_then_unwrap::OR_THEN_UNWRAP), LintId::of(useless_conversion::USELESS_CONVERSION), LintId::of(vec::USELESS_VEC), LintId::of(vec_init_then_push::VEC_INIT_THEN_PUSH), diff --git a/clippy_lints/src/lib.register_complexity.rs b/clippy_lints/src/lib.register_complexity.rs index 94ff53c2a60..45ad1520396 100644 --- a/clippy_lints/src/lib.register_complexity.rs +++ b/clippy_lints/src/lib.register_complexity.rs @@ -94,7 +94,7 @@ LintId::of(unit_types::UNIT_ARG), LintId::of(unnecessary_sort_by::UNNECESSARY_SORT_BY), LintId::of(unwrap::UNNECESSARY_UNWRAP), - LintId::of(use_unwrap_or::USE_UNWRAP_OR), + LintId::of(or_then_unwrap::OR_THEN_UNWRAP), LintId::of(useless_conversion::USELESS_CONVERSION), LintId::of(zero_div_zero::ZERO_DIVIDED_BY_ZERO), ]) diff --git a/clippy_lints/src/lib.register_lints.rs b/clippy_lints/src/lib.register_lints.rs index d1e13647e7e..aad0c8735ee 100644 --- a/clippy_lints/src/lib.register_lints.rs +++ b/clippy_lints/src/lib.register_lints.rs @@ -528,7 +528,7 @@ unwrap_in_result::UNWRAP_IN_RESULT, upper_case_acronyms::UPPER_CASE_ACRONYMS, use_self::USE_SELF, - use_unwrap_or::USE_UNWRAP_OR, + or_then_unwrap::OR_THEN_UNWRAP, useless_conversion::USELESS_CONVERSION, vec::USELESS_VEC, vec_init_then_push::VEC_INIT_THEN_PUSH, diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 9c9e9643bc9..fdab58935ef 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -322,6 +322,7 @@ macro_rules! declare_clippy_lint { mod open_options; mod option_env_unwrap; mod option_if_let_else; +mod or_then_unwrap; mod overflow_check_conditional; mod panic_in_result_fn; mod panic_unimplemented; @@ -394,7 +395,6 @@ macro_rules! declare_clippy_lint { mod unwrap_in_result; mod upper_case_acronyms; mod use_self; -mod use_unwrap_or; mod useless_conversion; mod vec; mod vec_init_then_push; @@ -867,7 +867,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: ignore_publish: cargo_ignore_publish, }) }); - store.register_late_pass(|| Box::new(use_unwrap_or::UseUnwrapOr)); + store.register_late_pass(|| Box::new(or_then_unwrap::OrThenUnwrap)); // add lints here, do not remove this comment, it's used in `new_lint` } diff --git a/clippy_lints/src/use_unwrap_or.rs b/clippy_lints/src/or_then_unwrap.rs similarity index 95% rename from clippy_lints/src/use_unwrap_or.rs rename to clippy_lints/src/or_then_unwrap.rs index 3e40014f50f..d467fbdfe02 100644 --- a/clippy_lints/src/use_unwrap_or.rs +++ b/clippy_lints/src/or_then_unwrap.rs @@ -37,13 +37,13 @@ /// let value = option.unwrap_or(fallback); /// ``` #[clippy::version = "1.61.0"] - pub USE_UNWRAP_OR, + pub OR_THEN_UNWRAP, complexity, "checks for `.or(…).unwrap()` calls to Options and Results." } -declare_lint_pass!(UseUnwrapOr => [USE_UNWRAP_OR]); +declare_lint_pass!(OrThenUnwrap => [OR_THEN_UNWRAP]); -impl<'tcx> LateLintPass<'tcx> for UseUnwrapOr { +impl<'tcx> LateLintPass<'tcx> for OrThenUnwrap { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // look for x.or().unwrap() if_chain! { @@ -73,7 +73,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { span_lint_and_help( cx, - USE_UNWRAP_OR, + OR_THEN_UNWRAP, or_span.to(*unwrap_span), title, None, diff --git a/tests/ui/use_unwrap_or.rs b/tests/ui/or_then_unwrap.rs similarity index 97% rename from tests/ui/use_unwrap_or.rs rename to tests/ui/or_then_unwrap.rs index dd55b33739d..cbc3c387da0 100644 --- a/tests/ui/use_unwrap_or.rs +++ b/tests/ui/or_then_unwrap.rs @@ -1,4 +1,4 @@ -#![warn(clippy::use_unwrap_or)] +#![warn(clippy::or_then_unwrap)] #![allow(clippy::map_identity)] struct SomeStruct {} diff --git a/tests/ui/use_unwrap_or.stderr b/tests/ui/or_then_unwrap.stderr similarity index 78% rename from tests/ui/use_unwrap_or.stderr rename to tests/ui/or_then_unwrap.stderr index 796778a293d..fdd718b3580 100644 --- a/tests/ui/use_unwrap_or.stderr +++ b/tests/ui/or_then_unwrap.stderr @@ -1,14 +1,14 @@ error: .or(Some(…)).unwrap() found - --> $DIR/use_unwrap_or.rs:22:20 + --> $DIR/or_then_unwrap.rs:22:20 | LL | let _ = option.or(Some("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: `-D clippy::use-unwrap-or` implied by `-D warnings` + = note: `-D clippy::or-then-unwrap` implied by `-D warnings` = help: use `unwrap_or()` instead error: .or(Ok(…)).unwrap() found - --> $DIR/use_unwrap_or.rs:25:20 + --> $DIR/or_then_unwrap.rs:25:20 | LL | let _ = result.or::<&str>(Ok("fallback")).unwrap(); // should trigger lint | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^