Skip to content
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

Don't ICE when encountering error regions when confirming object method candidate #128239

Merged
merged 1 commit into from
Jul 29, 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
14 changes: 13 additions & 1 deletion compiler/rustc_hir_typeck/src/method/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions tests/crashes/122914.rs

This file was deleted.

11 changes: 11 additions & 0 deletions tests/ui/methods/dont-ice-on-object-lookup-w-error-region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Fix for issue: #122914

use std::future::Future;
use std::pin::Pin;

fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
//~^ ERROR use of undeclared lifetime name `'missing`
let _ = x.poll(todo!());
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/methods/dont-ice-on-object-lookup-w-error-region.stderr
Original file line number Diff line number Diff line change
@@ -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<Output = ()>>) {
| - ^^^^^^^^ 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`.
Loading