@@ -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,
@@ -601,7 +601,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
601
601
hir:: ItemKind :: Impl { .. } => {
602
602
tcx. ensure ( ) . generics_of ( def_id) ;
603
603
tcx. ensure ( ) . type_of ( def_id) ;
604
- tcx. ensure ( ) . impl_trait_ref ( def_id) ;
604
+ tcx. ensure ( ) . impl_trait_header ( def_id) ;
605
605
tcx. ensure ( ) . predicates_of ( def_id) ;
606
606
}
607
607
hir:: ItemKind :: Trait ( ..) => {
@@ -1326,19 +1326,20 @@ fn suggest_impl_trait<'tcx>(
1326
1326
None
1327
1327
}
1328
1328
1329
- fn impl_trait_ref (
1329
+ fn impl_trait_header (
1330
1330
tcx : TyCtxt < ' _ > ,
1331
1331
def_id : LocalDefId ,
1332
- ) -> Option < ty:: EarlyBinder < ty:: TraitRef < ' _ > > > {
1332
+ ) -> Option < ( ty:: EarlyBinder < ty:: TraitRef < ' _ > > , ty :: ImplPolarity ) > {
1333
1333
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 ( ) ;
1335
1336
impl_
1336
1337
. of_trait
1337
1338
. as_ref ( )
1338
1339
. map ( |ast_trait_ref| {
1339
1340
let selfty = tcx. type_of ( def_id) . instantiate_identity ( ) ;
1340
1341
1341
- if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1342
+ let impl_trait_ref = if let Some ( ErrorGuaranteed { .. } ) = check_impl_constness (
1342
1343
tcx,
1343
1344
tcx. is_const_trait_impl_raw ( def_id. to_def_id ( ) ) ,
1344
1345
ast_trait_ref,
@@ -1363,9 +1364,9 @@ fn impl_trait_ref(
1363
1364
icx. astconv ( ) . instantiate_mono_trait_ref ( trait_ref, selfty)
1364
1365
} else {
1365
1366
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 ) )
1367
1369
} )
1368
- . map ( ty:: EarlyBinder :: bind)
1369
1370
}
1370
1371
1371
1372
fn check_impl_constness (
@@ -1394,42 +1395,38 @@ fn check_impl_constness(
1394
1395
}
1395
1396
1396
1397
fn impl_polarity ( tcx : TyCtxt < ' _ > , def_id : LocalDefId ) -> ty:: ImplPolarity {
1397
- let is_rustc_reservation = tcx. has_attr ( def_id, sym:: rustc_reservation_impl) ;
1398
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
- } ) => {
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, .. } => {
1405
1411
if is_rustc_reservation {
1406
1412
let span = span. to ( of_trait. as_ref ( ) . map_or ( * span, |t| t. path . span ) ) ;
1407
1413
tcx. dcx ( ) . span_err ( span, "reservation impls can't be negative" ) ;
1408
1414
}
1409
1415
ty:: ImplPolarity :: Negative
1410
1416
}
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 , .. } => {
1416
1418
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" ) ;
1418
1420
}
1419
1421
ty:: ImplPolarity :: Positive
1420
1422
}
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 ( _) , .. } => {
1426
1424
if is_rustc_reservation {
1427
1425
ty:: ImplPolarity :: Reservation
1428
1426
} else {
1429
1427
ty:: ImplPolarity :: Positive
1430
1428
}
1431
1429
}
1432
- item => bug ! ( "impl_polarity: {:?} not an impl" , item) ,
1433
1430
}
1434
1431
}
1435
1432
0 commit comments