Skip to content

Commit 3071647

Browse files
Assert that MemCategorizationVisitor actually errors when it bails ungracefully
1 parent e3029d2 commit 3071647

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

compiler/rustc_hir_typeck/src/mem_categorization.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,15 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
131131
match ty {
132132
Some(ty) => {
133133
let ty = self.resolve_vars_if_possible(ty);
134-
if ty.references_error() || ty.is_ty_var() {
134+
if ty.references_error() {
135135
debug!("resolve_type_vars_or_error: error from {:?}", ty);
136136
Err(())
137+
} else if ty.is_ty_var() {
138+
debug!("resolve_type_vars_or_error: infer var from {:?}", ty);
139+
self.tcx()
140+
.dcx()
141+
.span_delayed_bug(self.tcx().hir().span(id), "encountered type variable");
142+
Err(())
137143
} else {
138144
Ok(ty)
139145
}
@@ -210,6 +216,9 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
210216
Some(t) => Ok(t.ty),
211217
None => {
212218
debug!("By-ref binding of non-derefable type");
219+
self.tcx()
220+
.dcx()
221+
.span_delayed_bug(pat.span, "by-ref binding of non-derefable type");
213222
Err(())
214223
}
215224
}
@@ -488,6 +497,10 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
488497
Some(mt) => mt.ty,
489498
None => {
490499
debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
500+
self.tcx().dcx().span_delayed_bug(
501+
self.tcx().hir().span(node.hir_id()),
502+
"explicit deref of non-derefable type",
503+
);
491504
return Err(());
492505
}
493506
};
@@ -732,6 +745,9 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
732745
PatKind::Slice(before, ref slice, after) => {
733746
let Some(element_ty) = place_with_id.place.ty().builtin_index() else {
734747
debug!("explicit index of non-indexable type {:?}", place_with_id);
748+
self.tcx()
749+
.dcx()
750+
.span_delayed_bug(pat.span, "explicit index of non-indexable type");
735751
return Err(());
736752
};
737753
let elt_place = self.cat_projection(

0 commit comments

Comments
 (0)