about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/box_default.fixed18
-rw-r--r--tests/ui/box_default.rs16
-rw-r--r--tests/ui/box_default.stderr16
3 files changed, 47 insertions, 3 deletions
diff --git a/tests/ui/box_default.fixed b/tests/ui/box_default.fixed
index 48408e19125..fea7405c685 100644
--- a/tests/ui/box_default.fixed
+++ b/tests/ui/box_default.fixed
@@ -21,7 +21,7 @@ macro_rules! outer {
 fn main() {
     let _string: Box<String> = Box::default();
     let _byte = Box::<u8>::default();
-    let _vec = Box::<Vec<u8>>::default();
+    let _vec = Box::<Vec::<u8>>::default();
     let _impl = Box::<ImplementsDefault>::default();
     let _impl2 = Box::<ImplementsDefault>::default();
     let _impl3: Box<ImplementsDefault> = Box::default();
@@ -104,3 +104,19 @@ fn issue_11868() {
     foo(bar!(vec![]));
     foo(bar!(vec![1]));
 }
+
+// Issue #11927: The quickfix for the `Box::new` suggests replacing with `Box::<Inner>::default()`,
+// removing the `outer::` segment.
+fn issue_11927() {
+    mod outer {
+        #[derive(Default)]
+        pub struct Inner {
+            _i: usize,
+        }
+    }
+
+    fn foo() {
+        let _b = Box::<outer::Inner>::default();
+        let _b = Box::<std::collections::HashSet::<i32>>::default();
+    }
+}
diff --git a/tests/ui/box_default.rs b/tests/ui/box_default.rs
index 58b91270747..eecba7464ec 100644
--- a/tests/ui/box_default.rs
+++ b/tests/ui/box_default.rs
@@ -104,3 +104,19 @@ fn issue_11868() {
     foo(bar!(vec![]));
     foo(bar!(vec![1]));
 }
+
+// Issue #11927: The quickfix for the `Box::new` suggests replacing with `Box::<Inner>::default()`,
+// removing the `outer::` segment.
+fn issue_11927() {
+    mod outer {
+        #[derive(Default)]
+        pub struct Inner {
+            _i: usize,
+        }
+    }
+
+    fn foo() {
+        let _b = Box::new(outer::Inner::default());
+        let _b = Box::new(std::collections::HashSet::<i32>::new());
+    }
+}
diff --git a/tests/ui/box_default.stderr b/tests/ui/box_default.stderr
index f727b377319..8bb5917a627 100644
--- a/tests/ui/box_default.stderr
+++ b/tests/ui/box_default.stderr
@@ -17,7 +17,7 @@ error: `Box::new(_)` of default value
   --> tests/ui/box_default.rs:24:16
    |
 LL |     let _vec = Box::new(Vec::<u8>::new());
-   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec<u8>>::default()`
+   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Vec::<u8>>::default()`
 
 error: `Box::new(_)` of default value
   --> tests/ui/box_default.rs:25:17
@@ -97,5 +97,17 @@ error: `Box::new(_)` of default value
 LL |             Some(Box::new(Foo::default()))
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<Foo>::default()`
 
-error: aborting due to 16 previous errors
+error: `Box::new(_)` of default value
+  --> tests/ui/box_default.rs:119:18
+   |
+LL |         let _b = Box::new(outer::Inner::default());
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<outer::Inner>::default()`
+
+error: `Box::new(_)` of default value
+  --> tests/ui/box_default.rs:120:18
+   |
+LL |         let _b = Box::new(std::collections::HashSet::<i32>::new());
+   |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Box::<std::collections::HashSet::<i32>>::default()`
+
+error: aborting due to 18 previous errors