db.span_note(i.body.span, "same as this");
// Note: this does not use `span_suggestion` on purpose: there is no clean way
- // to
- // remove the other arm. Building a span and suggest to replace it to "" makes
- // an
- // even more confusing error message. Also in order not to make up a span for
- // the
- // whole pattern, the suggestion is only shown when there is only one pattern.
- // The
- // user should know about `|` if they are already using it…
+ // to remove the other arm. Building a span and suggest to replace it to ""
+ // makes an even more confusing error message. Also in order not to make up a
+ // span for the whole pattern, the suggestion is only shown when there is only
+ // one pattern. The user should know about `|` if they are already using it…
if i.pats.len() == 1 && j.pats.len() == 1 {
let lhs = snippet(cx, i.pats[0].span, "<pat1>");
Ok(_) => println!("ok"),
Err(_) => {unreachable!();}
}
+
+ // no warning because of the guard
+ match x {
+ Ok(x) if x*x == 64 => println!("ok"),
+ Ok(_) => println!("ok"),
+ Err(_) => println!("err")
+ }
+
+ match (x, Some(1i32)) {
+ (Ok(x), Some(_)) => println!("ok {}", x),
+ (Ok(_), Some(x)) => println!("ok {}", x),
+ _ => println!("err")
+ }
+
+ // no warning because of the different types for x
+ match (x, Some(1.0f64)) {
+ (Ok(x), Some(_)) => println!("ok {}", x),
+ (Ok(_), Some(x)) => println!("ok {}", x),
+ _ => println!("err")
+ }
}
fn main() {
| ^^^^^^^^^^^^^^
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+error: this `match` has identical arm bodies
+ --> $DIR/matches.rs:290:29
+ |
+290 | (Ok(_), Some(x)) => println!("ok {}", x),
+ | ^^^^^^^^^^^^^^^^^^^^
+ |
+note: same as this
+ --> $DIR/matches.rs:289:29
+ |
+289 | (Ok(x), Some(_)) => println!("ok {}", x),
+ | ^^^^^^^^^^^^^^^^^^^^
+note: consider refactoring into `(Ok(x), Some(_)) | (Ok(_), Some(x))`
+ --> $DIR/matches.rs:289:29
+ |
+289 | (Ok(x), Some(_)) => println!("ok {}", x),
+ | ^^^^^^^^^^^^^^^^^^^^
+ = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
+