diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index 78ce0bf9cc16b..d1ca05780930a 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -443,13 +443,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ) -> bool /* did we suggest to call a function because of missing parenthesis? */ { err.span_label(span, ty.to_string()); if let FnDef(def_id, _) = ty.sty { + let source_map = self.tcx.sess.source_map(); + let hir_id = match self.tcx.hir().as_local_hir_id(def_id) { + Some(hir_id) => hir_id, + None => return false, + }; if self.tcx.has_typeck_tables(def_id) == false { return false; } - let source_map = self.tcx.sess.source_map(); - let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap(); let fn_sig = { - match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(*hir_id) { + match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(hir_id) { Some(f) => f.clone(), None => { bug!("No fn-sig entry for def_id={:?}", def_id); @@ -458,11 +461,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { }; let other_ty = if let FnDef(def_id, _) = other_ty.sty { + let hir_id = match self.tcx.hir().as_local_hir_id(def_id) { + Some(hir_id) => hir_id, + None => return false, + }; if self.tcx.has_typeck_tables(def_id) == false { return false; } - let hir_id = &self.tcx.hir().as_local_hir_id(def_id).unwrap(); - match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(*hir_id) { + match self.tcx.typeck_tables_of(def_id).liberated_fn_sigs().get(hir_id) { Some(f) => f.clone().output(), None => { bug!("No fn-sig entry for def_id={:?}", def_id);