-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Split non_local_definitions
lint tests in separate test files
#123653
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ check-pass | ||
//@ edition:2021 | ||
//@ aux-build:non_local_macro.rs | ||
// | ||
// To suggest any Cargo specific help/note rustc wants | ||
// the `CARGO_CRATE_NAME` env to be set, so we set it | ||
//@ rustc-env:CARGO_CRATE_NAME=non_local_def | ||
// | ||
// and since we specifically want to check the presence | ||
// of the `cargo update` suggestion we assert it here. | ||
//@ error-pattern: `cargo update -p non_local_macro` | ||
|
||
extern crate non_local_macro; | ||
|
||
struct LocalStruct; | ||
|
||
non_local_macro::non_local_impl!(LocalStruct); | ||
//~^ WARN non-local `impl` definition | ||
|
||
fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/cargo-update.rs:17:1 | ||
| | ||
LL | non_local_macro::non_local_impl!(LocalStruct); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current constant `_IMPL_DEBUG` | ||
= 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: 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: 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 | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//@ check-pass | ||
//@ edition:2021 | ||
//@ rustc-env:CARGO_CRATE_NAME=non_local_def | ||
|
||
#![feature(inline_const)] | ||
|
||
struct Test; | ||
|
||
trait Uto {} | ||
const Z: () = { | ||
trait Uto1 {} | ||
|
||
impl Uto1 for Test {} // the trait is local, don't lint | ||
|
||
impl Uto for &Test {} | ||
//~^ WARN non-local `impl` definition | ||
}; | ||
|
||
trait Ano {} | ||
const _: () = { | ||
impl Ano for &Test {} // ignored since the parent is an anon-const | ||
}; | ||
|
||
trait Uto2 {} | ||
static A: u32 = { | ||
impl Uto2 for Test {} | ||
//~^ WARN non-local `impl` definition | ||
|
||
1 | ||
}; | ||
|
||
trait Uto3 {} | ||
const B: u32 = { | ||
impl Uto3 for Test {} | ||
//~^ WARN non-local `impl` definition | ||
|
||
trait Uto4 {} | ||
impl Uto4 for Test {} | ||
|
||
1 | ||
}; | ||
|
||
trait Uto5 {} | ||
fn main() { | ||
impl Test { | ||
//~^ WARN non-local `impl` definition | ||
fn foo() {} | ||
} | ||
|
||
|
||
const { | ||
impl Test { | ||
//~^ WARN non-local `impl` definition | ||
fn hoo() {} | ||
} | ||
|
||
1 | ||
}; | ||
|
||
const _: u32 = { | ||
impl Test { | ||
//~^ WARN non-local `impl` definition | ||
fn foo2() {} | ||
} | ||
|
||
1 | ||
}; | ||
} | ||
|
||
trait Uto9 {} | ||
trait Uto10 {} | ||
const _: u32 = { | ||
let _a = || { | ||
impl Uto9 for Test {} | ||
//~^ WARN non-local `impl` definition | ||
|
||
1 | ||
}; | ||
|
||
type A = [u32; { | ||
impl Uto10 for Test {} | ||
//~^ WARN non-local `impl` definition | ||
|
||
1 | ||
}]; | ||
|
||
1 | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:15:5 | ||
| | ||
LL | const Z: () = { | ||
| - help: use a const-anon item to suppress this lint: `_` | ||
... | ||
LL | impl Uto for &Test {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current constant `Z` | ||
= 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 | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:26:5 | ||
| | ||
LL | impl Uto2 for Test {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current static `A` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:34:5 | ||
| | ||
LL | impl Uto3 for Test {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current constant `B` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:45:5 | ||
| | ||
LL | / impl Test { | ||
LL | | | ||
LL | | fn foo() {} | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:52:9 | ||
| | ||
LL | / impl Test { | ||
LL | | | ||
LL | | fn hoo() {} | ||
LL | | } | ||
| |_________^ | ||
| | ||
= help: move this `impl` block outside the of the current inline constant `<unnameable>` and up 2 bodies | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:61:9 | ||
| | ||
LL | / impl Test { | ||
LL | | | ||
LL | | fn foo2() {} | ||
LL | | } | ||
| |_________^ | ||
| | ||
= help: move this `impl` block outside the of the current constant `_` and up 2 bodies | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:74:9 | ||
| | ||
LL | impl Uto9 for Test {} | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current closure `<unnameable>` and up 2 bodies | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/consts.rs:81:9 | ||
| | ||
LL | impl Uto10 for Test {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: move this `impl` block outside the of the current constant expression `<unnameable>` and up 2 bodies | ||
= 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> | ||
|
||
warning: 8 warnings emitted | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//@ check-pass | ||
//@ edition:2021 | ||
|
||
struct Dog; | ||
|
||
fn main() { | ||
impl PartialEq<()> for Dog { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &()) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl PartialEq<()> for &Dog { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &()) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl PartialEq<Dog> for () { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &Dog) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl PartialEq<&Dog> for () { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &&Dog) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl PartialEq<Dog> for &Dog { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &Dog) -> bool { | ||
todo!() | ||
} | ||
} | ||
|
||
impl PartialEq<&Dog> for &Dog { | ||
//~^ WARN non-local `impl` definition | ||
fn eq(&self, _: &&Dog) -> bool { | ||
todo!() | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:7:5 | ||
| | ||
LL | / impl PartialEq<()> for Dog { | ||
LL | | | ||
LL | | fn eq(&self, _: &()) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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 | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:14:5 | ||
| | ||
LL | / impl PartialEq<()> for &Dog { | ||
LL | | | ||
LL | | fn eq(&self, _: &()) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:21:5 | ||
| | ||
LL | / impl PartialEq<Dog> for () { | ||
LL | | | ||
LL | | fn eq(&self, _: &Dog) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:28:5 | ||
| | ||
LL | / impl PartialEq<&Dog> for () { | ||
LL | | | ||
LL | | fn eq(&self, _: &&Dog) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:35:5 | ||
| | ||
LL | / impl PartialEq<Dog> for &Dog { | ||
LL | | | ||
LL | | fn eq(&self, _: &Dog) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/exhaustive-trait.rs:42:5 | ||
| | ||
LL | / impl PartialEq<&Dog> for &Dog { | ||
LL | | | ||
LL | | fn eq(&self, _: &&Dog) -> bool { | ||
LL | | todo!() | ||
LL | | } | ||
LL | | } | ||
| |_____^ | ||
| | ||
= help: move this `impl` block outside the of the current function `main` | ||
= 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> | ||
|
||
warning: 6 warnings emitted | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.