]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/min_rust_version_attr.rs
Auto merge of #79780 - camelid:use-summary_opts, r=GuillaumeGomez
[rust.git] / src / tools / clippy / tests / ui / min_rust_version_attr.rs
1 #![allow(clippy::redundant_clone)]
2 #![feature(custom_inner_attributes)]
3 #![clippy::msrv = "1.0.0"]
4
5 use std::ops::Deref;
6
7 fn option_as_ref_deref() {
8     let mut opt = Some(String::from("123"));
9
10     let _ = opt.as_ref().map(String::as_str);
11     let _ = opt.as_ref().map(|x| x.as_str());
12     let _ = opt.as_mut().map(String::as_mut_str);
13     let _ = opt.as_mut().map(|x| x.as_mut_str());
14 }
15
16 fn match_like_matches() {
17     let _y = match Some(5) {
18         Some(0) => true,
19         _ => false,
20     };
21 }
22
23 fn match_same_arms() {
24     match (1, 2, 3) {
25         (1, .., 3) => 42,
26         (.., 3) => 42, //~ ERROR match arms have same body
27         _ => 0,
28     };
29 }
30
31 fn match_same_arms2() {
32     let _ = match Some(42) {
33         Some(_) => 24,
34         None => 24, //~ ERROR match arms have same body
35     };
36 }
37
38 pub fn manual_strip_msrv() {
39     let s = "hello, world!";
40     if s.starts_with("hello, ") {
41         assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
42     }
43 }
44
45 fn main() {
46     option_as_ref_deref();
47     match_like_matches();
48     match_same_arms();
49     match_same_arms2();
50     manual_strip_msrv();
51 }
52
53 mod meets_msrv {
54     #![feature(custom_inner_attributes)]
55     #![clippy::msrv = "1.45.0"]
56
57     fn main() {
58         let s = "hello, world!";
59         if s.starts_with("hello, ") {
60             assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
61         }
62     }
63 }
64
65 mod just_under_msrv {
66     #![feature(custom_inner_attributes)]
67     #![clippy::msrv = "1.46.0"]
68
69     fn main() {
70         let s = "hello, world!";
71         if s.starts_with("hello, ") {
72             assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
73         }
74     }
75 }
76
77 mod just_above_msrv {
78     #![feature(custom_inner_attributes)]
79     #![clippy::msrv = "1.44.0"]
80
81     fn main() {
82         let s = "hello, world!";
83         if s.starts_with("hello, ") {
84             assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
85         }
86     }
87 }