Skip to content

Commit 645a9c3

Browse files
committed
Move things from traits module to types as well
1 parent 508a1ec commit 645a9c3

File tree

12 files changed

+107
-110
lines changed

12 files changed

+107
-110
lines changed

crates/hir/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ use hir_ty::{
5555
autoderef, could_unify,
5656
method_resolution::{self, TyFingerprint},
5757
primitive::UintTy,
58-
traits::{FnTrait, Solution, SolutionVariables},
58+
traits::FnTrait,
5959
AliasEq, AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, CanonicalVarKinds, Cast,
60-
DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Substitution,
61-
TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind, TyVariableKind, WhereClause,
60+
DebruijnIndex, InEnvironment, Interner, QuantifiedWhereClause, Scalar, Solution,
61+
SolutionVariables, Substitution, TraitEnvironment, Ty, TyBuilder, TyDefId, TyKind,
62+
TyVariableKind, WhereClause,
6263
};
6364
use itertools::Itertools;
6465
use rustc_hash::FxHashSet;

crates/hir_ty/src/autoderef.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ use hir_expand::name::name;
1212
use log::{info, warn};
1313

1414
use crate::{
15-
db::HirDatabase,
16-
traits::{InEnvironment, Solution},
17-
AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex, Interner, Ty,
18-
TyBuilder, TyKind,
15+
db::HirDatabase, AliasEq, AliasTy, BoundVar, Canonical, CanonicalVarKinds, DebruijnIndex,
16+
InEnvironment, Interner, Solution, Ty, TyBuilder, TyKind,
1917
};
2018

2119
const AUTODEREF_RECURSION_LIMIT: usize = 10;

crates/hir_ty/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
123123
&self,
124124
krate: CrateId,
125125
goal: crate::Canonical<crate::InEnvironment<crate::DomainGoal>>,
126-
) -> Option<crate::traits::Solution>;
126+
) -> Option<crate::Solution>;
127127

128128
#[salsa::invoke(crate::traits::chalk::program_clauses_for_chalk_env_query)]
129129
fn program_clauses_for_chalk_env(

crates/hir_ty/src/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ use stdx::impl_from;
3737
use syntax::SmolStr;
3838

3939
use super::{
40-
traits::{DomainGoal, Guidance, Solution},
41-
InEnvironment, ProjectionTy, TraitEnvironment, TraitRef, Ty, TypeWalk,
40+
DomainGoal, Guidance, InEnvironment, ProjectionTy, Solution, TraitEnvironment, TraitRef, Ty,
41+
TypeWalk,
4242
};
4343
use crate::{
4444
db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode,

crates/hir_ty/src/infer/coerce.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use chalk_ir::{cast::Cast, Mutability, TyVariableKind};
88
use hir_def::lang_item::LangItemTarget;
99

10-
use crate::{autoderef, traits::Solution, Interner, Ty, TyBuilder, TyKind};
10+
use crate::{autoderef, Interner, Solution, Ty, TyBuilder, TyKind};
1111

1212
use super::{InEnvironment, InferenceContext};
1313

crates/hir_ty/src/infer/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ use crate::{
2020
method_resolution, op,
2121
primitive::{self, UintTy},
2222
to_chalk_trait_id,
23-
traits::{chalk::from_chalk, FnTrait, InEnvironment},
23+
traits::{chalk::from_chalk, FnTrait},
2424
utils::{generics, variant_data, Generics},
25-
AdtId, Binders, CallableDefId, FnPointer, FnSig, Interner, Rawness, Scalar, Substitution,
26-
TraitRef, Ty, TyBuilder, TyKind,
25+
AdtId, Binders, CallableDefId, FnPointer, FnSig, InEnvironment, Interner, Rawness, Scalar,
26+
Substitution, TraitRef, Ty, TyBuilder, TyKind,
2727
};
2828

2929
use super::{

crates/hir_ty/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub use lower::{
4949
associated_type_shorthand_candidates, callable_item_sig, CallableDefId, ImplTraitLoweringMode,
5050
TyDefId, TyLoweringContext, ValueTyDefId,
5151
};
52-
pub use traits::{AliasEq, DomainGoal, InEnvironment, TraitEnvironment};
52+
pub use traits::TraitEnvironment;
5353
pub use types::*;
5454
pub use walk::TypeWalk;
5555

crates/hir_ty/src/method_resolution.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ pub fn implements_trait_unique(
800800
let goal = generic_implements_goal(db, env, trait_, ty.clone());
801801
let solution = db.trait_solve(krate, goal);
802802

803-
matches!(solution, Some(crate::traits::Solution::Unique(_)))
803+
matches!(solution, Some(crate::Solution::Unique(_)))
804804
}
805805

806806
/// This creates Substs for a trait with the given Self type and type variables

crates/hir_ty/src/traits.rs

Lines changed: 2 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use hir_def::{lang_item::LangItemTarget, TraitId};
88
use stdx::panic_context;
99

1010
use 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

1515
use 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.
12374
pub(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)]
285201
pub enum FnTrait {
286202
FnOnce,

crates/hir_ty/src/traits/chalk/mapping.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ use base_db::salsa::InternKey;
1010
use hir_def::{GenericDefId, TypeAliasId};
1111

1212
use crate::{
13-
db::HirDatabase,
14-
primitive::UintTy,
15-
traits::{Canonical, DomainGoal},
16-
AliasTy, CallableDefId, FnPointer, GenericArg, InEnvironment, OpaqueTy, ProjectionTy,
17-
QuantifiedWhereClause, Scalar, Substitution, TraitRef, Ty, TypeWalk, WhereClause,
13+
db::HirDatabase, primitive::UintTy, AliasTy, CallableDefId, Canonical, DomainGoal, FnPointer,
14+
GenericArg, InEnvironment, OpaqueTy, ProjectionTy, QuantifiedWhereClause, Scalar, Substitution,
15+
TraitRef, Ty, TypeWalk, WhereClause,
1816
};
1917

2018
use super::interner::*;

0 commit comments

Comments
 (0)