Skip to content

Commit

Permalink
Switch back non_local_definitions lint to allow-by-default
Browse files Browse the repository at this point in the history
as request T-lang is requesting some major changes in the lint inner
workings in rust-lang#126768#issuecomment-2192634762
  • Loading branch information
Urgau committed Jun 27, 2024
1 parent d929a42 commit 0c0dfb8
Show file tree
Hide file tree
Showing 27 changed files with 169 additions and 95 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 @@ -50,7 +50,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/rustdoc-ui/doctest/non_local_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//@ normalize-stderr-test: "tests/rustdoc-ui/doctest" -> "$$DIR"
//@ normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"

#![doc(test(attr(warn(non_local_definitions))))]

//! ```
//! #[macro_export]
//! macro_rules! a_macro { () => {} }
Expand Down
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,13 +1,17 @@
warning: non-local `macro_rules!` definition, `#[macro_export]` macro should be written at top level module
--> $DIR/non_local_defs.rs:9:1
--> $DIR/non_local_defs.rs:11:1
|
LL | macro_rules! a_macro { () => {} }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove the `#[macro_export]` or make this doc-test a standalone test with its own `fn main() { ... }`
= note: a `macro_rules!` definition is non-local if it is nested inside an item and has a `#[macro_export]` attribute
= 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:8:9
|
LL | #![warn(non_local_definitions)]
| ^^^^^^^^^^^^^^^^^^^^^

warning: 1 warning emitted

2 changes: 1 addition & 1 deletion tests/rustdoc-ui/doctest/non_local_defs.stdout
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

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

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

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, `impl` blocks should be written at the same level as their item
--> $DIR/cargo-update.rs:17:1
--> $DIR/cargo-update.rs:19:1
|
LL | non_local_macro::non_local_impl!(LocalStruct);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -14,7 +14,11 @@ LL | non_local_macro::non_local_impl!(LocalStruct);
= 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`
= 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
= 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/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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:13:5
--> $DIR/consts.rs:15:5
|
LL | const Z: () = {
| -----------
Expand All @@ -17,10 +17,14 @@ LL | impl Uto for &Test {}
= 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`
= 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
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:24:5
--> $DIR/consts.rs:26:5
|
LL | static A: u32 = {
| ------------- move the `impl` block outside of this static `A`
Expand All @@ -36,7 +40,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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:32:5
--> $DIR/consts.rs:34:5
|
LL | const B: u32 = {
| ------------ move the `impl` block outside of this constant `B`
Expand All @@ -52,7 +56,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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:43:5
--> $DIR/consts.rs:45:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -65,7 +69,7 @@ LL | impl 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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:50:9
--> $DIR/consts.rs:52:9
|
LL | const {
| ___________-
Expand All @@ -84,7 +88,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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:59:9
--> $DIR/consts.rs:61:9
|
LL | const _: u32 = {
| ------------ move the `impl` block outside of this constant `_` and up 2 bodies
Expand All @@ -98,7 +102,7 @@ LL | impl 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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:72:9
--> $DIR/consts.rs:74:9
|
LL | let _a = || {
| -- move the `impl` block outside of this closure `<unnameable>` and up 2 bodies
Expand All @@ -113,7 +117,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, `impl` blocks should be written at the same level as their item
--> $DIR/consts.rs:79:9
--> $DIR/consts.rs:81:9
|
LL | type A = [u32; {
| ____________________-
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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:7:5
--> $DIR/exhaustive-trait.rs:9:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -12,10 +12,14 @@ LL | impl PartialEq<()> for Dog {
= 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
= 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`
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:14:5
--> $DIR/exhaustive-trait.rs:16:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -31,7 +35,7 @@ LL | impl PartialEq<()> for &Dog {
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:21:5
--> $DIR/exhaustive-trait.rs:23:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -47,7 +51,7 @@ LL | impl PartialEq<Dog> for () {
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:28:5
--> $DIR/exhaustive-trait.rs:30:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -63,7 +67,7 @@ LL | impl PartialEq<&Dog> for () {
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:35:5
--> $DIR/exhaustive-trait.rs:37:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
Expand All @@ -79,7 +83,7 @@ LL | impl PartialEq<Dog> for &Dog {
= 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, `impl` blocks should be written at the same level as their item
--> $DIR/exhaustive-trait.rs:42:5
--> $DIR/exhaustive-trait.rs:44:5
|
LL | fn main() {
| --------- move the `impl` block outside of this function `main`
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

0 comments on commit 0c0dfb8

Please sign in to comment.