@@ -78,8 +78,7 @@ pub fn provide(providers: &mut Providers) {
7878 trait_def,
7979 adt_def,
8080 fn_sig,
81- impl_trait_ref,
82- impl_polarity,
81+ impl_trait_header,
8382 coroutine_kind,
8483 coroutine_for_closure,
8584 collect_mod_item_types,
@@ -601,7 +600,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
601600 hir:: ItemKind :: Impl { .. } => {
602601 tcx. ensure ( ) . generics_of ( def_id) ;
603602 tcx. ensure ( ) . type_of ( def_id) ;
604- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
603+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
605604 tcx. ensure ( ) . predicates_of ( def_id) ;
606605 }
607606 hir:: ItemKind :: Trait ( ..) => {
@@ -1326,19 +1325,20 @@ fn suggest_impl_trait<'tcx>(
13261325 None
13271326}
13281327
1329- fn impl_trait_ref (
1328+ fn impl_trait_header (
13301329 tcx : TyCtxt < ' _ > ,
13311330 def_id : LocalDefId ,
1332- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1331+ ) -> Option < ty:: EarlyBinder < ty:: ImplTraitHeader < ' _ > > > {
13331332 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 ( ) ;
13351335 impl_
13361336 . of_trait
13371337 . as_ref ( )
13381338 . map ( |ast_trait_ref| {
13391339 let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
13401340
1341- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1341+ let trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
13421342 tcx,
13431343 tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
13441344 ast_trait_ref,
@@ -1363,9 +1363,12 @@ fn impl_trait_ref(
13631363 icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
13641364 } else {
13651365 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+ } )
13671371 } )
1368- . map ( ty:: EarlyBinder :: bind)
13691372}
13701373
13711374fn check_impl_constness (
@@ -1393,43 +1396,34 @@ fn check_impl_constness(
13931396 } ) )
13941397}
13951398
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 {
13971405 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, .. } => {
14051408 if is_rustc_reservation {
14061409 let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
14071410 tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
14081411 }
14091412 ty:: ImplPolarity :: Negative
14101413 }
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 , .. } => {
14161415 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" ) ;
14181417 }
14191418 ty:: ImplPolarity :: Positive
14201419 }
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 ( _) , .. } => {
14261421 if is_rustc_reservation {
14271422 ty:: ImplPolarity :: Reservation
14281423 } else {
14291424 ty:: ImplPolarity :: Positive
14301425 }
14311426 }
1432- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
14331427 }
14341428}
14351429
0 commit comments