aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/type_ref.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/type_ref.rs')
-rw-r--r--crates/hir_def/src/type_ref.rs18
1 files changed, 11 insertions, 7 deletions
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index 9e44547cb..cbde6b940 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -5,7 +5,7 @@ use hir_expand::{name::Name, AstId, InFile};
5use std::convert::TryInto; 5use std::convert::TryInto;
6use syntax::ast; 6use syntax::ast;
7 7
8use crate::{body::LowerCtx, path::Path}; 8use crate::{body::LowerCtx, intern::Interned, path::Path};
9 9
10#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] 10#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
11pub enum Mutability { 11pub enum Mutability {
@@ -72,6 +72,10 @@ impl TraitRef {
72} 72}
73 73
74/// Compare ty::Ty 74/// Compare ty::Ty
75///
76/// Note: Most users of `TypeRef` that end up in the salsa database intern it using
77/// `Interned<TypeRef>` to save space. But notably, nested `TypeRef`s are not interned, since that
78/// does not seem to save any noticeable amount of memory.
75#[derive(Clone, PartialEq, Eq, Hash, Debug)] 79#[derive(Clone, PartialEq, Eq, Hash, Debug)]
76pub enum TypeRef { 80pub enum TypeRef {
77 Never, 81 Never,
@@ -87,8 +91,8 @@ pub enum TypeRef {
87 /// A fn pointer. Last element of the vector is the return type. 91 /// A fn pointer. Last element of the vector is the return type.
88 Fn(Vec<TypeRef>, bool /*varargs*/), 92 Fn(Vec<TypeRef>, bool /*varargs*/),
89 // For 93 // For
90 ImplTrait(Vec<TypeBound>), 94 ImplTrait(Vec<Interned<TypeBound>>),
91 DynTrait(Vec<TypeBound>), 95 DynTrait(Vec<Interned<TypeBound>>),
92 Macro(AstId<ast::MacroCall>), 96 Macro(AstId<ast::MacroCall>),
93 Error, 97 Error,
94} 98}
@@ -228,7 +232,7 @@ impl TypeRef {
228 | TypeRef::Slice(type_ref) => go(&type_ref, f), 232 | TypeRef::Slice(type_ref) => go(&type_ref, f),
229 TypeRef::ImplTrait(bounds) | TypeRef::DynTrait(bounds) => { 233 TypeRef::ImplTrait(bounds) | TypeRef::DynTrait(bounds) => {
230 for bound in bounds { 234 for bound in bounds {
231 match bound { 235 match bound.as_ref() {
232 TypeBound::Path(path) => go_path(path, f), 236 TypeBound::Path(path) => go_path(path, f),
233 TypeBound::Lifetime(_) | TypeBound::Error => (), 237 TypeBound::Lifetime(_) | TypeBound::Error => (),
234 } 238 }
@@ -258,7 +262,7 @@ impl TypeRef {
258 go(type_ref, f); 262 go(type_ref, f);
259 } 263 }
260 for bound in &binding.bounds { 264 for bound in &binding.bounds {
261 match bound { 265 match bound.as_ref() {
262 TypeBound::Path(path) => go_path(path, f), 266 TypeBound::Path(path) => go_path(path, f),
263 TypeBound::Lifetime(_) | TypeBound::Error => (), 267 TypeBound::Lifetime(_) | TypeBound::Error => (),
264 } 268 }
@@ -273,9 +277,9 @@ impl TypeRef {
273pub(crate) fn type_bounds_from_ast( 277pub(crate) fn type_bounds_from_ast(
274 lower_ctx: &LowerCtx, 278 lower_ctx: &LowerCtx,
275 type_bounds_opt: Option<ast::TypeBoundList>, 279 type_bounds_opt: Option<ast::TypeBoundList>,
276) -> Vec<TypeBound> { 280) -> Vec<Interned<TypeBound>> {
277 if let Some(type_bounds) = type_bounds_opt { 281 if let Some(type_bounds) = type_bounds_opt {
278 type_bounds.bounds().map(|it| TypeBound::from_ast(lower_ctx, it)).collect() 282 type_bounds.bounds().map(|it| Interned::new(TypeBound::from_ast(lower_ctx, it))).collect()
279 } else { 283 } else {
280 vec![] 284 vec![]
281 } 285 }