diff options
Diffstat (limited to 'tests/ui/box_default.fixed')
| -rw-r--r-- | tests/ui/box_default.fixed | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed new file mode 100644 index 00000000000..7fbb272ce5a --- /dev/null +++ b/tests/ui/box_default.fixed @@ -0,0 +1,43 @@ +// run-rustfix +#![warn(clippy::box_default)] + +#[derive(Default)] +struct ImplementsDefault; + +struct OwnDefault; + +impl OwnDefault { + fn default() -> Self { + Self + } +} + +macro_rules! outer { + ($e: expr) => { + $e + }; +} + +fn main() { + let _string: Box<String> = Box::default(); + let _byte = Box::<u8>::default(); + let _vec = Box::<std::vec::Vec<u8>>::default(); + let _impl = Box::<ImplementsDefault>::default(); + let _impl2 = Box::<ImplementsDefault>::default(); + let _impl3: Box<ImplementsDefault> = Box::default(); + let _own = Box::new(OwnDefault::default()); // should not lint + let _in_macro = outer!(Box::<std::string::String>::default()); + let _string_default = outer!(Box::<std::string::String>::default()); + let _vec2: Box<Vec<ImplementsDefault>> = Box::default(); + let _vec3: Box<Vec<bool>> = Box::default(); + let _vec4: Box<_> = Box::<std::vec::Vec<bool>>::default(); + let _more = ret_ty_fn(); + call_ty_fn(Box::default()); +} + +fn ret_ty_fn() -> Box<bool> { + Box::<bool>::default() +} + +#[allow(clippy::boxed_local)] +fn call_ty_fn(_b: Box<u8>) {} |
