forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix trait solver overflow with
non_local_definitions
lint
- Loading branch information
Showing
3 changed files
with
41 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
14 changes: 14 additions & 0 deletions
14
tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs
This file contains 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,14 @@ | ||
//@ check-pass | ||
//@ edition:2021 | ||
|
||
// https://github.com/rust-lang/rust/issues/123573#issue-2229428739 | ||
|
||
pub trait Test {} | ||
|
||
impl<'a, T: 'a> Test for &[T] where &'a T: Test {} | ||
|
||
fn main() { | ||
struct Local {} | ||
impl Test for &Local {} | ||
//~^ WARN non-local `impl` definition | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr
This file contains 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,14 @@ | ||
warning: non-local `impl` definition, they should be avoided as they go against expectation | ||
--> $DIR/trait-solver-overflow-123573.rs:12:5 | ||
| | ||
LL | impl Test for &Local {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= 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: 1 warning emitted | ||
|