Skip to content

Commit

Permalink
Auto merge of rust-lang#117884 - bvanjoi:fix-117794, r=compiler-errors
Browse files Browse the repository at this point in the history
skip rpit constraint checker if borrowck return type error

Fixes rust-lang#117794
Fixes rust-lang#117886
Fixes rust-lang#119025

Prior to change rust-lang#117418, the value of `concrete_opaque_types` for `mir_borrock(T::a::opaque)` was `None`. However, due to modifications in `body.local_decls`, the return value had been changed.

The changed of `body.local_decls` has let to the addition of `ty:Error` to `infcx.opaque_type_storage.opaque_types` during `TypeChecker::equate_inputs_and_outputs`. This is due to it utilizing the output of a function signature that was appended during `construct_error`(which previously only appended a `ty::Error`) and then execute `TypeChecker::Related_types`.

Therefore, in this PR, I've implemented a condition to bypass the rpit check when an error is encountered.

r? `@compiler-errors`
  • Loading branch information
bors committed Dec 17, 2023
2 parents 3a2aa58 + 64e311a commit d14e52b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_hir_analysis/src/collect/type_of/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,10 @@ pub(super) fn find_opaque_ty_constraints_for_rpit<'tcx>(

let mir_opaque_ty = tcx.mir_borrowck(owner_def_id).concrete_opaque_types.get(&def_id).copied();
if let Some(mir_opaque_ty) = mir_opaque_ty {
if mir_opaque_ty.references_error() {
return mir_opaque_ty.ty;
}

let scope = tcx.local_def_id_to_hir_id(owner_def_id);
debug!(?scope);
let mut locator = RpitConstraintChecker { def_id, tcx, found: mir_opaque_ty };
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/traits/issue-117794.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
trait Foo {}

trait T {
fn a(&self) -> impl Foo {
self.b(|| 0)
//~^ ERROR no method named `b` found for reference `&Self` in the current scope
}
}

fn main() {}
9 changes: 9 additions & 0 deletions tests/ui/traits/issue-117794.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0599]: no method named `b` found for reference `&Self` in the current scope
--> $DIR/issue-117794.rs:5:14
|
LL | self.b(|| 0)
| ^ help: there is a method with a similar name: `a`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.

0 comments on commit d14e52b

Please sign in to comment.