@@ -79,8 +79,7 @@ pub fn provide(providers: &mut Providers) {
79
79
trait_def,
80
80
adt_def,
81
81
fn_sig,
82
- impl_trait_ref,
83
- impl_polarity,
82
+ impl_trait_header,
84
83
coroutine_kind,
85
84
coroutine_for_closure,
86
85
collect_mod_item_types,
@@ -600,7 +599,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
600
599
hir:: ItemKind :: Impl { .. } => {
601
600
tcx. ensure ( ) . generics_of ( def_id) ;
602
601
tcx. ensure ( ) . type_of ( def_id) ;
603
- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
602
+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
604
603
tcx. ensure ( ) . predicates_of ( def_id) ;
605
604
}
606
605
hir:: ItemKind :: Trait ( ..) => {
@@ -1499,19 +1498,20 @@ fn suggest_impl_trait<'tcx>(
1499
1498
None
1500
1499
}
1501
1500
1502
- fn impl_trait_ref (
1501
+ fn impl_trait_header (
1503
1502
tcx : TyCtxt < ' _ > ,
1504
1503
def_id : LocalDefId ,
1505
- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1504
+ ) -> Option < ty:: EarlyBinder < ty:: ImplTraitHeader < ' _ > > > {
1506
1505
let icx = ItemCtxt :: new ( tcx, def_id) ;
1507
- let impl_ = tcx. hir ( ) . expect_item ( def_id) . expect_impl ( ) ;
1506
+ let item = tcx. hir ( ) . expect_item ( def_id) ;
1507
+ let impl_ = item. expect_impl ( ) ;
1508
1508
impl_
1509
1509
. of_trait
1510
1510
. as_ref ( )
1511
1511
. map ( |ast_trait_ref| {
1512
1512
let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1513
1513
1514
- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1514
+ let trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1515
1515
tcx,
1516
1516
tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
1517
1517
ast_trait_ref,
@@ -1536,9 +1536,12 @@ fn impl_trait_ref(
1536
1536
icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
1537
1537
} else {
1538
1538
icx. astconv ( ) . instantiate_mono_trait_ref ( ast_trait_ref, selfty)
1539
- }
1539
+ } ;
1540
+ ty:: EarlyBinder :: bind ( ty:: ImplTraitHeader {
1541
+ trait_ref,
1542
+ polarity : polarity_of_impl ( tcx, def_id, impl_, item. span )
1543
+ } )
1540
1544
} )
1541
- . map ( ty:: EarlyBinder :: bind)
1542
1545
}
1543
1546
1544
1547
fn check_impl_constness (
@@ -1566,43 +1569,34 @@ fn check_impl_constness(
1566
1569
} ) )
1567
1570
}
1568
1571
1569
- fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1572
+ fn polarity_of_impl (
1573
+ tcx : TyCtxt < ' _ > ,
1574
+ def_id : LocalDefId ,
1575
+ impl_ : & hir:: Impl < ' _ > ,
1576
+ span : Span ,
1577
+ ) -> ty:: ImplPolarity {
1570
1578
let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1571
- let item = tcx. hir ( ) . expect_item ( def_id) ;
1572
- match & item. kind {
1573
- hir:: ItemKind :: Impl ( hir:: Impl {
1574
- polarity : hir:: ImplPolarity :: Negative ( span) ,
1575
- of_trait,
1576
- ..
1577
- } ) => {
1579
+ match & impl_ {
1580
+ hir:: Impl { polarity : hir:: ImplPolarity :: Negative ( span) , of_trait, .. } => {
1578
1581
if is_rustc_reservation {
1579
1582
let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
1580
1583
tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
1581
1584
}
1582
1585
ty:: ImplPolarity :: Negative
1583
1586
}
1584
- hir:: ItemKind :: Impl ( hir:: Impl {
1585
- polarity : hir:: ImplPolarity :: Positive ,
1586
- of_trait : None ,
1587
- ..
1588
- } ) => {
1587
+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : None , .. } => {
1589
1588
if is_rustc_reservation {
1590
- tcx. dcx ( ) . span_err ( item . span , "reservation impls can't be inherent" ) ;
1589
+ tcx. dcx ( ) . span_err ( span, "reservation impls can't be inherent" ) ;
1591
1590
}
1592
1591
ty:: ImplPolarity :: Positive
1593
1592
}
1594
- hir:: ItemKind :: Impl ( hir:: Impl {
1595
- polarity : hir:: ImplPolarity :: Positive ,
1596
- of_trait : Some ( _) ,
1597
- ..
1598
- } ) => {
1593
+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : Some ( _) , .. } => {
1599
1594
if is_rustc_reservation {
1600
1595
ty:: ImplPolarity :: Reservation
1601
1596
} else {
1602
1597
ty:: ImplPolarity :: Positive
1603
1598
}
1604
1599
}
1605
- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
1606
1600
}
1607
1601
}
1608
1602
0 commit comments