1 #![allow(clippy::redundant_clone)]
2 #![feature(custom_inner_attributes)]
3 #![clippy::msrv = "1.0.0"]
5 use std::ops::{Deref, RangeFrom};
8 let log2_10 = 3.321928094887362;
9 let log10_2 = 0.301029995663981;
12 fn cloned_instead_of_copied() {
13 let _ = [1].iter().cloned();
16 fn option_as_ref_deref() {
17 let mut opt = Some(String::from("123"));
19 let _ = opt.as_ref().map(String::as_str);
20 let _ = opt.as_ref().map(|x| x.as_str());
21 let _ = opt.as_mut().map(String::as_mut_str);
22 let _ = opt.as_mut().map(|x| x.as_mut_str());
25 fn match_like_matches() {
26 let _y = match Some(5) {
32 fn match_same_arms() {
35 (.., 3) => 42, //~ ERROR match arms have same body
40 fn match_same_arms2() {
41 let _ = match Some(42) {
43 None => 24, //~ ERROR match arms have same body
47 pub fn manual_strip_msrv() {
48 let s = "hello, world!";
49 if s.starts_with("hello, ") {
50 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
54 pub fn redundant_fieldnames() {
56 let _ = RangeFrom { start: start };
59 pub fn redundant_static_lifetime() {
60 const VAR_ONE: &'static str = "Test constant #1";
63 pub fn checked_conversion() {
65 let _ = value <= (u32::max_value() as i64) && value >= 0;
66 let _ = value <= (u32::MAX as i64) && value >= 0;
69 pub struct FromOverInto(String);
71 impl Into<FromOverInto> for String {
72 fn into(self) -> FromOverInto {
77 pub fn filter_map_next() {
78 let a = ["1", "lol", "3", "NaN", "5"];
81 let _: Option<u32> = vec![1, 2, 3, 4, 5, 6]
93 #[allow(clippy::no_effect)]
94 #[allow(clippy::short_circuit_statement)]
95 #[allow(clippy::unnecessary_operation)]
96 pub fn manual_range_contains() {
114 fn replace_with_default() {
115 let mut s = String::from("foo");
116 let _ = std::mem::replace(&mut s, String::default());
122 // Check for `option.map(_).unwrap_or(_)` use.
126 // Should lint even though this call is on a separate line.
131 fn missing_const_for_fn() -> i32 {
135 fn unnest_or_patterns() {
137 if let TS(0, x) | TS(1, x) = TS(0, 0) {}
140 #[cfg_attr(rustfmt, rustfmt_skip)]
141 fn deprecated_cfg_attr() {}
143 #[warn(clippy::cast_lossless)]
144 fn int_from_bool() -> u8 {
149 let x: Result<u32, &str> = Ok(10);
150 x.err().expect("Testing expect_err");
153 fn cast_abs_to_unsigned() {
155 assert_eq!(10u32, x.abs() as u32);
160 checked_conversion();
161 redundant_fieldnames();
162 redundant_static_lifetime();
163 option_as_ref_deref();
164 match_like_matches();
168 manual_range_contains();
170 replace_with_default();
172 missing_const_for_fn();
173 unnest_or_patterns();
176 cast_abs_to_unsigned();
179 mod just_under_msrv {
180 #![feature(custom_inner_attributes)]
181 #![clippy::msrv = "1.44.0"]
184 let s = "hello, world!";
185 if s.starts_with("hello, ") {
186 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
192 #![feature(custom_inner_attributes)]
193 #![clippy::msrv = "1.45.0"]
196 let s = "hello, world!";
197 if s.starts_with("hello, ") {
198 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
203 mod just_above_msrv {
204 #![feature(custom_inner_attributes)]
205 #![clippy::msrv = "1.46.0"]
208 let s = "hello, world!";
209 if s.starts_with("hello, ") {
210 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");