@@ -376,9 +376,9 @@ fn check_predicates<'tcx>(
376
376
let always_applicable_traits = impl1_predicates
377
377
. iter ( )
378
378
. copied ( )
379
- . filter ( |( clause, _span) | {
379
+ . filter ( |& ( clause, _span) | {
380
380
matches ! (
381
- trait_predicate_kind ( tcx, clause. as_predicate ( ) ) ,
381
+ trait_specialization_kind ( tcx, clause) ,
382
382
Some ( TraitSpecializationKind :: AlwaysApplicable )
383
383
)
384
384
} )
@@ -402,7 +402,7 @@ fn check_predicates<'tcx>(
402
402
. iter ( )
403
403
. any ( |pred2| trait_predicates_eq ( tcx, clause. as_predicate ( ) , * pred2, span) )
404
404
{
405
- check_specialization_on ( tcx, clause. as_predicate ( ) , span)
405
+ check_specialization_on ( tcx, clause, span)
406
406
}
407
407
}
408
408
}
@@ -441,19 +441,16 @@ fn trait_predicates_eq<'tcx>(
441
441
}
442
442
443
443
#[ instrument( level = "debug" , skip( tcx) ) ]
444
- fn check_specialization_on < ' tcx > ( tcx : TyCtxt < ' tcx > , predicate : ty:: Predicate < ' tcx > , span : Span ) {
445
- match predicate . kind ( ) . skip_binder ( ) {
444
+ fn check_specialization_on < ' tcx > ( tcx : TyCtxt < ' tcx > , clause : ty:: Clause < ' tcx > , span : Span ) {
445
+ match clause . kind ( ) . skip_binder ( ) {
446
446
// Global predicates are either always true or always false, so we
447
447
// are fine to specialize on.
448
- _ if predicate . is_global ( ) => ( ) ,
448
+ _ if clause . is_global ( ) => ( ) ,
449
449
// We allow specializing on explicitly marked traits with no associated
450
450
// items.
451
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( ty:: TraitPredicate {
452
- trait_ref,
453
- polarity : _,
454
- } ) ) => {
451
+ ty:: ClauseKind :: Trait ( ty:: TraitPredicate { trait_ref, polarity : _ } ) => {
455
452
if !matches ! (
456
- trait_predicate_kind ( tcx, predicate ) ,
453
+ trait_specialization_kind ( tcx, clause ) ,
457
454
Some ( TraitSpecializationKind :: Marker )
458
455
) {
459
456
tcx. sess
@@ -467,18 +464,15 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
467
464
. emit ( ) ;
468
465
}
469
466
}
470
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Projection ( ty:: ProjectionPredicate {
471
- projection_ty,
472
- term,
473
- } ) ) => {
467
+ ty:: ClauseKind :: Projection ( ty:: ProjectionPredicate { projection_ty, term } ) => {
474
468
tcx. sess
475
469
. struct_span_err (
476
470
span,
477
471
format ! ( "cannot specialize on associated type `{projection_ty} == {term}`" , ) ,
478
472
)
479
473
. emit ( ) ;
480
474
}
481
- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstArgHasType ( ..) ) => {
475
+ ty:: ClauseKind :: ConstArgHasType ( ..) => {
482
476
// FIXME(min_specialization), FIXME(const_generics):
483
477
// It probably isn't right to allow _every_ `ConstArgHasType` but I am somewhat unsure
484
478
// about the actual rules that would be sound. Can't just always error here because otherwise
@@ -490,33 +484,25 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
490
484
}
491
485
_ => {
492
486
tcx. sess
493
- . struct_span_err ( span, format ! ( "cannot specialize on predicate `{predicate }`" ) )
487
+ . struct_span_err ( span, format ! ( "cannot specialize on predicate `{clause }`" ) )
494
488
. emit ( ) ;
495
489
}
496
490
}
497
491
}
498
492
499
- fn trait_predicate_kind < ' tcx > (
493
+ fn trait_specialization_kind < ' tcx > (
500
494
tcx : TyCtxt < ' tcx > ,
501
- predicate : ty:: Predicate < ' tcx > ,
495
+ clause : ty:: Clause < ' tcx > ,
502
496
) -> Option < TraitSpecializationKind > {
503
- match predicate. kind ( ) . skip_binder ( ) {
504
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Trait ( ty:: TraitPredicate {
505
- trait_ref,
506
- polarity : _,
507
- } ) ) => Some ( tcx. trait_def ( trait_ref. def_id ) . specialization_kind ) ,
508
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives ( _) )
509
- | ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives ( _) )
510
- | ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Projection ( _) )
511
- | ty:: PredicateKind :: Clause ( ty:: ClauseKind :: ConstArgHasType ( ..) )
512
- | ty:: PredicateKind :: AliasRelate ( ..)
513
- | ty:: PredicateKind :: Clause ( ty:: ClauseKind :: WellFormed ( _) )
514
- | ty:: PredicateKind :: Subtype ( _)
515
- | ty:: PredicateKind :: Coerce ( _)
516
- | ty:: PredicateKind :: ObjectSafe ( _)
517
- | ty:: PredicateKind :: ClosureKind ( ..)
518
- | ty:: PredicateKind :: Clause ( ty:: ClauseKind :: ConstEvaluatable ( ..) )
519
- | ty:: PredicateKind :: ConstEquate ( ..)
520
- | ty:: PredicateKind :: Ambiguous => None ,
497
+ match clause. kind ( ) . skip_binder ( ) {
498
+ ty:: ClauseKind :: Trait ( ty:: TraitPredicate { trait_ref, polarity : _ } ) => {
499
+ Some ( tcx. trait_def ( trait_ref. def_id ) . specialization_kind )
500
+ }
501
+ ty:: ClauseKind :: RegionOutlives ( _)
502
+ | ty:: ClauseKind :: TypeOutlives ( _)
503
+ | ty:: ClauseKind :: Projection ( _)
504
+ | ty:: ClauseKind :: ConstArgHasType ( ..)
505
+ | ty:: ClauseKind :: WellFormed ( _)
506
+ | ty:: ClauseKind :: ConstEvaluatable ( ..) => None ,
521
507
}
522
508
}
0 commit comments