aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-05-01 15:48:05 +0100
committerFlorian Diebold <[email protected]>2019-05-04 17:18:30 +0100
commit99492278ac8c8a9caf3981b4406dcac6724a6a93 (patch)
tree8ce60ceed908065c416d707942b2c4452ab8f0be /crates/ra_hir/src
parent6c3ee834d6452c5caa244c3c58504992de38baa4 (diff)
Implement Deref<Target=[Ty]> for Substs
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ty.rs35
-rw-r--r--crates/ra_hir/src/ty/infer/unify.rs1
2 files changed, 18 insertions, 18 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 538148956..e7c39487d 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -13,6 +13,7 @@ mod infer;
13pub(crate) mod display; 13pub(crate) mod display;
14 14
15use std::sync::Arc; 15use std::sync::Arc;
16use std::ops::Deref;
16use std::{fmt, mem}; 17use std::{fmt, mem};
17 18
18use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams}; 19use crate::{Name, AdtDef, type_ref::Mutability, db::HirDatabase, Trait, GenericParams};
@@ -155,14 +156,6 @@ impl Substs {
155 Substs(self.0.iter().cloned().take(n).collect::<Vec<_>>().into()) 156 Substs(self.0.iter().cloned().take(n).collect::<Vec<_>>().into())
156 } 157 }
157 158
158 pub fn iter(&self) -> impl Iterator<Item = &Ty> {
159 self.0.iter()
160 }
161
162 pub fn len(&self) -> usize {
163 self.0.len()
164 }
165
166 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) { 159 pub fn walk_mut(&mut self, f: &mut impl FnMut(&mut Ty)) {
167 // Without an Arc::make_mut_slice, we can't avoid the clone here: 160 // Without an Arc::make_mut_slice, we can't avoid the clone here:
168 let mut v: Vec<_> = self.0.iter().cloned().collect(); 161 let mut v: Vec<_> = self.0.iter().cloned().collect();
@@ -210,6 +203,14 @@ impl From<Vec<Ty>> for Substs {
210 } 203 }
211} 204}
212 205
206impl Deref for Substs {
207 type Target = [Ty];
208
209 fn deref(&self) -> &[Ty] {
210 &self.0
211 }
212}
213
213/// A trait with type parameters. This includes the `Self`, so this represents a concrete type implementing the trait. 214/// A trait with type parameters. This includes the `Self`, so this represents a concrete type implementing the trait.
214/// Name to be bikeshedded: TraitBound? TraitImplements? 215/// Name to be bikeshedded: TraitBound? TraitImplements?
215#[derive(Clone, PartialEq, Eq, Debug, Hash)] 216#[derive(Clone, PartialEq, Eq, Debug, Hash)]
@@ -221,7 +222,7 @@ pub struct TraitRef {
221 222
222impl TraitRef { 223impl TraitRef {
223 pub fn self_ty(&self) -> &Ty { 224 pub fn self_ty(&self) -> &Ty {
224 &self.substs.0[0] 225 &self.substs[0]
225 } 226 }
226 227
227 pub fn subst(mut self, substs: &Substs) -> TraitRef { 228 pub fn subst(mut self, substs: &Substs) -> TraitRef {
@@ -399,8 +400,8 @@ impl Ty {
399 pub fn subst(self, substs: &Substs) -> Ty { 400 pub fn subst(self, substs: &Substs) -> Ty {
400 self.fold(&mut |ty| match ty { 401 self.fold(&mut |ty| match ty {
401 Ty::Param { idx, name } => { 402 Ty::Param { idx, name } => {
402 if (idx as usize) < substs.0.len() { 403 if (idx as usize) < substs.len() {
403 substs.0[idx as usize].clone() 404 substs[idx as usize].clone()
404 } else { 405 } else {
405 Ty::Param { idx, name } 406 Ty::Param { idx, name }
406 } 407 }
@@ -413,8 +414,8 @@ impl Ty {
413 pub fn subst_bound_vars(self, substs: &Substs) -> Ty { 414 pub fn subst_bound_vars(self, substs: &Substs) -> Ty {
414 self.fold(&mut |ty| match ty { 415 self.fold(&mut |ty| match ty {
415 Ty::Bound(idx) => { 416 Ty::Bound(idx) => {
416 if (idx as usize) < substs.0.len() { 417 if (idx as usize) < substs.len() {
417 substs.0[idx as usize].clone() 418 substs[idx as usize].clone()
418 } else { 419 } else {
419 Ty::Bound(idx) 420 Ty::Bound(idx)
420 } 421 }
@@ -466,8 +467,8 @@ impl HirDisplay for ApplicationTy {
466 TypeCtor::Never => write!(f, "!")?, 467 TypeCtor::Never => write!(f, "!")?,
467 TypeCtor::Tuple => { 468 TypeCtor::Tuple => {
468 let ts = &self.parameters; 469 let ts = &self.parameters;
469 if ts.0.len() == 1 { 470 if ts.len() == 1 {
470 write!(f, "({},)", ts.0[0].display(f.db))?; 471 write!(f, "({},)", ts[0].display(f.db))?;
471 } else { 472 } else {
472 write!(f, "(")?; 473 write!(f, "(")?;
473 f.write_joined(&*ts.0, ", ")?; 474 f.write_joined(&*ts.0, ", ")?;
@@ -491,7 +492,7 @@ impl HirDisplay for ApplicationTy {
491 CallableDef::Function(_) => write!(f, "fn {}", name)?, 492 CallableDef::Function(_) => write!(f, "fn {}", name)?,
492 CallableDef::Struct(_) | CallableDef::EnumVariant(_) => write!(f, "{}", name)?, 493 CallableDef::Struct(_) | CallableDef::EnumVariant(_) => write!(f, "{}", name)?,
493 } 494 }
494 if self.parameters.0.len() > 0 { 495 if self.parameters.len() > 0 {
495 write!(f, "<")?; 496 write!(f, "<")?;
496 f.write_joined(&*self.parameters.0, ", ")?; 497 f.write_joined(&*self.parameters.0, ", ")?;
497 write!(f, ">")?; 498 write!(f, ">")?;
@@ -507,7 +508,7 @@ impl HirDisplay for ApplicationTy {
507 } 508 }
508 .unwrap_or_else(Name::missing); 509 .unwrap_or_else(Name::missing);
509 write!(f, "{}", name)?; 510 write!(f, "{}", name)?;
510 if self.parameters.0.len() > 0 { 511 if self.parameters.len() > 0 {
511 write!(f, "<")?; 512 write!(f, "<")?;
512 f.write_joined(&*self.parameters.0, ", ")?; 513 f.write_joined(&*self.parameters.0, ", ")?;
513 write!(f, ">")?; 514 write!(f, ">")?;
diff --git a/crates/ra_hir/src/ty/infer/unify.rs b/crates/ra_hir/src/ty/infer/unify.rs
index 7918b007b..5edb95c31 100644
--- a/crates/ra_hir/src/ty/infer/unify.rs
+++ b/crates/ra_hir/src/ty/infer/unify.rs
@@ -61,7 +61,6 @@ where
61 pub fn canonicalize_trait_ref(&mut self, trait_ref: TraitRef) -> Canonical<TraitRef> { 61 pub fn canonicalize_trait_ref(&mut self, trait_ref: TraitRef) -> Canonical<TraitRef> {
62 let substs = trait_ref 62 let substs = trait_ref
63 .substs 63 .substs
64 .0
65 .iter() 64 .iter()
66 .map(|ty| self.canonicalize_ty(ty.clone()).value) 65 .map(|ty| self.canonicalize_ty(ty.clone()).value)
67 .collect::<Vec<_>>(); 66 .collect::<Vec<_>>();