diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:11:38 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:13:23 +0000 |
commit | 20431706a863f92cb37dc512fef6e48d192aaf2c (patch) | |
tree | 2867f13f5fd5437ba628c67d7f87309ccadcd286 /src/tools/clippy/tests/ui/box_default.fixed | |
parent | Releasing progress-linux version 1.65.0+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.tar.xz rustc-20431706a863f92cb37dc512fef6e48d192aaf2c.zip |
Merging upstream version 1.66.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/box_default.fixed')
-rw-r--r-- | src/tools/clippy/tests/ui/box_default.fixed | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/box_default.fixed b/src/tools/clippy/tests/ui/box_default.fixed new file mode 100644 index 000000000..911fa856a --- /dev/null +++ b/src/tools/clippy/tests/ui/box_default.fixed @@ -0,0 +1,57 @@ +// 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>) { + issue_9621_dyn_trait(); +} + +use std::io::{Read, Result}; + +impl Read for ImplementsDefault { + fn read(&mut self, _: &mut [u8]) -> Result<usize> { + Ok(0) + } +} + +fn issue_9621_dyn_trait() { + let _: Box<dyn Read> = Box::<ImplementsDefault>::default(); +} |