@@ -18,9 +18,8 @@ use rustc_middle::mir::interpret::ErrorHandled;
1818use rustc_middle:: traits:: solve:: NoSolution ;
1919use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
2020use rustc_middle:: ty:: {
21- self , AdtKind , GenericArgKind , GenericArgs , GenericParamDefKind , Ty , TyCtxt , TypeFlags ,
22- TypeFoldable , TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , TypingMode ,
23- Upcast ,
21+ self , GenericArgKind , GenericArgs , GenericParamDefKind , Ty , TyCtxt , TypeFlags , TypeFoldable ,
22+ TypeSuperVisitable , TypeVisitable , TypeVisitableExt , TypeVisitor , TypingMode , Upcast ,
2423} ;
2524use rustc_middle:: { bug, span_bug} ;
2625use rustc_session:: parse:: feature_err;
@@ -290,9 +289,6 @@ pub(super) fn check_item<'tcx>(
290289 res
291290 }
292291 hir:: ItemKind :: Fn { sig, .. } => check_item_fn ( tcx, def_id, sig. decl ) ,
293- hir:: ItemKind :: Struct ( ..) => check_type_defn ( tcx, item, false ) ,
294- hir:: ItemKind :: Union ( ..) => check_type_defn ( tcx, item, true ) ,
295- hir:: ItemKind :: Enum ( ..) => check_type_defn ( tcx, item, true ) ,
296292 // Note: do not add new entries to this match. Instead add all new logic in `check_item_type`
297293 _ => span_bug ! ( item. span, "should have been handled by the type based wf check: {item:?}" ) ,
298294 }
@@ -990,15 +986,15 @@ pub(crate) fn check_associated_item(
990986}
991987
992988/// In a type definition, we check that to ensure that the types of the fields are well-formed.
993- fn check_type_defn < ' tcx > (
989+ pub ( crate ) fn check_type_defn < ' tcx > (
994990 tcx : TyCtxt < ' tcx > ,
995- item : & hir :: Item < ' tcx > ,
991+ item : LocalDefId ,
996992 all_sized : bool ,
997993) -> Result < ( ) , ErrorGuaranteed > {
998- let _ = tcx. representability ( item. owner_id . def_id ) ;
999- let adt_def = tcx. adt_def ( item. owner_id ) ;
994+ let _ = tcx. representability ( item) ;
995+ let adt_def = tcx. adt_def ( item) ;
1000996
1001- enter_wf_checking_ctxt ( tcx, item. owner_id . def_id , |wfcx| {
997+ enter_wf_checking_ctxt ( tcx, item, |wfcx| {
1002998 let variants = adt_def. variants ( ) ;
1003999 let packed = adt_def. repr ( ) . packed ( ) ;
10041000
@@ -1025,18 +1021,13 @@ fn check_type_defn<'tcx>(
10251021 }
10261022 }
10271023 let field_id = field. did . expect_local ( ) ;
1028- let hir:: FieldDef { ty : hir_ty, .. } =
1029- tcx. hir_node_by_def_id ( field_id) . expect_field ( ) ;
1024+ let span = tcx. ty_span ( field_id) ;
10301025 let ty = wfcx. deeply_normalize (
1031- hir_ty . span ,
1026+ span,
10321027 None ,
10331028 tcx. type_of ( field. did ) . instantiate_identity ( ) ,
10341029 ) ;
1035- wfcx. register_wf_obligation (
1036- hir_ty. span ,
1037- Some ( WellFormedLoc :: Ty ( field_id) ) ,
1038- ty. into ( ) ,
1039- )
1030+ wfcx. register_wf_obligation ( span, Some ( WellFormedLoc :: Ty ( field_id) ) , ty. into ( ) )
10401031 }
10411032
10421033 // For DST, or when drop needs to copy things around, all
@@ -1056,35 +1047,21 @@ fn check_type_defn<'tcx>(
10561047 variant. fields . raw [ ..variant. fields . len ( ) - unsized_len] . iter ( ) . enumerate ( )
10571048 {
10581049 let last = idx == variant. fields . len ( ) - 1 ;
1059- let field_id = field. did . expect_local ( ) ;
1060- let hir:: FieldDef { ty : hir_ty, .. } =
1061- tcx. hir_node_by_def_id ( field_id) . expect_field ( ) ;
1062- let ty = wfcx. normalize (
1063- hir_ty. span ,
1064- None ,
1065- tcx. type_of ( field. did ) . instantiate_identity ( ) ,
1066- ) ;
1050+ let span = tcx. ty_span ( field. did . expect_local ( ) ) ;
1051+ let ty = wfcx. normalize ( span, None , tcx. type_of ( field. did ) . instantiate_identity ( ) ) ;
10671052 wfcx. register_bound (
10681053 traits:: ObligationCause :: new (
1069- hir_ty . span ,
1054+ span,
10701055 wfcx. body_def_id ,
10711056 ObligationCauseCode :: FieldSized {
1072- adt_kind : match & item. kind {
1073- ItemKind :: Struct ( ..) => AdtKind :: Struct ,
1074- ItemKind :: Union ( ..) => AdtKind :: Union ,
1075- ItemKind :: Enum ( ..) => AdtKind :: Enum ,
1076- kind => span_bug ! (
1077- item. span,
1078- "should be wfchecking an ADT, got {kind:?}"
1079- ) ,
1080- } ,
1081- span : hir_ty. span ,
1057+ adt_kind : adt_def. adt_kind ( ) ,
1058+ span,
10821059 last,
10831060 } ,
10841061 ) ,
10851062 wfcx. param_env ,
10861063 ty,
1087- tcx. require_lang_item ( LangItem :: Sized , hir_ty . span ) ,
1064+ tcx. require_lang_item ( LangItem :: Sized , span) ,
10881065 ) ;
10891066 }
10901067
@@ -1100,7 +1077,7 @@ fn check_type_defn<'tcx>(
11001077 }
11011078 }
11021079
1103- check_where_clauses ( wfcx, item. owner_id . def_id ) ;
1080+ check_where_clauses ( wfcx, item) ;
11041081 Ok ( ( ) )
11051082 } )
11061083}
0 commit comments