]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/match_as_ref.fixed
Rollup merge of #102581 - jyn514:src-detection, r=Mark-Simulacrum
[rust.git] / src / tools / clippy / tests / ui / match_as_ref.fixed
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<&()> = owned.as_ref();
9
10     let mut mut_owned: Option<()> = None;
11     let borrow_mut: Option<&mut ()> = mut_owned.as_mut();
12 }
13
14 mod issue4437 {
15     use std::{error::Error, fmt, num::ParseIntError};
16
17     #[derive(Debug)]
18     struct E {
19         source: Option<ParseIntError>,
20     }
21
22     impl Error for E {
23         fn source(&self) -> Option<&(dyn Error + 'static)> {
24             self.source.as_ref().map(|x| x as _)
25         }
26     }
27
28     impl fmt::Display for E {
29         fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
30             unimplemented!()
31         }
32     }
33 }
34
35 fn main() {
36     // Don't lint
37     let _ = match Some(0) {
38         #[cfg(feature = "foo")]
39         Some(ref x) if *x > 50 => None,
40         Some(ref x) => Some(x),
41         None => None,
42     };
43 }