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);
158 fn manual_rem_euclid() {
160 let _: i32 = ((x % 4) + 4) % 4;
165 checked_conversion();
166 redundant_fieldnames();
167 redundant_static_lifetime();
168 option_as_ref_deref();
169 match_like_matches();
173 manual_range_contains();
175 replace_with_default();
177 missing_const_for_fn();
178 unnest_or_patterns();
181 cast_abs_to_unsigned();
185 mod just_under_msrv {
186 #![feature(custom_inner_attributes)]
187 #![clippy::msrv = "1.44.0"]
190 let s = "hello, world!";
191 if s.starts_with("hello, ") {
192 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
198 #![feature(custom_inner_attributes)]
199 #![clippy::msrv = "1.45.0"]
202 let s = "hello, world!";
203 if s.starts_with("hello, ") {
204 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
209 mod just_above_msrv {
210 #![feature(custom_inner_attributes)]
211 #![clippy::msrv = "1.46.0"]
214 let s = "hello, world!";
215 if s.starts_with("hello, ") {
216 assert_eq!(s["hello, ".len()..].to_uppercase(), "WORLD!");
221 mod const_rem_euclid {
222 #![feature(custom_inner_attributes)]
223 #![clippy::msrv = "1.50.0"]
225 pub const fn const_rem_euclid_4(num: i32) -> i32 {