@@ -247,6 +247,16 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
247247 self . maybe_typeck_results = maybe_typeck_results;
248248 }
249249
250+ fn visit_anon_const ( & mut self , ct : & ' tcx hir:: AnonConst ) {
251+ // FIXME: Typeck'ing anon consts leads to ICEs in rustc if the parent body wasn't typeck'ed
252+ // yet. See #156418. Figure out what the best and proper solution for this is. Until
253+ // then, let's prevent `typeck` from being called on anon consts by not setting
254+ // `maybe_typeck_results` to `Some(_)`.
255+ let maybe_typeck_results = self . maybe_typeck_results . take ( ) ;
256+ self . visit_body ( self . tcx . hir_body ( ct. body ) ) ;
257+ self . maybe_typeck_results = maybe_typeck_results;
258+ }
259+
250260 fn visit_path ( & mut self , path : & hir:: Path < ' tcx > , _id : HirId ) {
251261 if self . handle_macro ( path. span ) {
252262 return ;
@@ -318,9 +328,9 @@ impl<'tcx> Visitor<'tcx> for SpanMapVisitor<'tcx> {
318328 fn visit_expr ( & mut self , expr : & ' tcx hir:: Expr < ' tcx > ) {
319329 match expr. kind {
320330 ExprKind :: MethodCall ( segment, ..) => {
321- // Exprs *have* to exist in a body, so typeck results should always be available.
322- let typeck_results = self . maybe_typeck_results ( ) . unwrap ( ) ;
323- if let Some ( def_id ) = typeck_results . type_dependent_def_id ( expr . hir_id ) {
331+ if let Some ( typeck_results ) = self . maybe_typeck_results ( )
332+ && let Some ( def_id ) = typeck_results . type_dependent_def_id ( expr . hir_id )
333+ {
324334 self . matches . insert ( segment. ident . span . into ( ) , self . link_for_def ( def_id) ) ;
325335 }
326336 }
0 commit comments