aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty.rs')
-rw-r--r--crates/ra_hir/src/ty.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 0bb716569..1d9e7b76c 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -21,7 +21,7 @@ pub(crate) use infer::{infer, InferenceResult, InferTy};
21use display::{HirDisplay, HirFormatter}; 21use display::{HirDisplay, HirFormatter};
22 22
23#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] 23#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
24pub enum TypeName { 24pub enum TypeCtor {
25 /// The primitive boolean type. Written as `bool`. 25 /// The primitive boolean type. Written as `bool`.
26 Bool, 26 Bool,
27 27
@@ -87,7 +87,7 @@ pub enum TypeName {
87 87
88#[derive(Clone, PartialEq, Eq, Debug)] 88#[derive(Clone, PartialEq, Eq, Debug)]
89pub struct ApplicationTy { 89pub struct ApplicationTy {
90 pub name: TypeName, 90 pub name: TypeCtor,
91 pub parameters: Substs, 91 pub parameters: Substs,
92} 92}
93 93
@@ -191,17 +191,17 @@ impl FnSig {
191} 191}
192 192
193impl Ty { 193impl Ty {
194 pub fn simple(name: TypeName) -> Ty { 194 pub fn simple(name: TypeCtor) -> Ty {
195 Ty::Apply(ApplicationTy { name, parameters: Substs::empty() }) 195 Ty::Apply(ApplicationTy { name, parameters: Substs::empty() })
196 } 196 }
197 pub fn apply_one(name: TypeName, param: Ty) -> Ty { 197 pub fn apply_one(name: TypeCtor, param: Ty) -> Ty {
198 Ty::Apply(ApplicationTy { name, parameters: Substs::single(param) }) 198 Ty::Apply(ApplicationTy { name, parameters: Substs::single(param) })
199 } 199 }
200 pub fn apply(name: TypeName, parameters: Substs) -> Ty { 200 pub fn apply(name: TypeCtor, parameters: Substs) -> Ty {
201 Ty::Apply(ApplicationTy { name, parameters }) 201 Ty::Apply(ApplicationTy { name, parameters })
202 } 202 }
203 pub fn unit() -> Self { 203 pub fn unit() -> Self {
204 Ty::apply(TypeName::Tuple, Substs::empty()) 204 Ty::apply(TypeCtor::Tuple, Substs::empty())
205 } 205 }
206 206
207 pub fn walk(&self, f: &mut impl FnMut(&Ty)) { 207 pub fn walk(&self, f: &mut impl FnMut(&Ty)) {
@@ -236,7 +236,7 @@ impl Ty {
236 236
237 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> { 237 pub fn as_reference(&self) -> Option<(&Ty, Mutability)> {
238 match self { 238 match self {
239 Ty::Apply(ApplicationTy { name: TypeName::Ref(mutability), parameters }) => { 239 Ty::Apply(ApplicationTy { name: TypeCtor::Ref(mutability), parameters }) => {
240 Some((parameters.as_single(), *mutability)) 240 Some((parameters.as_single(), *mutability))
241 } 241 }
242 _ => None, 242 _ => None,
@@ -245,7 +245,7 @@ impl Ty {
245 245
246 pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> { 246 pub fn as_adt(&self) -> Option<(AdtDef, &Substs)> {
247 match self { 247 match self {
248 Ty::Apply(ApplicationTy { name: TypeName::Adt(adt_def), parameters }) => { 248 Ty::Apply(ApplicationTy { name: TypeCtor::Adt(adt_def), parameters }) => {
249 Some((*adt_def, parameters)) 249 Some((*adt_def, parameters))
250 } 250 }
251 _ => None, 251 _ => None,
@@ -254,7 +254,7 @@ impl Ty {
254 254
255 pub fn as_tuple(&self) -> Option<&Substs> { 255 pub fn as_tuple(&self) -> Option<&Substs> {
256 match self { 256 match self {
257 Ty::Apply(ApplicationTy { name: TypeName::Tuple, parameters }) => Some(parameters), 257 Ty::Apply(ApplicationTy { name: TypeCtor::Tuple, parameters }) => Some(parameters),
258 _ => None, 258 _ => None,
259 } 259 }
260 } 260 }
@@ -262,8 +262,8 @@ impl Ty {
262 fn builtin_deref(&self) -> Option<Ty> { 262 fn builtin_deref(&self) -> Option<Ty> {
263 match self { 263 match self {
264 Ty::Apply(a_ty) => match a_ty.name { 264 Ty::Apply(a_ty) => match a_ty.name {
265 TypeName::Ref(..) => Some(Ty::clone(a_ty.parameters.as_single())), 265 TypeCtor::Ref(..) => Some(Ty::clone(a_ty.parameters.as_single())),
266 TypeName::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())), 266 TypeCtor::RawPtr(..) => Some(Ty::clone(a_ty.parameters.as_single())),
267 _ => None, 267 _ => None,
268 }, 268 },
269 _ => None, 269 _ => None,
@@ -318,25 +318,25 @@ impl HirDisplay for &Ty {
318impl HirDisplay for ApplicationTy { 318impl HirDisplay for ApplicationTy {
319 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result { 319 fn hir_fmt(&self, f: &mut HirFormatter<impl HirDatabase>) -> fmt::Result {
320 match self.name { 320 match self.name {
321 TypeName::Bool => write!(f, "bool")?, 321 TypeCtor::Bool => write!(f, "bool")?,
322 TypeName::Char => write!(f, "char")?, 322 TypeCtor::Char => write!(f, "char")?,
323 TypeName::Int(t) => write!(f, "{}", t)?, 323 TypeCtor::Int(t) => write!(f, "{}", t)?,
324 TypeName::Float(t) => write!(f, "{}", t)?, 324 TypeCtor::Float(t) => write!(f, "{}", t)?,
325 TypeName::Str => write!(f, "str")?, 325 TypeCtor::Str => write!(f, "str")?,
326 TypeName::Slice | TypeName::Array => { 326 TypeCtor::Slice | TypeCtor::Array => {
327 let t = self.parameters.as_single(); 327 let t = self.parameters.as_single();
328 write!(f, "[{}]", t.display(f.db))?; 328 write!(f, "[{}]", t.display(f.db))?;
329 } 329 }
330 TypeName::RawPtr(m) => { 330 TypeCtor::RawPtr(m) => {
331 let t = self.parameters.as_single(); 331 let t = self.parameters.as_single();
332 write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?; 332 write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?;
333 } 333 }
334 TypeName::Ref(m) => { 334 TypeCtor::Ref(m) => {
335 let t = self.parameters.as_single(); 335 let t = self.parameters.as_single();
336 write!(f, "&{}{}", m.as_keyword_for_ref(), t.display(f.db))?; 336 write!(f, "&{}{}", m.as_keyword_for_ref(), t.display(f.db))?;
337 } 337 }
338 TypeName::Never => write!(f, "!")?, 338 TypeCtor::Never => write!(f, "!")?,
339 TypeName::Tuple => { 339 TypeCtor::Tuple => {
340 let ts = &self.parameters; 340 let ts = &self.parameters;
341 if ts.0.len() == 1 { 341 if ts.0.len() == 1 {
342 write!(f, "({},)", ts.0[0].display(f.db))?; 342 write!(f, "({},)", ts.0[0].display(f.db))?;
@@ -346,13 +346,13 @@ impl HirDisplay for ApplicationTy {
346 write!(f, ")")?; 346 write!(f, ")")?;
347 } 347 }
348 } 348 }
349 TypeName::FnPtr => { 349 TypeCtor::FnPtr => {
350 let sig = FnSig::from_fn_ptr_substs(&self.parameters); 350 let sig = FnSig::from_fn_ptr_substs(&self.parameters);
351 write!(f, "fn(")?; 351 write!(f, "fn(")?;
352 f.write_joined(sig.params(), ", ")?; 352 f.write_joined(sig.params(), ", ")?;
353 write!(f, ") -> {}", sig.ret().display(f.db))?; 353 write!(f, ") -> {}", sig.ret().display(f.db))?;
354 } 354 }
355 TypeName::FnDef(def) => { 355 TypeCtor::FnDef(def) => {
356 let sig = f.db.callable_item_signature(def); 356 let sig = f.db.callable_item_signature(def);
357 let name = match def { 357 let name = match def {
358 CallableDef::Function(ff) => ff.name(f.db), 358 CallableDef::Function(ff) => ff.name(f.db),
@@ -372,7 +372,7 @@ impl HirDisplay for ApplicationTy {
372 f.write_joined(sig.params(), ", ")?; 372 f.write_joined(sig.params(), ", ")?;
373 write!(f, ") -> {}", sig.ret().display(f.db))?; 373 write!(f, ") -> {}", sig.ret().display(f.db))?;
374 } 374 }
375 TypeName::Adt(def_id) => { 375 TypeCtor::Adt(def_id) => {
376 let name = match def_id { 376 let name = match def_id {
377 AdtDef::Struct(s) => s.name(f.db), 377 AdtDef::Struct(s) => s.name(f.db),
378 AdtDef::Enum(e) => e.name(f.db), 378 AdtDef::Enum(e) => e.name(f.db),