Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make non-local-def lint Allow by default #124950

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions tests/rustdoc-ui/doctest/non_local_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"

//! ```
//! #![warn(non_local_definitions)]
//! #[macro_export]
//! macro_rules! a_macro { () => {} }
//! ```
8 changes: 6 additions & 2 deletions tests/rustdoc-ui/doctest/non_local_defs.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: non-local `macro_rules!` definition, they should be avoided as they go against expectation
--> $DIR/non_local_defs.rs:9:1
--> $DIR/non_local_defs.rs:10:1
|
LL | macro_rules! a_macro { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,11 @@ LL | macro_rules! a_macro { () => {} }
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
= note: one exception to the rule are anon-const (`const _: () = { ... }`) at top-level module
= 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/non_local_defs.rs:7:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^

warning: 1 warning emitted

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
Loading
Loading