summary refs log tree commit diff
path: root/tests/ui/self
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2023-03-11 15:43:11 +0100
committerGitHub <noreply@github.com>2023-03-11 15:43:11 +0100
commitfbc121fdfd30daad5b99bae1aac4d6bd4d42ba02 (patch)
tree20a69adee2d22412e2e043ff363156dde11ef4f5 /tests/ui/self
parente350fe4e608b653da47e8012d13ef701613e717b (diff)
parenta90abd64fbb0764007d93d60823161f05f564259 (diff)
downloadrust-fbc121fdfd30daad5b99bae1aac4d6bd4d42ba02.tar.gz
rust-fbc121fdfd30daad5b99bae1aac4d6bd4d42ba02.zip
Rollup merge of #104363 - WaffleLapkin:bonk_box_new, r=Nilstrieb
Make `unused_allocation` lint against `Box::new` too

Previously it only linted against `box` syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something :shrug:

This means that code like the following will be linted against:
```rust
Box::new([1, 2, 3]).len();
f(&Box::new(1)); // where f : &i32 -> ()
```
The lint works by checking if a `Box::new` (or `box`) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against:
```rust
let boxed = Box::new([1, 2, 3]); // no lint
boxed.len();
```
Diffstat (limited to 'tests/ui/self')
-rw-r--r--tests/ui/self/arbitrary_self_types_trait.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/tests/ui/self/arbitrary_self_types_trait.rs b/tests/ui/self/arbitrary_self_types_trait.rs
index 973c7cae85a..c4651ec7177 100644
--- a/tests/ui/self/arbitrary_self_types_trait.rs
+++ b/tests/ui/self/arbitrary_self_types_trait.rs
@@ -1,4 +1,5 @@
 // run-pass
+#![allow(unused_allocation)]
 
 use std::rc::Rc;
 
@@ -13,7 +14,7 @@ impl Trait for Vec<i32> {
 }
 
 fn main() {
-    let v = vec![1,2,3];
+    let v = vec![1, 2, 3];
 
-    assert_eq!(&[1,2,3], Box::new(Rc::new(v)).trait_method());
+    assert_eq!(&[1, 2, 3], Box::new(Rc::new(v)).trait_method());
 }