about summary refs log tree commit diff
path: root/tests/ui/malformed
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-04-19 22:54:53 -0400
committerMichael Goulet <michael@errs.io>2024-05-18 13:08:34 -0400
commit5ee4db4e05ecb845fa99b8863a080014f7ada9cb (patch)
treed3beddec12b295f7d59d3f90424747944a5912be /tests/ui/malformed
parent685a80f7a0935c8e5016d8c9cd491937af155dd0 (diff)
downloadrust-5ee4db4e05ecb845fa99b8863a080014f7ada9cb.tar.gz
rust-5ee4db4e05ecb845fa99b8863a080014f7ada9cb.zip
Warn/error on self ctor from outer item in inner item
Diffstat (limited to 'tests/ui/malformed')
-rw-r--r--tests/ui/malformed/do-not-ice-on-note_and_explain.rs17
-rw-r--r--tests/ui/malformed/do-not-ice-on-note_and_explain.stderr85
2 files changed, 20 insertions, 82 deletions
diff --git a/tests/ui/malformed/do-not-ice-on-note_and_explain.rs b/tests/ui/malformed/do-not-ice-on-note_and_explain.rs
index e65276fb738..be0b18a00d2 100644
--- a/tests/ui/malformed/do-not-ice-on-note_and_explain.rs
+++ b/tests/ui/malformed/do-not-ice-on-note_and_explain.rs
@@ -1,7 +1,12 @@
 struct A<B>(B);
-impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-//~^ ERROR the size for values of type `B` cannot be known at compilation time
-//~| ERROR the size for values of type `B` cannot be known at compilation time
-//~| ERROR mismatched types
-//~| ERROR mismatched types
-//~| ERROR `main` function not found in crate
+
+impl<B> A<B> {
+    fn d() {
+        fn d() {
+            Self(1)
+            //~^ ERROR can't reference `Self` constructor from outer item
+        }
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/malformed/do-not-ice-on-note_and_explain.stderr b/tests/ui/malformed/do-not-ice-on-note_and_explain.stderr
index 41d0f17366b..11a8c01e490 100644
--- a/tests/ui/malformed/do-not-ice-on-note_and_explain.stderr
+++ b/tests/ui/malformed/do-not-ice-on-note_and_explain.stderr
@@ -1,79 +1,12 @@
-error[E0601]: `main` function not found in crate `do_not_ice_on_note_and_explain`
-  --> $DIR/do-not-ice-on-note_and_explain.rs:2:37
+error[E0401]: can't reference `Self` constructor from outer item
+  --> $DIR/do-not-ice-on-note_and_explain.rs:6:13
    |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-   |                                     ^ consider adding a `main` function to `$DIR/do-not-ice-on-note_and_explain.rs`
+LL | impl<B> A<B> {
+   | ------------ the inner item doesn't inherit generics from this impl, so `Self` is invalid to reference
+...
+LL |             Self(1)
+   |             ^^^^ help: replace `Self` with the actual type: `A`
 
-error[E0277]: the size for values of type `B` cannot be known at compilation time
-  --> $DIR/do-not-ice-on-note_and_explain.rs:2:32
-   |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-   |      -                    ---- ^ doesn't have a size known at compile-time
-   |      |                    |
-   |      |                    required by a bound introduced by this call
-   |      this type parameter needs to be `Sized`
-   |
-note: required by a bound in `A`
-  --> $DIR/do-not-ice-on-note_and_explain.rs:1:10
-   |
-LL | struct A<B>(B);
-   |          ^ required by this bound in `A`
-
-error[E0308]: mismatched types
-  --> $DIR/do-not-ice-on-note_and_explain.rs:2:32
-   |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-   |                           ---- ^ expected type parameter `B`, found integer
-   |                           |
-   |                           arguments to this function are incorrect
-   |
-   = note: expected type parameter `B`
-                        found type `{integer}`
-note: tuple struct defined here
-  --> $DIR/do-not-ice-on-note_and_explain.rs:1:8
-   |
-LL | struct A<B>(B);
-   |        ^
-
-error[E0308]: mismatched types
-  --> $DIR/do-not-ice-on-note_and_explain.rs:2:27
-   |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-   |                           ^^^^^^^ expected `()`, found `A<B>`
-   |
-   = note: expected unit type `()`
-                 found struct `A<B>`
-help: consider using a semicolon here
-   |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1);}}}
-   |                                  +
-help: try adding a return type
-   |
-LL | impl<B>A<B>{fn d(){fn d() -> A<B>{Self(1)}}}
-   |                           +++++++
-
-error[E0277]: the size for values of type `B` cannot be known at compilation time
-  --> $DIR/do-not-ice-on-note_and_explain.rs:2:27
-   |
-LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}}
-   |      -                    ^^^^^^^ doesn't have a size known at compile-time
-   |      |
-   |      this type parameter needs to be `Sized`
-   |
-note: required by an implicit `Sized` bound in `A`
-  --> $DIR/do-not-ice-on-note_and_explain.rs:1:10
-   |
-LL | struct A<B>(B);
-   |          ^ required by the implicit `Sized` requirement on this type parameter in `A`
-help: you could relax the implicit `Sized` bound on `B` if it were used through indirection like `&B` or `Box<B>`
-  --> $DIR/do-not-ice-on-note_and_explain.rs:1:10
-   |
-LL | struct A<B>(B);
-   |          ^  - ...if indirection were used here: `Box<B>`
-   |          |
-   |          this could be changed to `B: ?Sized`...
-
-error: aborting due to 5 previous errors
+error: aborting due to 1 previous error
 
-Some errors have detailed explanations: E0277, E0308, E0601.
-For more information about an error, try `rustc --explain E0277`.
+For more information about this error, try `rustc --explain E0401`.