diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 150e917c73988..ebddf4e04f145 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -130,7 +130,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn local_ty(&self, span: Span, nid: hir::HirId) -> LocalTy<'tcx> { self.locals.borrow().get(&nid).cloned().unwrap_or_else(|| { - span_bug!(span, "no type for local variable {}", self.tcx.hir().node_to_string(nid)) + let err = self.tcx.ty_error_with_message( + span, + &format!("no type for local variable {}", self.tcx.hir().node_to_string(nid)), + ); + LocalTy { decl_ty: err, revealed_ty: err } }) } diff --git a/src/test/ui/typeck/issue-106030.rs b/src/test/ui/typeck/issue-106030.rs new file mode 100644 index 0000000000000..8652d237a5719 --- /dev/null +++ b/src/test/ui/typeck/issue-106030.rs @@ -0,0 +1,5 @@ +fn main() { + unknown(1, |glyf| { //~ ERROR: cannot find function `unknown` in this scope + let actual = glyf; + }); +} diff --git a/src/test/ui/typeck/issue-106030.stderr b/src/test/ui/typeck/issue-106030.stderr new file mode 100644 index 0000000000000..666dca01b373d --- /dev/null +++ b/src/test/ui/typeck/issue-106030.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `unknown` in this scope + --> $DIR/issue-106030.rs:2:5 + | +LL | unknown(1, |glyf| { + | ^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0425`.