From 8d2c12e5540d801a48eae396eac6aa350ce8c1b1 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 26 Jul 2024 13:18:29 -0400 Subject: [PATCH] Don't ICE when encountering error regions when confirming object method candidate --- compiler/rustc_hir_typeck/src/method/confirm.rs | 14 +++++++++++++- tests/crashes/122914.rs | 11 ----------- .../dont-ice-on-object-lookup-w-error-region.rs | 11 +++++++++++ ...dont-ice-on-object-lookup-w-error-region.stderr | 11 +++++++++++ 4 files changed, 35 insertions(+), 12 deletions(-) delete mode 100644 tests/crashes/122914.rs create mode 100644 tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs create mode 100644 tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr diff --git a/compiler/rustc_hir_typeck/src/method/confirm.rs b/compiler/rustc_hir_typeck/src/method/confirm.rs index e70431a68ff..be3de812a96 100644 --- a/compiler/rustc_hir_typeck/src/method/confirm.rs +++ b/compiler/rustc_hir_typeck/src/method/confirm.rs @@ -16,7 +16,8 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{ - self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, UserArgs, UserType, + self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, UserArgs, + UserType, }; use rustc_middle::{bug, span_bug}; use rustc_span::{Span, DUMMY_SP}; @@ -268,6 +269,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { probe::ObjectPick => { let trait_def_id = pick.item.container_id(self.tcx); + + // This shouldn't happen for non-region error kinds, but may occur + // when we have error regions. Specifically, since we canonicalize + // during method steps, we may successfully deref when we assemble + // the pick, but fail to deref when we try to extract the object + // type from the pick during confirmation. This is fine, we're basically + // already doomed by this point. + if self_ty.references_error() { + return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]); + } + self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| { // The object data has no entry for the Self // Type. For the purposes of this method call, we diff --git a/tests/crashes/122914.rs b/tests/crashes/122914.rs deleted file mode 100644 index 63a84bc8099..00000000000 --- a/tests/crashes/122914.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ known-bug: #122914 -use std::future::Future; -use std::pin::Pin; - -impl<'a, F> Poll { - fn project<'_>(self: Pin<&'pin mut Future>) -> Projection<'pin, 'a, F> { - me.local_set.with(|| { - let _ = self.poll(cx); - }) - } -} diff --git a/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs b/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs new file mode 100644 index 00000000000..0a6d196364f --- /dev/null +++ b/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs @@ -0,0 +1,11 @@ +// Fix for issue: #122914 + +use std::future::Future; +use std::pin::Pin; + +fn project(x: Pin<&'missing mut dyn Future>) { + //~^ ERROR use of undeclared lifetime name `'missing` + let _ = x.poll(todo!()); +} + +fn main() {} diff --git a/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr b/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr new file mode 100644 index 00000000000..2c33941be43 --- /dev/null +++ b/tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr @@ -0,0 +1,11 @@ +error[E0261]: use of undeclared lifetime name `'missing` + --> $DIR/dont-ice-on-object-lookup-w-error-region.rs:6:20 + | +LL | fn project(x: Pin<&'missing mut dyn Future>) { + | - ^^^^^^^^ undeclared lifetime + | | + | help: consider introducing lifetime `'missing` here: `<'missing>` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0261`.