Skip to content

Commit 72b6ede

Browse files
wesleywisermattstam
authored andcommitted
Make non-local-def lint Allow by default
(cherry picked from commit 23015b9ff4a7f829c2e0c884bdc0bcdb3c6d86f7)
1 parent ce5ab6b commit 72b6ede

21 files changed

+131
-71
lines changed

compiler/rustc_lint/src/non_local_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ declare_lint! {
4646
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
4747
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
4848
pub NON_LOCAL_DEFINITIONS,
49-
Warn,
49+
Allow,
5050
"checks for non-local definitions",
5151
report_in_external_macro
5252
}

tests/ui/lint/non-local-defs/cargo-update.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
// of the `cargo update` suggestion we assert it here.
1111
//@ error-pattern: `cargo update -p non_local_macro`
1212

13+
#![warn(non_local_definitions)]
14+
1315
extern crate non_local_macro;
1416

1517
struct LocalStruct;

tests/ui/lint/non-local-defs/cargo-update.stderr

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, they should be avoided as they go against expectation
2-
--> $DIR/cargo-update.rs:17:1
2+
--> $DIR/cargo-update.rs:19:1
33
|
44
LL | non_local_macro::non_local_impl!(LocalStruct);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -9,7 +9,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
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
1010
= 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>
1111
= 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
12+
note: the lint level is defined here
13+
--> $DIR/cargo-update.rs:13:9
14+
|
15+
LL | #![warn(non_local_definitions)]
16+
| ^^^^^^^^^^^^^^^^^^^^^
1317
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
1418

1519
warning: 1 warning emitted

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

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
//@ edition:2021
33
//@ rustc-env:CARGO_CRATE_NAME=non_local_def
44

5+
#![warn(non_local_definitions)]
6+
57
struct Test;
68

79
trait Uto {}

tests/ui/lint/non-local-defs/consts.stderr

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, they should be avoided as they go against expectation
2-
--> $DIR/consts.rs:13:5
2+
--> $DIR/consts.rs:15:5
33
|
44
LL | const Z: () = {
55
| - help: use a const-anon item to suppress this lint: `_`
@@ -11,10 +11,14 @@ LL | impl Uto for &Test {}
1111
= 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`
1212
= 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
1313
= 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
14+
note: the lint level is defined here
15+
--> $DIR/consts.rs:5:9
16+
|
17+
LL | #![warn(non_local_definitions)]
18+
| ^^^^^^^^^^^^^^^^^^^^^
1519

1620
warning: non-local `impl` definition, they should be avoided as they go against expectation
17-
--> $DIR/consts.rs:24:5
21+
--> $DIR/consts.rs:26:5
1822
|
1923
LL | impl Uto2 for Test {}
2024
| ^^^^^^^^^^^^^^^^^^^^^
@@ -25,7 +29,7 @@ LL | impl Uto2 for Test {}
2529
= 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>
2630

2731
warning: non-local `impl` definition, they should be avoided as they go against expectation
28-
--> $DIR/consts.rs:32:5
32+
--> $DIR/consts.rs:34:5
2933
|
3034
LL | impl Uto3 for Test {}
3135
| ^^^^^^^^^^^^^^^^^^^^^
@@ -36,7 +40,7 @@ LL | impl Uto3 for Test {}
3640
= 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>
3741

3842
warning: non-local `impl` definition, they should be avoided as they go against expectation
39-
--> $DIR/consts.rs:43:5
43+
--> $DIR/consts.rs:45:5
4044
|
4145
LL | / impl Test {
4246
LL | |
@@ -50,7 +54,7 @@ LL | | }
5054
= 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>
5155

5256
warning: non-local `impl` definition, they should be avoided as they go against expectation
53-
--> $DIR/consts.rs:50:9
57+
--> $DIR/consts.rs:52:9
5458
|
5559
LL | / impl Test {
5660
LL | |
@@ -64,7 +68,7 @@ LL | | }
6468
= 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>
6569

6670
warning: non-local `impl` definition, they should be avoided as they go against expectation
67-
--> $DIR/consts.rs:59:9
71+
--> $DIR/consts.rs:61:9
6872
|
6973
LL | / impl Test {
7074
LL | |
@@ -78,7 +82,7 @@ LL | | }
7882
= 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>
7983

8084
warning: non-local `impl` definition, they should be avoided as they go against expectation
81-
--> $DIR/consts.rs:72:9
85+
--> $DIR/consts.rs:74:9
8286
|
8387
LL | impl Uto9 for Test {}
8488
| ^^^^^^^^^^^^^^^^^^^^^
@@ -89,7 +93,7 @@ LL | impl Uto9 for Test {}
8993
= 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>
9094

9195
warning: non-local `impl` definition, they should be avoided as they go against expectation
92-
--> $DIR/consts.rs:79:9
96+
--> $DIR/consts.rs:81:9
9397
|
9498
LL | impl Uto10 for Test {}
9599
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/lint/non-local-defs/exhaustive-trait.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ check-pass
22
//@ edition:2021
33

4+
#![warn(non_local_definitions)]
5+
46
struct Dog;
57

68
fn main() {

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

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, they should be avoided as they go against expectation
2-
--> $DIR/exhaustive-trait.rs:7:5
2+
--> $DIR/exhaustive-trait.rs:9:5
33
|
44
LL | / impl PartialEq<()> for Dog {
55
LL | |
@@ -13,10 +13,14 @@ LL | | }
1313
= 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`
1414
= 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
1515
= 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
16+
note: the lint level is defined here
17+
--> $DIR/exhaustive-trait.rs:4:9
18+
|
19+
LL | #![warn(non_local_definitions)]
20+
| ^^^^^^^^^^^^^^^^^^^^^
1721

1822
warning: non-local `impl` definition, they should be avoided as they go against expectation
19-
--> $DIR/exhaustive-trait.rs:14:5
23+
--> $DIR/exhaustive-trait.rs:16:5
2024
|
2125
LL | / impl PartialEq<()> for &Dog {
2226
LL | |
@@ -32,7 +36,7 @@ LL | | }
3236
= 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>
3337

3438
warning: non-local `impl` definition, they should be avoided as they go against expectation
35-
--> $DIR/exhaustive-trait.rs:21:5
39+
--> $DIR/exhaustive-trait.rs:23:5
3640
|
3741
LL | / impl PartialEq<Dog> for () {
3842
LL | |
@@ -48,7 +52,7 @@ LL | | }
4852
= 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>
4953

5054
warning: non-local `impl` definition, they should be avoided as they go against expectation
51-
--> $DIR/exhaustive-trait.rs:28:5
55+
--> $DIR/exhaustive-trait.rs:30:5
5256
|
5357
LL | / impl PartialEq<&Dog> for () {
5458
LL | |
@@ -64,7 +68,7 @@ LL | | }
6468
= 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>
6569

6670
warning: non-local `impl` definition, they should be avoided as they go against expectation
67-
--> $DIR/exhaustive-trait.rs:35:5
71+
--> $DIR/exhaustive-trait.rs:37:5
6872
|
6973
LL | / impl PartialEq<Dog> for &Dog {
7074
LL | |
@@ -80,7 +84,7 @@ LL | | }
8084
= 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>
8185

8286
warning: non-local `impl` definition, they should be avoided as they go against expectation
83-
--> $DIR/exhaustive-trait.rs:42:5
87+
--> $DIR/exhaustive-trait.rs:44:5
8488
|
8589
LL | / impl PartialEq<&Dog> for &Dog {
8690
LL | |

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ check-pass
22
//@ edition:2021
33

4+
#![warn(non_local_definitions)]
5+
46
use std::fmt::Display;
57

68
trait Trait {}

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

+25-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `impl` definition, they should be avoided as they go against expectation
2-
--> $DIR/exhaustive.rs:10:5
2+
--> $DIR/exhaustive.rs:12:5
33
|
44
LL | / impl Test {
55
LL | |
@@ -11,10 +11,14 @@ LL | | }
1111
= 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`
1212
= 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
1313
= 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
14+
note: the lint level is defined here
15+
--> $DIR/exhaustive.rs:4:9
16+
|
17+
LL | #![warn(non_local_definitions)]
18+
| ^^^^^^^^^^^^^^^^^^^^^
1519

1620
warning: non-local `impl` definition, they should be avoided as they go against expectation
17-
--> $DIR/exhaustive.rs:15:5
21+
--> $DIR/exhaustive.rs:17:5
1822
|
1923
LL | / impl Display for Test {
2024
LL | |
@@ -30,7 +34,7 @@ LL | | }
3034
= 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>
3135

3236
warning: non-local `impl` definition, they should be avoided as they go against expectation
33-
--> $DIR/exhaustive.rs:22:5
37+
--> $DIR/exhaustive.rs:24:5
3438
|
3539
LL | impl dyn Trait {}
3640
| ^^^^^^^^^^^^^^^^^
@@ -41,7 +45,7 @@ LL | impl dyn Trait {}
4145
= 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>
4246

4347
warning: non-local `impl` definition, they should be avoided as they go against expectation
44-
--> $DIR/exhaustive.rs:25:5
48+
--> $DIR/exhaustive.rs:27:5
4549
|
4650
LL | impl<T: Trait> Trait for Vec<T> { }
4751
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -52,7 +56,7 @@ LL | impl<T: Trait> Trait for Vec<T> { }
5256
= 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>
5357

5458
warning: non-local `impl` definition, they should be avoided as they go against expectation
55-
--> $DIR/exhaustive.rs:28:5
59+
--> $DIR/exhaustive.rs:30:5
5660
|
5761
LL | impl Trait for &dyn Trait {}
5862
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -63,7 +67,7 @@ LL | impl Trait for &dyn Trait {}
6367
= 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>
6468

6569
warning: non-local `impl` definition, they should be avoided as they go against expectation
66-
--> $DIR/exhaustive.rs:31:5
70+
--> $DIR/exhaustive.rs:33:5
6771
|
6872
LL | impl Trait for *mut Test {}
6973
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -74,7 +78,7 @@ LL | impl Trait for *mut Test {}
7478
= 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>
7579

7680
warning: non-local `impl` definition, they should be avoided as they go against expectation
77-
--> $DIR/exhaustive.rs:34:5
81+
--> $DIR/exhaustive.rs:36:5
7882
|
7983
LL | impl Trait for *mut [Test] {}
8084
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -85,7 +89,7 @@ LL | impl Trait for *mut [Test] {}
8589
= 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>
8690

8791
warning: non-local `impl` definition, they should be avoided as they go against expectation
88-
--> $DIR/exhaustive.rs:37:5
92+
--> $DIR/exhaustive.rs:39:5
8993
|
9094
LL | impl Trait for [Test; 8] {}
9195
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -96,7 +100,7 @@ LL | impl Trait for [Test; 8] {}
96100
= 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>
97101

98102
warning: non-local `impl` definition, they should be avoided as they go against expectation
99-
--> $DIR/exhaustive.rs:40:5
103+
--> $DIR/exhaustive.rs:42:5
100104
|
101105
LL | impl Trait for (Test,) {}
102106
| ^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -107,7 +111,7 @@ LL | impl Trait for (Test,) {}
107111
= 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>
108112

109113
warning: non-local `impl` definition, they should be avoided as they go against expectation
110-
--> $DIR/exhaustive.rs:43:5
114+
--> $DIR/exhaustive.rs:45:5
111115
|
112116
LL | impl Trait for fn(Test) -> () {}
113117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -118,7 +122,7 @@ LL | impl Trait for fn(Test) -> () {}
118122
= 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>
119123

120124
warning: non-local `impl` definition, they should be avoided as they go against expectation
121-
--> $DIR/exhaustive.rs:46:5
125+
--> $DIR/exhaustive.rs:48:5
122126
|
123127
LL | impl Trait for fn() -> Test {}
124128
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -129,7 +133,7 @@ LL | impl Trait for fn() -> Test {}
129133
= 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>
130134

131135
warning: non-local `impl` definition, they should be avoided as they go against expectation
132-
--> $DIR/exhaustive.rs:50:9
136+
--> $DIR/exhaustive.rs:52:9
133137
|
134138
LL | impl Trait for Test {}
135139
| ^^^^^^^^^^^^^^^^^^^^^^
@@ -140,7 +144,7 @@ LL | impl Trait for Test {}
140144
= 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>
141145

142146
warning: non-local `impl` definition, they should be avoided as they go against expectation
143-
--> $DIR/exhaustive.rs:58:5
147+
--> $DIR/exhaustive.rs:60:5
144148
|
145149
LL | impl Trait for *mut InsideMain {}
146150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -151,7 +155,7 @@ LL | impl Trait for *mut InsideMain {}
151155
= 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>
152156

153157
warning: non-local `impl` definition, they should be avoided as they go against expectation
154-
--> $DIR/exhaustive.rs:60:5
158+
--> $DIR/exhaustive.rs:62:5
155159
|
156160
LL | impl Trait for *mut [InsideMain] {}
157161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -162,7 +166,7 @@ LL | impl Trait for *mut [InsideMain] {}
162166
= 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>
163167

164168
warning: non-local `impl` definition, they should be avoided as they go against expectation
165-
--> $DIR/exhaustive.rs:62:5
169+
--> $DIR/exhaustive.rs:64:5
166170
|
167171
LL | impl Trait for [InsideMain; 8] {}
168172
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -173,7 +177,7 @@ LL | impl Trait for [InsideMain; 8] {}
173177
= 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>
174178

175179
warning: non-local `impl` definition, they should be avoided as they go against expectation
176-
--> $DIR/exhaustive.rs:64:5
180+
--> $DIR/exhaustive.rs:66:5
177181
|
178182
LL | impl Trait for (InsideMain,) {}
179183
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -184,7 +188,7 @@ LL | impl Trait for (InsideMain,) {}
184188
= 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>
185189

186190
warning: non-local `impl` definition, they should be avoided as they go against expectation
187-
--> $DIR/exhaustive.rs:66:5
191+
--> $DIR/exhaustive.rs:68:5
188192
|
189193
LL | impl Trait for fn(InsideMain) -> () {}
190194
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -195,7 +199,7 @@ LL | impl Trait for fn(InsideMain) -> () {}
195199
= 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>
196200

197201
warning: non-local `impl` definition, they should be avoided as they go against expectation
198-
--> $DIR/exhaustive.rs:68:5
202+
--> $DIR/exhaustive.rs:70:5
199203
|
200204
LL | impl Trait for fn() -> InsideMain {}
201205
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -206,7 +210,7 @@ LL | impl Trait for fn() -> InsideMain {}
206210
= 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>
207211

208212
warning: non-local `impl` definition, they should be avoided as they go against expectation
209-
--> $DIR/exhaustive.rs:72:9
213+
--> $DIR/exhaustive.rs:74:9
210214
|
211215
LL | / impl Display for InsideMain {
212216
LL | |
@@ -222,7 +226,7 @@ LL | | }
222226
= 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>
223227

224228
warning: non-local `impl` definition, they should be avoided as they go against expectation
225-
--> $DIR/exhaustive.rs:79:9
229+
--> $DIR/exhaustive.rs:81:9
226230
|
227231
LL | / impl InsideMain {
228232
LL | |

tests/ui/lint/non-local-defs/from-local-for-global.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//@ check-pass
22
//@ edition:2021
33

4+
#![warn(non_local_definitions)]
5+
46
struct Cat;
57
struct Wrap<T>(T);
68

0 commit comments

Comments
 (0)