@@ -305,9 +305,6 @@ enum BuiltinImplConditions<'tcx> {
305
305
/// There is no built-in impl. There may be some other
306
306
/// candidate (a where-clause or user-defined impl).
307
307
None ,
308
- /// There is *no* impl for this, builtin or not. Ignore
309
- /// all where-clauses.
310
- Never ,
311
308
/// It is unknown whether there is an impl.
312
309
Ambiguous
313
310
}
@@ -781,13 +778,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
781
778
mut obligation : TraitObligation < ' tcx > )
782
779
-> Result < EvaluationResult , OverflowError >
783
780
{
784
- debug ! ( "evaluate_trait_predicate_recursively({:?})" ,
785
- obligation) ;
781
+ debug ! ( "evaluate_trait_predicate_recursively({:?})" , obligation) ;
786
782
787
- if !self . intercrate . is_some ( ) && obligation. is_global ( ) {
788
- // If a param env is consistent, global obligations do not depend on its particular
789
- // value in order to work, so we can clear out the param env and get better
790
- // caching. (If the current param env is inconsistent, we don't care what happens).
783
+ if self . intercrate . is_none ( ) && obligation. is_global ( )
784
+ && obligation. param_env . caller_bounds . iter ( ) . all ( |bound| bound. needs_subst ( ) ) {
785
+ // If a param env has no global bounds, global obligations do not
786
+ // depend on its particular value in order to work, so we can clear
787
+ // out the param env and get better caching.
791
788
debug ! ( "evaluate_trait_predicate_recursively({:?}) - in global" , obligation) ;
792
789
obligation. param_env = obligation. param_env . without_caller_bounds ( ) ;
793
790
}
@@ -1451,22 +1448,22 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
1451
1448
let sized_conditions = self . sized_conditions ( obligation) ;
1452
1449
self . assemble_builtin_bound_candidates ( sized_conditions,
1453
1450
& mut candidates) ?;
1454
- } else if lang_items. unsize_trait ( ) == Some ( def_id) {
1455
- self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
1456
- } else {
1457
- if lang_items. clone_trait ( ) == Some ( def_id) {
1458
- // Same builtin conditions as `Copy`, i.e. every type which has builtin support
1459
- // for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
1460
- // types have builtin support for `Clone`.
1461
- let clone_conditions = self . copy_clone_conditions ( obligation) ;
1462
- self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ?;
1463
- }
1464
-
1465
- self . assemble_generator_candidates ( obligation, & mut candidates) ?;
1466
- self . assemble_closure_candidates ( obligation, & mut candidates) ?;
1467
- self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ?;
1468
- self . assemble_candidates_from_impls ( obligation, & mut candidates) ?;
1469
- self . assemble_candidates_from_object_ty ( obligation, & mut candidates) ;
1451
+ } else if lang_items. unsize_trait ( ) == Some ( def_id) {
1452
+ self . assemble_candidates_for_unsizing ( obligation, & mut candidates) ;
1453
+ } else {
1454
+ if lang_items. clone_trait ( ) == Some ( def_id) {
1455
+ // Same builtin conditions as `Copy`, i.e. every type which has builtin support
1456
+ // for `Copy` also has builtin support for `Clone`, + tuples and arrays of `Clone`
1457
+ // types have builtin support for `Clone`.
1458
+ let clone_conditions = self . copy_clone_conditions ( obligation) ;
1459
+ self . assemble_builtin_bound_candidates ( clone_conditions, & mut candidates) ?;
1460
+ }
1461
+
1462
+ self . assemble_generator_candidates ( obligation, & mut candidates) ?;
1463
+ self . assemble_closure_candidates ( obligation, & mut candidates) ?;
1464
+ self . assemble_fn_pointer_candidates ( obligation, & mut candidates) ?;
1465
+ self . assemble_candidates_from_impls ( obligation, & mut candidates) ?;
1466
+ self . assemble_candidates_from_object_ty ( obligation, & mut candidates) ;
1470
1467
}
1471
1468
1472
1469
self . assemble_candidates_from_projected_tys ( obligation, & mut candidates) ;
@@ -2081,13 +2078,8 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2081
2078
// BUILTIN BOUNDS
2082
2079
//
2083
2080
// These cover the traits that are built-in to the language
2084
- // itself. This includes `Copy` and `Sized` for sure. For the
2085
- // moment, it also includes `Send` / `Sync` and a few others, but
2086
- // those will hopefully change to library-defined traits in the
2087
- // future.
2081
+ // itself: `Copy`, `Clone` and `Sized`.
2088
2082
2089
- // HACK: if this returns an error, selection exits without considering
2090
- // other impls.
2091
2083
fn assemble_builtin_bound_candidates < ' o > ( & mut self ,
2092
2084
conditions : BuiltinImplConditions < ' tcx > ,
2093
2085
candidates : & mut SelectionCandidateSet < ' tcx > )
@@ -2106,14 +2098,13 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2106
2098
debug ! ( "assemble_builtin_bound_candidates: ambiguous builtin" ) ;
2107
2099
Ok ( candidates. ambiguous = true )
2108
2100
}
2109
- BuiltinImplConditions :: Never => { Err ( Unimplemented ) }
2110
2101
}
2111
2102
}
2112
2103
2113
2104
fn sized_conditions ( & mut self , obligation : & TraitObligation < ' tcx > )
2114
2105
-> BuiltinImplConditions < ' tcx >
2115
2106
{
2116
- use self :: BuiltinImplConditions :: { Ambiguous , None , Never , Where } ;
2107
+ use self :: BuiltinImplConditions :: { Ambiguous , None , Where } ;
2117
2108
2118
2109
// NOTE: binder moved to (*)
2119
2110
let self_ty = self . infcx . shallow_resolve (
@@ -2130,7 +2121,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2130
2121
Where ( ty:: Binder :: dummy ( Vec :: new ( ) ) )
2131
2122
}
2132
2123
2133
- ty:: TyStr | ty:: TySlice ( _) | ty:: TyDynamic ( ..) | ty:: TyForeign ( ..) => Never ,
2124
+ ty:: TyStr | ty:: TySlice ( _) | ty:: TyDynamic ( ..) | ty:: TyForeign ( ..) => None ,
2134
2125
2135
2126
ty:: TyTuple ( tys) => {
2136
2127
Where ( ty:: Binder :: bind ( tys. last ( ) . into_iter ( ) . cloned ( ) . collect ( ) ) )
@@ -2164,7 +2155,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2164
2155
let self_ty = self . infcx . shallow_resolve (
2165
2156
obligation. predicate . skip_binder ( ) . self_ty ( ) ) ;
2166
2157
2167
- use self :: BuiltinImplConditions :: { Ambiguous , None , Never , Where } ;
2158
+ use self :: BuiltinImplConditions :: { Ambiguous , None , Where } ;
2168
2159
2169
2160
match self_ty. sty {
2170
2161
ty:: TyInfer ( ty:: IntVar ( _) ) | ty:: TyInfer ( ty:: FloatVar ( _) ) |
@@ -2182,7 +2173,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2182
2173
ty:: TyDynamic ( ..) | ty:: TyStr | ty:: TySlice ( ..) |
2183
2174
ty:: TyGenerator ( ..) | ty:: TyGeneratorWitness ( ..) | ty:: TyForeign ( ..) |
2184
2175
ty:: TyRef ( _, _, hir:: MutMutable ) => {
2185
- Never
2176
+ None
2186
2177
}
2187
2178
2188
2179
ty:: TyArray ( element_ty, _) => {
@@ -2202,7 +2193,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2202
2193
if is_copy_trait || is_clone_trait {
2203
2194
Where ( ty:: Binder :: bind ( substs. upvar_tys ( def_id, self . tcx ( ) ) . collect ( ) ) )
2204
2195
} else {
2205
- Never
2196
+ None
2206
2197
}
2207
2198
}
2208
2199
0 commit comments