about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authoryonip23 <yoni@tabnine.com>2022-05-11 23:11:52 +0300
committeryonip23 <yoni@tabnine.com>2022-05-11 23:11:52 +0300
commit344888a5820c2ae2d7c88ecf14bcaffb60ca2bc5 (patch)
tree980e3484bcf6421218af64e05b0323e6bedd1853 /tests/ui
parentf3e01c4f6a12ad1bd70813875ed84dbe8c830df7 (diff)
downloadrust-344888a5820c2ae2d7c88ecf14bcaffb60ca2bc5.tar.gz
rust-344888a5820c2ae2d7c88ecf14bcaffb60ca2bc5.zip
fix review comments
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/rc_clone_in_vec_init/arc.rs9
-rw-r--r--tests/ui/rc_clone_in_vec_init/arc.stderr36
-rw-r--r--tests/ui/rc_clone_in_vec_init/rc.rs9
-rw-r--r--tests/ui/rc_clone_in_vec_init/rc.stderr36
4 files changed, 84 insertions, 6 deletions
diff --git a/tests/ui/rc_clone_in_vec_init/arc.rs b/tests/ui/rc_clone_in_vec_init/arc.rs
index 9f4e27dfa62..bef2c67a1a5 100644
--- a/tests/ui/rc_clone_in_vec_init/arc.rs
+++ b/tests/ui/rc_clone_in_vec_init/arc.rs
@@ -16,6 +16,15 @@ fn should_warn_complex_case() {
         }));
         2
     ];
+
+    let v1 = vec![
+        Arc::new(Mutex::new({
+            let x = 1;
+            dbg!(x);
+            x
+        }));
+        2
+    ];
 }
 
 fn should_not_warn_custom_arc() {
diff --git a/tests/ui/rc_clone_in_vec_init/arc.stderr b/tests/ui/rc_clone_in_vec_init/arc.stderr
index 3de96c6f175..387580c2431 100644
--- a/tests/ui/rc_clone_in_vec_init/arc.stderr
+++ b/tests/ui/rc_clone_in_vec_init/arc.stderr
@@ -40,17 +40,47 @@ help: consider initializing each `Arc` element individually
    |
 LL ~     let v = {
 LL +         let mut v = Vec::with_capacity(2);
-LL +         (0..2).for_each(|_| v.push(std::sync::Arc::new..));
+LL +         (0..2).for_each(|_| v.push(std::sync::Arc::new(..)));
 LL +         v
 LL ~     };
    |
 help: or if this is intentional, consider extracting the `Arc` initialization to a variable
    |
 LL ~     let v = {
-LL +         let data = std::sync::Arc::new..;
+LL +         let data = std::sync::Arc::new(..);
 LL +         vec![data; 2]
 LL ~     };
    |
 
-error: aborting due to 2 previous errors
+error: calling `Arc::new` in `vec![elem; len]`
+  --> $DIR/arc.rs:20:14
+   |
+LL |       let v1 = vec![
+   |  ______________^
+LL | |         Arc::new(Mutex::new({
+LL | |             let x = 1;
+LL | |             dbg!(x);
+...  |
+LL | |         2
+LL | |     ];
+   | |_____^
+   |
+   = note: each element will point to the same `Arc` instance
+help: consider initializing each `Arc` element individually
+   |
+LL ~     let v1 = {
+LL +         let mut v = Vec::with_capacity(2);
+LL +         (0..2).for_each(|_| v.push(Arc::new(..)));
+LL +         v
+LL ~     };
+   |
+help: or if this is intentional, consider extracting the `Arc` initialization to a variable
+   |
+LL ~     let v1 = {
+LL +         let data = Arc::new(..);
+LL +         vec![data; 2]
+LL ~     };
+   |
+
+error: aborting due to 3 previous errors
 
diff --git a/tests/ui/rc_clone_in_vec_init/rc.rs b/tests/ui/rc_clone_in_vec_init/rc.rs
index 5e2834aa902..79c23cafa2c 100644
--- a/tests/ui/rc_clone_in_vec_init/rc.rs
+++ b/tests/ui/rc_clone_in_vec_init/rc.rs
@@ -17,6 +17,15 @@ fn should_warn_complex_case() {
         }));
         2
     ];
+
+    let v1 = vec![
+        Rc::new(Mutex::new({
+            let x = 1;
+            dbg!(x);
+            x
+        }));
+        2
+    ];
 }
 
 fn should_not_warn_custom_arc() {
diff --git a/tests/ui/rc_clone_in_vec_init/rc.stderr b/tests/ui/rc_clone_in_vec_init/rc.stderr
index e05f024cf9d..4ce53eecbbd 100644
--- a/tests/ui/rc_clone_in_vec_init/rc.stderr
+++ b/tests/ui/rc_clone_in_vec_init/rc.stderr
@@ -40,17 +40,47 @@ help: consider initializing each `Rc` element individually
    |
 LL ~     let v = {
 LL +         let mut v = Vec::with_capacity(2);
-LL +         (0..2).for_each(|_| v.push(std::rc::Rc::new..));
+LL +         (0..2).for_each(|_| v.push(std::rc::Rc::new(..)));
 LL +         v
 LL ~     };
    |
 help: or if this is intentional, consider extracting the `Rc` initialization to a variable
    |
 LL ~     let v = {
-LL +         let data = std::rc::Rc::new..;
+LL +         let data = std::rc::Rc::new(..);
 LL +         vec![data; 2]
 LL ~     };
    |
 
-error: aborting due to 2 previous errors
+error: calling `Rc::new` in `vec![elem; len]`
+  --> $DIR/rc.rs:21:14
+   |
+LL |       let v1 = vec![
+   |  ______________^
+LL | |         Rc::new(Mutex::new({
+LL | |             let x = 1;
+LL | |             dbg!(x);
+...  |
+LL | |         2
+LL | |     ];
+   | |_____^
+   |
+   = note: each element will point to the same `Rc` instance
+help: consider initializing each `Rc` element individually
+   |
+LL ~     let v1 = {
+LL +         let mut v = Vec::with_capacity(2);
+LL +         (0..2).for_each(|_| v.push(Rc::new(..)));
+LL +         v
+LL ~     };
+   |
+help: or if this is intentional, consider extracting the `Rc` initialization to a variable
+   |
+LL ~     let v1 = {
+LL +         let data = Rc::new(..);
+LL +         vec![data; 2]
+LL ~     };
+   |
+
+error: aborting due to 3 previous errors