Skip to content

Commit

Permalink
Don't trigger refinement lint if predicates reference errors
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 22, 2024
1 parent 0f6e1ae commit 8eb1558
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/impl-trait/in-trait/refine-err.rs
Original file line number Diff line number Diff line change
@@ -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() {}
9 changes: 9 additions & 0 deletions tests/ui/impl-trait/in-trait/refine-err.stderr
Original file line number Diff line number Diff line change
@@ -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`.
1 change: 0 additions & 1 deletion tests/ui/impl-trait/in-trait/span-bug-issue-121457.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
19 changes: 1 addition & 18 deletions tests/ui/impl-trait/in-trait/span-bug-issue-121457.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

0 comments on commit 8eb1558

Please sign in to comment.