@@ -78,8 +78,7 @@ pub fn provide(providers: &mut Providers) {
78
78
trait_def,
79
79
adt_def,
80
80
fn_sig,
81
- impl_trait_ref,
82
- impl_polarity,
81
+ impl_trait_header,
83
82
coroutine_kind,
84
83
coroutine_for_closure,
85
84
collect_mod_item_types,
@@ -601,7 +600,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
601
600
hir:: ItemKind :: Impl { .. } => {
602
601
tcx. ensure ( ) . generics_of ( def_id) ;
603
602
tcx. ensure ( ) . type_of ( def_id) ;
604
- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
603
+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
605
604
tcx. ensure ( ) . predicates_of ( def_id) ;
606
605
}
607
606
hir:: ItemKind :: Trait ( ..) => {
@@ -1326,19 +1325,20 @@ fn suggest_impl_trait<'tcx>(
1326
1325
None
1327
1326
}
1328
1327
1329
- fn impl_trait_ref (
1328
+ fn impl_trait_header (
1330
1329
tcx : TyCtxt < ' _ > ,
1331
1330
def_id : LocalDefId ,
1332
- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1331
+ ) -> Option < ty:: EarlyBinder < ty:: ImplTraitHeader < ' _ > > > {
1333
1332
let icx = ItemCtxt :: new ( tcx, def_id) ;
1334
- let impl_ = tcx. hir ( ) . expect_item ( def_id) . expect_impl ( ) ;
1333
+ let item = tcx. hir ( ) . expect_item ( def_id) ;
1334
+ let impl_ = item. expect_impl ( ) ;
1335
1335
impl_
1336
1336
. of_trait
1337
1337
. as_ref ( )
1338
1338
. map ( |ast_trait_ref| {
1339
1339
let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1340
1340
1341
- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1341
+ let trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1342
1342
tcx,
1343
1343
tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
1344
1344
ast_trait_ref,
@@ -1363,9 +1363,12 @@ fn impl_trait_ref(
1363
1363
icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
1364
1364
} else {
1365
1365
icx. astconv ( ) . instantiate_mono_trait_ref ( ast_trait_ref, selfty)
1366
- }
1366
+ } ;
1367
+ ty:: EarlyBinder :: bind ( ty:: ImplTraitHeader {
1368
+ trait_ref,
1369
+ polarity : polarity_of_impl_item ( tcx, def_id, impl_, item. span )
1370
+ } )
1367
1371
} )
1368
- . map ( ty:: EarlyBinder :: bind)
1369
1372
}
1370
1373
1371
1374
fn check_impl_constness (
@@ -1393,43 +1396,34 @@ fn check_impl_constness(
1393
1396
} ) )
1394
1397
}
1395
1398
1396
- fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1399
+ fn polarity_of_impl_item (
1400
+ tcx : TyCtxt < ' _ > ,
1401
+ def_id : LocalDefId ,
1402
+ impl_ : & hir:: Impl < ' _ > ,
1403
+ span : Span ,
1404
+ ) -> ty:: ImplPolarity {
1397
1405
let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1398
- let item = tcx. hir ( ) . expect_item ( def_id) ;
1399
- match & item. kind {
1400
- hir:: ItemKind :: Impl ( hir:: Impl {
1401
- polarity : hir:: ImplPolarity :: Negative ( span) ,
1402
- of_trait,
1403
- ..
1404
- } ) => {
1406
+ match & impl_ {
1407
+ hir:: Impl { polarity : hir:: ImplPolarity :: Negative ( span) , of_trait, .. } => {
1405
1408
if is_rustc_reservation {
1406
1409
let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
1407
1410
tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
1408
1411
}
1409
1412
ty:: ImplPolarity :: Negative
1410
1413
}
1411
- hir:: ItemKind :: Impl ( hir:: Impl {
1412
- polarity : hir:: ImplPolarity :: Positive ,
1413
- of_trait : None ,
1414
- ..
1415
- } ) => {
1414
+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : None , .. } => {
1416
1415
if is_rustc_reservation {
1417
- tcx. dcx ( ) . span_err ( item . span , "reservation impls can't be inherent" ) ;
1416
+ tcx. dcx ( ) . span_err ( span, "reservation impls can't be inherent" ) ;
1418
1417
}
1419
1418
ty:: ImplPolarity :: Positive
1420
1419
}
1421
- hir:: ItemKind :: Impl ( hir:: Impl {
1422
- polarity : hir:: ImplPolarity :: Positive ,
1423
- of_trait : Some ( _) ,
1424
- ..
1425
- } ) => {
1420
+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : Some ( _) , .. } => {
1426
1421
if is_rustc_reservation {
1427
1422
ty:: ImplPolarity :: Reservation
1428
1423
} else {
1429
1424
ty:: ImplPolarity :: Positive
1430
1425
}
1431
1426
}
1432
- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
1433
1427
}
1434
1428
}
1435
1429
0 commit comments