Skip to content

Commit 28c1743

Browse files
authored
Rollup merge of #128239 - compiler-errors:error-on-object-cand-confirm, r=oli-obk
Don't ICE when encountering error regions when confirming object method candidate See the inline comment for an explanation. Fixes #122914
2 parents 162db34 + 8d2c12e commit 28c1743

File tree

4 files changed

+35
-12
lines changed

4 files changed

+35
-12
lines changed

compiler/rustc_hir_typeck/src/method/confirm.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ use rustc_middle::ty::adjustment::{
1616
};
1717
use rustc_middle::ty::fold::TypeFoldable;
1818
use rustc_middle::ty::{
19-
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, UserArgs, UserType,
19+
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, UserArgs,
20+
UserType,
2021
};
2122
use rustc_middle::{bug, span_bug};
2223
use rustc_span::{Span, DUMMY_SP};
@@ -269,6 +270,17 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
269270

270271
probe::ObjectPick => {
271272
let trait_def_id = pick.item.container_id(self.tcx);
273+
274+
// This shouldn't happen for non-region error kinds, but may occur
275+
// when we have error regions. Specifically, since we canonicalize
276+
// during method steps, we may successfully deref when we assemble
277+
// the pick, but fail to deref when we try to extract the object
278+
// type from the pick during confirmation. This is fine, we're basically
279+
// already doomed by this point.
280+
if self_ty.references_error() {
281+
return ty::GenericArgs::extend_with_error(self.tcx, trait_def_id, &[]);
282+
}
283+
272284
self.extract_existential_trait_ref(self_ty, |this, object_ty, principal| {
273285
// The object data has no entry for the Self
274286
// Type. For the purposes of this method call, we

tests/crashes/122914.rs

-11
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Fix for issue: #122914
2+
3+
use std::future::Future;
4+
use std::pin::Pin;
5+
6+
fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
7+
//~^ ERROR use of undeclared lifetime name `'missing`
8+
let _ = x.poll(todo!());
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0261]: use of undeclared lifetime name `'missing`
2+
--> $DIR/dont-ice-on-object-lookup-w-error-region.rs:6:20
3+
|
4+
LL | fn project(x: Pin<&'missing mut dyn Future<Output = ()>>) {
5+
| - ^^^^^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'missing` here: `<'missing>`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)