@@ -18,9 +18,8 @@ use rustc_middle::mir::interpret::ErrorHandled;
18
18
use rustc_middle:: traits:: solve:: NoSolution ;
19
19
use rustc_middle:: ty:: trait_def:: TraitSpecializationKind ;
20
20
use 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 ,
24
23
} ;
25
24
use rustc_middle:: { bug, span_bug} ;
26
25
use rustc_session:: parse:: feature_err;
@@ -290,9 +289,6 @@ pub(super) fn check_item<'tcx>(
290
289
res
291
290
}
292
291
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 ) ,
296
292
// Note: do not add new entries to this match. Instead add all new logic in `check_item_type`
297
293
_ => span_bug ! ( item. span, "should have been handled by the type based wf check: {item:?}" ) ,
298
294
}
@@ -990,15 +986,15 @@ pub(crate) fn check_associated_item(
990
986
}
991
987
992
988
/// 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 > (
994
990
tcx : TyCtxt < ' tcx > ,
995
- item : & hir :: Item < ' tcx > ,
991
+ item : LocalDefId ,
996
992
all_sized : bool ,
997
993
) -> 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) ;
1000
996
1001
- enter_wf_checking_ctxt ( tcx, item. owner_id . def_id , |wfcx| {
997
+ enter_wf_checking_ctxt ( tcx, item, |wfcx| {
1002
998
let variants = adt_def. variants ( ) ;
1003
999
let packed = adt_def. repr ( ) . packed ( ) ;
1004
1000
@@ -1025,18 +1021,13 @@ fn check_type_defn<'tcx>(
1025
1021
}
1026
1022
}
1027
1023
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) ;
1030
1025
let ty = wfcx. deeply_normalize (
1031
- hir_ty . span ,
1026
+ span,
1032
1027
None ,
1033
1028
tcx. type_of ( field. did ) . instantiate_identity ( ) ,
1034
1029
) ;
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 ( ) )
1040
1031
}
1041
1032
1042
1033
// For DST, or when drop needs to copy things around, all
@@ -1056,35 +1047,21 @@ fn check_type_defn<'tcx>(
1056
1047
variant. fields . raw [ ..variant. fields . len ( ) - unsized_len] . iter ( ) . enumerate ( )
1057
1048
{
1058
1049
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 ( ) ) ;
1067
1052
wfcx. register_bound (
1068
1053
traits:: ObligationCause :: new (
1069
- hir_ty . span ,
1054
+ span,
1070
1055
wfcx. body_def_id ,
1071
1056
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,
1082
1059
last,
1083
1060
} ,
1084
1061
) ,
1085
1062
wfcx. param_env ,
1086
1063
ty,
1087
- tcx. require_lang_item ( LangItem :: Sized , hir_ty . span ) ,
1064
+ tcx. require_lang_item ( LangItem :: Sized , span) ,
1088
1065
) ;
1089
1066
}
1090
1067
@@ -1100,7 +1077,7 @@ fn check_type_defn<'tcx>(
1100
1077
}
1101
1078
}
1102
1079
1103
- check_where_clauses ( wfcx, item. owner_id . def_id ) ;
1080
+ check_where_clauses ( wfcx, item) ;
1104
1081
Ok ( ( ) )
1105
1082
} )
1106
1083
}
0 commit comments