Skip to content

Commit d47dbf5

Browse files
authored
Merge pull request #3234 from matthiaskrgr/fix_3064_crash
if_let_redundant_pattern_matching: use Span.to() instead of Span.with_hi() to fix crash.
2 parents d67286b + a578cb2 commit d47dbf5

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

clippy_lints/src/if_let_redundant_pattern_matching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
8787
arms[0].pats[0].span,
8888
&format!("redundant pattern matching, consider using `{}`", good_method),
8989
|db| {
90-
let span = expr.span.with_hi(op.span.hi());
90+
let span = expr.span.to(op.span);
9191
db.span_suggestion_with_applicability(
9292
span,
9393
"try this",

tests/ui/if_let_redundant_pattern_matching.stderr

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,33 @@ error: redundant pattern matching, consider using `is_ok()`
22
--> $DIR/if_let_redundant_pattern_matching.rs:19:12
33
|
44
19 | if let Ok(_) = Ok::<i32, i32>(42) {}
5-
| -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
5+
| -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()`
66
|
77
= note: `-D clippy::if-let-redundant-pattern-matching` implied by `-D warnings`
88

99
error: redundant pattern matching, consider using `is_err()`
1010
--> $DIR/if_let_redundant_pattern_matching.rs:21:12
1111
|
12-
21 | if let Err(_) = Err::<i32, i32>(42) {
13-
| -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
12+
21 | if let Err(_) = Err::<i32, i32>(42) {
13+
| _____- ^^^^^^
14+
22 | | }
15+
| |_____- help: try this: `if Err::<i32, i32>(42).is_err()`
1416

1517
error: redundant pattern matching, consider using `is_none()`
1618
--> $DIR/if_let_redundant_pattern_matching.rs:24:12
1719
|
18-
24 | if let None = None::<()> {
19-
| -------^^^^------------- help: try this: `if None::<()>.is_none()`
20+
24 | if let None = None::<()> {
21+
| _____- ^^^^
22+
25 | | }
23+
| |_____- help: try this: `if None::<()>.is_none()`
2024

2125
error: redundant pattern matching, consider using `is_some()`
2226
--> $DIR/if_let_redundant_pattern_matching.rs:27:12
2327
|
24-
27 | if let Some(_) = Some(42) {
25-
| -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
28+
27 | if let Some(_) = Some(42) {
29+
| _____- ^^^^^^^
30+
28 | | }
31+
| |_____- help: try this: `if Some(42).is_some()`
2632

2733
error: aborting due to 4 previous errors
2834

0 commit comments

Comments
 (0)