@@ -309,11 +309,11 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
309
309
check_item_type ( tcx, def_id, ty. span , UnsizedHandling :: Forbid )
310
310
}
311
311
hir:: ItemKind :: Struct ( _, hir_generics) => check_type_defn ( tcx, item, false )
312
- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
312
+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
313
313
hir:: ItemKind :: Union ( _, hir_generics) => check_type_defn ( tcx, item, true )
314
- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
314
+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
315
315
hir:: ItemKind :: Enum ( _, hir_generics) => check_type_defn ( tcx, item, true )
316
- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) ) ,
316
+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) ) ,
317
317
hir:: ItemKind :: Trait ( ..) => check_trait ( tcx, item) ,
318
318
hir:: ItemKind :: TraitAlias ( ..) => check_trait ( tcx, item) ,
319
319
// `ForeignItem`s are handled separately.
@@ -323,7 +323,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
323
323
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
324
324
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
325
325
check_item_type ( tcx, def_id, hir_ty. span , UnsizedHandling :: Allow )
326
- . and ( check_variances_for_type_defn ( tcx, item, hir_generics) )
326
+ . and ( check_variances_for_type_defn ( tcx, item. owner_id . def_id , hir_generics) )
327
327
} else {
328
328
Ok ( ( ) )
329
329
}
@@ -1801,30 +1801,30 @@ fn receiver_is_implemented<'tcx>(
1801
1801
1802
1802
fn check_variances_for_type_defn < ' tcx > (
1803
1803
tcx : TyCtxt < ' tcx > ,
1804
- item : & hir :: Item < ' tcx > ,
1804
+ item : LocalDefId ,
1805
1805
hir_generics : & hir:: Generics < ' tcx > ,
1806
1806
) -> Result < ( ) , ErrorGuaranteed > {
1807
- let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item. owner_id ) ;
1807
+ let identity_args = ty:: GenericArgs :: identity_for_item ( tcx, item) ;
1808
1808
1809
- match item . kind {
1810
- ItemKind :: Enum ( .. ) | ItemKind :: Struct ( .. ) | ItemKind :: Union ( .. ) => {
1811
- for field in tcx. adt_def ( item. owner_id ) . all_fields ( ) {
1809
+ match tcx . def_kind ( item ) {
1810
+ DefKind :: Enum | DefKind :: Struct | DefKind :: Union => {
1811
+ for field in tcx. adt_def ( item) . all_fields ( ) {
1812
1812
field. ty ( tcx, identity_args) . error_reported ( ) ?;
1813
1813
}
1814
1814
}
1815
- ItemKind :: TyAlias ( .. ) => {
1815
+ DefKind :: TyAlias => {
1816
1816
assert ! (
1817
- tcx. type_alias_is_lazy( item. owner_id ) ,
1817
+ tcx. type_alias_is_lazy( item) ,
1818
1818
"should not be computing variance of non-weak type alias"
1819
1819
) ;
1820
- tcx. type_of ( item. owner_id ) . skip_binder ( ) . error_reported ( ) ?;
1820
+ tcx. type_of ( item) . skip_binder ( ) . error_reported ( ) ?;
1821
1821
}
1822
- kind => span_bug ! ( item . span , "cannot compute the variances of {kind:?}" ) ,
1822
+ kind => span_bug ! ( tcx . def_span ( item ) , "cannot compute the variances of {kind:?}" ) ,
1823
1823
}
1824
1824
1825
- let ty_predicates = tcx. predicates_of ( item. owner_id ) ;
1825
+ let ty_predicates = tcx. predicates_of ( item) ;
1826
1826
assert_eq ! ( ty_predicates. parent, None ) ;
1827
- let variances = tcx. variances_of ( item. owner_id ) ;
1827
+ let variances = tcx. variances_of ( item) ;
1828
1828
1829
1829
let mut constrained_parameters: FxHashSet < _ > = variances
1830
1830
. iter ( )
@@ -1837,7 +1837,7 @@ fn check_variances_for_type_defn<'tcx>(
1837
1837
1838
1838
// Lazily calculated because it is only needed in case of an error.
1839
1839
let explicitly_bounded_params = LazyCell :: new ( || {
1840
- let icx = crate :: collect:: ItemCtxt :: new ( tcx, item. owner_id . def_id ) ;
1840
+ let icx = crate :: collect:: ItemCtxt :: new ( tcx, item) ;
1841
1841
hir_generics
1842
1842
. predicates
1843
1843
. iter ( )
@@ -1853,7 +1853,7 @@ fn check_variances_for_type_defn<'tcx>(
1853
1853
. collect :: < FxHashSet < _ > > ( )
1854
1854
} ) ;
1855
1855
1856
- let ty_generics = tcx. generics_of ( item. owner_id ) ;
1856
+ let ty_generics = tcx. generics_of ( item) ;
1857
1857
1858
1858
let mut res = Ok ( ( ) ) ;
1859
1859
@@ -1886,7 +1886,7 @@ fn check_variances_for_type_defn<'tcx>(
1886
1886
hir:: ParamName :: Error ( guar) => res = Err ( guar) ,
1887
1887
_ => {
1888
1888
let has_explicit_bounds = explicitly_bounded_params. contains ( & parameter) ;
1889
- res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item. kind ) ) ;
1889
+ res = Err ( report_bivariance ( tcx, hir_param, has_explicit_bounds, item) ) ;
1890
1890
}
1891
1891
}
1892
1892
}
@@ -1897,12 +1897,12 @@ fn report_bivariance(
1897
1897
tcx : TyCtxt < ' _ > ,
1898
1898
param : & rustc_hir:: GenericParam < ' _ > ,
1899
1899
has_explicit_bounds : bool ,
1900
- item_kind : ItemKind < ' _ > ,
1900
+ item : LocalDefId ,
1901
1901
) -> ErrorGuaranteed {
1902
1902
let param_name = param. name . ident ( ) ;
1903
1903
1904
- let help = match item_kind {
1905
- ItemKind :: Enum ( .. ) | ItemKind :: Struct ( .. ) | ItemKind :: Union ( .. ) => {
1904
+ let help = match tcx . def_kind ( item ) {
1905
+ DefKind :: Enum | DefKind :: Struct | DefKind :: Union => {
1906
1906
if let Some ( def_id) = tcx. lang_items ( ) . phantom_data ( ) {
1907
1907
errors:: UnusedGenericParameterHelp :: Adt {
1908
1908
param_name,
@@ -1912,7 +1912,7 @@ fn report_bivariance(
1912
1912
errors:: UnusedGenericParameterHelp :: AdtNoPhantomData { param_name }
1913
1913
}
1914
1914
}
1915
- ItemKind :: TyAlias ( .. ) => errors:: UnusedGenericParameterHelp :: TyAlias { param_name } ,
1915
+ DefKind :: TyAlias => errors:: UnusedGenericParameterHelp :: TyAlias { param_name } ,
1916
1916
item_kind => bug ! ( "report_bivariance: unexpected item kind: {item_kind:?}" ) ,
1917
1917
} ;
1918
1918
0 commit comments