11use crate :: autoderef:: Autoderef ;
2+ use crate :: collect:: CollectItemTypesVisitor ;
23use crate :: constrained_generic_params:: { identify_constrained_generic_params, Parameter } ;
34use crate :: errors;
45
6+ use hir:: intravisit:: Visitor ;
57use rustc_ast as ast;
68use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexSet } ;
79use 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<()
225227 ?item. owner_id,
226228 item. name = ? tcx. def_path_str( def_id)
227229 ) ;
230+ CollectItemTypesVisitor { tcx } . visit_item ( item) ;
228231
229232 let res = match item. kind {
230233 // 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<()
248251 let header = tcx. impl_trait_header ( def_id) ;
249252 let is_auto = header
250253 . 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) ?;
251256 let mut res = Ok ( ( ) ) ;
252257 if let ( hir:: Defaultness :: Default { .. } , true ) = ( impl_. defaultness , is_auto) {
253258 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<()
334339 res
335340}
336341
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 > {
338346 let def_id = item. owner_id . def_id ;
339347
348+ CollectItemTypesVisitor { tcx } . visit_foreign_item ( item) ;
349+
340350 debug ! (
341351 ?item. owner_id,
342352 item. name = ? tcx. def_path_str( def_id)
@@ -353,12 +363,14 @@ fn check_foreign_item(tcx: TyCtxt<'_>, item: &hir::ForeignItem<'_>) -> Result<()
353363 }
354364}
355365
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 > ,
359369) -> Result < ( ) , ErrorGuaranteed > {
360370 let def_id = trait_item. owner_id . def_id ;
361371
372+ CollectItemTypesVisitor { tcx } . visit_trait_item ( trait_item) ;
373+
362374 let ( method_sig, span) = match trait_item. kind {
363375 hir:: TraitItemKind :: Fn ( ref sig, _) => ( Some ( sig) , trait_item. span ) ,
364376 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
895907 }
896908}
897909
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+
899916 let ( method_sig, span) = match impl_item. kind {
900917 hir:: ImplItemKind :: Fn ( ref sig, _) => ( Some ( sig) , impl_item. span ) ,
901918 // Constrain binding and overflow error spans to `<Ty>` in `type foo = <Ty>`.
0 commit comments