@@ -2956,52 +2956,51 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
2956
2956
} ) ;
2957
2957
let source_ty = tcx. mk_dynamic ( existential_predicates, region_b) ;
2958
2958
2959
- /*
2960
- // Require that the traits involved in this upcast are **equal**;
2961
- // only the **lifetime bound** is changed.
2962
- //
2963
- // FIXME: This condition is arguably too strong -- it would
2964
- // suffice for the source trait to be a *subtype* of the target
2965
- // trait. In particular, changing from something like
2966
- // `for<'a, 'b> Foo<'a, 'b>` to `for<'a> Foo<'a, 'a>` should be
2967
- // permitted. And, indeed, in the in commit
2968
- // 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
2969
- // condition was loosened. However, when the leak check was
2970
- // added back, using subtype here actually guides the coercion
2971
- // code in such a way that it accepts `old-lub-glb-object.rs`.
2972
- // This is probably a good thing, but I've modified this to `.eq`
2973
- // because I want to continue rejecting that test (as we have
2974
- // done for quite some time) before we are firmly comfortable
2975
- // with what our behavior should be there. -nikomatsakis
2976
- let InferOk { obligations, .. } = self
2977
- .infcx
2978
- .at(&obligation.cause, obligation.param_env)
2979
- .eq(target, source_ty) // FIXME -- see above
2980
- .map_err(|_| Unimplemented)?;
2981
- nested.extend(obligations);
2982
- */
2983
-
2984
- // Register obligations for `dyn TraitA1 [TraitA2...]: TraitB1 [TraitB2...]`.
2985
- nested. extend (
2986
- data_b. iter ( )
2987
- // HACK(alexreg | nikomatsakis): we handle auto traits specially here
2988
- // because of cases like like `dyn Foo + Send + 'a` ->
2989
- // `dyn Foo + Send + 'b`, which requires proving the obligation
2990
- // `dyn Foo + Send: Send`. This is unfortunately ambiguous under the
2991
- // current trait solver model: it holds both because `Send` is a supertrait
2992
- // of `Foo + Send` and because there's an automatic impl of `Send` for the
2993
- // trait object.
2994
- . filter ( |predicate| {
2995
- match predicate. skip_binder ( ) {
2996
- ty:: ExistentialPredicate :: AutoTrait ( did) =>
2997
- !data_a. auto_traits ( ) . any ( |did_a| did_a == * did) ,
2998
- _ => true ,
2999
- }
3000
- } )
3001
- . map ( |predicate|
3002
- predicate_to_obligation ( predicate. with_self_ty ( tcx, source_ty) )
3003
- ) ,
3004
- ) ;
2959
+ if tcx. features ( ) . trait_upcasting {
2960
+ // Register obligations for `dyn TraitA1 [TraitA2...]: TraitB1 [TraitB2...]`.
2961
+ nested. extend (
2962
+ data_b. iter ( )
2963
+ // HACK(alexreg | nikomatsakis): we handle auto traits specially here
2964
+ // because of cases like like `dyn Foo + Send + 'a` ->
2965
+ // `dyn Foo + Send + 'b`, which requires proving the obligation
2966
+ // `dyn Foo + Send: Send`. This is unfortunately ambiguous under the
2967
+ // current trait solver model: it holds both because `Send` is a
2968
+ // supertrait of `Foo + Send` and because there's an automatic impl of
2969
+ // `Send` for the trait object.
2970
+ . filter ( |predicate| {
2971
+ match predicate. skip_binder ( ) {
2972
+ ty:: ExistentialPredicate :: AutoTrait ( did) =>
2973
+ !data_a. auto_traits ( ) . any ( |did_a| did_a == * did) ,
2974
+ _ => true ,
2975
+ }
2976
+ } )
2977
+ . map ( |predicate|
2978
+ predicate_to_obligation ( predicate. with_self_ty ( tcx, source_ty) )
2979
+ ) ,
2980
+ ) ;
2981
+ } else {
2982
+ // Require that the traits involved in this upcast are **equal**;
2983
+ // only the **lifetime bound** is changed.
2984
+ //
2985
+ // FIXME: This condition is arguably too strong -- it would
2986
+ // suffice for the source trait to be a *subtype* of the target
2987
+ // trait. In particular, changing from something like
2988
+ // `for<'a, 'b> Foo<'a, 'b>` to `for<'a> Foo<'a, 'a>` should be
2989
+ // permitted. And, indeed, in the in commit
2990
+ // 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
2991
+ // condition was loosened. However, when the leak check was
2992
+ // added back, using subtype here actually guides the coercion
2993
+ // code in such a way that it accepts `old-lub-glb-object.rs`.
2994
+ // This is probably a good thing, but I've modified this to `.eq`
2995
+ // because I want to continue rejecting that test (as we have
2996
+ // done for quite some time) before we are firmly comfortable
2997
+ // with what our behavior should be there. -nikomatsakis
2998
+ let InferOk { obligations, .. } = self . infcx
2999
+ . at ( & obligation. cause , obligation. param_env )
3000
+ . eq ( target, source_ty) // FIXME: see above.
3001
+ . map_err ( |_| Unimplemented ) ?;
3002
+ nested. extend ( obligations) ;
3003
+ }
3005
3004
3006
3005
// Register an obligation for `'a: 'b`.
3007
3006
let outlives = ty:: OutlivesPredicate ( region_a, region_b) ;
0 commit comments