@@ -3,92 +3,22 @@ use rustc_data_structures::intern::Interned;
33use rustc_macros:: { HashStable , TypeFoldable , TypeVisitable } ;
44use rustc_next_trait_solver as ir;
55pub use rustc_next_trait_solver:: solve:: * ;
6- use rustc_span:: def_id:: DefId ;
76
8- use crate :: infer:: canonical:: { CanonicalVarValues , QueryRegionConstraints } ;
9- use crate :: traits:: query:: NoSolution ;
10- use crate :: traits:: Canonical ;
7+ use crate :: infer:: canonical:: QueryRegionConstraints ;
118use crate :: ty:: {
129 self , FallibleTypeFolder , Ty , TyCtxt , TypeFoldable , TypeFolder , TypeVisitable , TypeVisitor ,
1310} ;
1411
15- use super :: BuiltinImplSource ;
16-
1712mod cache;
18- pub mod inspect;
1913
2014pub use cache:: { CacheData , EvaluationCache } ;
2115
22- pub type Goal < ' tcx , P > = ir_solve:: Goal < TyCtxt < ' tcx > , P > ;
23- 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- }
16+ pub type Goal < ' tcx , P > = ir:: solve:: Goal < TyCtxt < ' tcx > , P > ;
17+ pub type QueryInput < ' tcx , P > = ir:: solve:: QueryInput < TyCtxt < ' tcx > , P > ;
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 > > ;
9222
9323/// Additional constraints returned on success.
9424#[ derive( Debug , PartialEq , Eq , Clone , Hash , HashStable , Default ) ]
@@ -107,18 +37,6 @@ impl<'tcx> std::ops::Deref for PredefinedOpaques<'tcx> {
10737 }
10838}
10939
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-
12240#[ derive( Debug , PartialEq , Eq , Copy , Clone , Hash , HashStable ) ]
12341pub struct ExternalConstraints < ' tcx > ( pub ( crate ) Interned < ' tcx , ExternalConstraintsData < ' tcx > > ) ;
12442
@@ -225,68 +143,3 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for PredefinedOpaques<'tcx> {
225143 self . opaque_types . visit_with ( visitor)
226144 }
227145}
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