Skip to content

Don't trigger refinement lint if predicates reference errors #129417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
Loading