Skip to content

Commit 23015b9

Browse files
committed
Make non-local-def lint Allow by default
1 parent 238c1e7 commit 23015b9

23 files changed

+138
-73
lines changed

compiler/rustc_lint/src/non_local_def.rs

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

tests/rustdoc-ui/doctest/non_local_defs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
66

77
//! ```
8+
//! #![warn(non_local_definitions)]
89
//! #[macro_export]
910
//! macro_rules! a_macro { () => {} }
1011
//! ```
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
2-
--> $DIR/non_local_defs.rs:9:1
2+
--> $DIR/non_local_defs.rs:10:1
33
|
44
LL | macro_rules! a_macro { () => {} }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -8,7 +8,11 @@ LL | macro_rules! a_macro { () => {} }
88
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
99
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
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>
11-
= note: `#[warn(non_local_definitions)]` on by default
11+
note: the lint level is defined here
12+
--> $DIR/non_local_defs.rs:7:9
13+
|
14+
LL | #![warn(non_local_definitions)]
15+
| ^^^^^^^^^^^^^^^^^^^^^
1216

1317
warning: 1 warning emitted
1418

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 13 additions & 9 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 11 additions & 7 deletions
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

Lines changed: 2 additions & 0 deletions
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 {}

0 commit comments

Comments
 (0)