@@ -376,9 +376,9 @@ fn check_predicates<'tcx>(
376376 let always_applicable_traits = impl1_predicates
377377 . iter ( )
378378 . copied ( )
379- . filter ( |( clause, _span) | {
379+ . filter ( |& ( clause, _span) | {
380380 matches ! (
381- trait_predicate_kind ( tcx, clause. as_predicate ( ) ) ,
381+ trait_specialization_kind ( tcx, clause) ,
382382 Some ( TraitSpecializationKind :: AlwaysApplicable )
383383 )
384384 } )
@@ -402,7 +402,7 @@ fn check_predicates<'tcx>(
402402 . iter ( )
403403 . any ( |pred2| trait_predicates_eq ( tcx, clause. as_predicate ( ) , * pred2, span) )
404404 {
405- check_specialization_on ( tcx, clause. as_predicate ( ) , span)
405+ check_specialization_on ( tcx, clause, span)
406406 }
407407 }
408408}
@@ -441,19 +441,16 @@ fn trait_predicates_eq<'tcx>(
441441}
442442
443443#[ 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 ( ) {
446446 // Global predicates are either always true or always false, so we
447447 // are fine to specialize on.
448- _ if predicate . is_global ( ) => ( ) ,
448+ _ if clause . is_global ( ) => ( ) ,
449449 // We allow specializing on explicitly marked traits with no associated
450450 // 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 : _ } ) => {
455452 if !matches ! (
456- trait_predicate_kind ( tcx, predicate ) ,
453+ trait_specialization_kind ( tcx, clause ) ,
457454 Some ( TraitSpecializationKind :: Marker )
458455 ) {
459456 tcx. sess
@@ -467,18 +464,15 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
467464 . emit ( ) ;
468465 }
469466 }
470- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: Projection ( ty:: ProjectionPredicate {
471- projection_ty,
472- term,
473- } ) ) => {
467+ ty:: ClauseKind :: Projection ( ty:: ProjectionPredicate { projection_ty, term } ) => {
474468 tcx. sess
475469 . struct_span_err (
476470 span,
477471 format ! ( "cannot specialize on associated type `{projection_ty} == {term}`" , ) ,
478472 )
479473 . emit ( ) ;
480474 }
481- ty:: PredicateKind :: Clause ( ty :: ClauseKind :: ConstArgHasType ( ..) ) => {
475+ ty:: ClauseKind :: ConstArgHasType ( ..) => {
482476 // FIXME(min_specialization), FIXME(const_generics):
483477 // It probably isn't right to allow _every_ `ConstArgHasType` but I am somewhat unsure
484478 // 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
490484 }
491485 _ => {
492486 tcx. sess
493- . struct_span_err ( span, format ! ( "cannot specialize on predicate `{predicate }`" ) )
487+ . struct_span_err ( span, format ! ( "cannot specialize on predicate `{clause }`" ) )
494488 . emit ( ) ;
495489 }
496490 }
497491}
498492
499- fn trait_predicate_kind < ' tcx > (
493+ fn trait_specialization_kind < ' tcx > (
500494 tcx : TyCtxt < ' tcx > ,
501- predicate : ty:: Predicate < ' tcx > ,
495+ clause : ty:: Clause < ' tcx > ,
502496) -> 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 ,
521507 }
522508}
0 commit comments