From 70858508a56e2426c8b97bc846301e0e2dd631f6 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 22 Dec 2022 21:18:39 +0900 Subject: [PATCH] Return `TyKind::Error` instead of `span_bug!` Signed-off-by: Yuki Okushi --- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 6 +++++- src/test/ui/typeck/issue-106030.rs | 5 +++++ src/test/ui/typeck/issue-106030.stderr | 9 +++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/typeck/issue-106030.rs create mode 100644 src/test/ui/typeck/issue-106030.stderr 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`.