@@ -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,
@@ -598,7 +598,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
598598 hir:: ItemKind :: Impl { .. } => {
599599 tcx. ensure ( ) . generics_of ( def_id) ;
600600 tcx. ensure ( ) . type_of ( def_id) ;
601- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
601+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
602602 tcx. ensure ( ) . predicates_of ( def_id) ;
603603 }
604604 hir:: ItemKind :: Trait ( ..) => {
@@ -1323,19 +1323,20 @@ fn suggest_impl_trait<'tcx>(
13231323 None
13241324}
13251325
1326- fn impl_trait_ref (
1326+ fn impl_trait_header (
13271327 tcx : TyCtxt < ' _ > ,
13281328 def_id : LocalDefId ,
1329- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1329+ ) -> Option < ( ty:: EarlyBinder < ty:: TraitRef < ' _ > > , ty :: ImplPolarity ) > {
13301330 let icx = ItemCtxt :: new ( tcx, def_id) ;
1331- let impl_ = tcx. hir ( ) . expect_item ( def_id) . expect_impl ( ) ;
1331+ let item = tcx. hir ( ) . expect_item ( def_id) ;
1332+ let impl_ = item. expect_impl ( ) ;
13321333 impl_
13331334 . of_trait
13341335 . as_ref ( )
13351336 . map ( |ast_trait_ref| {
13361337 let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
13371338
1338- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1339+ let impl_trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
13391340 tcx,
13401341 tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
13411342 ast_trait_ref,
@@ -1360,9 +1361,9 @@ fn impl_trait_ref(
13601361 icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
13611362 } else {
13621363 icx. astconv ( ) . instantiate_mono_trait_ref ( ast_trait_ref, selfty)
1363- }
1364+ } ;
1365+ ( ty:: EarlyBinder :: bind ( impl_trait_ref) , polarity_of_impl ( tcx, def_id, impl_, item. span ) )
13641366 } )
1365- . map ( ty:: EarlyBinder :: bind)
13661367}
13671368
13681369fn check_impl_constness (
@@ -1391,42 +1392,38 @@ fn check_impl_constness(
13911392}
13921393
13931394fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1394- let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
13951395 let item = tcx. hir ( ) . expect_item ( def_id) ;
1396- match & item. kind {
1397- hir:: ItemKind :: Impl ( hir:: Impl {
1398- polarity : hir:: ImplPolarity :: Negative ( span) ,
1399- of_trait,
1400- ..
1401- } ) => {
1396+ polarity_of_impl ( tcx, def_id, item. expect_impl ( ) , item. span )
1397+ }
1398+
1399+ fn polarity_of_impl (
1400+ tcx : TyCtxt < ' _ > ,
1401+ def_id : LocalDefId ,
1402+ impl_ : & hir:: Impl < ' _ > ,
1403+ span : Span ,
1404+ ) -> ty:: ImplPolarity {
1405+ let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1406+ match & impl_ {
1407+ hir:: Impl { polarity : hir:: ImplPolarity :: Negative ( span) , of_trait, .. } => {
14021408 if is_rustc_reservation {
14031409 let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
14041410 tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
14051411 }
14061412 ty:: ImplPolarity :: Negative
14071413 }
1408- hir:: ItemKind :: Impl ( hir:: Impl {
1409- polarity : hir:: ImplPolarity :: Positive ,
1410- of_trait : None ,
1411- ..
1412- } ) => {
1414+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : None , .. } => {
14131415 if is_rustc_reservation {
1414- tcx. dcx ( ) . span_err ( item . span , "reservation impls can't be inherent" ) ;
1416+ tcx. dcx ( ) . span_err ( span, "reservation impls can't be inherent" ) ;
14151417 }
14161418 ty:: ImplPolarity :: Positive
14171419 }
1418- hir:: ItemKind :: Impl ( hir:: Impl {
1419- polarity : hir:: ImplPolarity :: Positive ,
1420- of_trait : Some ( _) ,
1421- ..
1422- } ) => {
1420+ hir:: Impl { polarity : hir:: ImplPolarity :: Positive , of_trait : Some ( _) , .. } => {
14231421 if is_rustc_reservation {
14241422 ty:: ImplPolarity :: Reservation
14251423 } else {
14261424 ty:: ImplPolarity :: Positive
14271425 }
14281426 }
1429- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
14301427 }
14311428}
14321429
0 commit comments