Skip to content

Commit

Permalink
Rollup merge of rust-lang#123653 - Urgau:split-test-non_local_defs, r…
Browse files Browse the repository at this point in the history
…=compiler-errors

Split `non_local_definitions` lint tests in separate test files

This PR splits the giant `non_local_definitions` lint UI test in separate test files.

This change is extracted from rust-lang#123594 (where it was requested rust-lang#123594 (comment)), to ease the review of the other PR and to reduce the size of the other PR.

r? `@compiler-errors`
  • Loading branch information
GuillaumeGomez committed Apr 9, 2024
2 parents a63892d + ddc16e9 commit 1ea980b
Show file tree
Hide file tree
Showing 22 changed files with 1,375 additions and 1,196 deletions.
File renamed without changes.
20 changes: 20 additions & 0 deletions tests/ui/lint/non-local-defs/cargo-update.rs
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() {}
16 changes: 16 additions & 0 deletions tests/ui/lint/non-local-defs/cargo-update.stderr
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

88 changes: 88 additions & 0 deletions tests/ui/lint/non-local-defs/consts.rs
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
};
103 changes: 103 additions & 0 deletions tests/ui/lint/non-local-defs/consts.stderr
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

48 changes: 48 additions & 0 deletions tests/ui/lint/non-local-defs/exhaustive-trait.rs
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!()
}
}
}
99 changes: 99 additions & 0 deletions tests/ui/lint/non-local-defs/exhaustive-trait.stderr
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

Loading

0 comments on commit 1ea980b

Please sign in to comment.