@@ -78,7 +78,7 @@ pub fn provide(providers: &mut Providers) {
7878 trait_def,
7979 adt_def,
8080 fn_sig,
81- impl_trait_ref ,
81+ impl_trait_header ,
8282 impl_polarity,
8383 coroutine_kind,
8484 coroutine_for_closure,
@@ -601,7 +601,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
601601 hir:: ItemKind :: Impl { .. } => {
602602 tcx. ensure ( ) . generics_of ( def_id) ;
603603 tcx. ensure ( ) . type_of ( def_id) ;
604- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
604+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
605605 tcx. ensure ( ) . predicates_of ( def_id) ;
606606 }
607607 hir:: ItemKind :: Trait ( ..) => {
@@ -1326,19 +1326,20 @@ fn suggest_impl_trait<'tcx>(
13261326 None
13271327}
13281328
1329- fn impl_trait_ref (
1329+ fn impl_trait_header (
13301330 tcx : TyCtxt < ' _ > ,
13311331 def_id : LocalDefId ,
1332- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1332+ ) -> Option < ( ty:: EarlyBinder < ty:: TraitRef < ' _ > > , ty :: ImplPolarity ) > {
13331333 let icx = ItemCtxt :: new ( tcx, def_id) ;
1334- let impl_ = tcx. hir ( ) . expect_item ( def_id) . expect_impl ( ) ;
1334+ let item = tcx. hir ( ) . expect_item ( def_id) ;
1335+ let impl_ = item. expect_impl ( ) ;
13351336 impl_
13361337 . of_trait
13371338 . as_ref ( )
13381339 . map ( |ast_trait_ref| {
13391340 let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
13401341
1341- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1342+ let impl_trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
13421343 tcx,
13431344 tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
13441345 ast_trait_ref,
@@ -1363,9 +1364,9 @@ fn impl_trait_ref(
13631364 icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
13641365 } else {
13651366 icx. astconv ( ) . instantiate_mono_trait_ref ( ast_trait_ref, selfty)
1366- }
1367+ } ;
1368+ ( ty:: EarlyBinder :: bind ( impl_trait_ref) , polarity_of_impl_item ( tcx, def_id, impl_, item. span ) )
13671369 } )
1368- . map ( ty:: EarlyBinder :: bind)
13691370}
13701371
13711372fn check_impl_constness (
@@ -1394,42 +1395,38 @@ fn check_impl_constness(
13941395}
13951396
13961397fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1397- let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
13981398 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- } ) => {
1399+ polarity_of_impl_item ( tcx, def_id, item. expect_impl ( ) , item. span )
1400+ }
1401+
1402+ fn polarity_of_impl_item (
1403+ tcx : TyCtxt < ' _ > ,
1404+ def_id : LocalDefId ,
1405+ impl_ : & hir:: Impl < ' _ > ,
1406+ span : Span ,
1407+ ) -> ty:: ImplPolarity {
1408+ let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1409+ match & impl_ {
1410+ hir:: Impl { polarity : hir:: ImplPolarity :: Negative ( span) , of_trait, .. } => {
14051411 if is_rustc_reservation {
14061412 let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
14071413 tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
14081414 }
14091415 ty:: ImplPolarity :: Negative
14101416 }
1411- hir:: ItemKind :: Impl ( hir:: Impl {
1412- polarity : hir:: ImplPolarity :: Positive ,
1413- of_trait : None ,
1414- ..
1415- } ) => {
1417+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : None , .. } => {
14161418 if is_rustc_reservation {
1417- tcx. dcx ( ) . span_err ( item . span , "reservation impls can't be inherent" ) ;
1419+ tcx. dcx ( ) . span_err ( span, "reservation impls can't be inherent" ) ;
14181420 }
14191421 ty:: ImplPolarity :: Positive
14201422 }
1421- hir:: ItemKind :: Impl ( hir:: Impl {
1422- polarity : hir:: ImplPolarity :: Positive ,
1423- of_trait : Some ( _) ,
1424- ..
1425- } ) => {
1423+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : Some ( _) , .. } => {
14261424 if is_rustc_reservation {
14271425 ty:: ImplPolarity :: Reservation
14281426 } else {
14291427 ty:: ImplPolarity :: Positive
14301428 }
14311429 }
1432- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
14331430 }
14341431}
14351432
0 commit comments