Skip to content

Commit 1ea980b

Browse files
Rollup merge of rust-lang#123653 - Urgau:split-test-non_local_defs, r=compiler-errors
Split `non_local_definitions` lint tests in separate test files This PR splits the giant `non_local_definitions` lint UI test in separate test files. This change is extracted from rust-lang#123594 (where it was requested rust-lang#123594 (comment)), to ease the review of the other PR and to reduce the size of the other PR. r? `@compiler-errors`
2 parents a63892d + ddc16e9 commit 1ea980b

22 files changed

+1375
-1196
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
//@ aux-build:non_local_macro.rs
4+
//
5+
// To suggest any Cargo specific help/note rustc wants
6+
// the `CARGO_CRATE_NAME` env to be set, so we set it
7+
//@ rustc-env:CARGO_CRATE_NAME=non_local_def
8+
//
9+
// and since we specifically want to check the presence
10+
// of the `cargo update` suggestion we assert it here.
11+
//@ error-pattern: `cargo update -p non_local_macro`
12+
13+
extern crate non_local_macro;
14+
15+
struct LocalStruct;
16+
17+
non_local_macro::non_local_impl!(LocalStruct);
18+
//~^ WARN non-local `impl` definition
19+
20+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/cargo-update.rs:17:1
3+
|
4+
LL | non_local_macro::non_local_impl!(LocalStruct);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: move this `impl` block outside the of the current constant `_IMPL_DEBUG`
8+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
9+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
10+
= 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>
11+
= note: the macro `non_local_macro::non_local_impl` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
12+
= note: `#[warn(non_local_definitions)]` on by default
13+
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
warning: 1 warning emitted
16+
+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
//@ rustc-env:CARGO_CRATE_NAME=non_local_def
4+
5+
#![feature(inline_const)]
6+
7+
struct Test;
8+
9+
trait Uto {}
10+
const Z: () = {
11+
trait Uto1 {}
12+
13+
impl Uto1 for Test {} // the trait is local, don't lint
14+
15+
impl Uto for &Test {}
16+
//~^ WARN non-local `impl` definition
17+
};
18+
19+
trait Ano {}
20+
const _: () = {
21+
impl Ano for &Test {} // ignored since the parent is an anon-const
22+
};
23+
24+
trait Uto2 {}
25+
static A: u32 = {
26+
impl Uto2 for Test {}
27+
//~^ WARN non-local `impl` definition
28+
29+
1
30+
};
31+
32+
trait Uto3 {}
33+
const B: u32 = {
34+
impl Uto3 for Test {}
35+
//~^ WARN non-local `impl` definition
36+
37+
trait Uto4 {}
38+
impl Uto4 for Test {}
39+
40+
1
41+
};
42+
43+
trait Uto5 {}
44+
fn main() {
45+
impl Test {
46+
//~^ WARN non-local `impl` definition
47+
fn foo() {}
48+
}
49+
50+
51+
const {
52+
impl Test {
53+
//~^ WARN non-local `impl` definition
54+
fn hoo() {}
55+
}
56+
57+
1
58+
};
59+
60+
const _: u32 = {
61+
impl Test {
62+
//~^ WARN non-local `impl` definition
63+
fn foo2() {}
64+
}
65+
66+
1
67+
};
68+
}
69+
70+
trait Uto9 {}
71+
trait Uto10 {}
72+
const _: u32 = {
73+
let _a = || {
74+
impl Uto9 for Test {}
75+
//~^ WARN non-local `impl` definition
76+
77+
1
78+
};
79+
80+
type A = [u32; {
81+
impl Uto10 for Test {}
82+
//~^ WARN non-local `impl` definition
83+
84+
1
85+
}];
86+
87+
1
88+
};
+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/consts.rs:15:5
3+
|
4+
LL | const Z: () = {
5+
| - help: use a const-anon item to suppress this lint: `_`
6+
...
7+
LL | impl Uto for &Test {}
8+
| ^^^^^^^^^^^^^^^^^^^^^
9+
|
10+
= help: move this `impl` block outside the of the current constant `Z`
11+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
12+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
13+
= 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>
14+
= note: `#[warn(non_local_definitions)]` on by default
15+
16+
warning: non-local `impl` definition, they should be avoided as they go against expectation
17+
--> $DIR/consts.rs:26:5
18+
|
19+
LL | impl Uto2 for Test {}
20+
| ^^^^^^^^^^^^^^^^^^^^^
21+
|
22+
= help: move this `impl` block outside the of the current static `A`
23+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
24+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
25+
= 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>
26+
27+
warning: non-local `impl` definition, they should be avoided as they go against expectation
28+
--> $DIR/consts.rs:34:5
29+
|
30+
LL | impl Uto3 for Test {}
31+
| ^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
= help: move this `impl` block outside the of the current constant `B`
34+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
35+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
36+
= 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>
37+
38+
warning: non-local `impl` definition, they should be avoided as they go against expectation
39+
--> $DIR/consts.rs:45:5
40+
|
41+
LL | / impl Test {
42+
LL | |
43+
LL | | fn foo() {}
44+
LL | | }
45+
| |_____^
46+
|
47+
= help: move this `impl` block outside the of the current function `main`
48+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
49+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
50+
= 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>
51+
52+
warning: non-local `impl` definition, they should be avoided as they go against expectation
53+
--> $DIR/consts.rs:52:9
54+
|
55+
LL | / impl Test {
56+
LL | |
57+
LL | | fn hoo() {}
58+
LL | | }
59+
| |_________^
60+
|
61+
= help: move this `impl` block outside the of the current inline constant `<unnameable>` and up 2 bodies
62+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
63+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
64+
= 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>
65+
66+
warning: non-local `impl` definition, they should be avoided as they go against expectation
67+
--> $DIR/consts.rs:61:9
68+
|
69+
LL | / impl Test {
70+
LL | |
71+
LL | | fn foo2() {}
72+
LL | | }
73+
| |_________^
74+
|
75+
= help: move this `impl` block outside the of the current constant `_` and up 2 bodies
76+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
77+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
78+
= 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>
79+
80+
warning: non-local `impl` definition, they should be avoided as they go against expectation
81+
--> $DIR/consts.rs:74:9
82+
|
83+
LL | impl Uto9 for Test {}
84+
| ^^^^^^^^^^^^^^^^^^^^^
85+
|
86+
= help: move this `impl` block outside the of the current closure `<unnameable>` and up 2 bodies
87+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
88+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
89+
= 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>
90+
91+
warning: non-local `impl` definition, they should be avoided as they go against expectation
92+
--> $DIR/consts.rs:81:9
93+
|
94+
LL | impl Uto10 for Test {}
95+
| ^^^^^^^^^^^^^^^^^^^^^^
96+
|
97+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
98+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
99+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
100+
= 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>
101+
102+
warning: 8 warnings emitted
103+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
struct Dog;
5+
6+
fn main() {
7+
impl PartialEq<()> for Dog {
8+
//~^ WARN non-local `impl` definition
9+
fn eq(&self, _: &()) -> bool {
10+
todo!()
11+
}
12+
}
13+
14+
impl PartialEq<()> for &Dog {
15+
//~^ WARN non-local `impl` definition
16+
fn eq(&self, _: &()) -> bool {
17+
todo!()
18+
}
19+
}
20+
21+
impl PartialEq<Dog> for () {
22+
//~^ WARN non-local `impl` definition
23+
fn eq(&self, _: &Dog) -> bool {
24+
todo!()
25+
}
26+
}
27+
28+
impl PartialEq<&Dog> for () {
29+
//~^ WARN non-local `impl` definition
30+
fn eq(&self, _: &&Dog) -> bool {
31+
todo!()
32+
}
33+
}
34+
35+
impl PartialEq<Dog> for &Dog {
36+
//~^ WARN non-local `impl` definition
37+
fn eq(&self, _: &Dog) -> bool {
38+
todo!()
39+
}
40+
}
41+
42+
impl PartialEq<&Dog> for &Dog {
43+
//~^ WARN non-local `impl` definition
44+
fn eq(&self, _: &&Dog) -> bool {
45+
todo!()
46+
}
47+
}
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/exhaustive-trait.rs:7:5
3+
|
4+
LL | / impl PartialEq<()> for Dog {
5+
LL | |
6+
LL | | fn eq(&self, _: &()) -> bool {
7+
LL | | todo!()
8+
LL | | }
9+
LL | | }
10+
| |_____^
11+
|
12+
= help: move this `impl` block outside the of the current function `main`
13+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
14+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
15+
= 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>
16+
= note: `#[warn(non_local_definitions)]` on by default
17+
18+
warning: non-local `impl` definition, they should be avoided as they go against expectation
19+
--> $DIR/exhaustive-trait.rs:14:5
20+
|
21+
LL | / impl PartialEq<()> for &Dog {
22+
LL | |
23+
LL | | fn eq(&self, _: &()) -> bool {
24+
LL | | todo!()
25+
LL | | }
26+
LL | | }
27+
| |_____^
28+
|
29+
= help: move this `impl` block outside the of the current function `main`
30+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
31+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
32+
= 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>
33+
34+
warning: non-local `impl` definition, they should be avoided as they go against expectation
35+
--> $DIR/exhaustive-trait.rs:21:5
36+
|
37+
LL | / impl PartialEq<Dog> for () {
38+
LL | |
39+
LL | | fn eq(&self, _: &Dog) -> bool {
40+
LL | | todo!()
41+
LL | | }
42+
LL | | }
43+
| |_____^
44+
|
45+
= help: move this `impl` block outside the of the current function `main`
46+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
47+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
48+
= 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>
49+
50+
warning: non-local `impl` definition, they should be avoided as they go against expectation
51+
--> $DIR/exhaustive-trait.rs:28:5
52+
|
53+
LL | / impl PartialEq<&Dog> for () {
54+
LL | |
55+
LL | | fn eq(&self, _: &&Dog) -> bool {
56+
LL | | todo!()
57+
LL | | }
58+
LL | | }
59+
| |_____^
60+
|
61+
= help: move this `impl` block outside the of the current function `main`
62+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
63+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
64+
= 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>
65+
66+
warning: non-local `impl` definition, they should be avoided as they go against expectation
67+
--> $DIR/exhaustive-trait.rs:35:5
68+
|
69+
LL | / impl PartialEq<Dog> for &Dog {
70+
LL | |
71+
LL | | fn eq(&self, _: &Dog) -> bool {
72+
LL | | todo!()
73+
LL | | }
74+
LL | | }
75+
| |_____^
76+
|
77+
= help: move this `impl` block outside the of the current function `main`
78+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
79+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
80+
= 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>
81+
82+
warning: non-local `impl` definition, they should be avoided as they go against expectation
83+
--> $DIR/exhaustive-trait.rs:42:5
84+
|
85+
LL | / impl PartialEq<&Dog> for &Dog {
86+
LL | |
87+
LL | | fn eq(&self, _: &&Dog) -> bool {
88+
LL | | todo!()
89+
LL | | }
90+
LL | | }
91+
| |_____^
92+
|
93+
= help: move this `impl` block outside the of the current function `main`
94+
= note: an `impl` definition is non-local if it is nested inside an item and may impact type checking outside of that item. This can be the case if neither the trait or the self type are at the same nesting level as the `impl`
95+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module and anon-const at the same nesting as the trait or type
96+
= 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>
97+
98+
warning: 6 warnings emitted
99+

0 commit comments

Comments
 (0)