summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/redundant_allocation.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /src/tools/clippy/tests/ui/redundant_allocation.rs
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+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.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/redundant_allocation.rs b/src/tools/clippy/tests/ui/redundant_allocation.rs
index 9eb58a3e5..e70f8e71f 100644
--- a/src/tools/clippy/tests/ui/redundant_allocation.rs
+++ b/src/tools/clippy/tests/ui/redundant_allocation.rs
@@ -14,14 +14,24 @@ mod outer_box {
use std::sync::Arc;
pub fn box_test6<T>(foo: Box<Rc<T>>) {}
+ //~^ ERROR: usage of `Box<Rc<T>>`
+ //~| NOTE: `Rc<T>` is already on the heap, `Box<Rc<T>>` makes an extra allocation
pub fn box_test7<T>(foo: Box<Arc<T>>) {}
+ //~^ ERROR: usage of `Box<Arc<T>>`
+ //~| NOTE: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
pub fn box_test8() -> Box<Rc<SubT<usize>>> {
+ //~^ ERROR: usage of `Box<Rc<SubT<usize>>>`
+ //~| NOTE: `Rc<SubT<usize>>` is already on the heap, `Box<Rc<SubT<usize>>>` makes an e
unimplemented!();
}
pub fn box_test9<T>(foo: Box<Arc<T>>) -> Box<Arc<SubT<T>>> {
+ //~^ ERROR: usage of `Box<Arc<T>>`
+ //~| NOTE: `Arc<T>` is already on the heap, `Box<Arc<T>>` makes an extra allocation
+ //~| ERROR: usage of `Box<Arc<SubT<T>>>`
+ //~| NOTE: `Arc<SubT<T>>` is already on the heap, `Box<Arc<SubT<T>>>` makes an extra a
unimplemented!();
}
}
@@ -33,14 +43,24 @@ mod outer_rc {
use std::sync::Arc;
pub fn rc_test5(a: Rc<Box<bool>>) {}
+ //~^ ERROR: usage of `Rc<Box<bool>>`
+ //~| NOTE: `Box<bool>` is already on the heap, `Rc<Box<bool>>` makes an extra allocati
pub fn rc_test7(a: Rc<Arc<bool>>) {}
+ //~^ ERROR: usage of `Rc<Arc<bool>>`
+ //~| NOTE: `Arc<bool>` is already on the heap, `Rc<Arc<bool>>` makes an extra allocati
pub fn rc_test8() -> Rc<Box<SubT<usize>>> {
+ //~^ ERROR: usage of `Rc<Box<SubT<usize>>>`
+ //~| NOTE: `Box<SubT<usize>>` is already on the heap, `Rc<Box<SubT<usize>>>` makes an
unimplemented!();
}
pub fn rc_test9<T>(foo: Rc<Arc<T>>) -> Rc<Arc<SubT<T>>> {
+ //~^ ERROR: usage of `Rc<Arc<T>>`
+ //~| NOTE: `Arc<T>` is already on the heap, `Rc<Arc<T>>` makes an extra allocation
+ //~| ERROR: usage of `Rc<Arc<SubT<T>>>`
+ //~| NOTE: `Arc<SubT<T>>` is already on the heap, `Rc<Arc<SubT<T>>>` makes an extra al
unimplemented!();
}
}
@@ -52,14 +72,24 @@ mod outer_arc {
use std::sync::Arc;
pub fn arc_test5(a: Arc<Box<bool>>) {}
+ //~^ ERROR: usage of `Arc<Box<bool>>`
+ //~| NOTE: `Box<bool>` is already on the heap, `Arc<Box<bool>>` makes an extra allocat
pub fn arc_test6(a: Arc<Rc<bool>>) {}
+ //~^ ERROR: usage of `Arc<Rc<bool>>`
+ //~| NOTE: `Rc<bool>` is already on the heap, `Arc<Rc<bool>>` makes an extra allocatio
pub fn arc_test8() -> Arc<Box<SubT<usize>>> {
+ //~^ ERROR: usage of `Arc<Box<SubT<usize>>>`
+ //~| NOTE: `Box<SubT<usize>>` is already on the heap, `Arc<Box<SubT<usize>>>` makes an
unimplemented!();
}
pub fn arc_test9<T>(foo: Arc<Rc<T>>) -> Arc<Rc<SubT<T>>> {
+ //~^ ERROR: usage of `Arc<Rc<T>>`
+ //~| NOTE: `Rc<T>` is already on the heap, `Arc<Rc<T>>` makes an extra allocation
+ //~| ERROR: usage of `Arc<Rc<SubT<T>>>`
+ //~| NOTE: `Rc<SubT<T>>` is already on the heap, `Arc<Rc<SubT<T>>>` makes an extra all
unimplemented!();
}
}
@@ -82,6 +112,8 @@ mod box_dyn {
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>>>) {}
+ //~^ ERROR: usage of `Rc<Box<Box<dyn T>>>`
+ //~| NOTE: `Box<Box<dyn T>>` is already on the heap, `Rc<Box<Box<dyn T>>>` makes an ex
}
// https://github.com/rust-lang/rust-clippy/issues/8604
@@ -114,9 +146,22 @@ mod box_fat_ptr {
pub fn test_box_custom(_: Box<Box<DynSized>>) {}
pub fn test_rc_box_str(_: Rc<Box<Box<str>>>) {}
+ //~^ ERROR: usage of `Rc<Box<Box<str>>>`
+ //~| NOTE: `Box<Box<str>>` is already on the heap, `Rc<Box<Box<str>>>` makes an extra
pub fn test_rc_box_slice(_: Rc<Box<Box<[usize]>>>) {}
+ //~^ ERROR: usage of `Rc<Box<Box<[usize]>>>`
+ //~| NOTE: `Box<Box<[usize]>>` is already on the heap, `Rc<Box<Box<[usize]>>>` makes a
pub fn test_rc_box_path(_: Rc<Box<Box<Path>>>) {}
+ //~^ ERROR: usage of `Rc<Box<Box<Path>>>`
+ //~| NOTE: `Box<Box<Path>>` is already on the heap, `Rc<Box<Box<Path>>>` makes an extr
pub fn test_rc_box_custom(_: Rc<Box<Box<DynSized>>>) {}
+ //~^ ERROR: usage of `Rc<Box<Box<DynSized>>>`
+ //~| NOTE: `Box<Box<DynSized>>` is already on the heap, `Rc<Box<Box<DynSized>>>` makes
+}
+
+// https://github.com/rust-lang/rust-clippy/issues/11417
+fn type_in_closure() {
+ let _ = |_: &mut Box<Box<dyn ToString>>| {};
}
fn main() {}