Skip to content

Commit

Permalink
Make non-local-def lint Allow by default
Browse files Browse the repository at this point in the history
  • Loading branch information
wesleywiser committed May 10, 2024
1 parent 238c1e7 commit 22ba917
Show file tree
Hide file tree
Showing 21 changed files with 131 additions and 71 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/non_local_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ declare_lint! {
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
pub NON_LOCAL_DEFINITIONS,
Warn,
Allow,
"checks for non-local definitions",
report_in_external_macro
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/cargo-update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
// of the `cargo update` suggestion we assert it here.
//@ error-pattern: `cargo update -p non_local_macro`

#![warn(non_local_definitions)]

extern crate non_local_macro;

struct LocalStruct;
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/lint/non-local-defs/cargo-update.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/cargo-update.rs:17:1
--> $DIR/cargo-update.rs:19:1
|
LL | non_local_macro::non_local_impl!(LocalStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
= 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
= 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>
= 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`
= note: `#[warn(non_local_definitions)]` on by default
note: the lint level is defined here
--> $DIR/cargo-update.rs:13:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^
= note: this warning originates in the macro `non_local_macro::non_local_impl` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//@ edition:2021
//@ rustc-env:CARGO_CRATE_NAME=non_local_def

#![warn(non_local_definitions)]

struct Test;

trait Uto {}
Expand Down
22 changes: 13 additions & 9 deletions tests/ui/lint/non-local-defs/consts.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/consts.rs:13:5
--> $DIR/consts.rs:15:5
|
LL | const Z: () = {
| - help: use a const-anon item to suppress this lint: `_`
Expand All @@ -11,10 +11,14 @@ LL | impl Uto for &Test {}
= 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`
= 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
= 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>
= note: `#[warn(non_local_definitions)]` on by default
note: the lint level is defined here
--> $DIR/consts.rs:5:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/consts.rs:79:9
--> $DIR/consts.rs:81:9
|
LL | impl Uto10 for Test {}
| ^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/exhaustive-trait.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ check-pass
//@ edition:2021

#![warn(non_local_definitions)]

struct Dog;

fn main() {
Expand Down
18 changes: 11 additions & 7 deletions tests/ui/lint/non-local-defs/exhaustive-trait.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/exhaustive-trait.rs:7:5
--> $DIR/exhaustive-trait.rs:9:5
|
LL | / impl PartialEq<()> for Dog {
LL | |
Expand All @@ -13,10 +13,14 @@ LL | | }
= 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`
= 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
= 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>
= note: `#[warn(non_local_definitions)]` on by default
note: the lint level is defined here
--> $DIR/exhaustive-trait.rs:4:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^

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

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

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

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

warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/exhaustive-trait.rs:42:5
--> $DIR/exhaustive-trait.rs:44:5
|
LL | / impl PartialEq<&Dog> for &Dog {
LL | |
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/exhaustive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ check-pass
//@ edition:2021

#![warn(non_local_definitions)]

use std::fmt::Display;

trait Trait {}
Expand Down
46 changes: 25 additions & 21 deletions tests/ui/lint/non-local-defs/exhaustive.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/exhaustive.rs:10:5
--> $DIR/exhaustive.rs:12:5
|
LL | / impl Test {
LL | |
Expand All @@ -11,10 +11,14 @@ LL | | }
= 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`
= 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
= 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>
= note: `#[warn(non_local_definitions)]` on by default
note: the lint level is defined here
--> $DIR/exhaustive.rs:4:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

warning: non-local `impl` definition, they should be avoided as they go against expectation
--> $DIR/exhaustive.rs:79:9
--> $DIR/exhaustive.rs:81:9
|
LL | / impl InsideMain {
LL | |
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/lint/non-local-defs/from-local-for-global.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//@ check-pass
//@ edition:2021

#![warn(non_local_definitions)]

struct Cat;
struct Wrap<T>(T);

Expand Down
Loading

0 comments on commit 22ba917

Please sign in to comment.