@@ -163,7 +163,7 @@ pub struct CollectItemTypesVisitor<'tcx> {
163
163
/// and suggest adding type parameters in the appropriate place, taking into consideration any and
164
164
/// all already existing generic type parameters to avoid suggesting a name that is already in use.
165
165
pub ( crate ) fn placeholder_type_error < ' tcx > (
166
- tcx : TyCtxt < ' tcx > ,
166
+ cx : & dyn HirTyLowerer < ' tcx > ,
167
167
generics : Option < & hir:: Generics < ' _ > > ,
168
168
placeholder_types : Vec < Span > ,
169
169
suggest : bool ,
@@ -174,21 +174,21 @@ pub(crate) fn placeholder_type_error<'tcx>(
174
174
return ;
175
175
}
176
176
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)
178
178
. emit ( ) ;
179
179
}
180
180
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 > ,
183
183
generics : Option < & hir:: Generics < ' _ > > ,
184
184
placeholder_types : Vec < Span > ,
185
185
additional_spans : Vec < Span > ,
186
186
suggest : bool ,
187
187
hir_ty : Option < & hir:: Ty < ' _ > > ,
188
188
kind : & ' static str ,
189
- ) -> Diag < ' tcx > {
189
+ ) -> Diag < ' cx > {
190
190
if placeholder_types. is_empty ( ) {
191
- return bad_placeholder ( tcx , additional_spans, kind) ;
191
+ return bad_placeholder ( cx , additional_spans, kind) ;
192
192
}
193
193
194
194
let params = generics. map ( |g| g. params ) . unwrap_or_default ( ) ;
@@ -212,7 +212,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
212
212
}
213
213
214
214
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) ;
216
216
217
217
// Suggest, but only if it is not a function in const or static
218
218
if suggest {
@@ -226,7 +226,7 @@ pub(crate) fn placeholder_type_error_diag<'tcx>(
226
226
227
227
// Check if parent is const or static
228
228
is_const_or_static = matches ! (
229
- tcx. parent_hir_node( hir_ty. hir_id) ,
229
+ cx . tcx( ) . parent_hir_node( hir_ty. hir_id) ,
230
230
Node :: Item ( & hir:: Item {
231
231
kind: hir:: ItemKind :: Const ( ..) | hir:: ItemKind :: Static ( ..) ,
232
232
..
@@ -269,7 +269,16 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
269
269
let mut visitor = HirPlaceholderCollector :: default ( ) ;
270
270
visitor. visit_item ( item) ;
271
271
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
+ ) ;
273
282
}
274
283
275
284
impl < ' tcx > Visitor < ' tcx > for CollectItemTypesVisitor < ' tcx > {
@@ -331,15 +340,15 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
331
340
///////////////////////////////////////////////////////////////////////////
332
341
// Utility types and common code for the above passes.
333
342
334
- fn bad_placeholder < ' tcx > (
335
- tcx : TyCtxt < ' tcx > ,
343
+ fn bad_placeholder < ' cx , ' tcx > (
344
+ cx : & ' cx dyn HirTyLowerer < ' tcx > ,
336
345
mut spans : Vec < Span > ,
337
346
kind : & ' static str ,
338
- ) -> Diag < ' tcx > {
347
+ ) -> Diag < ' cx > {
339
348
let kind = if kind. ends_with ( 's' ) { format ! ( "{kind}es" ) } else { format ! ( "{kind}s" ) } ;
340
349
341
350
spans. sort ( ) ;
342
- tcx . dcx ( ) . create_err ( errors:: PlaceholderNotAllowedItemSignatures { spans, kind } )
351
+ cx . dcx ( ) . create_err ( errors:: PlaceholderNotAllowedItemSignatures { spans, kind } )
343
352
}
344
353
345
354
impl < ' tcx > ItemCtxt < ' tcx > {
@@ -383,14 +392,13 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
383
392
fn re_infer ( & self , span : Span , reason : RegionInferReason < ' _ > ) -> ty:: Region < ' tcx > {
384
393
if let RegionInferReason :: BorrowedObjectLifetimeDefault = reason {
385
394
let e = struct_span_code_err ! (
386
- self . tcx ( ) . dcx( ) ,
395
+ self . dcx( ) ,
387
396
span,
388
397
E0228 ,
389
398
"the lifetime bound for this object type cannot be deduced \
390
399
from context; please supply an explicit bound"
391
400
)
392
401
. emit ( ) ;
393
- self . set_tainted_by_errors ( e) ;
394
402
ty:: Region :: new_error ( self . tcx ( ) , e)
395
403
} else {
396
404
// This indicates an illegal lifetime in a non-assoc-trait position
@@ -515,10 +523,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
515
523
None
516
524
}
517
525
518
- fn set_tainted_by_errors ( & self , err : ErrorGuaranteed ) {
519
- self . tainted_by_errors . set ( Some ( err) ) ;
520
- }
521
-
522
526
fn lower_fn_sig (
523
527
& self ,
524
528
decl : & hir:: FnDecl < ' tcx > ,
@@ -576,7 +580,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
576
580
// `ident_span` to not emit an error twice when we have `fn foo(_: fn() -> _)`.
577
581
578
582
let mut diag = crate :: collect:: placeholder_type_error_diag (
579
- tcx ,
583
+ self ,
580
584
generics,
581
585
visitor. 0 ,
582
586
infer_replacements. iter ( ) . map ( |( s, _) | * s) . collect ( ) ,
@@ -596,7 +600,7 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
596
600
) ;
597
601
}
598
602
599
- self . set_tainted_by_errors ( diag. emit ( ) ) ;
603
+ diag. emit ( ) ;
600
604
}
601
605
602
606
( input_tys, output_ty)
@@ -645,6 +649,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
645
649
let it = tcx. hir ( ) . item ( item_id) ;
646
650
debug ! ( item = %it. ident, id = %it. hir_id( ) ) ;
647
651
let def_id = item_id. owner_id . def_id ;
652
+ let icx = ItemCtxt :: new ( tcx, def_id) ;
648
653
649
654
match & it. kind {
650
655
// These don't define types.
@@ -669,7 +674,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
669
674
let mut visitor = HirPlaceholderCollector :: default ( ) ;
670
675
visitor. visit_foreign_item ( item) ;
671
676
placeholder_type_error (
672
- tcx ,
677
+ icx . lowerer ( ) ,
673
678
None ,
674
679
visitor. 0 ,
675
680
false ,
@@ -748,7 +753,14 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
748
753
if !ty. is_suggestable_infer_ty ( ) {
749
754
let mut visitor = HirPlaceholderCollector :: default ( ) ;
750
755
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
+ ) ;
752
764
}
753
765
}
754
766
@@ -766,6 +778,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
766
778
let trait_item = tcx. hir ( ) . trait_item ( trait_item_id) ;
767
779
let def_id = trait_item_id. owner_id ;
768
780
tcx. ensure ( ) . generics_of ( def_id) ;
781
+ let icx = ItemCtxt :: new ( tcx, def_id. def_id ) ;
769
782
770
783
match trait_item. kind {
771
784
hir:: TraitItemKind :: Fn ( ..) => {
@@ -782,7 +795,14 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
782
795
// Account for `const C: _;`.
783
796
let mut visitor = HirPlaceholderCollector :: default ( ) ;
784
797
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
+ ) ;
786
806
}
787
807
}
788
808
@@ -793,7 +813,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
793
813
// Account for `type T = _;`.
794
814
let mut visitor = HirPlaceholderCollector :: default ( ) ;
795
815
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" ) ;
797
817
}
798
818
799
819
hir:: TraitItemKind :: Type ( _, None ) => {
@@ -804,7 +824,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
804
824
let mut visitor = HirPlaceholderCollector :: default ( ) ;
805
825
visitor. visit_trait_item ( trait_item) ;
806
826
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" ) ;
808
828
}
809
829
} ;
810
830
@@ -817,6 +837,7 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
817
837
tcx. ensure ( ) . type_of ( def_id) ;
818
838
tcx. ensure ( ) . predicates_of ( def_id) ;
819
839
let impl_item = tcx. hir ( ) . impl_item ( impl_item_id) ;
840
+ let icx = ItemCtxt :: new ( tcx, def_id. def_id ) ;
820
841
match impl_item. kind {
821
842
hir:: ImplItemKind :: Fn ( ..) => {
822
843
tcx. ensure ( ) . codegen_fn_attrs ( def_id) ;
@@ -827,14 +848,21 @@ fn lower_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
827
848
let mut visitor = HirPlaceholderCollector :: default ( ) ;
828
849
visitor. visit_impl_item ( impl_item) ;
829
850
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" ) ;
831
852
}
832
853
hir:: ImplItemKind :: Const ( ty, _) => {
833
854
// Account for `const T: _ = ..;`
834
855
if !ty. is_suggestable_infer_ty ( ) {
835
856
let mut visitor = HirPlaceholderCollector :: default ( ) ;
836
857
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
+ ) ;
838
866
}
839
867
}
840
868
}
@@ -1385,7 +1413,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
1385
1413
..
1386
1414
} )
1387
1415
| Item ( hir:: Item { kind : ItemKind :: Fn ( sig, generics, _) , .. } ) => {
1388
- infer_return_ty_for_fn_sig ( tcx , sig, generics, def_id, & icx)
1416
+ infer_return_ty_for_fn_sig ( sig, generics, def_id, & icx)
1389
1417
}
1390
1418
1391
1419
ImplItem ( hir:: ImplItem { kind : ImplItemKind :: Fn ( sig, _) , generics, .. } ) => {
@@ -1402,7 +1430,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
1402
1430
None ,
1403
1431
)
1404
1432
} else {
1405
- infer_return_ty_for_fn_sig ( tcx , sig, generics, def_id, & icx)
1433
+ infer_return_ty_for_fn_sig ( sig, generics, def_id, & icx)
1406
1434
}
1407
1435
}
1408
1436
@@ -1455,12 +1483,12 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_, ty::PolyFn
1455
1483
}
1456
1484
1457
1485
fn infer_return_ty_for_fn_sig < ' tcx > (
1458
- tcx : TyCtxt < ' tcx > ,
1459
1486
sig : & hir:: FnSig < ' tcx > ,
1460
1487
generics : & hir:: Generics < ' _ > ,
1461
1488
def_id : LocalDefId ,
1462
1489
icx : & ItemCtxt < ' tcx > ,
1463
1490
) -> ty:: PolyFnSig < ' tcx > {
1491
+ let tcx = icx. tcx ;
1464
1492
let hir_id = tcx. local_def_id_to_hir_id ( def_id) ;
1465
1493
1466
1494
match sig. decl . output . get_infer_ret_ty ( ) {
@@ -1492,7 +1520,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
1492
1520
let mut visitor = HirPlaceholderCollector :: default ( ) ;
1493
1521
visitor. visit_ty ( ty) ;
1494
1522
1495
- let mut diag = bad_placeholder ( tcx , visitor. 0 , "return type" ) ;
1523
+ let mut diag = bad_placeholder ( icx . lowerer ( ) , visitor. 0 , "return type" ) ;
1496
1524
let ret_ty = fn_sig. output ( ) ;
1497
1525
// Don't leak types into signatures unless they're nameable!
1498
1526
// For example, if a function returns itself, we don't want that
0 commit comments