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