about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2018-09-28 21:09:57 +0200
committerMatthias Krüger <matthias.krueger@famsik.de>2018-10-08 17:34:43 +0200
commita578cb2d62d4ff1ddbf9034d2924e1a68f55723c (patch)
treea40a4f1453546d8173bbaf3c0679a12566174040
parentd67286b70b98110302c8324a2f1b2ca3d087501c (diff)
downloadrust-a578cb2d62d4ff1ddbf9034d2924e1a68f55723c.tar.gz
rust-a578cb2d62d4ff1ddbf9034d2924e1a68f55723c.zip
if_let_redundant_pattern_matching: use Span.to() instead of Span.with_hi() to fix crash.
Fixes #3064
-rw-r--r--clippy_lints/src/if_let_redundant_pattern_matching.rs2
-rw-r--r--tests/ui/if_let_redundant_pattern_matching.stderr20
2 files changed, 14 insertions, 8 deletions
diff --git a/clippy_lints/src/if_let_redundant_pattern_matching.rs b/clippy_lints/src/if_let_redundant_pattern_matching.rs
index 4ee8d9f0ca7..8b42eaa528e 100644
--- a/clippy_lints/src/if_let_redundant_pattern_matching.rs
+++ b/clippy_lints/src/if_let_redundant_pattern_matching.rs
@@ -87,7 +87,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
                     arms[0].pats[0].span,
                     &format!("redundant pattern matching, consider using `{}`", good_method),
                     |db| {
-                        let span = expr.span.with_hi(op.span.hi());
+                        let span = expr.span.to(op.span);
                         db.span_suggestion_with_applicability(
                             span,
                             "try this",
diff --git a/tests/ui/if_let_redundant_pattern_matching.stderr b/tests/ui/if_let_redundant_pattern_matching.stderr
index 00eb7885540..5111de67189 100644
--- a/tests/ui/if_let_redundant_pattern_matching.stderr
+++ b/tests/ui/if_let_redundant_pattern_matching.stderr
@@ -2,27 +2,33 @@ error: redundant pattern matching, consider using `is_ok()`
   --> $DIR/if_let_redundant_pattern_matching.rs:19:12
    |
 19 |     if let Ok(_) = Ok::<i32, i32>(42) {}
-   |     -------^^^^^--------------------- help: try this: `if Ok::<i32, i32>(42).is_ok()`
+   |     -------^^^^^------------------------ help: try this: `if Ok::<i32, i32>(42).is_ok()`
    |
    = note: `-D clippy::if-let-redundant-pattern-matching` implied by `-D warnings`
 
 error: redundant pattern matching, consider using `is_err()`
   --> $DIR/if_let_redundant_pattern_matching.rs:21:12
    |
-21 |     if let Err(_) = Err::<i32, i32>(42) {
-   |     -------^^^^^^---------------------- help: try this: `if Err::<i32, i32>(42).is_err()`
+21 |       if let Err(_) = Err::<i32, i32>(42) {
+   |  _____-      ^^^^^^
+22 | |     }
+   | |_____- help: try this: `if Err::<i32, i32>(42).is_err()`
 
 error: redundant pattern matching, consider using `is_none()`
   --> $DIR/if_let_redundant_pattern_matching.rs:24:12
    |
-24 |     if let None = None::<()> {
-   |     -------^^^^------------- help: try this: `if None::<()>.is_none()`
+24 |       if let None = None::<()> {
+   |  _____-      ^^^^
+25 | |     }
+   | |_____- help: try this: `if None::<()>.is_none()`
 
 error: redundant pattern matching, consider using `is_some()`
   --> $DIR/if_let_redundant_pattern_matching.rs:27:12
    |
-27 |     if let Some(_) = Some(42) {
-   |     -------^^^^^^^----------- help: try this: `if Some(42).is_some()`
+27 |       if let Some(_) = Some(42) {
+   |  _____-      ^^^^^^^
+28 | |     }
+   | |_____- help: try this: `if Some(42).is_some()`
 
 error: aborting due to 4 previous errors