diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/redundant_allocation.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/redundant_allocation.rs')
-rw-r--r-- | src/tools/clippy/tests/ui/redundant_allocation.rs | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/redundant_allocation.rs b/src/tools/clippy/tests/ui/redundant_allocation.rs new file mode 100644 index 000000000..cf7d8c6e3 --- /dev/null +++ b/src/tools/clippy/tests/ui/redundant_allocation.rs @@ -0,0 +1,135 @@ +#![warn(clippy::all)] +#![allow(clippy::boxed_local, clippy::needless_pass_by_value)] +#![allow(clippy::blacklisted_name, unused_variables, dead_code)] +#![allow(unused_imports)] + +pub struct MyStruct; + +pub struct SubT<T> { + foo: T, +} + +pub enum MyEnum { + One, + Two, +} + +mod outer_box { + use crate::MyEnum; + use crate::MyStruct; + use crate::SubT; + use std::boxed::Box; + use std::rc::Rc; + use std::sync::Arc; + + pub fn box_test6<T>(foo: Box<Rc<T>>) {} + + pub fn box_test7<T>(foo: Box<Arc<T>>) {} + + pub fn box_test8() -> Box<Rc<SubT<usize>>> { + unimplemented!(); + } + + pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> { + unimplemented!(); + } +} + +mod outer_rc { + use crate::MyEnum; + use crate::MyStruct; + use crate::SubT; + use std::boxed::Box; + use std::rc::Rc; + use std::sync::Arc; + + pub fn rc_test5(a: Rc<Box<bool>>) {} + + pub fn rc_test7(a: Rc<Arc<bool>>) {} + + pub fn rc_test8() -> Rc<Box<SubT<usize>>> { + unimplemented!(); + } + + pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> { + unimplemented!(); + } +} + +mod outer_arc { + use crate::MyEnum; + use crate::MyStruct; + use crate::SubT; + use std::boxed::Box; + use std::rc::Rc; + use std::sync::Arc; + + pub fn arc_test5(a: Arc<Box<bool>>) {} + + pub fn arc_test6(a: Arc<Rc<bool>>) {} + + pub fn arc_test8() -> Arc<Box<SubT<usize>>> { + unimplemented!(); + } + + pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> { + unimplemented!(); + } +} + +// https://github.com/rust-lang/rust-clippy/issues/7487 +mod box_dyn { + use std::boxed::Box; + use std::rc::Rc; + use std::sync::Arc; + + pub trait T {} + + struct S { + a: Box<Box<dyn T>>, + b: Rc<Box<dyn T>>, + c: Arc<Box<dyn T>>, + } + + pub fn test_box(_: Box<Box<dyn T>>) {} + pub fn test_rc(_: Rc<Box<dyn T>>) {} + pub fn test_arc(_: Arc<Box<dyn T>>) {} + pub fn test_rc_box(_: Rc<Box<Box<dyn T>>>) {} +} + +// https://github.com/rust-lang/rust-clippy/issues/8604 +mod box_fat_ptr { + use std::boxed::Box; + use std::path::Path; + use std::rc::Rc; + use std::sync::Arc; + + pub struct DynSized { + foo: [usize], + } + + struct S { + a: Box<Box<str>>, + b: Rc<Box<str>>, + c: Arc<Box<str>>, + + e: Box<Box<[usize]>>, + f: Box<Box<Path>>, + g: Box<Box<DynSized>>, + } + + pub fn test_box_str(_: Box<Box<str>>) {} + pub fn test_rc_str(_: Rc<Box<str>>) {} + pub fn test_arc_str(_: Arc<Box<str>>) {} + + pub fn test_box_slice(_: Box<Box<[usize]>>) {} + pub fn test_box_path(_: Box<Box<Path>>) {} + pub fn test_box_custom(_: Box<Box<DynSized>>) {} + + pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {} + pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {} + pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {} + pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {} +} + +fn main() {} |