@@ -21,11 +21,13 @@ use rustc_hir::def_id::DefId;
2121use rustc_infer:: infer:: canonical:: { Canonical , CanonicalVarValues } ;
2222use rustc_infer:: infer:: { InferCtxt , InferOk , TyCtxtInferExt } ;
2323use rustc_infer:: traits:: query:: NoSolution ;
24- use rustc_infer:: traits:: Obligation ;
25- use rustc_middle:: traits:: solve:: { ExternalConstraints , ExternalConstraintsData } ;
24+ use rustc_middle:: traits:: solve:: {
25+ CanonicalGoal , CanonicalResponse , Certainty , ExternalConstraints , ExternalConstraintsData ,
26+ Goal , MaybeCause , QueryResult , Response ,
27+ } ;
2628use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
2729use rustc_middle:: ty:: {
28- CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , ToPredicate , TypeOutlivesPredicate ,
30+ CoercePredicate , RegionOutlivesPredicate , SubtypePredicate , TypeOutlivesPredicate ,
2931} ;
3032use rustc_span:: DUMMY_SP ;
3133
@@ -43,45 +45,6 @@ mod trait_goals;
4345pub use eval_ctxt:: EvalCtxt ;
4446pub use fulfill:: FulfillmentCtxt ;
4547
46- /// A goal is a statement, i.e. `predicate`, we want to prove
47- /// given some assumptions, i.e. `param_env`.
48- ///
49- /// Most of the time the `param_env` contains the `where`-bounds of the function
50- /// we're currently typechecking while the `predicate` is some trait bound.
51- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , TypeFoldable , TypeVisitable ) ]
52- pub struct Goal < ' tcx , P > {
53- param_env : ty:: ParamEnv < ' tcx > ,
54- predicate : P ,
55- }
56-
57- impl < ' tcx , P > Goal < ' tcx , P > {
58- pub fn new (
59- tcx : TyCtxt < ' tcx > ,
60- param_env : ty:: ParamEnv < ' tcx > ,
61- predicate : impl ToPredicate < ' tcx , P > ,
62- ) -> Goal < ' tcx , P > {
63- Goal { param_env, predicate : predicate. to_predicate ( tcx) }
64- }
65-
66- /// Updates the goal to one with a different `predicate` but the same `param_env`.
67- fn with < Q > ( self , tcx : TyCtxt < ' tcx > , predicate : impl ToPredicate < ' tcx , Q > ) -> Goal < ' tcx , Q > {
68- Goal { param_env : self . param_env , predicate : predicate. to_predicate ( tcx) }
69- }
70- }
71-
72- impl < ' tcx , P > From < Obligation < ' tcx , P > > for Goal < ' tcx , P > {
73- fn from ( obligation : Obligation < ' tcx , P > ) -> Goal < ' tcx , P > {
74- Goal { param_env : obligation. param_env , predicate : obligation. predicate }
75- }
76- }
77- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , TypeFoldable , TypeVisitable ) ]
78- pub struct Response < ' tcx > {
79- pub var_values : CanonicalVarValues < ' tcx > ,
80- /// Additional constraints returned by this query.
81- pub external_constraints : ExternalConstraints < ' tcx > ,
82- pub certainty : Certainty ,
83- }
84-
8548trait CanonicalResponseExt {
8649 fn has_no_inference_or_external_constraints ( & self ) -> bool ;
8750}
@@ -94,56 +57,6 @@ impl<'tcx> CanonicalResponseExt for Canonical<'tcx, Response<'tcx>> {
9457 }
9558}
9659
97- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , TypeFoldable , TypeVisitable ) ]
98- pub enum Certainty {
99- Yes ,
100- Maybe ( MaybeCause ) ,
101- }
102-
103- impl Certainty {
104- pub const AMBIGUOUS : Certainty = Certainty :: Maybe ( MaybeCause :: Ambiguity ) ;
105-
106- /// When proving multiple goals using **AND**, e.g. nested obligations for an impl,
107- /// use this function to unify the certainty of these goals
108- pub fn unify_and ( self , other : Certainty ) -> Certainty {
109- match ( self , other) {
110- ( Certainty :: Yes , Certainty :: Yes ) => Certainty :: Yes ,
111- ( Certainty :: Yes , Certainty :: Maybe ( _) ) => other,
112- ( Certainty :: Maybe ( _) , Certainty :: Yes ) => self ,
113- ( Certainty :: Maybe ( MaybeCause :: Overflow ) , Certainty :: Maybe ( MaybeCause :: Overflow ) ) => {
114- Certainty :: Maybe ( MaybeCause :: Overflow )
115- }
116- // If at least one of the goals is ambiguous, hide the overflow as the ambiguous goal
117- // may still result in failure.
118- ( Certainty :: Maybe ( MaybeCause :: Ambiguity ) , Certainty :: Maybe ( _) )
119- | ( Certainty :: Maybe ( _) , Certainty :: Maybe ( MaybeCause :: Ambiguity ) ) => {
120- Certainty :: Maybe ( MaybeCause :: Ambiguity )
121- }
122- }
123- }
124- }
125-
126- /// Why we failed to evaluate a goal.
127- #[ derive( Debug , PartialEq , Eq , Clone , Copy , Hash , TypeFoldable , TypeVisitable ) ]
128- pub enum MaybeCause {
129- /// We failed due to ambiguity. This ambiguity can either
130- /// be a true ambiguity, i.e. there are multiple different answers,
131- /// or we hit a case where we just don't bother, e.g. `?x: Trait` goals.
132- Ambiguity ,
133- /// We gave up due to an overflow, most often by hitting the recursion limit.
134- Overflow ,
135- }
136-
137- type CanonicalGoal < ' tcx , T = ty:: Predicate < ' tcx > > = Canonical < ' tcx , Goal < ' tcx , T > > ;
138- type CanonicalResponse < ' tcx > = Canonical < ' tcx , Response < ' tcx > > ;
139- /// The result of evaluating a canonical query.
140- ///
141- /// FIXME: We use a different type than the existing canonical queries. This is because
142- /// we need to add a `Certainty` for `overflow` and may want to restructure this code without
143- /// having to worry about changes to currently used code. Once we've made progress on this
144- /// solver, merge the two responses again.
145- pub type QueryResult < ' tcx > = Result < CanonicalResponse < ' tcx > , NoSolution > ;
146-
14760pub trait InferCtxtEvalExt < ' tcx > {
14861 /// Evaluates a goal from **outside** of the trait solver.
14962 ///
0 commit comments