@@ -3,92 +3,22 @@ use rustc_data_structures::intern::Interned;
3
3
use rustc_macros:: { HashStable , TypeFoldable , TypeVisitable } ;
4
4
use rustc_next_trait_solver:: solve as ir_solve;
5
5
pub use rustc_next_trait_solver:: solve:: * ;
6
- use rustc_span:: def_id:: DefId ;
7
6
8
- use crate :: infer:: canonical:: { CanonicalVarValues , QueryRegionConstraints } ;
9
- use crate :: traits:: query:: NoSolution ;
10
- use crate :: traits:: Canonical ;
7
+ use crate :: infer:: canonical:: QueryRegionConstraints ;
11
8
use crate :: ty:: {
12
9
self , FallibleTypeFolder , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeVisitable , TypeVisitor ,
13
10
} ;
14
11
15
- use super :: BuiltinImplSource ;
16
-
17
12
mod cache;
18
- pub mod inspect;
19
13
20
14
pub use cache:: { CacheData , EvaluationCache } ;
21
15
22
16
pub type Goal < ' tcx , P > = ir_solve:: Goal < TyCtxt < ' tcx > , P > ;
23
17
pub type QueryInput < ' tcx , P > = ir_solve:: QueryInput < TyCtxt < ' tcx > , P > ;
24
-
25
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , HashStable , TypeFoldable , TypeVisitable ) ]
26
- pub struct Response < ' tcx > {
27
- pub certainty : Certainty ,
28
- pub var_values : CanonicalVarValues < ' tcx > ,
29
- /// Additional constraints returned by this query.
30
- pub external_constraints : ExternalConstraints < ' tcx > ,
31
- }
32
-
33
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , HashStable , TypeFoldable , TypeVisitable ) ]
34
- pub enum Certainty {
35
- Yes ,
36
- Maybe ( MaybeCause ) ,
37
- }
38
-
39
- impl Certainty {
40
- pub const AMBIGUOUS : Certainty = Certainty :: Maybe ( MaybeCause :: Ambiguity ) ;
41
-
42
- /// Use this function to merge the certainty of multiple nested subgoals.
43
- ///
44
- /// Given an impl like `impl<T: Foo + Bar> Baz for T {}`, we have 2 nested
45
- /// subgoals whenever we use the impl as a candidate: `T: Foo` and `T: Bar`.
46
- /// If evaluating `T: Foo` results in ambiguity and `T: Bar` results in
47
- /// success, we merge these two responses. This results in ambiguity.
48
- ///
49
- /// If we unify ambiguity with overflow, we return overflow. This doesn't matter
50
- /// inside of the solver as we do not distinguish ambiguity from overflow. It does
51
- /// however matter for diagnostics. If `T: Foo` resulted in overflow and `T: Bar`
52
- /// in ambiguity without changing the inference state, we still want to tell the
53
- /// user that `T: Baz` results in overflow.
54
- pub fn unify_with ( self , other : Certainty ) -> Certainty {
55
- match ( self , other) {
56
- ( Certainty :: Yes , Certainty :: Yes ) => Certainty :: Yes ,
57
- ( Certainty :: Yes , Certainty :: Maybe ( _) ) => other,
58
- ( Certainty :: Maybe ( _) , Certainty :: Yes ) => self ,
59
- ( Certainty :: Maybe ( a) , Certainty :: Maybe ( b) ) => Certainty :: Maybe ( a. unify_with ( b) ) ,
60
- }
61
- }
62
-
63
- pub const fn overflow ( suggest_increasing_limit : bool ) -> Certainty {
64
- Certainty :: Maybe ( MaybeCause :: Overflow { suggest_increasing_limit } )
65
- }
66
- }
67
-
68
- /// Why we failed to evaluate a goal.
69
- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , HashStable , TypeFoldable , TypeVisitable ) ]
70
- pub enum MaybeCause {
71
- /// We failed due to ambiguity. This ambiguity can either
72
- /// be a true ambiguity, i.e. there are multiple different answers,
73
- /// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
74
- Ambiguity ,
75
- /// We gave up due to an overflow, most often by hitting the recursion limit.
76
- Overflow { suggest_increasing_limit : bool } ,
77
- }
78
-
79
- impl MaybeCause {
80
- fn unify_with ( self , other : MaybeCause ) -> MaybeCause {
81
- match ( self , other) {
82
- ( MaybeCause :: Ambiguity , MaybeCause :: Ambiguity ) => MaybeCause :: Ambiguity ,
83
- ( MaybeCause :: Ambiguity , MaybeCause :: Overflow { .. } ) => other,
84
- ( MaybeCause :: Overflow { .. } , MaybeCause :: Ambiguity ) => self ,
85
- (
86
- MaybeCause :: Overflow { suggest_increasing_limit : a } ,
87
- MaybeCause :: Overflow { suggest_increasing_limit : b } ,
88
- ) => MaybeCause :: Overflow { suggest_increasing_limit : a || b } ,
89
- }
90
- }
91
- }
18
+ pub type QueryResult < ' tcx > = ir_solve:: QueryResult < TyCtxt < ' tcx > > ;
19
+ pub type CandidateSource < ' tcx > = ir_solve:: CandidateSource < TyCtxt < ' tcx > > ;
20
+ pub type CanonicalInput < ' tcx , P = ty:: Predicate < ' tcx > > = ir_solve:: CanonicalInput < TyCtxt < ' tcx > , P > ;
21
+ pub type CanonicalResponse < ' tcx > = ir_solve:: CanonicalResponse < TyCtxt < ' tcx > > ;
92
22
93
23
/// Additional constraints returned on success.
94
24
#[ derive( Debug , PartialEq , Eq , Clone , Hash , HashStable , Default ) ]
@@ -107,18 +37,6 @@ impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
107
37
}
108
38
}
109
39
110
- pub type CanonicalInput < ' tcx , T = ty:: Predicate < ' tcx > > = Canonical < ' tcx , QueryInput < ' tcx , T > > ;
111
-
112
- pub type CanonicalResponse < ' tcx > = Canonical < ' tcx , Response < ' tcx > > ;
113
-
114
- /// The result of evaluating a canonical query.
115
- ///
116
- /// FIXME: We use a different type than the existing canonical queries. This is because
117
- /// we need to add a `Certainty` for `overflow` and may want to restructure this code without
118
- /// having to worry about changes to currently used code. Once we've made progress on this
119
- /// solver, merge the two responses again.
120
- pub type QueryResult < ' tcx > = Result < CanonicalResponse < ' tcx > , NoSolution > ;
121
-
122
40
#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash , HashStable ) ]
123
41
pub struct ExternalConstraints < ' tcx > ( pub ( crate ) Interned < ' tcx , ExternalConstraintsData < ' tcx > > ) ;
124
42
@@ -225,68 +143,3 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
225
143
self . opaque_types . visit_with ( visitor)
226
144
}
227
145
}
228
-
229
- /// Possible ways the given goal can be proven.
230
- #[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
231
- pub enum CandidateSource {
232
- /// A user written impl.
233
- ///
234
- /// ## Examples
235
- ///
236
- /// ```rust
237
- /// fn main() {
238
- /// let x: Vec<u32> = Vec::new();
239
- /// // This uses the impl from the standard library to prove `Vec<T>: Clone`.
240
- /// let y = x.clone();
241
- /// }
242
- /// ```
243
- Impl ( DefId ) ,
244
- /// A builtin impl generated by the compiler. When adding a new special
245
- /// trait, try to use actual impls whenever possible. Builtin impls should
246
- /// only be used in cases where the impl cannot be manually be written.
247
- ///
248
- /// Notable examples are auto traits, `Sized`, and `DiscriminantKind`.
249
- /// For a list of all traits with builtin impls, check out the
250
- /// `EvalCtxt::assemble_builtin_impl_candidates` method.
251
- BuiltinImpl ( BuiltinImplSource ) ,
252
- /// An assumption from the environment.
253
- ///
254
- /// More precisely we've used the `n-th` assumption in the `param_env`.
255
- ///
256
- /// ## Examples
257
- ///
258
- /// ```rust
259
- /// fn is_clone<T: Clone>(x: T) -> (T, T) {
260
- /// // This uses the assumption `T: Clone` from the `where`-bounds
261
- /// // to prove `T: Clone`.
262
- /// (x.clone(), x)
263
- /// }
264
- /// ```
265
- ParamEnv ( usize ) ,
266
- /// If the self type is an alias type, e.g. an opaque type or a projection,
267
- /// we know the bounds on that alias to hold even without knowing its concrete
268
- /// underlying type.
269
- ///
270
- /// More precisely this candidate is using the `n-th` bound in the `item_bounds` of
271
- /// the self type.
272
- ///
273
- /// ## Examples
274
- ///
275
- /// ```rust
276
- /// trait Trait {
277
- /// type Assoc: Clone;
278
- /// }
279
- ///
280
- /// fn foo<T: Trait>(x: <T as Trait>::Assoc) {
281
- /// // We prove `<T as Trait>::Assoc` by looking at the bounds on `Assoc` in
282
- /// // in the trait definition.
283
- /// let _y = x.clone();
284
- /// }
285
- /// ```
286
- AliasBound ,
287
- /// A candidate that is registered only during coherence to represent some
288
- /// yet-unknown impl that could be produced downstream without violating orphan
289
- /// rules.
290
- // FIXME: Merge this with the forced ambiguity candidates, so those don't use `Misc`.
291
- CoherenceUnknowable ,
292
- }
0 commit comments