1 #![allow(clippy::redundant_clone, clippy::unnecessary_operation)]
2 #![warn(clippy::manual_non_exhaustive, clippy::borrow_as_ptr, clippy::manual_bits)]
4 use std::mem::{size_of, size_of_val};
15 // user forgot to remove the marker
25 fn option_as_ref_deref() {
26 let mut opt = Some(String::from("123"));
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());
34 fn match_like_matches() {
35 let _y = match Some(5) {
41 fn match_same_arms() {
49 fn match_same_arms2() {
50 let _ = match Some(42) {
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!");
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]);
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();
79 let _p = &val as *const i32;
82 let _p_mut = &mut val_mut as *mut i32;
87 size_of_val(&0u32) * 8;
91 option_as_ref_deref();
96 check_index_refutable_slice();