|
99 | 99 | W: Write,
|
100 | 100 | {
|
101 | 101 | let def_id = body.source.def_id();
|
102 |
| - let body_span = hir_body(tcx, def_id).value.span; |
| 102 | + let hir_body = hir_body(tcx, def_id); |
| 103 | + if hir_body.is_none() { |
| 104 | + return Ok(()); |
| 105 | + } |
| 106 | + let body_span = hir_body.unwrap().value.span; |
103 | 107 | let mut span_viewables = Vec::new();
|
104 | 108 | for (bb, data) in body.basic_blocks().iter_enumerated() {
|
105 | 109 | match spanview {
|
@@ -664,19 +668,16 @@ fn fn_span<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Span {
|
664 | 668 | let hir_id =
|
665 | 669 | tcx.hir().local_def_id_to_hir_id(def_id.as_local().expect("expected DefId is local"));
|
666 | 670 | let fn_decl_span = tcx.hir().span(hir_id);
|
667 |
| - let body_span = hir_body(tcx, def_id).value.span; |
668 |
| - if fn_decl_span.ctxt() == body_span.ctxt() { |
669 |
| - fn_decl_span.to(body_span) |
| 671 | + if let Some(body_span) = hir_body(tcx, def_id).map(|hir_body| hir_body.value.span) { |
| 672 | + if fn_decl_span.ctxt() == body_span.ctxt() { fn_decl_span.to(body_span) } else { body_span } |
670 | 673 | } else {
|
671 |
| - // This probably occurs for functions defined via macros |
672 |
| - body_span |
| 674 | + fn_decl_span |
673 | 675 | }
|
674 | 676 | }
|
675 | 677 |
|
676 |
| -fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx rustc_hir::Body<'tcx> { |
| 678 | +fn hir_body<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> Option<&'tcx rustc_hir::Body<'tcx>> { |
677 | 679 | let hir_node = tcx.hir().get_if_local(def_id).expect("expected DefId is local");
|
678 |
| - let fn_body_id = hir::map::associated_body(hir_node).expect("HIR node is a function with body"); |
679 |
| - tcx.hir().body(fn_body_id) |
| 680 | + hir::map::associated_body(hir_node).map(|fn_body_id| tcx.hir().body(fn_body_id)) |
680 | 681 | }
|
681 | 682 |
|
682 | 683 | fn escape_html(s: &str) -> String {
|
|
0 commit comments