|
1 | 1 | // run-rustfix
|
2 | 2 |
|
3 |
| -#![feature(lint_reasons)] |
| 3 | +#![feature(custom_inner_attributes, lint_reasons)] |
4 | 4 |
|
5 | 5 | #[warn(clippy::all, clippy::needless_borrow)]
|
6 | 6 | #[allow(unused_variables, clippy::unnecessary_mut_passed)]
|
@@ -127,6 +127,20 @@ fn main() {
|
127 | 127 | 0
|
128 | 128 | }
|
129 | 129 | }
|
| 130 | + |
| 131 | + let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); |
| 132 | + let _ = std::path::Path::new(".").join(&&"."); |
| 133 | + deref_target_is_x(&X); |
| 134 | + multiple_constraints(&[[""]]); |
| 135 | + multiple_constraints_normalizes_to_same(&X, X); |
| 136 | + let _ = Some("").unwrap_or(&""); |
| 137 | + |
| 138 | + only_sized(&""); // Don't lint. `Sized` is only bound |
| 139 | + let _ = std::any::Any::type_id(&""); // Don't lint. `Any` is only bound |
| 140 | + let _ = Box::new(&""); // Don't lint. Type parameter appears in return type |
| 141 | + ref_as_ref_path(&""); // Don't lint. Argument type is not a type parameter |
| 142 | + refs_only(&()); // Don't lint. `&T` implements trait, but `T` doesn't |
| 143 | + multiple_constraints_normalizes_to_different(&[[""]], &[""]); // Don't lint. Projected type appears in arguments |
130 | 144 | }
|
131 | 145 |
|
132 | 146 | #[allow(clippy::needless_borrowed_reference)]
|
@@ -183,3 +197,104 @@ mod issue9160 {
|
183 | 197 | }
|
184 | 198 | }
|
185 | 199 | }
|
| 200 | + |
| 201 | +#[derive(Clone, Copy)] |
| 202 | +struct X; |
| 203 | + |
| 204 | +impl std::ops::Deref for X { |
| 205 | + type Target = X; |
| 206 | + fn deref(&self) -> &Self::Target { |
| 207 | + self |
| 208 | + } |
| 209 | +} |
| 210 | + |
| 211 | +fn deref_target_is_x<T>(_: T) |
| 212 | +where |
| 213 | + T: std::ops::Deref<Target = X>, |
| 214 | +{ |
| 215 | +} |
| 216 | + |
| 217 | +fn multiple_constraints<T, U, V, X, Y>(_: T) |
| 218 | +where |
| 219 | + T: IntoIterator<Item = U> + IntoIterator<Item = X>, |
| 220 | + U: IntoIterator<Item = V>, |
| 221 | + V: AsRef<str>, |
| 222 | + X: IntoIterator<Item = Y>, |
| 223 | + Y: AsRef<std::ffi::OsStr>, |
| 224 | +{ |
| 225 | +} |
| 226 | + |
| 227 | +fn multiple_constraints_normalizes_to_same<T, U, V>(_: T, _: V) |
| 228 | +where |
| 229 | + T: std::ops::Deref<Target = U>, |
| 230 | + U: std::ops::Deref<Target = V>, |
| 231 | +{ |
| 232 | +} |
| 233 | + |
| 234 | +fn only_sized<T>(_: T) {} |
| 235 | + |
| 236 | +fn ref_as_ref_path<T: 'static>(_: &'static T) |
| 237 | +where |
| 238 | + &'static T: AsRef<std::path::Path>, |
| 239 | +{ |
| 240 | +} |
| 241 | + |
| 242 | +trait RefsOnly { |
| 243 | + type Referent; |
| 244 | +} |
| 245 | + |
| 246 | +impl<T> RefsOnly for &T { |
| 247 | + type Referent = T; |
| 248 | +} |
| 249 | + |
| 250 | +fn refs_only<T, U>(_: T) |
| 251 | +where |
| 252 | + T: RefsOnly<Referent = U>, |
| 253 | +{ |
| 254 | +} |
| 255 | + |
| 256 | +fn multiple_constraints_normalizes_to_different<T, U, V>(_: T, _: U) |
| 257 | +where |
| 258 | + T: IntoIterator<Item = U>, |
| 259 | + U: IntoIterator<Item = V>, |
| 260 | + V: AsRef<str>, |
| 261 | +{ |
| 262 | +} |
| 263 | + |
| 264 | +// https://github.com/rust-lang/rust-clippy/pull/9136#pullrequestreview-1037379321 |
| 265 | +#[allow(dead_code)] |
| 266 | +mod copyable_iterator { |
| 267 | + #[derive(Clone, Copy)] |
| 268 | + struct Iter; |
| 269 | + impl Iterator for Iter { |
| 270 | + type Item = (); |
| 271 | + fn next(&mut self) -> Option<Self::Item> { |
| 272 | + None |
| 273 | + } |
| 274 | + } |
| 275 | + fn takes_iter(_: impl Iterator) {} |
| 276 | + fn dont_warn(mut x: Iter) { |
| 277 | + takes_iter(&mut x); |
| 278 | + } |
| 279 | + fn warn(mut x: &mut Iter) { |
| 280 | + takes_iter(&mut x) |
| 281 | + } |
| 282 | +} |
| 283 | + |
| 284 | +mod under_msrv { |
| 285 | + #![allow(dead_code)] |
| 286 | + #![clippy::msrv = "1.52.0"] |
| 287 | + |
| 288 | + fn foo() { |
| 289 | + let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); |
| 290 | + } |
| 291 | +} |
| 292 | + |
| 293 | +mod meets_msrv { |
| 294 | + #![allow(dead_code)] |
| 295 | + #![clippy::msrv = "1.53.0"] |
| 296 | + |
| 297 | + fn foo() { |
| 298 | + let _ = std::process::Command::new("ls").args(&["-a", "-l"]).status().unwrap(); |
| 299 | + } |
| 300 | +} |
0 commit comments