@@ -82,7 +82,7 @@ fn used_trait_imports(tcx: TyCtxt<'_>, def_id: LocalDefId) -> &UnordSet<LocalDef
8282 & tcx. typeck ( def_id) . used_trait_imports
8383}
8484
85- fn typeck < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> & ' tcx ty:: TypeckResults < ' tcx > {
85+ fn typeck_root < ' tcx > ( tcx : TyCtxt < ' tcx > , def_id : LocalDefId ) -> & ' tcx ty:: TypeckResults < ' tcx > {
8686 typeck_with_inspect ( tcx, def_id, None )
8787}
8888
@@ -95,6 +95,13 @@ pub fn inspect_typeck<'tcx>(
9595 def_id : LocalDefId ,
9696 inspect : ObligationInspector < ' tcx > ,
9797) -> & ' tcx ty:: TypeckResults < ' tcx > {
98+ // Closures' typeck results come from their outermost function,
99+ // as they are part of the same "inference environment".
100+ let typeck_root_def_id = tcx. typeck_root_def_id_local ( def_id) ;
101+ if typeck_root_def_id != def_id {
102+ return tcx. typeck ( typeck_root_def_id) ;
103+ }
104+
98105 typeck_with_inspect ( tcx, def_id, Some ( inspect) )
99106}
100107
@@ -104,12 +111,7 @@ fn typeck_with_inspect<'tcx>(
104111 def_id : LocalDefId ,
105112 inspector : Option < ObligationInspector < ' tcx > > ,
106113) -> & ' tcx ty:: TypeckResults < ' tcx > {
107- // Closures' typeck results come from their outermost function,
108- // as they are part of the same "inference environment".
109- let typeck_root_def_id = tcx. typeck_root_def_id_local ( def_id) ;
110- if typeck_root_def_id != def_id {
111- return tcx. typeck ( typeck_root_def_id) ;
112- }
114+ assert ! ( !tcx. is_typeck_child( def_id. to_def_id( ) ) ) ;
113115
114116 let id = tcx. local_def_id_to_hir_id ( def_id) ;
115117 let node = tcx. hir_node ( id) ;
@@ -660,7 +662,7 @@ fn fatally_break_rust(tcx: TyCtxt<'_>, span: Span) -> ! {
660662pub fn provide ( providers : & mut Providers ) {
661663 * providers = Providers {
662664 method_autoderef_steps : method:: probe:: method_autoderef_steps,
663- typeck ,
665+ typeck_root ,
664666 used_trait_imports,
665667 check_transmutes : intrinsicck:: check_transmutes,
666668 ..* providers
0 commit comments