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.
12 #![feature(exclusive_range_pattern)]
16 #![allow(unused, clippy::if_let_redundant_pattern_matching)]
17 #![warn(clippy::single_match_else, clippy::match_same_arms)]
25 static NODE: ExprNode = ExprNode::Unicorns;
30 fn unwrap_addr() -> Option<&'static ExprNode> {
31 match ExprNode::Butterflies {
32 ExprNode::ExprAddrOf => Some(&NODE),
33 _ => { let x = 5; None },
41 &Some(v) => println!("{:?}", v),
42 &None => println!("none"),
44 match v { // this doesn't trigger, we have a different pattern
45 &Some(v) => println!("some"),
46 other => println!("other"),
51 &(v, 1) => println!("{}", v),
52 _ => println!("none"),
54 // special case: using & both in expr and pats
57 &Some(v) => println!("{:?}", v),
58 &None => println!("none"),
60 // false positive: only wildcard pattern
63 _ => println!("none"),
81 0 ... 10 => println!("0 ... 10"),
82 0 ... 11 => println!("0 ... 11"),
87 0 ... 5 => println!("0 ... 5"),
88 6 ... 7 => println!("6 ... 7"),
89 FOO ... 11 => println!("0 ... 11"),
95 0 ... 5 => println!("0 ... 5"),
101 0 ... 2 => println!("0 ... 2"),
106 0 ... 10 => println!("0 ... 10"),
107 11 ... 50 => println!("11 ... 50"),
113 0 .. 2 => println!("0 .. 2"),
118 0 .. 10 => println!("0 .. 10"),
119 10 .. 50 => println!("10 .. 50"),
124 0 .. 11 => println!("0 .. 11"),
125 0 ... 11 => println!("0 ... 11"),
129 if let None = Some(42) {
131 } else if let None = Some(42) {
132 // another nothing :-)
136 fn match_wild_err_arm() {
137 let x: Result<i32, &str> = Ok(3);
140 Ok(3) => println!("ok"),
141 Ok(_) => println!("ok"),
142 Err(_) => panic!("err")
146 Ok(3) => println!("ok"),
147 Ok(_) => println!("ok"),
152 Ok(3) => println!("ok"),
153 Ok(_) => println!("ok"),
154 Err(_) => {panic!();}
157 // allowed when not with `panic!` block
159 Ok(3) => println!("ok"),
160 Ok(_) => println!("ok"),
161 Err(_) => println!("err")
164 // allowed when used with `unreachable!`
166 Ok(3) => println!("ok"),
167 Ok(_) => println!("ok"),
168 Err(_) => {unreachable!()}
172 Ok(3) => println!("ok"),
173 Ok(_) => println!("ok"),
174 Err(_) => unreachable!()
178 Ok(3) => println!("ok"),
179 Ok(_) => println!("ok"),
180 Err(_) => {unreachable!();}
183 // no warning because of the guard
185 Ok(x) if x*x == 64 => println!("ok"),
186 Ok(_) => println!("ok"),
187 Err(_) => println!("err")
190 // this used to be a false positive, see #1996
192 Ok(3) => println!("ok"),
193 Ok(x) if x*x == 64 => println!("ok 64"),
194 Ok(_) => println!("ok"),
195 Err(_) => println!("err")
198 match (x, Some(1i32)) {
199 (Ok(x), Some(_)) => println!("ok {}", x),
200 (Ok(_), Some(x)) => println!("ok {}", x),
204 // no warning because of the different types for x
205 match (x, Some(1.0f64)) {
206 (Ok(x), Some(_)) => println!("ok {}", x),
207 (Ok(_), Some(x)) => println!("ok {}", x),
211 // because of a bug, no warning was generated for this case before #2251
213 Ok(_tmp) => println!("ok"),
214 Ok(3) => println!("ok"),
215 Ok(_) => println!("ok"),
216 Err(_) => {unreachable!();}
221 let owned: Option<()> = None;
222 let borrowed: Option<&()> = match owned {
224 Some(ref v) => Some(v),
227 let mut mut_owned: Option<()> = None;
228 let borrow_mut: Option<&mut ()> = match mut_owned {
230 Some(ref mut v) => Some(v),