Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 13c1a01

Browse files
committed
Auto merge of rust-lang#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
2 parents 7f22b1c + 5f821fb commit 13c1a01

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12171217
LintId::of(&integer_division::INTEGER_DIVISION),
12181218
LintId::of(&let_underscore::LET_UNDERSCORE_MUST_USE),
12191219
LintId::of(&literal_representation::DECIMAL_LITERAL_REPRESENTATION),
1220+
LintId::of(&map_err_ignore::MAP_ERR_IGNORE),
12201221
LintId::of(&matches::REST_PAT_IN_FULLY_BOUND_STRUCTS),
12211222
LintId::of(&matches::WILDCARD_ENUM_MATCH_ARM),
12221223
LintId::of(&mem_forget::MEM_FORGET),
@@ -1283,7 +1284,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
12831284
LintId::of(&loops::EXPLICIT_ITER_LOOP),
12841285
LintId::of(&macro_use::MACRO_USE_IMPORTS),
12851286
LintId::of(&manual_ok_or::MANUAL_OK_OR),
1286-
LintId::of(&map_err_ignore::MAP_ERR_IGNORE),
12871287
LintId::of(&match_on_vec_items::MATCH_ON_VEC_ITEMS),
12881288
LintId::of(&matches::MATCH_BOOL),
12891289
LintId::of(&matches::MATCH_SAME_ARMS),

clippy_lints/src/map_err_ignore.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ declare_clippy_lint! {
9999
/// }
100100
/// ```
101101
pub MAP_ERR_IGNORE,
102-
pedantic,
102+
restriction,
103103
"`map_err` should not ignore the original error"
104104
}
105105

@@ -133,9 +133,9 @@ impl<'tcx> LateLintPass<'tcx> for MapErrIgnore {
133133
cx,
134134
MAP_ERR_IGNORE,
135135
body_span,
136-
"`map_err(|_|...` ignores the original error",
136+
"`map_err(|_|...` wildcard pattern discards the original error",
137137
None,
138-
"Consider wrapping the error in an enum variant",
138+
"Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)",
139139
);
140140
}
141141
}

tests/ui/map_err.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,9 @@ fn main() -> Result<(), Errors> {
2222

2323
println!("{:?}", x.map_err(|_| Errors::Ignored));
2424

25+
// Should not warn you because you explicitly ignore the parameter
26+
// using a named wildcard value
27+
println!("{:?}", x.map_err(|_foo| Errors::Ignored));
28+
2529
Ok(())
2630
}

tests/ui/map_err.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error: `map_err(|_|...` ignores the original error
1+
error: `map_err(|_|...` wildcard pattern discards the original error
22
--> $DIR/map_err.rs:23:32
33
|
44
LL | println!("{:?}", x.map_err(|_| Errors::Ignored));
55
| ^^^
66
|
77
= note: `-D clippy::map-err-ignore` implied by `-D warnings`
8-
= help: Consider wrapping the error in an enum variant
8+
= help: Consider storing the original error as a source in the new error, or silence this warning using an ignored identifier (`.map_err(|_foo| ...`)
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)