about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs7
-rw-r--r--tests/ui/impl-trait/in-trait/refine-err.rs14
-rw-r--r--tests/ui/impl-trait/in-trait/refine-err.stderr9
-rw-r--r--tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs1
-rw-r--r--tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr19
5 files changed, 30 insertions, 20 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
index 80daaa60324..d2b7ede6523 100644
--- a/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
+++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item/refine.rs
@@ -7,7 +7,8 @@ use rustc_lint_defs::builtin::{REFINING_IMPL_TRAIT_INTERNAL, REFINING_IMPL_TRAIT
 use rustc_middle::span_bug;
 use rustc_middle::traits::{ObligationCause, Reveal};
 use rustc_middle::ty::{
-    self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable, TypeVisitor,
+    self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperVisitable, TypeVisitable,
+    TypeVisitableExt, TypeVisitor,
 };
 use rustc_span::Span;
 use rustc_trait_selection::regions::InferCtxtRegionExt;
@@ -177,6 +178,10 @@ pub(super) fn check_refining_return_position_impl_trait_in_trait<'tcx>(
         return;
     };
 
+    if trait_bounds.references_error() || impl_bounds.references_error() {
+        return;
+    }
+
     // For quicker lookup, use an `IndexSet` (we don't use one earlier because
     // it's not foldable..).
     // Also, We have to anonymize binders in these types because they may contain
diff --git a/tests/ui/impl-trait/in-trait/refine-err.rs b/tests/ui/impl-trait/in-trait/refine-err.rs
new file mode 100644
index 00000000000..7518cee97c4
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine-err.rs
@@ -0,0 +1,14 @@
+#![deny(refining_impl_trait)]
+
+trait FromRow {
+    fn prepare(self) -> impl Fn() -> T;
+    //~^ ERROR cannot find type `T` in this scope
+}
+
+impl<T> FromRow for T {
+    fn prepare(self) -> impl Fn() -> T {
+        || todo!()
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/refine-err.stderr b/tests/ui/impl-trait/in-trait/refine-err.stderr
new file mode 100644
index 00000000000..6b4ef74d50a
--- /dev/null
+++ b/tests/ui/impl-trait/in-trait/refine-err.stderr
@@ -0,0 +1,9 @@
+error[E0412]: cannot find type `T` in this scope
+  --> $DIR/refine-err.rs:4:38
+   |
+LL |     fn prepare(self) -> impl Fn() -> T;
+   |                                      ^ not found in this scope
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0412`.
diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
index 7a51037324f..ab21dae7dc5 100644
--- a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
+++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
@@ -14,7 +14,6 @@ impl<'a, I: 'a + Iterable> Iterable for &'a I {
     //~^ ERROR binding for associated type `Item` references lifetime `'missing`
     //~| ERROR binding for associated type `Item` references lifetime `'missing`
     //~| ERROR `()` is not an iterator
-    //~| WARNING impl trait in impl method signature does not match trait method signature
 }
 
 fn main() {}
diff --git a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
index 67c4df0f3a9..d8a2eef94a1 100644
--- a/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
+++ b/tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
@@ -32,24 +32,7 @@ LL |     fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missin
    |
    = help: the trait `Iterator` is not implemented for `()`
 
-warning: impl trait in impl method signature does not match trait method signature
-  --> $DIR/span-bug-issue-121457.rs:13:51
-   |
-LL |     fn iter(&self) -> impl Iterator;
-   |                       ------------- return type from trait method defined here
-...
-LL |     fn iter(&self) -> impl for<'missing> Iterator<Item = Self::Item<'missing>> {}
-   |                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ this bound is stronger than that defined on the trait
-   |
-   = note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
-   = note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
-   = note: `#[warn(refining_impl_trait_reachable)]` on by default
-help: replace the return type so that it matches the trait
-   |
-LL |     fn iter(&self) -> impl Iterator {}
-   |                       ~~~~~~~~~~~~~
-
-error: aborting due to 4 previous errors; 1 warning emitted
+error: aborting due to 4 previous errors
 
 Some errors have detailed explanations: E0195, E0277, E0582.
 For more information about an error, try `rustc --explain E0195`.