@@ -652,7 +652,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
652652 & mut self ,
653653 stack : & TraitObligationStack < ' o , ' tcx > ,
654654 ) -> Result < EvaluationResult , OverflowError > {
655- // In intercrate mode, whenever any of the types are unbound,
655+ // In intercrate mode, whenever any of the generics are unbound,
656656 // there can always be an impl. Even if there are no impls in
657657 // this crate, perhaps the type would be unified with
658658 // something from another crate that does provide an impl.
@@ -677,7 +677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
677677 // terms of `Fn` etc, but we could probably make this more
678678 // precise still.
679679 let unbound_input_types =
680- stack. fresh_trait_ref . skip_binder ( ) . input_types ( ) . any ( |ty| ty. is_fresh ( ) ) ;
680+ stack. fresh_trait_ref . skip_binder ( ) . substs . types ( ) . any ( |ty| ty. is_fresh ( ) ) ;
681681 // This check was an imperfect workaround for a bug in the old
682682 // intercrate mode; it should be removed when that goes away.
683683 if unbound_input_types && self . intercrate {
@@ -3262,15 +3262,31 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
32623262 // substitution if we find that any of the input types, when
32633263 // simplified, do not match.
32643264
3265- obligation. predicate . skip_binder ( ) . input_types ( ) . zip ( impl_trait_ref. input_types ( ) ) . any (
3266- |( obligation_ty, impl_ty) | {
3267- let simplified_obligation_ty =
3268- fast_reject:: simplify_type ( self . tcx ( ) , obligation_ty, true ) ;
3269- let simplified_impl_ty = fast_reject:: simplify_type ( self . tcx ( ) , impl_ty, false ) ;
3270-
3271- simplified_obligation_ty. is_some ( )
3272- && simplified_impl_ty. is_some ( )
3273- && simplified_obligation_ty != simplified_impl_ty
3265+ obligation. predicate . skip_binder ( ) . trait_ref . substs . iter ( ) . zip ( impl_trait_ref. substs ) . any (
3266+ |( obligation_arg, impl_arg) | {
3267+ match ( obligation_arg. unpack ( ) , impl_arg. unpack ( ) ) {
3268+ ( GenericArgKind :: Type ( obligation_ty) , GenericArgKind :: Type ( impl_ty) ) => {
3269+ let simplified_obligation_ty =
3270+ fast_reject:: simplify_type ( self . tcx ( ) , obligation_ty, true ) ;
3271+ let simplified_impl_ty =
3272+ fast_reject:: simplify_type ( self . tcx ( ) , impl_ty, false ) ;
3273+
3274+ simplified_obligation_ty. is_some ( )
3275+ && simplified_impl_ty. is_some ( )
3276+ && simplified_obligation_ty != simplified_impl_ty
3277+ }
3278+ ( GenericArgKind :: Lifetime ( _) , GenericArgKind :: Lifetime ( _) ) => {
3279+ // Lifetimes can never cause a rejection.
3280+ false
3281+ }
3282+ ( GenericArgKind :: Const ( _) , GenericArgKind :: Const ( _) ) => {
3283+ // Conservatively ignore consts (i.e. assume they might
3284+ // unify later) until we have `fast_reject` support for
3285+ // them (if we'll ever need it, even).
3286+ false
3287+ }
3288+ _ => unreachable ! ( ) ,
3289+ }
32743290 } ,
32753291 )
32763292 }
0 commit comments