diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-03-01 13:29:54 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2021-03-01 13:29:54 +0000 |
commit | 4a9eec44787a0f2b35467ea98dd6f596671907f9 (patch) | |
tree | b2a941497dea3cc38adb6c55049668aa31b2554b | |
parent | cda13d54613006c7985da0489878605300ba05b8 (diff) | |
parent | 5d121cdb45f5199828ed64a2ca01a74998e023ad (diff) |
Merge #7826
7826: Introduce Ty::Alias r=Veykril a=Veykril
bors r+
Co-authored-by: Lukas Wirth <[email protected]>
-rw-r--r-- | crates/hir/src/code_model.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/autoderef.rs | 5 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/unsafe_check.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 19 | ||||
-rw-r--r-- | crates/hir_ty/src/infer.rs | 4 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/coerce.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 6 | ||||
-rw-r--r-- | crates/hir_ty/src/lib.rs | 76 | ||||
-rw-r--r-- | crates/hir_ty/src/lower.rs | 35 | ||||
-rw-r--r-- | crates/hir_ty/src/method_resolution.rs | 8 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk.rs | 10 | ||||
-rw-r--r-- | crates/hir_ty/src/traits/chalk/mapping.rs | 20 |
14 files changed, 109 insertions, 98 deletions
diff --git a/crates/hir/src/code_model.rs b/crates/hir/src/code_model.rs index 351ba75ff..00b0dc082 100644 --- a/crates/hir/src/code_model.rs +++ b/crates/hir/src/code_model.rs | |||
@@ -31,7 +31,7 @@ use hir_ty::{ | |||
31 | display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter}, | 31 | display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter}, |
32 | method_resolution, | 32 | method_resolution, |
33 | traits::{FnTrait, Solution, SolutionVariables}, | 33 | traits::{FnTrait, Solution, SolutionVariables}, |
34 | BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate, | 34 | AliasTy, BoundVar, CallableDefId, CallableSig, Canonical, DebruijnIndex, GenericPredicate, |
35 | InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, | 35 | InEnvironment, Obligation, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, |
36 | Ty, TyDefId, TyVariableKind, | 36 | Ty, TyDefId, TyVariableKind, |
37 | }; | 37 | }; |
@@ -1648,7 +1648,7 @@ impl Type { | |||
1648 | .build(); | 1648 | .build(); |
1649 | let predicate = ProjectionPredicate { | 1649 | let predicate = ProjectionPredicate { |
1650 | projection_ty: ProjectionTy { associated_ty: alias.id, parameters: subst }, | 1650 | projection_ty: ProjectionTy { associated_ty: alias.id, parameters: subst }, |
1651 | ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)), | 1651 | ty: Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)), |
1652 | }; | 1652 | }; |
1653 | let goal = Canonical { | 1653 | let goal = Canonical { |
1654 | value: InEnvironment::new( | 1654 | value: InEnvironment::new( |
@@ -1709,7 +1709,7 @@ impl Type { | |||
1709 | } | 1709 | } |
1710 | 1710 | ||
1711 | pub fn is_raw_ptr(&self) -> bool { | 1711 | pub fn is_raw_ptr(&self) -> bool { |
1712 | matches!(&self.ty.value, Ty::RawPtr(..)) | 1712 | matches!(&self.ty.value, Ty::Raw(..)) |
1713 | } | 1713 | } |
1714 | 1714 | ||
1715 | pub fn contains_unknown(&self) -> bool { | 1715 | pub fn contains_unknown(&self) -> bool { |
@@ -1937,7 +1937,7 @@ impl Type { | |||
1937 | walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); | 1937 | walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); |
1938 | } | 1938 | } |
1939 | } | 1939 | } |
1940 | Ty::Opaque(opaque_ty) => { | 1940 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { |
1941 | if let Some(bounds) = ty.impl_trait_bounds(db) { | 1941 | if let Some(bounds) = ty.impl_trait_bounds(db) { |
1942 | walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); | 1942 | walk_bounds(db, &type_.derived(ty.clone()), &bounds, cb); |
1943 | } | 1943 | } |
diff --git a/crates/hir_ty/src/autoderef.rs b/crates/hir_ty/src/autoderef.rs index 21d1e5446..be1fd1f13 100644 --- a/crates/hir_ty/src/autoderef.rs +++ b/crates/hir_ty/src/autoderef.rs | |||
@@ -81,7 +81,7 @@ fn deref_by_trait( | |||
81 | 81 | ||
82 | // Now do the assoc type projection | 82 | // Now do the assoc type projection |
83 | let projection = super::traits::ProjectionPredicate { | 83 | let projection = super::traits::ProjectionPredicate { |
84 | ty: Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())), | 84 | ty: Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, ty.value.kinds.len())), |
85 | projection_ty: super::ProjectionTy { associated_ty: target, parameters }, | 85 | projection_ty: super::ProjectionTy { associated_ty: target, parameters }, |
86 | }; | 86 | }; |
87 | 87 | ||
@@ -114,7 +114,8 @@ fn deref_by_trait( | |||
114 | // new variables in that case | 114 | // new variables in that case |
115 | 115 | ||
116 | for i in 1..vars.0.kinds.len() { | 116 | for i in 1..vars.0.kinds.len() { |
117 | if vars.0.value[i - 1] != Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, i - 1)) | 117 | if vars.0.value[i - 1] |
118 | != Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i - 1)) | ||
118 | { | 119 | { |
119 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.value, solution); | 120 | warn!("complex solution for derefing {:?}: {:?}, ignoring", ty.value, solution); |
120 | return None; | 121 | return None; |
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index b439915c7..e77a20fea 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -110,7 +110,7 @@ fn walk_unsafe( | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | Expr::UnaryOp { expr, op: UnaryOp::Deref } => { | 112 | Expr::UnaryOp { expr, op: UnaryOp::Deref } => { |
113 | if let Ty::RawPtr(..) = &infer[*expr] { | 113 | if let Ty::Raw(..) = &infer[*expr] { |
114 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); | 114 | unsafe_exprs.push(UnsafeExpr { expr: current, inside_unsafe_block }); |
115 | } | 115 | } |
116 | } | 116 | } |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index ff8211094..f3a4333cb 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -3,8 +3,9 @@ | |||
3 | use std::{borrow::Cow, fmt}; | 3 | use std::{borrow::Cow, fmt}; |
4 | 4 | ||
5 | use crate::{ | 5 | use crate::{ |
6 | db::HirDatabase, primitive, utils::generics, CallableDefId, CallableSig, GenericPredicate, | 6 | db::HirDatabase, primitive, utils::generics, AliasTy, CallableDefId, CallableSig, |
7 | Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, | 7 | GenericPredicate, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, |
8 | TraitRef, Ty, | ||
8 | }; | 9 | }; |
9 | use arrayvec::ArrayVec; | 10 | use arrayvec::ArrayVec; |
10 | use hir_def::{ | 11 | use hir_def::{ |
@@ -284,12 +285,12 @@ impl HirDisplay for Ty { | |||
284 | t.hir_fmt(f)?; | 285 | t.hir_fmt(f)?; |
285 | write!(f, "; _]")?; | 286 | write!(f, "; _]")?; |
286 | } | 287 | } |
287 | Ty::RawPtr(m, parameters) | Ty::Ref(m, parameters) => { | 288 | Ty::Raw(m, parameters) | Ty::Ref(m, parameters) => { |
288 | let t = parameters.as_single(); | 289 | let t = parameters.as_single(); |
289 | let ty_display = | 290 | let ty_display = |
290 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); | 291 | t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); |
291 | 292 | ||
292 | if matches!(self, Ty::RawPtr(..)) { | 293 | if matches!(self, Ty::Raw(..)) { |
293 | write!(f, "*{}", m.as_keyword_for_ptr())?; | 294 | write!(f, "*{}", m.as_keyword_for_ptr())?; |
294 | } else { | 295 | } else { |
295 | write!(f, "&{}", m.as_keyword_for_ref())?; | 296 | write!(f, "&{}", m.as_keyword_for_ref())?; |
@@ -300,10 +301,10 @@ impl HirDisplay for Ty { | |||
300 | Ty::Dyn(predicates) if predicates.len() > 1 => { | 301 | Ty::Dyn(predicates) if predicates.len() > 1 => { |
301 | Cow::Borrowed(predicates.as_ref()) | 302 | Cow::Borrowed(predicates.as_ref()) |
302 | } | 303 | } |
303 | &Ty::Opaque(OpaqueTy { | 304 | &Ty::Alias(AliasTy::Opaque(OpaqueTy { |
304 | opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx), | 305 | opaque_ty_id: OpaqueTyId::ReturnTypeImplTrait(func, idx), |
305 | ref parameters, | 306 | ref parameters, |
306 | }) => { | 307 | })) => { |
307 | datas = | 308 | datas = |
308 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); | 309 | f.db.return_type_impl_traits(func).expect("impl trait id without data"); |
309 | let data = (*datas) | 310 | let data = (*datas) |
@@ -518,7 +519,6 @@ impl HirDisplay for Ty { | |||
518 | write!(f, "{{closure}}")?; | 519 | write!(f, "{{closure}}")?; |
519 | } | 520 | } |
520 | } | 521 | } |
521 | Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, | ||
522 | Ty::Placeholder(id) => { | 522 | Ty::Placeholder(id) => { |
523 | let generics = generics(f.db.upcast(), id.parent); | 523 | let generics = generics(f.db.upcast(), id.parent); |
524 | let param_data = &generics.params.types[id.local_id]; | 524 | let param_data = &generics.params.types[id.local_id]; |
@@ -537,11 +537,12 @@ impl HirDisplay for Ty { | |||
537 | } | 537 | } |
538 | } | 538 | } |
539 | } | 539 | } |
540 | Ty::Bound(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?, | 540 | Ty::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index)?, |
541 | Ty::Dyn(predicates) => { | 541 | Ty::Dyn(predicates) => { |
542 | write_bounds_like_dyn_trait_with_prefix("dyn", predicates, f)?; | 542 | write_bounds_like_dyn_trait_with_prefix("dyn", predicates, f)?; |
543 | } | 543 | } |
544 | Ty::Opaque(opaque_ty) => { | 544 | Ty::Alias(AliasTy::Projection(p_ty)) => p_ty.hir_fmt(f)?, |
545 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { | ||
545 | match opaque_ty.opaque_ty_id { | 546 | match opaque_ty.opaque_ty_id { |
546 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 547 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { |
547 | let datas = | 548 | let datas = |
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index 1d78d1feb..18a4f5e8a 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs | |||
@@ -40,7 +40,7 @@ use super::{ | |||
40 | InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, | 40 | InEnvironment, ProjectionTy, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, |
41 | }; | 41 | }; |
42 | use crate::{ | 42 | use crate::{ |
43 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, | 43 | db::HirDatabase, infer::diagnostics::InferenceDiagnostic, lower::ImplTraitLoweringMode, AliasTy, |
44 | }; | 44 | }; |
45 | 45 | ||
46 | pub(crate) use unify::unify; | 46 | pub(crate) use unify::unify; |
@@ -395,7 +395,7 @@ impl<'a> InferenceContext<'a> { | |||
395 | fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty { | 395 | fn normalize_associated_types_in(&mut self, ty: Ty) -> Ty { |
396 | let ty = self.resolve_ty_as_possible(ty); | 396 | let ty = self.resolve_ty_as_possible(ty); |
397 | ty.fold(&mut |ty| match ty { | 397 | ty.fold(&mut |ty| match ty { |
398 | Ty::Projection(proj_ty) => self.normalize_projection_ty(proj_ty), | 398 | Ty::Alias(AliasTy::Projection(proj_ty)) => self.normalize_projection_ty(proj_ty), |
399 | _ => ty, | 399 | _ => ty, |
400 | }) | 400 | }) |
401 | } | 401 | } |
diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 667b26a76..c33d8c61e 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs | |||
@@ -73,19 +73,19 @@ impl<'a> InferenceContext<'a> { | |||
73 | match (&mut from_ty, to_ty) { | 73 | match (&mut from_ty, to_ty) { |
74 | // `*mut T` -> `*const T` | 74 | // `*mut T` -> `*const T` |
75 | // `&mut T` -> `&T` | 75 | // `&mut T` -> `&T` |
76 | (Ty::RawPtr(m1, ..), Ty::RawPtr(m2 @ Mutability::Shared, ..)) | 76 | (Ty::Raw(m1, ..), Ty::Raw(m2 @ Mutability::Shared, ..)) |
77 | | (Ty::Ref(m1, ..), Ty::Ref(m2 @ Mutability::Shared, ..)) => { | 77 | | (Ty::Ref(m1, ..), Ty::Ref(m2 @ Mutability::Shared, ..)) => { |
78 | *m1 = *m2; | 78 | *m1 = *m2; |
79 | } | 79 | } |
80 | // `&T` -> `*const T` | 80 | // `&T` -> `*const T` |
81 | // `&mut T` -> `*mut T`/`*const T` | 81 | // `&mut T` -> `*mut T`/`*const T` |
82 | (Ty::Ref(.., substs), &Ty::RawPtr(m2 @ Mutability::Shared, ..)) | 82 | (Ty::Ref(.., substs), &Ty::Raw(m2 @ Mutability::Shared, ..)) |
83 | | (Ty::Ref(Mutability::Mut, substs), &Ty::RawPtr(m2, ..)) => { | 83 | | (Ty::Ref(Mutability::Mut, substs), &Ty::Raw(m2, ..)) => { |
84 | from_ty = Ty::RawPtr(m2, substs.clone()); | 84 | from_ty = Ty::Raw(m2, substs.clone()); |
85 | } | 85 | } |
86 | 86 | ||
87 | // Illegal mutability conversion | 87 | // Illegal mutability conversion |
88 | (Ty::RawPtr(Mutability::Shared, ..), Ty::RawPtr(Mutability::Mut, ..)) | 88 | (Ty::Raw(Mutability::Shared, ..), Ty::Raw(Mutability::Mut, ..)) |
89 | | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false, | 89 | | (Ty::Ref(Mutability::Shared, ..), Ty::Ref(Mutability::Mut, ..)) => return false, |
90 | 90 | ||
91 | // `{function_type}` -> `fn()` | 91 | // `{function_type}` -> `fn()` |
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 928ad37a3..7852b3d23 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -479,7 +479,7 @@ impl<'a> InferenceContext<'a> { | |||
479 | }; | 479 | }; |
480 | let inner_ty = self.infer_expr_inner(*expr, &expectation); | 480 | let inner_ty = self.infer_expr_inner(*expr, &expectation); |
481 | match rawness { | 481 | match rawness { |
482 | Rawness::RawPtr => Ty::RawPtr(*mutability, Substs::single(inner_ty)), | 482 | Rawness::RawPtr => Ty::Raw(*mutability, Substs::single(inner_ty)), |
483 | Rawness::Ref => Ty::Ref(*mutability, Substs::single(inner_ty)), | 483 | Rawness::Ref => Ty::Ref(*mutability, Substs::single(inner_ty)), |
484 | } | 484 | } |
485 | } | 485 | } |
diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index b481aa1b3..99a89a7f3 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs | |||
@@ -68,7 +68,7 @@ impl<'a, 'b> Canonicalizer<'a, 'b> { | |||
68 | } else { | 68 | } else { |
69 | let root = self.ctx.table.var_unification_table.find(inner); | 69 | let root = self.ctx.table.var_unification_table.find(inner); |
70 | let position = self.add(InferenceVar::from_inner(root), kind); | 70 | let position = self.add(InferenceVar::from_inner(root), kind); |
71 | Ty::Bound(BoundVar::new(binders, position)) | 71 | Ty::BoundVar(BoundVar::new(binders, position)) |
72 | } | 72 | } |
73 | } | 73 | } |
74 | _ => ty, | 74 | _ => ty, |
@@ -110,7 +110,7 @@ impl<T> Canonicalized<T> { | |||
110 | pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { | 110 | pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { |
111 | ty.walk_mut_binders( | 111 | ty.walk_mut_binders( |
112 | &mut |ty, binders| { | 112 | &mut |ty, binders| { |
113 | if let &mut Ty::Bound(bound) = ty { | 113 | if let &mut Ty::BoundVar(bound) = ty { |
114 | if bound.debruijn >= binders { | 114 | if bound.debruijn >= binders { |
115 | let (v, k) = self.free_vars[bound.index]; | 115 | let (v, k) = self.free_vars[bound.index]; |
116 | *ty = Ty::InferenceVar(v, k); | 116 | *ty = Ty::InferenceVar(v, k); |
@@ -168,7 +168,7 @@ pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { | |||
168 | // (kind of hacky) | 168 | // (kind of hacky) |
169 | for (i, var) in vars.iter().enumerate() { | 169 | for (i, var) in vars.iter().enumerate() { |
170 | if &*table.resolve_ty_shallow(var) == var { | 170 | if &*table.resolve_ty_shallow(var) == var { |
171 | table.unify(var, &Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, i))); | 171 | table.unify(var, &Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, i))); |
172 | } | 172 | } |
173 | } | 173 | } |
174 | Some( | 174 | Some( |
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs index 1131eaf92..9bcaf6fa7 100644 --- a/crates/hir_ty/src/lib.rs +++ b/crates/hir_ty/src/lib.rs | |||
@@ -111,6 +111,19 @@ pub struct FnPointer { | |||
111 | pub substs: Substs, | 111 | pub substs: Substs, |
112 | } | 112 | } |
113 | 113 | ||
114 | #[derive(Clone, PartialEq, Eq, Debug, Hash)] | ||
115 | pub enum AliasTy { | ||
116 | /// A "projection" type corresponds to an (unnormalized) | ||
117 | /// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the | ||
118 | /// trait and all its parameters are fully known. | ||
119 | Projection(ProjectionTy), | ||
120 | /// An opaque type (`impl Trait`). | ||
121 | /// | ||
122 | /// This is currently only used for return type impl trait; each instance of | ||
123 | /// `impl Trait` in a return type gets its own ID. | ||
124 | Opaque(OpaqueTy), | ||
125 | } | ||
126 | |||
114 | /// A type. | 127 | /// A type. |
115 | /// | 128 | /// |
116 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents | 129 | /// See also the `TyKind` enum in rustc (librustc/ty/sty.rs), which represents |
@@ -141,7 +154,7 @@ pub enum Ty { | |||
141 | Slice(Substs), | 154 | Slice(Substs), |
142 | 155 | ||
143 | /// A raw pointer. Written as `*mut T` or `*const T` | 156 | /// A raw pointer. Written as `*mut T` or `*const T` |
144 | RawPtr(Mutability, Substs), | 157 | Raw(Mutability, Substs), |
145 | 158 | ||
146 | /// A reference; a pointer with an associated lifetime. Written as | 159 | /// A reference; a pointer with an associated lifetime. Written as |
147 | /// `&'a mut T` or `&'a T`. | 160 | /// `&'a mut T` or `&'a T`. |
@@ -193,16 +206,11 @@ pub enum Ty { | |||
193 | /// ``` | 206 | /// ``` |
194 | Function(FnPointer), | 207 | Function(FnPointer), |
195 | 208 | ||
196 | /// A "projection" type corresponds to an (unnormalized) | 209 | /// An "alias" type represents some form of type alias, such as: |
197 | /// projection like `<P0 as Trait<P1..Pn>>::Foo`. Note that the | 210 | /// - An associated type projection like `<T as Iterator>::Item` |
198 | /// trait and all its parameters are fully known. | 211 | /// - `impl Trait` types |
199 | Projection(ProjectionTy), | 212 | /// - Named type aliases like `type Foo<X> = Vec<X>` |
200 | 213 | Alias(AliasTy), | |
201 | /// An opaque type (`impl Trait`). | ||
202 | /// | ||
203 | /// This is currently only used for return type impl trait; each instance of | ||
204 | /// `impl Trait` in a return type gets its own ID. | ||
205 | Opaque(OpaqueTy), | ||
206 | 214 | ||
207 | /// A placeholder for a type parameter; for example, `T` in `fn f<T>(x: T) | 215 | /// A placeholder for a type parameter; for example, `T` in `fn f<T>(x: T) |
208 | /// {}` when we're type-checking the body of that function. In this | 216 | /// {}` when we're type-checking the body of that function. In this |
@@ -215,7 +223,7 @@ pub enum Ty { | |||
215 | /// parameters get turned into variables; during trait resolution, inference | 223 | /// parameters get turned into variables; during trait resolution, inference |
216 | /// variables get turned into bound variables and back; and in `Dyn` the | 224 | /// variables get turned into bound variables and back; and in `Dyn` the |
217 | /// `Self` type is represented with a bound variable as well. | 225 | /// `Self` type is represented with a bound variable as well. |
218 | Bound(BoundVar), | 226 | BoundVar(BoundVar), |
219 | 227 | ||
220 | /// A type variable used during type checking. | 228 | /// A type variable used during type checking. |
221 | InferenceVar(InferenceVar, TyVariableKind), | 229 | InferenceVar(InferenceVar, TyVariableKind), |
@@ -299,7 +307,7 @@ impl Substs { | |||
299 | generic_params | 307 | generic_params |
300 | .iter() | 308 | .iter() |
301 | .enumerate() | 309 | .enumerate() |
302 | .map(|(idx, _)| Ty::Bound(BoundVar::new(debruijn, idx))) | 310 | .map(|(idx, _)| Ty::BoundVar(BoundVar::new(debruijn, idx))) |
303 | .collect(), | 311 | .collect(), |
304 | ) | 312 | ) |
305 | } | 313 | } |
@@ -347,7 +355,7 @@ impl SubstsBuilder { | |||
347 | } | 355 | } |
348 | 356 | ||
349 | pub fn fill_with_bound_vars(self, debruijn: DebruijnIndex, starting_from: usize) -> Self { | 357 | pub fn fill_with_bound_vars(self, debruijn: DebruijnIndex, starting_from: usize) -> Self { |
350 | self.fill((starting_from..).map(|idx| Ty::Bound(BoundVar::new(debruijn, idx)))) | 358 | self.fill((starting_from..).map(|idx| Ty::BoundVar(BoundVar::new(debruijn, idx)))) |
351 | } | 359 | } |
352 | 360 | ||
353 | pub fn fill_with_unknown(self) -> Self { | 361 | pub fn fill_with_unknown(self) -> Self { |
@@ -627,7 +635,7 @@ impl Ty { | |||
627 | Ty::Ref(mutability, parameters) => { | 635 | Ty::Ref(mutability, parameters) => { |
628 | Some((parameters.as_single(), Rawness::Ref, *mutability)) | 636 | Some((parameters.as_single(), Rawness::Ref, *mutability)) |
629 | } | 637 | } |
630 | Ty::RawPtr(mutability, parameters) => { | 638 | Ty::Raw(mutability, parameters) => { |
631 | Some((parameters.as_single(), Rawness::RawPtr, *mutability)) | 639 | Some((parameters.as_single(), Rawness::RawPtr, *mutability)) |
632 | } | 640 | } |
633 | _ => None, | 641 | _ => None, |
@@ -688,9 +696,7 @@ impl Ty { | |||
688 | expr == expr2 && def == def2 | 696 | expr == expr2 && def == def2 |
689 | } | 697 | } |
690 | (Ty::Ref(mutability, ..), Ty::Ref(mutability2, ..)) | 698 | (Ty::Ref(mutability, ..), Ty::Ref(mutability2, ..)) |
691 | | (Ty::RawPtr(mutability, ..), Ty::RawPtr(mutability2, ..)) => { | 699 | | (Ty::Raw(mutability, ..), Ty::Raw(mutability2, ..)) => mutability == mutability2, |
692 | mutability == mutability2 | ||
693 | } | ||
694 | ( | 700 | ( |
695 | Ty::Function(FnPointer { num_args, sig, .. }), | 701 | Ty::Function(FnPointer { num_args, sig, .. }), |
696 | Ty::Function(FnPointer { num_args: num_args2, sig: sig2, .. }), | 702 | Ty::Function(FnPointer { num_args: num_args2, sig: sig2, .. }), |
@@ -721,7 +727,7 @@ impl Ty { | |||
721 | fn builtin_deref(&self) -> Option<Ty> { | 727 | fn builtin_deref(&self) -> Option<Ty> { |
722 | match self { | 728 | match self { |
723 | Ty::Ref(.., parameters) => Some(Ty::clone(parameters.as_single())), | 729 | Ty::Ref(.., parameters) => Some(Ty::clone(parameters.as_single())), |
724 | Ty::RawPtr(.., parameters) => Some(Ty::clone(parameters.as_single())), | 730 | Ty::Raw(.., parameters) => Some(Ty::clone(parameters.as_single())), |
725 | _ => None, | 731 | _ => None, |
726 | } | 732 | } |
727 | } | 733 | } |
@@ -757,7 +763,7 @@ impl Ty { | |||
757 | Ty::Adt(_, substs) | 763 | Ty::Adt(_, substs) |
758 | | Ty::Slice(substs) | 764 | | Ty::Slice(substs) |
759 | | Ty::Array(substs) | 765 | | Ty::Array(substs) |
760 | | Ty::RawPtr(_, substs) | 766 | | Ty::Raw(_, substs) |
761 | | Ty::Ref(_, substs) | 767 | | Ty::Ref(_, substs) |
762 | | Ty::FnDef(_, substs) | 768 | | Ty::FnDef(_, substs) |
763 | | Ty::Function(FnPointer { substs, .. }) | 769 | | Ty::Function(FnPointer { substs, .. }) |
@@ -780,7 +786,7 @@ impl Ty { | |||
780 | Ty::Adt(_, substs) | 786 | Ty::Adt(_, substs) |
781 | | Ty::Slice(substs) | 787 | | Ty::Slice(substs) |
782 | | Ty::Array(substs) | 788 | | Ty::Array(substs) |
783 | | Ty::RawPtr(_, substs) | 789 | | Ty::Raw(_, substs) |
784 | | Ty::Ref(_, substs) | 790 | | Ty::Ref(_, substs) |
785 | | Ty::FnDef(_, substs) | 791 | | Ty::FnDef(_, substs) |
786 | | Ty::Function(FnPointer { substs, .. }) | 792 | | Ty::Function(FnPointer { substs, .. }) |
@@ -797,7 +803,7 @@ impl Ty { | |||
797 | Ty::Adt(_, substs) | 803 | Ty::Adt(_, substs) |
798 | | Ty::Slice(substs) | 804 | | Ty::Slice(substs) |
799 | | Ty::Array(substs) | 805 | | Ty::Array(substs) |
800 | | Ty::RawPtr(_, substs) | 806 | | Ty::Raw(_, substs) |
801 | | Ty::Ref(_, substs) | 807 | | Ty::Ref(_, substs) |
802 | | Ty::FnDef(_, substs) | 808 | | Ty::FnDef(_, substs) |
803 | | Ty::Function(FnPointer { substs, .. }) | 809 | | Ty::Function(FnPointer { substs, .. }) |
@@ -834,7 +840,7 @@ impl Ty { | |||
834 | OpaqueTyId::ReturnTypeImplTrait(..) => None, | 840 | OpaqueTyId::ReturnTypeImplTrait(..) => None, |
835 | } | 841 | } |
836 | } | 842 | } |
837 | Ty::Opaque(opaque_ty) => { | 843 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { |
838 | let predicates = match opaque_ty.opaque_ty_id { | 844 | let predicates = match opaque_ty.opaque_ty_id { |
839 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { | 845 | OpaqueTyId::ReturnTypeImplTrait(func, idx) => { |
840 | db.return_type_impl_traits(func).map(|it| { | 846 | db.return_type_impl_traits(func).map(|it| { |
@@ -878,7 +884,7 @@ impl Ty { | |||
878 | _ => None, | 884 | _ => None, |
879 | } | 885 | } |
880 | } | 886 | } |
881 | Ty::Projection(projection_ty) => { | 887 | Ty::Alias(AliasTy::Projection(projection_ty)) => { |
882 | match projection_ty.associated_ty.lookup(db.upcast()).container { | 888 | match projection_ty.associated_ty.lookup(db.upcast()).container { |
883 | AssocContainerId::TraitId(trait_id) => Some(trait_id), | 889 | AssocContainerId::TraitId(trait_id) => Some(trait_id), |
884 | _ => None, | 890 | _ => None, |
@@ -956,7 +962,7 @@ pub trait TypeWalk { | |||
956 | { | 962 | { |
957 | self.walk_mut_binders( | 963 | self.walk_mut_binders( |
958 | &mut |ty, binders| { | 964 | &mut |ty, binders| { |
959 | if let &mut Ty::Bound(bound) = ty { | 965 | if let &mut Ty::BoundVar(bound) = ty { |
960 | if bound.debruijn >= binders { | 966 | if bound.debruijn >= binders { |
961 | *ty = substs.0[bound.index].clone().shift_bound_vars(binders); | 967 | *ty = substs.0[bound.index].clone().shift_bound_vars(binders); |
962 | } | 968 | } |
@@ -974,8 +980,8 @@ pub trait TypeWalk { | |||
974 | { | 980 | { |
975 | self.fold_binders( | 981 | self.fold_binders( |
976 | &mut |ty, binders| match ty { | 982 | &mut |ty, binders| match ty { |
977 | Ty::Bound(bound) if bound.debruijn >= binders => { | 983 | Ty::BoundVar(bound) if bound.debruijn >= binders => { |
978 | Ty::Bound(bound.shifted_in_from(n)) | 984 | Ty::BoundVar(bound.shifted_in_from(n)) |
979 | } | 985 | } |
980 | ty => ty, | 986 | ty => ty, |
981 | }, | 987 | }, |
@@ -987,21 +993,21 @@ pub trait TypeWalk { | |||
987 | impl TypeWalk for Ty { | 993 | impl TypeWalk for Ty { |
988 | fn walk(&self, f: &mut impl FnMut(&Ty)) { | 994 | fn walk(&self, f: &mut impl FnMut(&Ty)) { |
989 | match self { | 995 | match self { |
990 | Ty::Projection(p_ty) => { | 996 | Ty::Alias(AliasTy::Projection(p_ty)) => { |
991 | for t in p_ty.parameters.iter() { | 997 | for t in p_ty.parameters.iter() { |
992 | t.walk(f); | 998 | t.walk(f); |
993 | } | 999 | } |
994 | } | 1000 | } |
1001 | Ty::Alias(AliasTy::Opaque(o_ty)) => { | ||
1002 | for t in o_ty.parameters.iter() { | ||
1003 | t.walk(f); | ||
1004 | } | ||
1005 | } | ||
995 | Ty::Dyn(predicates) => { | 1006 | Ty::Dyn(predicates) => { |
996 | for p in predicates.iter() { | 1007 | for p in predicates.iter() { |
997 | p.walk(f); | 1008 | p.walk(f); |
998 | } | 1009 | } |
999 | } | 1010 | } |
1000 | Ty::Opaque(o_ty) => { | ||
1001 | for t in o_ty.parameters.iter() { | ||
1002 | t.walk(f); | ||
1003 | } | ||
1004 | } | ||
1005 | _ => { | 1011 | _ => { |
1006 | if let Some(substs) = self.substs() { | 1012 | if let Some(substs) = self.substs() { |
1007 | for t in substs.iter() { | 1013 | for t in substs.iter() { |
@@ -1019,7 +1025,7 @@ impl TypeWalk for Ty { | |||
1019 | binders: DebruijnIndex, | 1025 | binders: DebruijnIndex, |
1020 | ) { | 1026 | ) { |
1021 | match self { | 1027 | match self { |
1022 | Ty::Projection(p_ty) => { | 1028 | Ty::Alias(AliasTy::Projection(p_ty)) => { |
1023 | p_ty.parameters.walk_mut_binders(f, binders); | 1029 | p_ty.parameters.walk_mut_binders(f, binders); |
1024 | } | 1030 | } |
1025 | Ty::Dyn(predicates) => { | 1031 | Ty::Dyn(predicates) => { |
@@ -1027,7 +1033,7 @@ impl TypeWalk for Ty { | |||
1027 | p.walk_mut_binders(f, binders.shifted_in()); | 1033 | p.walk_mut_binders(f, binders.shifted_in()); |
1028 | } | 1034 | } |
1029 | } | 1035 | } |
1030 | Ty::Opaque(o_ty) => { | 1036 | Ty::Alias(AliasTy::Opaque(o_ty)) => { |
1031 | o_ty.parameters.walk_mut_binders(f, binders); | 1037 | o_ty.parameters.walk_mut_binders(f, binders); |
1032 | } | 1038 | } |
1033 | _ => { | 1039 | _ => { |
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 44bd95a9a..ca06c9fe2 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs | |||
@@ -31,8 +31,8 @@ use crate::{ | |||
31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, | 31 | all_super_trait_refs, associated_type_by_name_including_super_traits, generics, |
32 | make_mut_slice, variant_data, | 32 | make_mut_slice, variant_data, |
33 | }, | 33 | }, |
34 | Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, OpaqueTy, | 34 | AliasTy, Binders, BoundVar, CallableSig, DebruijnIndex, FnPointer, FnSig, GenericPredicate, |
35 | OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, | 35 | OpaqueTy, OpaqueTyId, PolyFnSig, ProjectionPredicate, ProjectionTy, ReturnTypeImplTrait, |
36 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, | 36 | ReturnTypeImplTraits, Substs, TraitEnvironment, TraitRef, Ty, TypeWalk, |
37 | }; | 37 | }; |
38 | 38 | ||
@@ -157,7 +157,7 @@ impl Ty { | |||
157 | } | 157 | } |
158 | TypeRef::RawPtr(inner, mutability) => { | 158 | TypeRef::RawPtr(inner, mutability) => { |
159 | let inner_ty = Ty::from_hir(ctx, inner); | 159 | let inner_ty = Ty::from_hir(ctx, inner); |
160 | Ty::RawPtr(*mutability, Substs::single(inner_ty)) | 160 | Ty::Raw(*mutability, Substs::single(inner_ty)) |
161 | } | 161 | } |
162 | TypeRef::Array(inner) => { | 162 | TypeRef::Array(inner) => { |
163 | let inner_ty = Ty::from_hir(ctx, inner); | 163 | let inner_ty = Ty::from_hir(ctx, inner); |
@@ -181,7 +181,7 @@ impl Ty { | |||
181 | }) | 181 | }) |
182 | } | 182 | } |
183 | TypeRef::DynTrait(bounds) => { | 183 | TypeRef::DynTrait(bounds) => { |
184 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 184 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
185 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 185 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
186 | bounds | 186 | bounds |
187 | .iter() | 187 | .iter() |
@@ -225,7 +225,10 @@ impl Ty { | |||
225 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); | 225 | let impl_trait_id = OpaqueTyId::ReturnTypeImplTrait(func, idx); |
226 | let generics = generics(ctx.db.upcast(), func.into()); | 226 | let generics = generics(ctx.db.upcast(), func.into()); |
227 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); | 227 | let parameters = Substs::bound_vars(&generics, ctx.in_binders); |
228 | Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) | 228 | Ty::Alias(AliasTy::Opaque(OpaqueTy { |
229 | opaque_ty_id: impl_trait_id, | ||
230 | parameters, | ||
231 | })) | ||
229 | } | 232 | } |
230 | ImplTraitLoweringMode::Param => { | 233 | ImplTraitLoweringMode::Param => { |
231 | let idx = ctx.impl_trait_counter.get(); | 234 | let idx = ctx.impl_trait_counter.get(); |
@@ -256,7 +259,7 @@ impl Ty { | |||
256 | } else { | 259 | } else { |
257 | (0, 0, 0, 0) | 260 | (0, 0, 0, 0) |
258 | }; | 261 | }; |
259 | Ty::Bound(BoundVar::new( | 262 | Ty::BoundVar(BoundVar::new( |
260 | ctx.in_binders, | 263 | ctx.in_binders, |
261 | idx as usize + parent_params + self_params + list_params, | 264 | idx as usize + parent_params + self_params + list_params, |
262 | )) | 265 | )) |
@@ -328,7 +331,7 @@ impl Ty { | |||
328 | TypeNs::TraitId(trait_) => { | 331 | TypeNs::TraitId(trait_) => { |
329 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there | 332 | // if this is a bare dyn Trait, we'll directly put the required ^0 for the self type in there |
330 | let self_ty = if remaining_segments.len() == 0 { | 333 | let self_ty = if remaining_segments.len() == 0 { |
331 | Some(Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0))) | 334 | Some(Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0))) |
332 | } else { | 335 | } else { |
333 | None | 336 | None |
334 | }; | 337 | }; |
@@ -344,10 +347,10 @@ impl Ty { | |||
344 | match found { | 347 | match found { |
345 | Some((super_trait_ref, associated_ty)) => { | 348 | Some((super_trait_ref, associated_ty)) => { |
346 | // FIXME handle type parameters on the segment | 349 | // FIXME handle type parameters on the segment |
347 | Ty::Projection(ProjectionTy { | 350 | Ty::Alias(AliasTy::Projection(ProjectionTy { |
348 | associated_ty, | 351 | associated_ty, |
349 | parameters: super_trait_ref.substs, | 352 | parameters: super_trait_ref.substs, |
350 | }) | 353 | })) |
351 | } | 354 | } |
352 | None => { | 355 | None => { |
353 | // FIXME: report error (associated type not found) | 356 | // FIXME: report error (associated type not found) |
@@ -371,7 +374,7 @@ impl Ty { | |||
371 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 374 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
372 | TypeParamLoweringMode::Variable => { | 375 | TypeParamLoweringMode::Variable => { |
373 | let idx = generics.param_idx(param_id).expect("matching generics"); | 376 | let idx = generics.param_idx(param_id).expect("matching generics"); |
374 | Ty::Bound(BoundVar::new(ctx.in_binders, idx)) | 377 | Ty::BoundVar(BoundVar::new(ctx.in_binders, idx)) |
375 | } | 378 | } |
376 | } | 379 | } |
377 | } | 380 | } |
@@ -469,10 +472,10 @@ impl Ty { | |||
469 | // associated_type_shorthand_candidates does not do that | 472 | // associated_type_shorthand_candidates does not do that |
470 | let substs = substs.shift_bound_vars(ctx.in_binders); | 473 | let substs = substs.shift_bound_vars(ctx.in_binders); |
471 | // FIXME handle type parameters on the segment | 474 | // FIXME handle type parameters on the segment |
472 | return Some(Ty::Projection(ProjectionTy { | 475 | return Some(Ty::Alias(AliasTy::Projection(ProjectionTy { |
473 | associated_ty, | 476 | associated_ty, |
474 | parameters: substs, | 477 | parameters: substs, |
475 | })); | 478 | }))); |
476 | } | 479 | } |
477 | 480 | ||
478 | None | 481 | None |
@@ -673,7 +676,7 @@ impl GenericPredicate { | |||
673 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), | 676 | TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), |
674 | TypeParamLoweringMode::Variable => { | 677 | TypeParamLoweringMode::Variable => { |
675 | let idx = generics.param_idx(param_id).expect("matching generics"); | 678 | let idx = generics.param_idx(param_id).expect("matching generics"); |
676 | Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, idx)) | 679 | Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, idx)) |
677 | } | 680 | } |
678 | } | 681 | } |
679 | } | 682 | } |
@@ -747,7 +750,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
747 | preds.extend(GenericPredicate::from_type_bound( | 750 | preds.extend(GenericPredicate::from_type_bound( |
748 | ctx, | 751 | ctx, |
749 | bound, | 752 | bound, |
750 | Ty::Projection(projection_ty.clone()), | 753 | Ty::Alias(AliasTy::Projection(projection_ty.clone())), |
751 | )); | 754 | )); |
752 | } | 755 | } |
753 | preds | 756 | preds |
@@ -757,7 +760,7 @@ fn assoc_type_bindings_from_type_bound<'a>( | |||
757 | impl ReturnTypeImplTrait { | 760 | impl ReturnTypeImplTrait { |
758 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { | 761 | fn from_hir(ctx: &TyLoweringContext, bounds: &[TypeBound]) -> Self { |
759 | mark::hit!(lower_rpit); | 762 | mark::hit!(lower_rpit); |
760 | let self_ty = Ty::Bound(BoundVar::new(DebruijnIndex::INNERMOST, 0)); | 763 | let self_ty = Ty::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)); |
761 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { | 764 | let predicates = ctx.with_shifted_in(DebruijnIndex::ONE, |ctx| { |
762 | bounds | 765 | bounds |
763 | .iter() | 766 | .iter() |
@@ -981,7 +984,7 @@ pub(crate) fn generic_defaults_query( | |||
981 | // Each default can only refer to previous parameters. | 984 | // Each default can only refer to previous parameters. |
982 | ty.walk_mut_binders( | 985 | ty.walk_mut_binders( |
983 | &mut |ty, binders| match ty { | 986 | &mut |ty, binders| match ty { |
984 | Ty::Bound(BoundVar { debruijn, index }) if *debruijn == binders => { | 987 | Ty::BoundVar(BoundVar { debruijn, index }) if *debruijn == binders => { |
985 | if *index >= idx { | 988 | if *index >= idx { |
986 | // type variable default referring to parameter coming | 989 | // type variable default referring to parameter coming |
987 | // after it. This is forbidden (FIXME: report | 990 | // after it. This is forbidden (FIXME: report |
diff --git a/crates/hir_ty/src/method_resolution.rs b/crates/hir_ty/src/method_resolution.rs index 8b1717873..dd5109d4e 100644 --- a/crates/hir_ty/src/method_resolution.rs +++ b/crates/hir_ty/src/method_resolution.rs | |||
@@ -51,7 +51,7 @@ impl TyFingerprint { | |||
51 | &Ty::Scalar(scalar) => TyFingerprint::Scalar(scalar), | 51 | &Ty::Scalar(scalar) => TyFingerprint::Scalar(scalar), |
52 | &Ty::Adt(adt, _) => TyFingerprint::Adt(adt), | 52 | &Ty::Adt(adt, _) => TyFingerprint::Adt(adt), |
53 | &Ty::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality), | 53 | &Ty::Tuple(cardinality, _) => TyFingerprint::Tuple(cardinality), |
54 | &Ty::RawPtr(mutability, ..) => TyFingerprint::RawPtr(mutability), | 54 | &Ty::Raw(mutability, ..) => TyFingerprint::RawPtr(mutability), |
55 | &Ty::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id), | 55 | &Ty::ForeignType(alias_id, ..) => TyFingerprint::ForeignType(alias_id), |
56 | &Ty::Function(FnPointer { num_args, sig, .. }) => TyFingerprint::FnPtr(num_args, sig), | 56 | &Ty::Function(FnPointer { num_args, sig, .. }) => TyFingerprint::FnPtr(num_args, sig), |
57 | Ty::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, | 57 | Ty::Dyn(_) => ty.dyn_trait().map(|trait_| TyFingerprint::Dyn(trait_))?, |
@@ -251,8 +251,8 @@ impl Ty { | |||
251 | } | 251 | } |
252 | Ty::Str => lang_item_crate!("str_alloc", "str"), | 252 | Ty::Str => lang_item_crate!("str_alloc", "str"), |
253 | Ty::Slice(_) => lang_item_crate!("slice_alloc", "slice"), | 253 | Ty::Slice(_) => lang_item_crate!("slice_alloc", "slice"), |
254 | Ty::RawPtr(Mutability::Shared, _) => lang_item_crate!("const_ptr"), | 254 | Ty::Raw(Mutability::Shared, _) => lang_item_crate!("const_ptr"), |
255 | Ty::RawPtr(Mutability::Mut, _) => lang_item_crate!("mut_ptr"), | 255 | Ty::Raw(Mutability::Mut, _) => lang_item_crate!("mut_ptr"), |
256 | Ty::Dyn(_) => { | 256 | Ty::Dyn(_) => { |
257 | return self.dyn_trait().and_then(|trait_| { | 257 | return self.dyn_trait().and_then(|trait_| { |
258 | mod_to_crate_ids(GenericDefId::TraitId(trait_).module(db.upcast())) | 258 | mod_to_crate_ids(GenericDefId::TraitId(trait_).module(db.upcast())) |
@@ -683,7 +683,7 @@ pub(crate) fn inherent_impl_substs( | |||
683 | fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { | 683 | fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { |
684 | s.fold_binders( | 684 | s.fold_binders( |
685 | &mut |ty, binders| { | 685 | &mut |ty, binders| { |
686 | if let Ty::Bound(bound) = &ty { | 686 | if let Ty::BoundVar(bound) = &ty { |
687 | if bound.index >= num_vars_to_keep && bound.debruijn >= binders { | 687 | if bound.index >= num_vars_to_keep && bound.debruijn >= binders { |
688 | Ty::Unknown | 688 | Ty::Unknown |
689 | } else { | 689 | } else { |
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index dfa51896b..e4cdb6d53 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -129,7 +129,7 @@ pub(crate) fn trait_solve_query( | |||
129 | log::info!("trait_solve_query({})", goal.value.value.display(db)); | 129 | log::info!("trait_solve_query({})", goal.value.value.display(db)); |
130 | 130 | ||
131 | if let Obligation::Projection(pred) = &goal.value.value { | 131 | if let Obligation::Projection(pred) = &goal.value.value { |
132 | if let Ty::Bound(_) = &pred.projection_ty.parameters[0] { | 132 | if let Ty::BoundVar(_) = &pred.projection_ty.parameters[0] { |
133 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible | 133 | // Hack: don't ask Chalk to normalize with an unknown self type, it'll say that's impossible |
134 | return Some(Solution::Ambig(Guidance::Unknown)); | 134 | return Some(Solution::Ambig(Guidance::Unknown)); |
135 | } | 135 | } |
diff --git a/crates/hir_ty/src/traits/chalk.rs b/crates/hir_ty/src/traits/chalk.rs index 3f5f5091f..e513fa8f4 100644 --- a/crates/hir_ty/src/traits/chalk.rs +++ b/crates/hir_ty/src/traits/chalk.rs | |||
@@ -90,7 +90,7 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
90 | ty: &Ty, | 90 | ty: &Ty, |
91 | binders: &CanonicalVarKinds<Interner>, | 91 | binders: &CanonicalVarKinds<Interner>, |
92 | ) -> Option<chalk_ir::TyVariableKind> { | 92 | ) -> Option<chalk_ir::TyVariableKind> { |
93 | if let Ty::Bound(bv) = ty { | 93 | if let Ty::BoundVar(bv) = ty { |
94 | let binders = binders.as_slice(&Interner); | 94 | let binders = binders.as_slice(&Interner); |
95 | if bv.debruijn == DebruijnIndex::INNERMOST { | 95 | if bv.debruijn == DebruijnIndex::INNERMOST { |
96 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { | 96 | if let chalk_ir::VariableKind::Ty(tk) = binders[bv.index].kind { |
@@ -220,18 +220,18 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> { | |||
220 | let impl_bound = GenericPredicate::Implemented(TraitRef { | 220 | let impl_bound = GenericPredicate::Implemented(TraitRef { |
221 | trait_: future_trait, | 221 | trait_: future_trait, |
222 | // Self type as the first parameter. | 222 | // Self type as the first parameter. |
223 | substs: Substs::single(Ty::Bound(BoundVar { | 223 | substs: Substs::single(Ty::BoundVar(BoundVar { |
224 | debruijn: DebruijnIndex::INNERMOST, | 224 | debruijn: DebruijnIndex::INNERMOST, |
225 | index: 0, | 225 | index: 0, |
226 | })), | 226 | })), |
227 | }); | 227 | }); |
228 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { | 228 | let proj_bound = GenericPredicate::Projection(ProjectionPredicate { |
229 | // The parameter of the opaque type. | 229 | // The parameter of the opaque type. |
230 | ty: Ty::Bound(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }), | 230 | ty: Ty::BoundVar(BoundVar { debruijn: DebruijnIndex::ONE, index: 0 }), |
231 | projection_ty: ProjectionTy { | 231 | projection_ty: ProjectionTy { |
232 | associated_ty: future_output, | 232 | associated_ty: future_output, |
233 | // Self type as the first parameter. | 233 | // Self type as the first parameter. |
234 | parameters: Substs::single(Ty::Bound(BoundVar::new( | 234 | parameters: Substs::single(Ty::BoundVar(BoundVar::new( |
235 | DebruijnIndex::INNERMOST, | 235 | DebruijnIndex::INNERMOST, |
236 | 0, | 236 | 0, |
237 | ))), | 237 | ))), |
@@ -392,7 +392,7 @@ pub(crate) fn associated_ty_data_query( | |||
392 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); | 392 | let resolver = hir_def::resolver::HasResolver::resolver(type_alias, db.upcast()); |
393 | let ctx = crate::TyLoweringContext::new(db, &resolver) | 393 | let ctx = crate::TyLoweringContext::new(db, &resolver) |
394 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); | 394 | .with_type_param_mode(crate::lower::TypeParamLoweringMode::Variable); |
395 | let self_ty = Ty::Bound(crate::BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)); | 395 | let self_ty = Ty::BoundVar(crate::BoundVar::new(crate::DebruijnIndex::INNERMOST, 0)); |
396 | let bounds = type_alias_data | 396 | let bounds = type_alias_data |
397 | .bounds | 397 | .bounds |
398 | .iter() | 398 | .iter() |
diff --git a/crates/hir_ty/src/traits/chalk/mapping.rs b/crates/hir_ty/src/traits/chalk/mapping.rs index 995ff6a9a..6e6055d80 100644 --- a/crates/hir_ty/src/traits/chalk/mapping.rs +++ b/crates/hir_ty/src/traits/chalk/mapping.rs | |||
@@ -16,8 +16,8 @@ use crate::{ | |||
16 | db::HirDatabase, | 16 | db::HirDatabase, |
17 | primitive::UintTy, | 17 | primitive::UintTy, |
18 | traits::{Canonical, Obligation}, | 18 | traits::{Canonical, Obligation}, |
19 | CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, OpaqueTyId, | 19 | AliasTy, CallableDefId, FnPointer, FnSig, GenericPredicate, InEnvironment, OpaqueTy, |
20 | ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty, | 20 | OpaqueTyId, ProjectionPredicate, ProjectionTy, Scalar, Substs, TraitEnvironment, TraitRef, Ty, |
21 | }; | 21 | }; |
22 | 22 | ||
23 | use super::interner::*; | 23 | use super::interner::*; |
@@ -63,7 +63,7 @@ impl ToChalk for Ty { | |||
63 | let substitution = substs.to_chalk(db); | 63 | let substitution = substs.to_chalk(db); |
64 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) | 64 | chalk_ir::TyKind::Tuple(cardinality.into(), substitution).intern(&Interner) |
65 | } | 65 | } |
66 | Ty::RawPtr(mutability, substs) => { | 66 | Ty::Raw(mutability, substs) => { |
67 | let ty = substs[0].clone().to_chalk(db); | 67 | let ty = substs[0].clone().to_chalk(db); |
68 | chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) | 68 | chalk_ir::TyKind::Raw(mutability.to_chalk(db), ty).intern(&Interner) |
69 | } | 69 | } |
@@ -88,7 +88,7 @@ impl ToChalk for Ty { | |||
88 | let substitution = substs.to_chalk(db); | 88 | let substitution = substs.to_chalk(db); |
89 | chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) | 89 | chalk_ir::TyKind::Adt(chalk_ir::AdtId(adt_id), substitution).intern(&Interner) |
90 | } | 90 | } |
91 | Ty::Projection(proj_ty) => { | 91 | Ty::Alias(AliasTy::Projection(proj_ty)) => { |
92 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); | 92 | let associated_ty_id = TypeAliasAsAssocType(proj_ty.associated_ty).to_chalk(db); |
93 | let substitution = proj_ty.parameters.to_chalk(db); | 93 | let substitution = proj_ty.parameters.to_chalk(db); |
94 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { | 94 | chalk_ir::AliasTy::Projection(chalk_ir::ProjectionTy { |
@@ -106,7 +106,7 @@ impl ToChalk for Ty { | |||
106 | } | 106 | } |
107 | .to_ty::<Interner>(&Interner) | 107 | .to_ty::<Interner>(&Interner) |
108 | } | 108 | } |
109 | Ty::Bound(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), | 109 | Ty::BoundVar(idx) => chalk_ir::TyKind::BoundVar(idx).intern(&Interner), |
110 | Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), | 110 | Ty::InferenceVar(..) => panic!("uncanonicalized infer ty"), |
111 | Ty::Dyn(predicates) => { | 111 | Ty::Dyn(predicates) => { |
112 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( | 112 | let where_clauses = chalk_ir::QuantifiedWhereClauses::from_iter( |
@@ -119,7 +119,7 @@ impl ToChalk for Ty { | |||
119 | }; | 119 | }; |
120 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) | 120 | chalk_ir::TyKind::Dyn(bounded_ty).intern(&Interner) |
121 | } | 121 | } |
122 | Ty::Opaque(opaque_ty) => { | 122 | Ty::Alias(AliasTy::Opaque(opaque_ty)) => { |
123 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); | 123 | let opaque_ty_id = opaque_ty.opaque_ty_id.to_chalk(db); |
124 | let substitution = opaque_ty.parameters.to_chalk(db); | 124 | let substitution = opaque_ty.parameters.to_chalk(db); |
125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { | 125 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(chalk_ir::OpaqueTy { |
@@ -146,12 +146,12 @@ impl ToChalk for Ty { | |||
146 | let associated_ty = | 146 | let associated_ty = |
147 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; | 147 | from_chalk::<TypeAliasAsAssocType, _>(db, proj.associated_ty_id).0; |
148 | let parameters = from_chalk(db, proj.substitution); | 148 | let parameters = from_chalk(db, proj.substitution); |
149 | Ty::Projection(ProjectionTy { associated_ty, parameters }) | 149 | Ty::Alias(AliasTy::Projection(ProjectionTy { associated_ty, parameters })) |
150 | } | 150 | } |
151 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { | 151 | chalk_ir::TyKind::Alias(chalk_ir::AliasTy::Opaque(opaque_ty)) => { |
152 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); | 152 | let impl_trait_id = from_chalk(db, opaque_ty.opaque_ty_id); |
153 | let parameters = from_chalk(db, opaque_ty.substitution); | 153 | let parameters = from_chalk(db, opaque_ty.substitution); |
154 | Ty::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters }) | 154 | Ty::Alias(AliasTy::Opaque(OpaqueTy { opaque_ty_id: impl_trait_id, parameters })) |
155 | } | 155 | } |
156 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { | 156 | chalk_ir::TyKind::Function(chalk_ir::FnPointer { |
157 | num_binders, | 157 | num_binders, |
@@ -170,7 +170,7 @@ impl ToChalk for Ty { | |||
170 | substs, | 170 | substs, |
171 | }) | 171 | }) |
172 | } | 172 | } |
173 | chalk_ir::TyKind::BoundVar(idx) => Ty::Bound(idx), | 173 | chalk_ir::TyKind::BoundVar(idx) => Ty::BoundVar(idx), |
174 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, | 174 | chalk_ir::TyKind::InferenceVar(_iv, _kind) => Ty::Unknown, |
175 | chalk_ir::TyKind::Dyn(where_clauses) => { | 175 | chalk_ir::TyKind::Dyn(where_clauses) => { |
176 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); | 176 | assert_eq!(where_clauses.bounds.binders.len(&Interner), 1); |
@@ -198,7 +198,7 @@ impl ToChalk for Ty { | |||
198 | Ty::Tuple(cardinality, from_chalk(db, subst)) | 198 | Ty::Tuple(cardinality, from_chalk(db, subst)) |
199 | } | 199 | } |
200 | chalk_ir::TyKind::Raw(mutability, ty) => { | 200 | chalk_ir::TyKind::Raw(mutability, ty) => { |
201 | Ty::RawPtr(from_chalk(db, mutability), Substs::single(from_chalk(db, ty))) | 201 | Ty::Raw(from_chalk(db, mutability), Substs::single(from_chalk(db, ty))) |
202 | } | 202 | } |
203 | chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), | 203 | chalk_ir::TyKind::Slice(ty) => Ty::Slice(Substs::single(from_chalk(db, ty))), |
204 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { | 204 | chalk_ir::TyKind::Ref(mutability, _lifetime, ty) => { |