]>
git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/or_then_unwrap.rs
3 #![warn(clippy::or_then_unwrap)]
4 #![allow(clippy::map_identity)]
8 fn or(self, _
: Option
<Self>) -> Self {
14 struct SomeOtherStruct {}
15 impl SomeOtherStruct
{
23 let option
: Option
<&str> = None
;
24 let _
= option
.or(Some("fallback")).unwrap(); // should trigger lint
26 let result
: Result
<&str, &str> = Err("Error");
27 let _
= result
.or
::<&str>(Ok("fallback")).unwrap(); // should trigger lint
29 // as part of a method chain
30 let option
: Option
<&str> = None
;
31 let _
= option
.map(|v
| v
).or(Some("fallback")).unwrap().to_string().chars(); // should trigger lint
34 let instance
= SomeStruct {}
;
35 let _
= instance
.or(Some(SomeStruct {}
)).unwrap(); // should not trigger lint
37 // or takes no argument
38 let instance
= SomeOtherStruct {}
;
39 let _
= instance
.or().unwrap(); // should not trigger lint and should not panic
42 let option
: Option
<&str> = None
;
43 let _
= option
.or(None
).unwrap(); // should not trigger lint
46 let result
: Result
<&str, &str> = Err("Error");
47 let _
= result
.or
::<&str>(Err("Other Error")).unwrap(); // should not trigger lint
49 // other function between
50 let option
: Option
<&str> = None
;
51 let _
= option
.or(Some("fallback")).map(|v
| v
).unwrap(); // should not trigger lint