1
1
use crate :: autoderef:: Autoderef ;
2
+ use crate :: collect:: CollectItemTypesVisitor ;
2
3
use crate :: constrained_generic_params:: { identify_constrained_generic_params, Parameter } ;
3
4
use crate :: errors;
4
5
6
+ use hir:: intravisit:: Visitor ;
5
7
use rustc_ast as ast;
6
8
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
7
9
use rustc_errors:: { codes:: * , pluralize, struct_span_code_err, Applicability , ErrorGuaranteed } ;
@@ -225,6 +227,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
225
227
?item. owner_id,
226
228
item. name = ? tcx. def_path_str( def_id)
227
229
) ;
230
+ CollectItemTypesVisitor { tcx } . visit_item ( item) ;
228
231
229
232
let res = match item. kind {
230
233
// Right now we check that every default trait implementation
@@ -248,6 +251,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
248
251
let header = tcx. impl_trait_header ( def_id) ;
249
252
let is_auto = header
250
253
. is_some_and ( |header| tcx. trait_is_auto ( header. skip_binder ( ) . trait_ref . def_id ) ) ;
254
+
255
+ crate :: impl_wf_check:: check_impl_wf ( tcx, def_id) ?;
251
256
let mut res = Ok ( ( ) ) ;
252
257
if let ( hir:: Defaultness :: Default { .. } , true ) = ( impl_. defaultness , is_auto) {
253
258
let sp = impl_. of_trait . as_ref ( ) . map_or ( item. span , |t| t. path . span ) ;
@@ -334,9 +339,14 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
334
339
res
335
340
}
336
341
337
- fn check_foreign_item ( tcx : TyCtxt < ' _ > , item : & hir:: ForeignItem < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
342
+ fn check_foreign_item < ' tcx > (
343
+ tcx : TyCtxt < ' tcx > ,
344
+ item : & ' tcx hir:: ForeignItem < ' tcx > ,
345
+ ) -> Result < ( ) , ErrorGuaranteed > {
338
346
let def_id = item. owner_id . def_id ;
339
347
348
+ CollectItemTypesVisitor { tcx } . visit_foreign_item ( item) ;
349
+
340
350
debug ! (
341
351
?item. owner_id,
342
352
item. name = ? tcx. def_path_str( def_id)
@@ -353,12 +363,14 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) -> Result<()
353
363
}
354
364
}
355
365
356
- fn check_trait_item (
357
- tcx : TyCtxt < ' _ > ,
358
- trait_item : & hir:: TraitItem < ' _ > ,
366
+ fn check_trait_item < ' tcx > (
367
+ tcx : TyCtxt < ' tcx > ,
368
+ trait_item : & ' tcx hir:: TraitItem < ' tcx > ,
359
369
) -> Result < ( ) , ErrorGuaranteed > {
360
370
let def_id = trait_item. owner_id . def_id ;
361
371
372
+ CollectItemTypesVisitor { tcx } . visit_trait_item ( trait_item) ;
373
+
362
374
let ( method_sig, span) = match trait_item. kind {
363
375
hir:: TraitItemKind :: Fn ( ref sig, _) => ( Some ( sig) , trait_item. span ) ,
364
376
hir:: TraitItemKind :: Type ( _bounds, Some ( ty) ) => ( None , ty. span ) ,
@@ -895,7 +907,12 @@ fn check_object_unsafe_self_trait_by_name(tcx: TyCtxt<'_>, item: &hir::TraitItem
895
907
}
896
908
}
897
909
898
- fn check_impl_item ( tcx : TyCtxt < ' _ > , impl_item : & hir:: ImplItem < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
910
+ fn check_impl_item < ' tcx > (
911
+ tcx : TyCtxt < ' tcx > ,
912
+ impl_item : & ' tcx hir:: ImplItem < ' tcx > ,
913
+ ) -> Result < ( ) , ErrorGuaranteed > {
914
+ CollectItemTypesVisitor { tcx } . visit_impl_item ( impl_item) ;
915
+
899
916
let ( method_sig, span) = match impl_item. kind {
900
917
hir:: ImplItemKind :: Fn ( ref sig, _) => ( Some ( sig) , impl_item. span ) ,
901
918
// Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
0 commit comments