@@ -8,8 +8,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId};
88use stdx:: panic_context;
99
1010use crate :: {
11- db:: HirDatabase , AliasTy , Canonical , DebruijnIndex , HirDisplay , Substitution , Ty , TyKind ,
12- TypeWalk , WhereClause ,
11+ db:: HirDatabase , AliasEq , AliasTy , Canonical , DomainGoal , Guidance , HirDisplay , InEnvironment ,
12+ Solution , SolutionVariables , Ty , TyKind , WhereClause ,
1313} ;
1414
1515use self :: chalk:: { from_chalk, Interner , ToChalk } ;
@@ -70,55 +70,6 @@ impl Default for TraitEnvironment {
7070 }
7171}
7272
73- /// Something (usually a goal), along with an environment.
74- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
75- pub struct InEnvironment < T > {
76- pub environment : chalk_ir:: Environment < Interner > ,
77- pub goal : T ,
78- }
79-
80- impl < T > InEnvironment < T > {
81- pub fn new ( environment : chalk_ir:: Environment < Interner > , value : T ) -> InEnvironment < T > {
82- InEnvironment { environment, goal : value }
83- }
84- }
85-
86- /// Something that needs to be proven (by Chalk) during type checking, e.g. that
87- /// a certain type implements a certain trait. Proving the Obligation might
88- /// result in additional information about inference variables.
89- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
90- pub enum DomainGoal {
91- Holds ( WhereClause ) ,
92- }
93-
94- #[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
95- pub struct AliasEq {
96- pub alias : AliasTy ,
97- pub ty : Ty ,
98- }
99-
100- impl TypeWalk for AliasEq {
101- fn walk ( & self , f : & mut impl FnMut ( & Ty ) ) {
102- self . ty . walk ( f) ;
103- match & self . alias {
104- AliasTy :: Projection ( projection_ty) => projection_ty. walk ( f) ,
105- AliasTy :: Opaque ( opaque) => opaque. walk ( f) ,
106- }
107- }
108-
109- fn walk_mut_binders (
110- & mut self ,
111- f : & mut impl FnMut ( & mut Ty , DebruijnIndex ) ,
112- binders : DebruijnIndex ,
113- ) {
114- self . ty . walk_mut_binders ( f, binders) ;
115- match & mut self . alias {
116- AliasTy :: Projection ( projection_ty) => projection_ty. walk_mut_binders ( f, binders) ,
117- AliasTy :: Opaque ( opaque) => opaque. walk_mut_binders ( f, binders) ,
118- }
119- }
120- }
121-
12273/// Solve a trait goal using Chalk.
12374pub ( crate ) fn trait_solve_query (
12475 db : & dyn HirDatabase ,
@@ -246,41 +197,6 @@ fn solution_from_chalk(
246197 }
247198}
248199
249- #[ derive( Clone , Debug , PartialEq , Eq ) ]
250- pub struct SolutionVariables ( pub Canonical < Substitution > ) ;
251-
252- #[ derive( Clone , Debug , PartialEq , Eq ) ]
253- /// A (possible) solution for a proposed goal.
254- pub enum Solution {
255- /// The goal indeed holds, and there is a unique value for all existential
256- /// variables.
257- Unique ( SolutionVariables ) ,
258-
259- /// The goal may be provable in multiple ways, but regardless we may have some guidance
260- /// for type inference. In this case, we don't return any lifetime
261- /// constraints, since we have not "committed" to any particular solution
262- /// yet.
263- Ambig ( Guidance ) ,
264- }
265-
266- #[ derive( Clone , Debug , PartialEq , Eq ) ]
267- /// When a goal holds ambiguously (e.g., because there are multiple possible
268- /// solutions), we issue a set of *guidance* back to type inference.
269- pub enum Guidance {
270- /// The existential variables *must* have the given values if the goal is
271- /// ever to hold, but that alone isn't enough to guarantee the goal will
272- /// actually hold.
273- Definite ( SolutionVariables ) ,
274-
275- /// There are multiple plausible values for the existentials, but the ones
276- /// here are suggested as the preferred choice heuristically. These should
277- /// be used for inference fallback only.
278- Suggested ( SolutionVariables ) ,
279-
280- /// There's no useful information to feed back to type inference
281- Unknown ,
282- }
283-
284200#[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
285201pub enum FnTrait {
286202 FnOnce ,
0 commit comments