]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_as_ref.rs
Move MSRV tests into the lint specific test files
[rust.git] / tests / ui / match_as_ref.rs
1 // run-rustfix
2
3 #![allow(unused)]
4 #![warn(clippy::match_as_ref)]
5
6 fn match_as_ref() {
7     let owned: Option<()> = None;
8     let borrowed: Option<&()> = match owned {
9         None => None,
10         Some(ref v) => Some(v),
11     };
12
13     let mut mut_owned: Option<()> = None;
14     let borrow_mut: Option<&mut ()> = match mut_owned {
15         None => None,
16         Some(ref mut v) => Some(v),
17     };
18 }
19
20 mod issue4437 {
21     use std::{error::Error, fmt, num::ParseIntError};
22
23     #[derive(Debug)]
24     struct E {
25         source: Option<ParseIntError>,
26     }
27
28     impl Error for E {
29         fn source(&self) -> Option<&(dyn Error + 'static)> {
30             match self.source {
31                 Some(ref s) => Some(s),
32                 None => None,
33             }
34         }
35     }
36
37     impl fmt::Display for E {
38         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39             unimplemented!()
40         }
41     }
42 }
43
44 fn main() {
45     // Don't lint
46     let _ = match Some(0) {
47         #[cfg(feature = "foo")]
48         Some(ref x) if *x > 50 => None,
49         Some(ref x) => Some(x),
50         None => None,
51     };
52 }