about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/lint/non-local-defs/consts.rs7
-rw-r--r--tests/ui/lint/non-local-defs/consts.stderr20
-rw-r--r--tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs34
-rw-r--r--tests/ui/lint/non-local-defs/convoluted-locals-131474.rs24
-rw-r--r--tests/ui/lint/non-local-defs/local.rs7
5 files changed, 89 insertions, 3 deletions
diff --git a/tests/ui/lint/non-local-defs/consts.rs b/tests/ui/lint/non-local-defs/consts.rs
index d8a497e43e5..5b9dab3cfd3 100644
--- a/tests/ui/lint/non-local-defs/consts.rs
+++ b/tests/ui/lint/non-local-defs/consts.rs
@@ -63,6 +63,13 @@ fn main() {
 
         1
     };
+
+    const _: () = {
+        const _: () = {
+            impl Test {}
+            //~^ WARN non-local `impl` definition
+        };
+    };
 }
 
 trait Uto9 {}
diff --git a/tests/ui/lint/non-local-defs/consts.stderr b/tests/ui/lint/non-local-defs/consts.stderr
index 7f76056c021..4bf50bae5ea 100644
--- a/tests/ui/lint/non-local-defs/consts.stderr
+++ b/tests/ui/lint/non-local-defs/consts.stderr
@@ -95,7 +95,21 @@ LL |         impl Test {
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
 
 warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
-  --> $DIR/consts.rs:72:9
+  --> $DIR/consts.rs:69:13
+   |
+LL |         const _: () = {
+   |         ----------- move the `impl` block outside of this constant `_` and up 3 bodies
+LL |             impl Test {}
+   |             ^^^^^----
+   |                  |
+   |                  `Test` is not local
+   |
+   = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
+   = note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
+   = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
+
+warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
+  --> $DIR/consts.rs:79:9
    |
 LL |     let _a = || {
    |              -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
@@ -109,7 +123,7 @@ LL |         impl Uto9 for Test {}
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
 
 warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
-  --> $DIR/consts.rs:79:9
+  --> $DIR/consts.rs:86:9
    |
 LL |       type A = [u32; {
    |  ____________________-
@@ -126,5 +140,5 @@ LL | |     }];
    = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
    = note: this lint may become deny-by-default in the edition 2024 and higher, see the tracking issue <https://github.com/rust-lang/rust/issues/120363>
 
-warning: 8 warnings emitted
+warning: 9 warnings emitted
 
diff --git a/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs b/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs
new file mode 100644
index 00000000000..cef0f0205e8
--- /dev/null
+++ b/tests/ui/lint/non-local-defs/convoluted-locals-131474-with-mods.rs
@@ -0,0 +1,34 @@
+// This test check that no matter the nesting of const-anons and modules
+// we consider them as transparent.
+//
+// Similar to https://github.com/rust-lang/rust/issues/131474
+
+//@ check-pass
+
+pub mod tmp {
+    pub mod tmp {
+        pub struct Test;
+    }
+}
+
+const _: () = {
+    const _: () = {
+        const _: () = {
+            const _: () = {
+                impl tmp::tmp::Test {}
+            };
+        };
+    };
+};
+
+const _: () = {
+    const _: () = {
+        mod tmp {
+            pub(super) struct InnerTest;
+        }
+
+        impl tmp::InnerTest {}
+    };
+};
+
+fn main() {}
diff --git a/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs b/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs
new file mode 100644
index 00000000000..4881723f13b
--- /dev/null
+++ b/tests/ui/lint/non-local-defs/convoluted-locals-131474.rs
@@ -0,0 +1,24 @@
+// This test check that no matter the nesting of const-anons we consider
+// them as transparent.
+//
+// https://github.com/rust-lang/rust/issues/131474
+
+//@ check-pass
+
+pub struct Test;
+
+const _: () = {
+    const _: () = {
+        impl Test {}
+    };
+};
+
+const _: () = {
+    const _: () = {
+        struct InnerTest;
+
+        impl InnerTest {}
+    };
+};
+
+fn main() {}
diff --git a/tests/ui/lint/non-local-defs/local.rs b/tests/ui/lint/non-local-defs/local.rs
index 166ee88c021..f7ecd68f59e 100644
--- a/tests/ui/lint/non-local-defs/local.rs
+++ b/tests/ui/lint/non-local-defs/local.rs
@@ -51,3 +51,10 @@ fn bitflags() {
         impl Flags {}
     };
 }
+
+fn bitflags_internal() {
+    const _: () = {
+        struct InternalFlags;
+        impl InternalFlags {}
+    };
+}