Skip to content

Commit e6b6fa6

Browse files
author
yimiliya
committed
Handle error types gracefully in cat_deref
The issue was that when type resolution fails (e.g., due to combining unstable features like pin_ergonomics with min_generic_const_args), `structurally_resolve_type` returns an error type. When `builtin_deref` is called on this error type, it returns `None`, causing the code to panic with "explicit deref of non-derefable type". The fix checks if the resolved type contains an error using `error_reported_in_ty` and returns early if so, allowing compilation to continue and report the actual error instead of ICE-ing.
1 parent 01bff9e commit e6b6fa6

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

compiler/rustc_hir_typeck/src/expr_use_visitor.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,11 +1510,14 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15101510
base_place: PlaceWithHirId<'tcx>,
15111511
) -> Result<PlaceWithHirId<'tcx>, Cx::Error> {
15121512
let base_curr_ty = base_place.place.ty();
1513-
let Some(deref_ty) = self
1513+
let resolved_ty = self
15141514
.cx
1515-
.structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty)
1516-
.builtin_deref(true)
1517-
else {
1515+
.structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty);
1516+
1517+
// If the type is an error (e.g., from prior inference failure), return early
1518+
self.cx.error_reported_in_ty(resolved_ty)?;
1519+
1520+
let Some(deref_ty) = resolved_ty.builtin_deref(true) else {
15181521
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
15191522
return Err(self
15201523
.cx
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Test for issue #153733: ICE with pin_ergonomics + async
2+
//@compile-flags: --edition=2024
3+
#![feature(min_generic_const_args)]
4+
#![feature(adt_const_params)]
5+
#![feature(pin_ergonomics)]
6+
7+
async fn other() {}
8+
9+
pub async fn uhoh() {
10+
other().await;
11+
}
12+
13+
fn main() {}

0 commit comments

Comments
 (0)