| #![warn(clippy::inline_trait_bounds)] | |
| // Free functions | |
| fn inline_simple<T>() where T: Clone {} | |
| //~^ inline_trait_bounds | |
| fn inline_multiple<T, U>() where T: Clone + Copy, U: core::fmt::Debug {} | |
| //~^ inline_trait_bounds | |
| fn inline_lifetime<'a, 'b>(x: &'a str, y: &'b str) -> &'b str where 'a: 'b { | |
| //~^ inline_trait_bounds | |
| y | |
| } | |
| #[allow(clippy::multiple_bound_locations)] | |
| fn inline_with_where<T>() | |
| //~^ inline_trait_bounds | |
| where | |
| T: core::fmt::Debug, T: Clone, | |
| { | |
| } | |
| fn inline_with_const<T, const N: usize>() where T: Clone {} | |
| //~^ inline_trait_bounds | |
| fn inline_with_return<T>(val: T) -> T where T: Clone { | |
| //~^ inline_trait_bounds | |
| val | |
| } | |
| // Trait methods | |
| trait MyTrait { | |
| fn trait_method_inline<T>(&self) where T: Clone; | |
| //~^ inline_trait_bounds | |
| fn trait_method_default<T>(&self) where T: Clone + Copy {} | |
| //~^ inline_trait_bounds | |
| fn trait_method_where<T>(&self) | |
| where | |
| T: Clone; | |
| } | |
| // Impl methods | |
| struct MyStruct; | |
| impl MyStruct { | |
| fn impl_method_inline<T>(&self) where T: Clone {} | |
| //~^ inline_trait_bounds | |
| fn impl_method_multiple<T, U>(&self) where T: Clone, U: core::fmt::Debug {} | |
| //~^ inline_trait_bounds | |
| } | |
| impl MyTrait for MyStruct { | |
| fn trait_method_inline<T>(&self) where T: Clone {} | |
| //~^ inline_trait_bounds | |
| fn trait_method_default<T>(&self) where T: Clone + Copy {} | |
| //~^ inline_trait_bounds | |
| fn trait_method_where<T>(&self) | |
| where | |
| T: Clone, | |
| { | |
| } | |
| } | |
| // Should NOT lint | |
| fn where_only<T>() | |
| where | |
| T: Clone, | |
| { | |
| } | |
| fn no_bounds<T, U>() {} | |
| fn no_generics() {} | |
| struct InlineStruct<T: Clone>(T); | |
| enum InlineEnum<T: Clone> { | |
| A(T), | |
| } | |
| #[allow(invalid_type_param_default)] | |
| //~v inline_trait_bounds | |
| fn with_default_value<T = u32>(x: T) -> T where T: Clone { | |
| x | |
| } | |
| mod issue17110 { | |
| #[automatically_derived] | |
| #[allow(invalid_type_param_default)] | |
| fn with_default_value<T: Clone = u32>(x: T) -> T { | |
| x | |
| } | |
| struct S; | |
| #[automatically_derived] | |
| impl S { | |
| #[allow(invalid_type_param_default)] | |
| fn with_default_value<T: Clone = u32>(x: T) -> T { | |
| x | |
| } | |
| } | |
| impl S { | |
| #[allow(invalid_type_param_default)] | |
| //~v inline_trait_bounds | |
| fn with_default_value_but_not_auto_derived<T = u32>(x: T) -> T where T: Clone { | |
| x | |
| } | |
| } | |
| #[automatically_derived] | |
| mod inner { | |
| impl super::S { | |
| #[allow(invalid_type_param_default)] | |
| fn with_default_value_again<T: Clone = u32>(x: T) -> T { | |
| x | |
| } | |
| } | |
| } | |
| } |