Auto merge of #6416 - deg4uss3r:map_err_restricted, r=ebroto
Moved map_err_ignore to restriction and updated help message This MR moves map_err_ignore lint from `pedantic` to the `restriction` category of lints and updates the help message to give the user an option to ignore the lint by naming the closure variable e.g. `.map_err(|_ignored| ...` --- changelog: move map_err_ignore to restriction category
This commit is contained in:
commit
13c1a01936
@ -1217,6 +1217,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
LintId::of(&integer_division::INTEGER_DIVISION),
|
LintId::of(&integer_division::INTEGER_DIVISION),
|
||||||
LintId::of(&let_underscore::LET_UNDERSCORE_MUST_USE),
|
LintId::of(&let_underscore::LET_UNDERSCORE_MUST_USE),
|
||||||
LintId::of(&literal_representation::DECIMAL_LITERAL_REPRESENTATION),
|
LintId::of(&literal_representation::DECIMAL_LITERAL_REPRESENTATION),
|
||||||
|
LintId::of(&map_err_ignore::MAP_ERR_IGNORE),
|
||||||
LintId::of(&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS),
|
LintId::of(&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS),
|
||||||
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
|
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
|
||||||
LintId::of(&mem_forget::MEM_FORGET),
|
LintId::of(&mem_forget::MEM_FORGET),
|
||||||
@ -1283,7 +1284,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
|
|||||||
LintId::of(&loops::EXPLICIT_ITER_LOOP),
|
LintId::of(&loops::EXPLICIT_ITER_LOOP),
|
||||||
LintId::of(¯o_use::MACRO_USE_IMPORTS),
|
LintId::of(¯o_use::MACRO_USE_IMPORTS),
|
||||||
LintId::of(&manual_ok_or::MANUAL_OK_OR),
|
LintId::of(&manual_ok_or::MANUAL_OK_OR),
|
||||||
LintId::of(&map_err_ignore::MAP_ERR_IGNORE),
|
|
||||||
LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS),
|
LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS),
|
||||||
LintId::of(&matches::MATCH_BOOL),
|
LintId::of(&matches::MATCH_BOOL),
|
||||||
LintId::of(&matches::MATCH_SAME_ARMS),
|
LintId::of(&matches::MATCH_SAME_ARMS),
|
||||||
|
@ -99,7 +99,7 @@
|
|||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub MAP_ERR_IGNORE,
|
pub MAP_ERR_IGNORE,
|
||||||
pedantic,
|
restriction,
|
||||||
"`map_err` should not ignore the original error"
|
"`map_err` should not ignore the original error"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,9 +133,9 @@ fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) {
|
|||||||
cx,
|
cx,
|
||||||
MAP_ERR_IGNORE,
|
MAP_ERR_IGNORE,
|
||||||
body_span,
|
body_span,
|
||||||
"`map_err(|_|...` ignores the original error",
|
"`map_err(|_|...` wildcard pattern discards the original error",
|
||||||
None,
|
None,
|
||||||
"Consider wrapping the error in an enum variant",
|
"Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,5 +22,9 @@ fn main() -> Result<(), Errors> {
|
|||||||
|
|
||||||
println!("{:?}", x.map_err(|_| Errors::Ignored));
|
println!("{:?}", x.map_err(|_| Errors::Ignored));
|
||||||
|
|
||||||
|
// Should not warn you because you explicitly ignore the parameter
|
||||||
|
// using a named wildcard value
|
||||||
|
println!("{:?}", x.map_err(|_foo| Errors::Ignored));
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
error: `map_err(|_|...` ignores the original error
|
error: `map_err(|_|...` wildcard pattern discards the original error
|
||||||
--> $DIR/map_err.rs:23:32
|
--> $DIR/map_err.rs:23:32
|
||||||
|
|
|
|
||||||
LL | println!("{:?}", x.map_err(|_| Errors::Ignored));
|
LL | println!("{:?}", x.map_err(|_| Errors::Ignored));
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::map-err-ignore` implied by `-D warnings`
|
= note: `-D clippy::map-err-ignore` implied by `-D warnings`
|
||||||
= help: Consider wrapping the error in an enum variant
|
= help: Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user