@@ -78,7 +78,7 @@ pub fn provide(providers: &mut Providers) {
78
78
trait_def,
79
79
adt_def,
80
80
fn_sig,
81
- impl_trait_ref ,
81
+ impl_trait_header ,
82
82
impl_polarity,
83
83
coroutine_kind,
84
84
coroutine_for_closure,
@@ -598,7 +598,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
598
598
hir:: ItemKind :: Impl { .. } => {
599
599
tcx. ensure ( ) . generics_of ( def_id) ;
600
600
tcx. ensure ( ) . type_of ( def_id) ;
601
- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
601
+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
602
602
tcx. ensure ( ) . predicates_of ( def_id) ;
603
603
}
604
604
hir:: ItemKind :: Trait ( ..) => {
@@ -1323,19 +1323,20 @@ fn suggest_impl_trait<'tcx>(
1323
1323
None
1324
1324
}
1325
1325
1326
- fn impl_trait_ref (
1326
+ fn impl_trait_header (
1327
1327
tcx : TyCtxt < ' _ > ,
1328
1328
def_id : LocalDefId ,
1329
- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1329
+ ) -> Option < ( ty:: EarlyBinder < ty:: TraitRef < ' _ > > , ty :: ImplPolarity ) > {
1330
1330
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 ( ) ;
1332
1333
impl_
1333
1334
. of_trait
1334
1335
. as_ref ( )
1335
1336
. map ( |ast_trait_ref| {
1336
1337
let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1337
1338
1338
- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1339
+ let impl_trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1339
1340
tcx,
1340
1341
tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
1341
1342
ast_trait_ref,
@@ -1360,9 +1361,9 @@ fn impl_trait_ref(
1360
1361
icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
1361
1362
} else {
1362
1363
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 ) )
1364
1366
} )
1365
- . map ( ty:: EarlyBinder :: bind)
1366
1367
}
1367
1368
1368
1369
fn check_impl_constness (
@@ -1391,42 +1392,38 @@ fn check_impl_constness(
1391
1392
}
1392
1393
1393
1394
fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1394
- let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1395
1395
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, .. } => {
1402
1408
if is_rustc_reservation {
1403
1409
let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
1404
1410
tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
1405
1411
}
1406
1412
ty:: ImplPolarity :: Negative
1407
1413
}
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 , .. } => {
1413
1415
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" ) ;
1415
1417
}
1416
1418
ty:: ImplPolarity :: Positive
1417
1419
}
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 ( _) , .. } => {
1423
1421
if is_rustc_reservation {
1424
1422
ty:: ImplPolarity :: Reservation
1425
1423
} else {
1426
1424
ty:: ImplPolarity :: Positive
1427
1425
}
1428
1426
}
1429
- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
1430
1427
}
1431
1428
}
1432
1429
0 commit comments