about summary refs log tree commit diff
path: root/tests/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-21 17:02:03 +0000
committerbors <bors@rust-lang.org>2024-04-21 17:02:03 +0000
commitf22a0c2d9f9cd83dfe84b65e9fa1b3fa8303c7b5 (patch)
tree2a90e9e916bbdddabdc338aa7d9149db9052a8cc /tests/ui
parentaa31bad26b6bbf71c2072465ddb0dfe807c2b7d5 (diff)
parentc2e2245fd86ac61e138af2ff604ccd5381627d38 (diff)
downloadrust-f22a0c2d9f9cd83dfe84b65e9fa1b3fa8303c7b5.tar.gz
rust-f22a0c2d9f9cd83dfe84b65e9fa1b3fa8303c7b5.zip
Auto merge of #123594 - Urgau:fix-non_local_def-lint-overflow, r=lcnr
Fix trait solver overflow with `non_local_definitions` lint

This PR fixes the trait solver overflow with the `non_local_definitions` lint reported in https://github.com/rust-lang/rust/issues/123573 using the suggestion from `@lcnr:` https://github.com/rust-lang/rust/issues/123573#issuecomment-2041348320 to use the next trait solver.

~~I have not (yet) tried to create a minimized repro~~ ``@compiler-errors`` did the minimization (thanks you) but I have manually tested on the `starlark-rust` project that it fixes the issue.

Fixes #123573
r? `@lcnr`
Diffstat (limited to 'tests/ui')
-rw-r--r--tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs14
-rw-r--r--tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr14
2 files changed, 28 insertions, 0 deletions
diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs
new file mode 100644
index 00000000000..4291426e046
--- /dev/null
+++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.rs
@@ -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
+}
diff --git a/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr
new file mode 100644
index 00000000000..9a8ab810835
--- /dev/null
+++ b/tests/ui/lint/non-local-defs/trait-solver-overflow-123573.stderr
@@ -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
+