@@ -163,7 +163,7 @@ pub struct CollectItemTypesVisitor<'tcx> {
163163/// and suggest adding type parameters in the appropriate place, taking into consideration any and
164164/// all already existing generic type parameters to avoid suggesting a name that is already in use.
165165pub ( crate ) fn placeholder_type_error < ' tcx > (
166- tcx : TyCtxt < ' tcx > ,
166+ cx : & dyn HirTyLowerer < ' tcx > ,
167167 generics : Option < & hir:: Generics < ' _ > > ,
168168 placeholder_types : Vec < Span > ,
169169 suggest : bool ,
@@ -174,21 +174,21 @@ pub(crate) fn placeholder_type_error<'tcx>(
174174 return ;
175175 }
176176
177- placeholder_type_error_diag ( tcx , generics, placeholder_types, vec ! [ ] , suggest, hir_ty, kind)
177+ placeholder_type_error_diag ( cx , generics, placeholder_types, vec ! [ ] , suggest, hir_ty, kind)
178178 . emit ( ) ;
179179}
180180
181- pub ( crate ) fn placeholder_type_error_diag < ' tcx > (
182- tcx : TyCtxt < ' tcx > ,
181+ pub ( crate ) fn placeholder_type_error_diag < ' cx , ' tcx > (
182+ cx : & ' cx dyn HirTyLowerer < ' tcx > ,
183183 generics : Option < & hir:: Generics < ' _ > > ,
184184 placeholder_types : Vec < Span > ,
185185 additional_spans : Vec < Span > ,
186186 suggest : bool ,
187187 hir_ty : Option < & hir:: Ty < ' _ > > ,
188188 kind : & ' static str ,
189- ) -> Diag < ' tcx > {
189+ ) -> Diag < ' cx > {
190190 if placeholder_types. is_empty ( ) {
191- return bad_placeholder ( tcx , additional_spans, kind) ;
191+ return bad_placeholder ( cx , additional_spans, kind) ;
192192 }
193193
194194 let params = generics. map ( |g| g. params ) . unwrap_or_default ( ) ;
@@ -212,7 +212,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
212212 }
213213
214214 let mut err =
215- bad_placeholder ( tcx , placeholder_types. into_iter ( ) . chain ( additional_spans) . collect ( ) , kind) ;
215+ bad_placeholder ( cx , placeholder_types. into_iter ( ) . chain ( additional_spans) . collect ( ) , kind) ;
216216
217217 // Suggest, but only if it is not a function in const or static
218218 if suggest {
@@ -226,7 +226,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
226226
227227 // Check if parent is const or static
228228 is_const_or_static = matches ! (
229- tcx. parent_hir_node( hir_ty. hir_id) ,
229+ cx . tcx( ) . parent_hir_node( hir_ty. hir_id) ,
230230 Node :: Item ( & hir:: Item {
231231 kind: hir:: ItemKind :: Const ( ..) | hir:: ItemKind :: Static ( ..) ,
232232 ..
@@ -269,7 +269,16 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
269269 let mut visitor = HirPlaceholderCollector :: default ( ) ;
270270 visitor. visit_item ( item) ;
271271
272- placeholder_type_error ( tcx, Some ( generics) , visitor. 0 , suggest, None , item. kind . descr ( ) ) ;
272+ let icx = ItemCtxt :: new ( tcx, item. owner_id . def_id ) ;
273+
274+ placeholder_type_error (
275+ icx. lowerer ( ) ,
276+ Some ( generics) ,
277+ visitor. 0 ,
278+ suggest,
279+ None ,
280+ item. kind . descr ( ) ,
281+ ) ;
273282}
274283
275284impl < ' tcx > Visitor < ' tcx > for CollectItemTypesVisitor < ' tcx > {
@@ -331,15 +340,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
331340///////////////////////////////////////////////////////////////////////////
332341// Utility types and common code for the above passes.
333342
334- fn bad_placeholder < ' tcx > (
335- tcx : TyCtxt < ' tcx > ,
343+ fn bad_placeholder < ' cx , ' tcx > (
344+ cx : & ' cx dyn HirTyLowerer < ' tcx > ,
336345 mut spans : Vec < Span > ,
337346 kind : & ' static str ,
338- ) -> Diag < ' tcx > {
347+ ) -> Diag < ' cx > {
339348 let kind = if kind. ends_with ( 's' ) { format ! ( "{kind}es" ) } else { format ! ( "{kind}s" ) } ;
340349
341350 spans. sort ( ) ;
342- tcx . dcx ( ) . create_err ( errors:: PlaceholderNotAllowedItemSignatures { spans, kind } )
351+ cx . dcx ( ) . create_err ( errors:: PlaceholderNotAllowedItemSignatures { spans, kind } )
343352}
344353
345354impl < ' tcx > ItemCtxt < ' tcx > {
@@ -383,14 +392,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
383392 fn re_infer ( & self , span : Span , reason : RegionInferReason < ' _ > ) -> ty:: Region < ' tcx > {
384393 if let RegionInferReason :: BorrowedObjectLifetimeDefault = reason {
385394 let e = struct_span_code_err ! (
386- self . tcx ( ) . dcx( ) ,
395+ self . dcx( ) ,
387396 span,
388397 E0228 ,
389398 "the lifetime bound for this object type cannot be deduced \
390399 from context; please supply an explicit bound"
391400 )
392401 . emit ( ) ;
393- self . set_tainted_by_errors ( e) ;
394402 ty:: Region :: new_error ( self . tcx ( ) , e)
395403 } else {
396404 // This indicates an illegal lifetime in a non-assoc-trait position
@@ -515,10 +523,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
515523 None
516524 }
517525
518- fn set_tainted_by_errors ( & self , err : ErrorGuaranteed ) {
519- self . tainted_by_errors . set ( Some ( err) ) ;
520- }
521-
522526 fn lower_fn_sig (
523527 & self ,
524528 decl : & hir:: FnDecl < ' tcx > ,
@@ -576,7 +580,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
576580 // `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`.
577581
578582 let mut diag = crate :: collect:: placeholder_type_error_diag (
579- tcx ,
583+ self ,
580584 generics,
581585 visitor. 0 ,
582586 infer_replacements. iter ( ) . map ( |( s, _) | * s) . collect ( ) ,
@@ -596,7 +600,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
596600 ) ;
597601 }
598602
599- self . set_tainted_by_errors ( diag. emit ( ) ) ;
603+ diag. emit ( ) ;
600604 }
601605
602606 ( input_tys, output_ty)
@@ -645,6 +649,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
645649 let it = tcx. hir ( ) . item ( item_id) ;
646650 debug ! ( item = %it. ident, id = %it. hir_id( ) ) ;
647651 let def_id = item_id. owner_id . def_id ;
652+ let icx = ItemCtxt :: new ( tcx, def_id) ;
648653
649654 match & it. kind {
650655 // These don't define types.
@@ -669,7 +674,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
669674 let mut visitor = HirPlaceholderCollector :: default ( ) ;
670675 visitor. visit_foreign_item ( item) ;
671676 placeholder_type_error (
672- tcx ,
677+ icx . lowerer ( ) ,
673678 None ,
674679 visitor. 0 ,
675680 false ,
@@ -748,7 +753,14 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
748753 if !ty. is_suggestable_infer_ty ( ) {
749754 let mut visitor = HirPlaceholderCollector :: default ( ) ;
750755 visitor. visit_item ( it) ;
751- placeholder_type_error ( tcx, None , visitor. 0 , false , None , it. kind . descr ( ) ) ;
756+ placeholder_type_error (
757+ icx. lowerer ( ) ,
758+ None ,
759+ visitor. 0 ,
760+ false ,
761+ None ,
762+ it. kind . descr ( ) ,
763+ ) ;
752764 }
753765 }
754766
@@ -766,6 +778,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
766778 let trait_item = tcx. hir ( ) . trait_item ( trait_item_id) ;
767779 let def_id = trait_item_id. owner_id ;
768780 tcx. ensure ( ) . generics_of ( def_id) ;
781+ let icx = ItemCtxt :: new ( tcx, def_id. def_id ) ;
769782
770783 match trait_item. kind {
771784 hir:: TraitItemKind :: Fn ( ..) => {
@@ -782,7 +795,14 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
782795 // Account for `const C: _;`.
783796 let mut visitor = HirPlaceholderCollector :: default ( ) ;
784797 visitor. visit_trait_item ( trait_item) ;
785- placeholder_type_error ( tcx, None , visitor. 0 , false , None , "associated constant" ) ;
798+ placeholder_type_error (
799+ icx. lowerer ( ) ,
800+ None ,
801+ visitor. 0 ,
802+ false ,
803+ None ,
804+ "associated constant" ,
805+ ) ;
786806 }
787807 }
788808
@@ -793,7 +813,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
793813 // Account for `type T = _;`.
794814 let mut visitor = HirPlaceholderCollector :: default ( ) ;
795815 visitor. visit_trait_item ( trait_item) ;
796- placeholder_type_error ( tcx , None , visitor. 0 , false , None , "associated type" ) ;
816+ placeholder_type_error ( icx . lowerer ( ) , None , visitor. 0 , false , None , "associated type" ) ;
797817 }
798818
799819 hir:: TraitItemKind :: Type ( _, None ) => {
@@ -804,7 +824,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
804824 let mut visitor = HirPlaceholderCollector :: default ( ) ;
805825 visitor. visit_trait_item ( trait_item) ;
806826
807- placeholder_type_error ( tcx , None , visitor. 0 , false , None , "associated type" ) ;
827+ placeholder_type_error ( icx . lowerer ( ) , None , visitor. 0 , false , None , "associated type" ) ;
808828 }
809829 } ;
810830
@@ -817,6 +837,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
817837 tcx. ensure ( ) . type_of ( def_id) ;
818838 tcx. ensure ( ) . predicates_of ( def_id) ;
819839 let impl_item = tcx. hir ( ) . impl_item ( impl_item_id) ;
840+ let icx = ItemCtxt :: new ( tcx, def_id. def_id ) ;
820841 match impl_item. kind {
821842 hir:: ImplItemKind :: Fn ( ..) => {
822843 tcx. ensure ( ) . codegen_fn_attrs ( def_id) ;
@@ -827,14 +848,21 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
827848 let mut visitor = HirPlaceholderCollector :: default ( ) ;
828849 visitor. visit_impl_item ( impl_item) ;
829850
830- placeholder_type_error ( tcx , None , visitor. 0 , false , None , "associated type" ) ;
851+ placeholder_type_error ( icx . lowerer ( ) , None , visitor. 0 , false , None , "associated type" ) ;
831852 }
832853 hir:: ImplItemKind :: Const ( ty, _) => {
833854 // Account for `const T: _ = ..;`
834855 if !ty. is_suggestable_infer_ty ( ) {
835856 let mut visitor = HirPlaceholderCollector :: default ( ) ;
836857 visitor. visit_impl_item ( impl_item) ;
837- placeholder_type_error ( tcx, None , visitor. 0 , false , None , "associated constant" ) ;
858+ placeholder_type_error (
859+ icx. lowerer ( ) ,
860+ None ,
861+ visitor. 0 ,
862+ false ,
863+ None ,
864+ "associated constant" ,
865+ ) ;
838866 }
839867 }
840868 }
@@ -1383,7 +1411,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
13831411 ..
13841412 } )
13851413 | Item ( hir:: Item { kind : ItemKind :: Fn ( sig, generics, _) , .. } ) => {
1386- infer_return_ty_for_fn_sig ( tcx , sig, generics, def_id, & icx)
1414+ infer_return_ty_for_fn_sig ( sig, generics, def_id, & icx)
13871415 }
13881416
13891417 ImplItem ( hir:: ImplItem { kind : ImplItemKind :: Fn ( sig, _) , generics, .. } ) => {
@@ -1400,7 +1428,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
14001428 None ,
14011429 )
14021430 } else {
1403- infer_return_ty_for_fn_sig ( tcx , sig, generics, def_id, & icx)
1431+ infer_return_ty_for_fn_sig ( sig, generics, def_id, & icx)
14041432 }
14051433 }
14061434
@@ -1453,12 +1481,12 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
14531481}
14541482
14551483fn infer_return_ty_for_fn_sig < ' tcx > (
1456- tcx : TyCtxt < ' tcx > ,
14571484 sig : & hir:: FnSig < ' tcx > ,
14581485 generics : & hir:: Generics < ' _ > ,
14591486 def_id : LocalDefId ,
14601487 icx : & ItemCtxt < ' tcx > ,
14611488) -> ty:: PolyFnSig < ' tcx > {
1489+ let tcx = icx. tcx ;
14621490 let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
14631491
14641492 match sig. decl . output . get_infer_ret_ty ( ) {
@@ -1490,7 +1518,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
14901518 let mut visitor = HirPlaceholderCollector :: default ( ) ;
14911519 visitor. visit_ty ( ty) ;
14921520
1493- let mut diag = bad_placeholder ( tcx , visitor. 0 , "return type" ) ;
1521+ let mut diag = bad_placeholder ( icx . lowerer ( ) , visitor. 0 , "return type" ) ;
14941522 let ret_ty = fn_sig. output ( ) ;
14951523 // Don't leak types into signatures unless they're nameable!
14961524 // For example, if a function returns itself, we don't want that
0 commit comments