refactor: rename lint to or_then_unwrap

This commit is contained in:
Max Baumann 2022-03-18 01:04:33 +01:00
parent 44c62c9aa2
commit 05e05eaed7
No known key found for this signature in database
GPG Key ID: 20FA1609B03B1D6D
8 changed files with 14 additions and 14 deletions

View File

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

View File

@ -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),

View File

@ -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),
])

View File

@ -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,

View File

@ -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`
}

View File

@ -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,

View File

@ -1,4 +1,4 @@
#![warn(clippy::use_unwrap_or)]
#![warn(clippy::or_then_unwrap)]
#![allow(clippy::map_identity)]
struct SomeStruct {}

View File

@ -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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^