@@ -79,8 +79,7 @@ pub fn provide(providers: &mut Providers) {
7979 trait_def,
8080 adt_def,
8181 fn_sig,
82- impl_trait_ref,
83- impl_polarity,
82+ impl_trait_header,
8483 coroutine_kind,
8584 coroutine_for_closure,
8685 collect_mod_item_types,
@@ -600,7 +599,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
600599 hir:: ItemKind :: Impl { .. } => {
601600 tcx. ensure ( ) . generics_of ( def_id) ;
602601 tcx. ensure ( ) . type_of ( def_id) ;
603- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
602+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
604603 tcx. ensure ( ) . predicates_of ( def_id) ;
605604 }
606605 hir:: ItemKind :: Trait ( ..) => {
@@ -1499,19 +1498,20 @@ fn suggest_impl_trait<'tcx>(
14991498 None
15001499}
15011500
1502- fn impl_trait_ref (
1501+ fn impl_trait_header (
15031502 tcx : TyCtxt < ' _ > ,
15041503 def_id : LocalDefId ,
1505- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1504+ ) -> Option < ty:: EarlyBinder < ty:: ImplTraitHeader < ' _ > > > {
15061505 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 ( ) ;
15081508 impl_
15091509 . of_trait
15101510 . as_ref ( )
15111511 . map ( |ast_trait_ref| {
15121512 let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
15131513
1514- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1514+ let trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
15151515 tcx,
15161516 tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
15171517 ast_trait_ref,
@@ -1536,9 +1536,12 @@ fn impl_trait_ref(
15361536 icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
15371537 } else {
15381538 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+ } )
15401544 } )
1541- . map ( ty:: EarlyBinder :: bind)
15421545}
15431546
15441547fn check_impl_constness (
@@ -1566,43 +1569,34 @@ fn check_impl_constness(
15661569 } ) )
15671570}
15681571
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 {
15701578 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, .. } => {
15781581 if is_rustc_reservation {
15791582 let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
15801583 tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
15811584 }
15821585 ty:: ImplPolarity :: Negative
15831586 }
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 , .. } => {
15891588 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" ) ;
15911590 }
15921591 ty:: ImplPolarity :: Positive
15931592 }
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 ( _) , .. } => {
15991594 if is_rustc_reservation {
16001595 ty:: ImplPolarity :: Reservation
16011596 } else {
16021597 ty:: ImplPolarity :: Positive
16031598 }
16041599 }
1605- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
16061600 }
16071601}
16081602
0 commit comments