1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![feature(exclusive_range_pattern)]
12 #![allow(unused, clippy::redundant_pattern_matching)]
13 #![warn(clippy::match_same_arms)]
21 &Some(v) => println!("{:?}", v),
22 &None => println!("none"),
25 // this doesn't trigger, we have a different pattern
26 &Some(v) => println!("some"),
27 other => println!("other"),
32 &(v, 1) => println!("{}", v),
33 _ => println!("none"),
35 // special case: using & both in expr and pats
38 &Some(v) => println!("{:?}", v),
39 &None => println!("none"),
41 // false positive: only wildcard pattern
44 _ => println!("none"),
58 fn match_wild_err_arm() {
59 let x: Result<i32, &str> = Ok(3);
62 Ok(3) => println!("ok"),
63 Ok(_) => println!("ok"),
64 Err(_) => panic!("err"),
68 Ok(3) => println!("ok"),
69 Ok(_) => println!("ok"),
74 Ok(3) => println!("ok"),
75 Ok(_) => println!("ok"),
81 // allowed when not with `panic!` block
83 Ok(3) => println!("ok"),
84 Ok(_) => println!("ok"),
85 Err(_) => println!("err"),
88 // allowed when used with `unreachable!`
90 Ok(3) => println!("ok"),
91 Ok(_) => println!("ok"),
92 Err(_) => unreachable!(),
96 Ok(3) => println!("ok"),
97 Ok(_) => println!("ok"),
98 Err(_) => unreachable!(),
102 Ok(3) => println!("ok"),
103 Ok(_) => println!("ok"),
109 // no warning because of the guard
111 Ok(x) if x * x == 64 => println!("ok"),
112 Ok(_) => println!("ok"),
113 Err(_) => println!("err"),
116 // this used to be a false positive, see #1996
118 Ok(3) => println!("ok"),
119 Ok(x) if x * x == 64 => println!("ok 64"),
120 Ok(_) => println!("ok"),
121 Err(_) => println!("err"),
124 match (x, Some(1i32)) {
125 (Ok(x), Some(_)) => println!("ok {}", x),
126 (Ok(_), Some(x)) => println!("ok {}", x),
127 _ => println!("err"),
130 // no warning because of the different types for x
131 match (x, Some(1.0f64)) {
132 (Ok(x), Some(_)) => println!("ok {}", x),
133 (Ok(_), Some(x)) => println!("ok {}", x),
134 _ => println!("err"),
137 // because of a bug, no warning was generated for this case before #2251
139 Ok(_tmp) => println!("ok"),
140 Ok(3) => println!("ok"),
141 Ok(_) => println!("ok"),
149 let owned: Option<()> = None;
150 let borrowed: Option<&()> = match owned {
152 Some(ref v) => Some(v),
155 let mut mut_owned: Option<()> = None;
156 let borrow_mut: Option<&mut ()> = match mut_owned {
158 Some(ref mut v) => Some(v),