]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui-toml/min_rust_version/min_rust_version.fixed
New upstream version 1.74.1+dfsg1
[rustc.git] / src / tools / clippy / tests / ui-toml / min_rust_version / min_rust_version.fixed
1 #![allow(clippy::redundant_clone, clippy::unnecessary_operation)]
2 #![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]
3
4 use std::mem::{size_of, size_of_val};
5 use std::ops::Deref;
6
7 mod enums {
8 enum E {
9 A,
10 B,
11 #[doc(hidden)]
12 _C,
13 }
14
15 // user forgot to remove the marker
16 #[non_exhaustive]
17 enum Ep {
18 A,
19 B,
20 #[doc(hidden)]
21 _C,
22 }
23 }
24
25 fn option_as_ref_deref() {
26 let mut opt = Some(String::from("123"));
27
28 let _ = opt.as_ref().map(String::as_str);
29 let _ = opt.as_ref().map(|x| x.as_str());
30 let _ = opt.as_mut().map(String::as_mut_str);
31 let _ = opt.as_mut().map(|x| x.as_mut_str());
32 }
33
34 fn match_like_matches() {
35 let _y = match Some(5) {
36 Some(0) => true,
37 _ => false,
38 };
39 }
40
41 fn match_same_arms() {
42 match (1, 2, 3) {
43 (1, .., 3) => 42,
44 (.., 3) => 42,
45 _ => 0,
46 };
47 }
48
49 fn match_same_arms2() {
50 let _ = match Some(42) {
51 Some(_) => 24,
52 None => 24,
53 };
54 }
55
56 fn manual_strip_msrv() {
57 let s = "hello, world!";
58 if s.starts_with("hello, ") {
59 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
60 }
61 }
62
63 fn check_index_refutable_slice() {
64 // This shouldn't trigger `clippy::index_refutable_slice` as the suggestion
65 // would only be valid from 1.42.0 onward
66 let slice: Option<&[u32]> = Some(&[1]);
67 if let Some(slice) = slice {
68 println!("{}", slice[0]);
69 }
70 }
71
72 fn map_clone_suggest_copied() {
73 // This should still trigger the lint but suggest `cloned()` instead of `copied()`
74 let _: Option<u64> = Some(&16).cloned();
75 }
76
77 fn borrow_as_ptr() {
78 let val = 1;
79 let _p = &val as *const i32;
80
81 let mut val_mut = 1;
82 let _p_mut = &mut val_mut as *mut i32;
83 }
84
85 fn manual_bits() {
86 size_of::<i8>() * 8;
87 size_of_val(&0u32) * 8;
88 }
89
90 fn main() {
91 option_as_ref_deref();
92 match_like_matches();
93 match_same_arms();
94 match_same_arms2();
95 manual_strip_msrv();
96 check_index_refutable_slice();
97 borrow_as_ptr();
98 }