Skip to content

Commit 0c0dfb8

Browse files
committed
Switch back non_local_definitions lint to allow-by-default
as request T-lang is requesting some major changes in the lint inner workings in rust-lang#126768#issuecomment-2192634762
1 parent d929a42 commit 0c0dfb8

27 files changed

+169
-95
lines changed

compiler/rustc_lint/src/non_local_def.rs

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

tests/rustdoc-ui/doctest/non_local_defs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
55
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
66

7+
#![doc(test(attr(warn(non_local_definitions))))]
8+
79
//! ```
810
//! #[macro_export]
911
//! macro_rules! a_macro { () => {} }
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
2-
--> $DIR/non_local_defs.rs:9:1
2+
--> $DIR/non_local_defs.rs:11:1
33
|
44
LL | macro_rules! a_macro { () => {} }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }`
88
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
99
= 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>
10-
= note: `#[warn(non_local_definitions)]` on by default
10+
note: the lint level is defined here
11+
--> $DIR/non_local_defs.rs:8:9
12+
|
13+
LL | #![warn(non_local_definitions)]
14+
| ^^^^^^^^^^^^^^^^^^^^^
1115

1216
warning: 1 warning emitted
1317

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
running 1 test
3-
test $DIR/non_local_defs.rs - (line 7) ... ok
3+
test $DIR/non_local_defs.rs - (line 9) ... ok
44

55
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
66

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, `impl` blocks should be written at the same level as their item
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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
1414
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1515
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
1616
= 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>
17-
= note: `#[warn(non_local_definitions)]` on by default
17+
note: the lint level is defined here
18+
--> $DIR/cargo-update.rs:13:9
19+
|
20+
LL | #![warn(non_local_definitions)]
21+
| ^^^^^^^^^^^^^^^^^^^^^
1822
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)
1923

2024
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, `impl` blocks should be written at the same level as their item
2-
--> $DIR/consts.rs:13:5
2+
--> $DIR/consts.rs:15:5
33
|
44
LL | const Z: () = {
55
| -----------
@@ -17,10 +17,14 @@ LL | impl Uto for &Test {}
1717
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1818
= note: items in an anonymous const item (`const _: () = { ... }`) are treated as in the same scope as the anonymous const's declaration for the purpose of this lint
1919
= 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>
20-
= note: `#[warn(non_local_definitions)]` on by default
20+
note: the lint level is defined here
21+
--> $DIR/consts.rs:5:9
22+
|
23+
LL | #![warn(non_local_definitions)]
24+
| ^^^^^^^^^^^^^^^^^^^^^
2125

2226
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
23-
--> $DIR/consts.rs:24:5
27+
--> $DIR/consts.rs:26:5
2428
|
2529
LL | static A: u32 = {
2630
| ------------- move the `impl` block outside of this static `A`
@@ -36,7 +40,7 @@ LL | impl Uto2 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, `impl` blocks should be written at the same level as their item
39-
--> $DIR/consts.rs:32:5
43+
--> $DIR/consts.rs:34:5
4044
|
4145
LL | const B: u32 = {
4246
| ------------ move the `impl` block outside of this constant `B`
@@ -52,7 +56,7 @@ LL | impl Uto3 for Test {}
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, `impl` blocks should be written at the same level as their item
55-
--> $DIR/consts.rs:43:5
59+
--> $DIR/consts.rs:45:5
5660
|
5761
LL | fn main() {
5862
| --------- move the `impl` block outside of this function `main`
@@ -65,7 +69,7 @@ LL | impl Test {
6569
= 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>
6670

6771
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
68-
--> $DIR/consts.rs:50:9
72+
--> $DIR/consts.rs:52:9
6973
|
7074
LL | const {
7175
| ___________-
@@ -84,7 +88,7 @@ LL | | };
8488
= 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>
8589

8690
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
87-
--> $DIR/consts.rs:59:9
91+
--> $DIR/consts.rs:61:9
8892
|
8993
LL | const _: u32 = {
9094
| ------------ move the `impl` block outside of this constant `_` and up 2 bodies
@@ -98,7 +102,7 @@ LL | impl Test {
98102
= 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>
99103

100104
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
101-
--> $DIR/consts.rs:72:9
105+
--> $DIR/consts.rs:74:9
102106
|
103107
LL | let _a = || {
104108
| -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
@@ -113,7 +117,7 @@ LL | impl Uto9 for Test {}
113117
= 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>
114118

115119
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
116-
--> $DIR/consts.rs:79:9
120+
--> $DIR/consts.rs:81:9
117121
|
118122
LL | type A = [u32; {
119123
| ____________________-

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, `impl` blocks should be written at the same level as their item
2-
--> $DIR/exhaustive-trait.rs:7:5
2+
--> $DIR/exhaustive-trait.rs:9:5
33
|
44
LL | fn main() {
55
| --------- move the `impl` block outside of this function `main`
@@ -12,10 +12,14 @@ LL | impl PartialEq<()> for Dog {
1212
= note: `impl` may be usable in bounds, etc. from outside the expression, which might e.g. make something constructible that previously wasn't, because it's still on a publicly-visible type
1313
= note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`
1414
= 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>
15-
= note: `#[warn(non_local_definitions)]` on by default
15+
note: the lint level is defined here
16+
--> $DIR/exhaustive-trait.rs:4:9
17+
|
18+
LL | #![warn(non_local_definitions)]
19+
| ^^^^^^^^^^^^^^^^^^^^^
1620

1721
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
18-
--> $DIR/exhaustive-trait.rs:14:5
22+
--> $DIR/exhaustive-trait.rs:16:5
1923
|
2024
LL | fn main() {
2125
| --------- move the `impl` block outside of this function `main`
@@ -31,7 +35,7 @@ LL | impl PartialEq<()> for &Dog {
3135
= 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>
3236

3337
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
34-
--> $DIR/exhaustive-trait.rs:21:5
38+
--> $DIR/exhaustive-trait.rs:23:5
3539
|
3640
LL | fn main() {
3741
| --------- move the `impl` block outside of this function `main`
@@ -47,7 +51,7 @@ LL | impl PartialEq<Dog> for () {
4751
= 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>
4852

4953
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
50-
--> $DIR/exhaustive-trait.rs:28:5
54+
--> $DIR/exhaustive-trait.rs:30:5
5155
|
5256
LL | fn main() {
5357
| --------- move the `impl` block outside of this function `main`
@@ -63,7 +67,7 @@ LL | impl PartialEq<&Dog> for () {
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, `impl` blocks should be written at the same level as their item
66-
--> $DIR/exhaustive-trait.rs:35:5
70+
--> $DIR/exhaustive-trait.rs:37:5
6771
|
6872
LL | fn main() {
6973
| --------- move the `impl` block outside of this function `main`
@@ -79,7 +83,7 @@ LL | impl PartialEq<Dog> for &Dog {
7983
= 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>
8084

8185
warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item
82-
--> $DIR/exhaustive-trait.rs:42:5
86+
--> $DIR/exhaustive-trait.rs:44:5
8387
|
8488
LL | fn main() {
8589
| --------- move the `impl` block outside of this function `main`

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 {}

0 commit comments

Comments
 (0)