Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8a1cbcf

Browse files
authoredApr 9, 2024
Unrolled build for rust-lang#123653
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 2805aed + ddc16e9 commit 8a1cbcf

22 files changed

+1375
-1196
lines changed
 
Lines changed: 20 additions & 0 deletions
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() {}
Lines changed: 16 additions & 0 deletions
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+
Lines changed: 88 additions & 0 deletions
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+
};
Lines changed: 103 additions & 0 deletions
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+
Lines changed: 48 additions & 0 deletions
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+
}
Lines changed: 99 additions & 0 deletions
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+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
use std::fmt::Display;
5+
6+
trait Trait {}
7+
struct Test;
8+
9+
fn main() {
10+
impl Test {
11+
//~^ WARN non-local `impl` definition
12+
fn foo() {}
13+
}
14+
15+
impl Display for Test {
16+
//~^ WARN non-local `impl` definition
17+
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18+
todo!()
19+
}
20+
}
21+
22+
impl dyn Trait {}
23+
//~^ WARN non-local `impl` definition
24+
25+
impl<T: Trait> Trait for Vec<T> { }
26+
//~^ WARN non-local `impl` definition
27+
28+
impl Trait for &dyn Trait {}
29+
//~^ WARN non-local `impl` definition
30+
31+
impl Trait for *mut Test {}
32+
//~^ WARN non-local `impl` definition
33+
34+
impl Trait for *mut [Test] {}
35+
//~^ WARN non-local `impl` definition
36+
37+
impl Trait for [Test; 8] {}
38+
//~^ WARN non-local `impl` definition
39+
40+
impl Trait for (Test,) {}
41+
//~^ WARN non-local `impl` definition
42+
43+
impl Trait for fn(Test) -> () {}
44+
//~^ WARN non-local `impl` definition
45+
46+
impl Trait for fn() -> Test {}
47+
//~^ WARN non-local `impl` definition
48+
49+
let _a = || {
50+
impl Trait for Test {}
51+
//~^ WARN non-local `impl` definition
52+
53+
1
54+
};
55+
56+
struct InsideMain;
57+
58+
impl Trait for *mut InsideMain {}
59+
//~^ WARN non-local `impl` definition
60+
impl Trait for *mut [InsideMain] {}
61+
//~^ WARN non-local `impl` definition
62+
impl Trait for [InsideMain; 8] {}
63+
//~^ WARN non-local `impl` definition
64+
impl Trait for (InsideMain,) {}
65+
//~^ WARN non-local `impl` definition
66+
impl Trait for fn(InsideMain) -> () {}
67+
//~^ WARN non-local `impl` definition
68+
impl Trait for fn() -> InsideMain {}
69+
//~^ WARN non-local `impl` definition
70+
71+
fn inside_inside() {
72+
impl Display for InsideMain {
73+
//~^ WARN non-local `impl` definition
74+
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
75+
todo!()
76+
}
77+
}
78+
79+
impl InsideMain {
80+
//~^ WARN non-local `impl` definition
81+
fn bar() {}
82+
}
83+
}
84+
}

‎tests/ui/lint/non-local-defs/exhaustive.stderr

Lines changed: 239 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
#![feature(inline_const)]
5+
6+
struct Cat;
7+
struct Wrap<T>(T);
8+
9+
fn main() {
10+
impl From<Cat> for () {
11+
//~^ WARN non-local `impl` definition
12+
fn from(_: Cat) -> () {
13+
todo!()
14+
}
15+
}
16+
17+
#[derive(Debug)]
18+
struct Elephant;
19+
20+
impl From<Wrap<Wrap<Elephant>>> for () {
21+
//~^ WARN non-local `impl` definition
22+
fn from(_: Wrap<Wrap<Elephant>>) -> Self {
23+
todo!()
24+
}
25+
}
26+
}
27+
28+
pub trait StillNonLocal {}
29+
30+
impl StillNonLocal for &str {}
31+
32+
fn only_global() {
33+
struct Foo;
34+
impl StillNonLocal for &Foo {}
35+
//~^ WARN non-local `impl` definition
36+
}
37+
38+
struct GlobalSameFunction;
39+
40+
fn same_function() {
41+
struct Local1(GlobalSameFunction);
42+
impl From<Local1> for GlobalSameFunction {
43+
//~^ WARN non-local `impl` definition
44+
fn from(x: Local1) -> GlobalSameFunction {
45+
x.0
46+
}
47+
}
48+
49+
struct Local2(GlobalSameFunction);
50+
impl From<Local2> for GlobalSameFunction {
51+
//~^ WARN non-local `impl` definition
52+
fn from(x: Local2) -> GlobalSameFunction {
53+
x.0
54+
}
55+
}
56+
}
57+
58+
struct GlobalDifferentFunction;
59+
60+
fn diff_function_1() {
61+
struct Local(GlobalDifferentFunction);
62+
63+
impl From<Local> for GlobalDifferentFunction {
64+
// FIXME(Urgau): Should warn but doesn't since we currently consider
65+
// the other impl to be "global", but that's not the case for the type-system
66+
fn from(x: Local) -> GlobalDifferentFunction {
67+
x.0
68+
}
69+
}
70+
}
71+
72+
fn diff_function_2() {
73+
struct Local(GlobalDifferentFunction);
74+
75+
impl From<Local> for GlobalDifferentFunction {
76+
// FIXME(Urgau): Should warn but doesn't since we currently consider
77+
// the other impl to be "global", but that's not the case for the type-system
78+
fn from(x: Local) -> GlobalDifferentFunction {
79+
x.0
80+
}
81+
}
82+
}
83+
84+
// https://github.com/rust-lang/rust/issues/121621#issuecomment-1976826895
85+
fn commonly_reported() {
86+
struct Local(u8);
87+
impl From<Local> for u8 {
88+
fn from(x: Local) -> u8 {
89+
x.0
90+
}
91+
}
92+
}
93+
94+
// https://github.com/rust-lang/rust/issues/121621#issue-2153187542
95+
pub trait Serde {}
96+
97+
impl Serde for &[u8] {}
98+
impl Serde for &str {}
99+
100+
fn serde() {
101+
struct Thing;
102+
impl Serde for &Thing {}
103+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/from-local-for-global.rs:10:5
3+
|
4+
LL | / impl From<Cat> for () {
5+
LL | |
6+
LL | | fn from(_: Cat) -> () {
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/from-local-for-global.rs:20:5
20+
|
21+
LL | / impl From<Wrap<Wrap<Elephant>>> for () {
22+
LL | |
23+
LL | | fn from(_: Wrap<Wrap<Elephant>>) -> Self {
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/from-local-for-global.rs:34:5
36+
|
37+
LL | impl StillNonLocal for &Foo {}
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
|
40+
= help: move this `impl` block outside the of the current function `only_global`
41+
= 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`
42+
= 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
43+
= 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>
44+
45+
warning: non-local `impl` definition, they should be avoided as they go against expectation
46+
--> $DIR/from-local-for-global.rs:42:5
47+
|
48+
LL | / impl From<Local1> for GlobalSameFunction {
49+
LL | |
50+
LL | | fn from(x: Local1) -> GlobalSameFunction {
51+
LL | | x.0
52+
LL | | }
53+
LL | | }
54+
| |_____^
55+
|
56+
= help: move this `impl` block outside the of the current function `same_function`
57+
= 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`
58+
= 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
59+
= 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>
60+
61+
warning: non-local `impl` definition, they should be avoided as they go against expectation
62+
--> $DIR/from-local-for-global.rs:50:5
63+
|
64+
LL | / impl From<Local2> for GlobalSameFunction {
65+
LL | |
66+
LL | | fn from(x: Local2) -> GlobalSameFunction {
67+
LL | | x.0
68+
LL | | }
69+
LL | | }
70+
| |_____^
71+
|
72+
= help: move this `impl` block outside the of the current function `same_function`
73+
= 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`
74+
= 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
75+
= 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>
76+
77+
warning: 5 warnings emitted
78+
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
trait Global {}
5+
6+
fn main() {
7+
trait Local {};
8+
9+
impl<T: Local> Global for Vec<T> { }
10+
//~^ WARN non-local `impl` definition
11+
}
12+
13+
trait Uto7 {}
14+
trait Uto8 {}
15+
16+
struct Test;
17+
18+
fn bad() {
19+
struct Local;
20+
impl Uto7 for Test where Local: std::any::Any {}
21+
//~^ WARN non-local `impl` definition
22+
23+
impl<T> Uto8 for T {}
24+
//~^ WARN non-local `impl` definition
25+
}
26+
27+
struct UwU<T>(T);
28+
29+
fn fun() {
30+
#[derive(Debug)]
31+
struct OwO;
32+
impl Default for UwU<OwO> {
33+
//~^ WARN non-local `impl` definition
34+
fn default() -> Self {
35+
UwU(OwO)
36+
}
37+
}
38+
}
39+
40+
fn meow() {
41+
#[derive(Debug)]
42+
struct Cat;
43+
impl AsRef<Cat> for () {
44+
//~^ WARN non-local `impl` definition
45+
fn as_ref(&self) -> &Cat { &Cat }
46+
}
47+
}
48+
49+
struct G;
50+
51+
fn fun2() {
52+
#[derive(Debug, Default)]
53+
struct B;
54+
impl PartialEq<B> for G {
55+
//~^ WARN non-local `impl` definition
56+
fn eq(&self, _: &B) -> bool {
57+
true
58+
}
59+
}
60+
}
61+
62+
struct Wrap<T>(T);
63+
64+
impl Wrap<Wrap<Wrap<()>>> {}
65+
66+
fn rawr() {
67+
struct Lion;
68+
69+
impl From<Wrap<Wrap<Lion>>> for () {
70+
//~^ WARN non-local `impl` definition
71+
fn from(_: Wrap<Wrap<Lion>>) -> Self {
72+
todo!()
73+
}
74+
}
75+
76+
impl From<()> for Wrap<Lion> {
77+
//~^ WARN non-local `impl` definition
78+
fn from(_: ()) -> Self {
79+
todo!()
80+
}
81+
}
82+
}
83+
84+
fn side_effects() {
85+
dbg!(().as_ref()); // prints `Cat`
86+
dbg!(UwU::default().0);
87+
let _ = G::eq(&G, dbg!(&<_>::default()));
88+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/generics.rs:9:5
3+
|
4+
LL | impl<T: Local> Global for Vec<T> { }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: move this `impl` block outside the of the current function `main`
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: `#[warn(non_local_definitions)]` on by default
12+
13+
warning: non-local `impl` definition, they should be avoided as they go against expectation
14+
--> $DIR/generics.rs:20:5
15+
|
16+
LL | impl Uto7 for Test where Local: std::any::Any {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= help: move this `impl` block outside the of the current function `bad`
20+
= 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`
21+
= 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
22+
= 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>
23+
24+
warning: non-local `impl` definition, they should be avoided as they go against expectation
25+
--> $DIR/generics.rs:23:5
26+
|
27+
LL | impl<T> Uto8 for T {}
28+
| ^^^^^^^^^^^^^^^^^^^^^
29+
|
30+
= help: move this `impl` block outside the of the current function `bad`
31+
= 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`
32+
= 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
33+
= 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>
34+
35+
warning: non-local `impl` definition, they should be avoided as they go against expectation
36+
--> $DIR/generics.rs:32:5
37+
|
38+
LL | / impl Default for UwU<OwO> {
39+
LL | |
40+
LL | | fn default() -> Self {
41+
LL | | UwU(OwO)
42+
LL | | }
43+
LL | | }
44+
| |_____^
45+
|
46+
= help: move this `impl` block outside the of the current function `fun`
47+
= 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`
48+
= 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
49+
= 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>
50+
51+
warning: non-local `impl` definition, they should be avoided as they go against expectation
52+
--> $DIR/generics.rs:43:5
53+
|
54+
LL | / impl AsRef<Cat> for () {
55+
LL | |
56+
LL | | fn as_ref(&self) -> &Cat { &Cat }
57+
LL | | }
58+
| |_____^
59+
|
60+
= help: move this `impl` block outside the of the current function `meow`
61+
= 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`
62+
= 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
63+
= 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>
64+
65+
warning: non-local `impl` definition, they should be avoided as they go against expectation
66+
--> $DIR/generics.rs:54:5
67+
|
68+
LL | / impl PartialEq<B> for G {
69+
LL | |
70+
LL | | fn eq(&self, _: &B) -> bool {
71+
LL | | true
72+
LL | | }
73+
LL | | }
74+
| |_____^
75+
|
76+
= help: move this `impl` block outside the of the current function `fun2`
77+
= 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`
78+
= 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
79+
= 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>
80+
81+
warning: non-local `impl` definition, they should be avoided as they go against expectation
82+
--> $DIR/generics.rs:69:5
83+
|
84+
LL | / impl From<Wrap<Wrap<Lion>>> for () {
85+
LL | |
86+
LL | | fn from(_: Wrap<Wrap<Lion>>) -> Self {
87+
LL | | todo!()
88+
LL | | }
89+
LL | | }
90+
| |_____^
91+
|
92+
= help: move this `impl` block outside the of the current function `rawr`
93+
= 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`
94+
= 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
95+
= 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>
96+
97+
warning: non-local `impl` definition, they should be avoided as they go against expectation
98+
--> $DIR/generics.rs:76:5
99+
|
100+
LL | / impl From<()> for Wrap<Lion> {
101+
LL | |
102+
LL | | fn from(_: ()) -> Self {
103+
LL | | todo!()
104+
LL | | }
105+
LL | | }
106+
| |_____^
107+
|
108+
= help: move this `impl` block outside the of the current function `rawr`
109+
= 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`
110+
= 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
111+
= 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>
112+
113+
warning: 8 warnings emitted
114+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
macro_rules! m {
5+
() => {
6+
trait MacroTrait {}
7+
struct OutsideStruct;
8+
fn my_func() {
9+
impl MacroTrait for OutsideStruct {}
10+
//~^ WARN non-local `impl` definition
11+
}
12+
}
13+
}
14+
15+
m!();
16+
17+
fn main() {}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/inside-macro_rules.rs:9:13
3+
|
4+
LL | impl MacroTrait for OutsideStruct {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | m!();
8+
| ---- in this macro invocation
9+
|
10+
= help: move this `impl` block outside the of the current function `my_func`
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+
= note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
warning: 1 warning emitted
18+

‎tests/ui/lint/non-local-defs/local.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
use std::fmt::Debug;
5+
6+
trait GlobalTrait {}
7+
8+
fn main() {
9+
struct InsideMain;
10+
11+
impl InsideMain {
12+
fn foo() {}
13+
}
14+
15+
impl GlobalTrait for InsideMain {}
16+
17+
impl Debug for InsideMain {
18+
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
19+
todo!()
20+
}
21+
}
22+
23+
impl PartialEq<()> for InsideMain {
24+
fn eq(&self, _: &()) -> bool {
25+
todo!()
26+
}
27+
}
28+
}
29+
30+
fn dyn_weirdness() {
31+
trait LocalTrait {}
32+
impl dyn LocalTrait {}
33+
impl GlobalTrait for dyn LocalTrait {}
34+
}
35+
36+
struct Test;
37+
mod do_not_lint_mod {
38+
pub trait Tait {}
39+
40+
impl super::Test {
41+
fn hugo() {}
42+
}
43+
44+
impl Tait for super::Test {}
45+
}
46+
47+
fn bitflags() {
48+
struct Flags;
49+
50+
const _: () = {
51+
impl Flags {}
52+
};
53+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
//@ aux-build:non_local_macro.rs
4+
//@ rustc-env:CARGO_CRATE_NAME=non_local_def
5+
6+
extern crate non_local_macro;
7+
8+
const B: u32 = {
9+
#[macro_export]
10+
macro_rules! m0 { () => { } };
11+
//~^ WARN non-local `macro_rules!` definition
12+
13+
1
14+
};
15+
16+
non_local_macro::non_local_macro_rules!(my_macro);
17+
//~^ WARN non-local `macro_rules!` definition
18+
19+
fn main() {
20+
#[macro_export]
21+
macro_rules! m { () => { } };
22+
//~^ WARN non-local `macro_rules!` definition
23+
24+
struct InsideMain;
25+
26+
impl InsideMain {
27+
fn bar() {
28+
#[macro_export]
29+
macro_rules! m2 { () => { } };
30+
//~^ WARN non-local `macro_rules!` definition
31+
}
32+
}
33+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
2+
--> $DIR/macro_rules.rs:10:5
3+
|
4+
LL | macro_rules! m0 { () => { } };
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `B`
8+
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
9+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
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: `#[warn(non_local_definitions)]` on by default
12+
13+
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
14+
--> $DIR/macro_rules.rs:16:1
15+
|
16+
LL | non_local_macro::non_local_macro_rules!(my_macro);
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current constant `_MACRO_EXPORT`
20+
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
21+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
22+
= 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>
23+
= note: the macro `non_local_macro::non_local_macro_rules` may come from an old version of the `non_local_macro` crate, try updating your dependency with `cargo update -p non_local_macro`
24+
= note: this warning originates in the macro `non_local_macro::non_local_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info)
25+
26+
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
27+
--> $DIR/macro_rules.rs:21:5
28+
|
29+
LL | macro_rules! m { () => { } };
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31+
|
32+
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current function `main`
33+
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
34+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
35+
= 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>
36+
37+
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
38+
--> $DIR/macro_rules.rs:29:13
39+
|
40+
LL | macro_rules! m2 { () => { } };
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
42+
|
43+
= help: remove the `#[macro_export]` or move this `macro_rules!` outside the of the current associated function `bar` and up 2 bodies
44+
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
45+
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
46+
= 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>
47+
48+
warning: 4 warnings emitted
49+
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//@ check-pass
2+
//@ edition:2021
3+
4+
trait Uto {}
5+
struct Test;
6+
7+
type A = [u32; {
8+
impl Uto for *mut Test {}
9+
//~^ WARN non-local `impl` definition
10+
11+
1
12+
}];
13+
14+
enum Enum {
15+
Discr = {
16+
impl Uto for Test {}
17+
//~^ WARN non-local `impl` definition
18+
19+
1
20+
}
21+
}
22+
23+
fn main() {
24+
let _array = [0i32; {
25+
impl Test {
26+
//~^ WARN non-local `impl` definition
27+
fn bar() {}
28+
}
29+
30+
1
31+
}];
32+
33+
type A = [u32; {
34+
impl Uto for &Test {}
35+
//~^ WARN non-local `impl` definition
36+
37+
1
38+
}];
39+
40+
fn a(_: [u32; {
41+
impl Uto for &(Test,) {}
42+
//~^ WARN non-local `impl` definition
43+
44+
1
45+
}]) {}
46+
47+
fn b() -> [u32; {
48+
impl Uto for &(Test,Test) {}
49+
//~^ WARN non-local `impl` definition
50+
51+
1
52+
}] { todo!() }
53+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
warning: non-local `impl` definition, they should be avoided as they go against expectation
2+
--> $DIR/weird-exprs.rs:8:5
3+
|
4+
LL | impl Uto for *mut Test {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: move this `impl` block outside the of the current constant expression `<unnameable>`
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: `#[warn(non_local_definitions)]` on by default
12+
13+
warning: non-local `impl` definition, they should be avoided as they go against expectation
14+
--> $DIR/weird-exprs.rs:16:9
15+
|
16+
LL | impl Uto for Test {}
17+
| ^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= help: move this `impl` block outside the of the current constant expression `<unnameable>`
20+
= 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`
21+
= 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
22+
= 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>
23+
24+
warning: non-local `impl` definition, they should be avoided as they go against expectation
25+
--> $DIR/weird-exprs.rs:25:9
26+
|
27+
LL | / impl Test {
28+
LL | |
29+
LL | | fn bar() {}
30+
LL | | }
31+
| |_________^
32+
|
33+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
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/weird-exprs.rs:34:9
40+
|
41+
LL | impl Uto for &Test {}
42+
| ^^^^^^^^^^^^^^^^^^^^^
43+
|
44+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
45+
= 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`
46+
= 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
47+
= 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>
48+
49+
warning: non-local `impl` definition, they should be avoided as they go against expectation
50+
--> $DIR/weird-exprs.rs:41:9
51+
|
52+
LL | impl Uto for &(Test,) {}
53+
| ^^^^^^^^^^^^^^^^^^^^^^^^
54+
|
55+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
56+
= 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`
57+
= 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
58+
= 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>
59+
60+
warning: non-local `impl` definition, they should be avoided as they go against expectation
61+
--> $DIR/weird-exprs.rs:48:9
62+
|
63+
LL | impl Uto for &(Test,Test) {}
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
65+
|
66+
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies
67+
= 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`
68+
= 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
69+
= 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>
70+
71+
warning: 6 warnings emitted
72+

‎tests/ui/lint/non_local_definitions.rs

Lines changed: 0 additions & 491 deletions
This file was deleted.

‎tests/ui/lint/non_local_definitions.stderr

Lines changed: 0 additions & 705 deletions
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.