diff options
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/adt.rs | 57 | ||||
-rw-r--r-- | crates/ra_hir_def/src/attr.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 6 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 71 | ||||
-rw-r--r-- | crates/ra_hir_def/src/data.rs | 18 | ||||
-rw-r--r-- | crates/ra_hir_def/src/diagnostics.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/expr.rs | 33 | ||||
-rw-r--r-- | crates/ra_hir_def/src/lang_item.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/raw.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/type_ref.rs | 4 |
10 files changed, 112 insertions, 91 deletions
diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 7fc4cd76e..be4b0accb 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs | |||
@@ -4,6 +4,7 @@ use std::sync::Arc; | |||
4 | 4 | ||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir_expand::{ | 6 | use hir_expand::{ |
7 | hygiene::Hygiene, | ||
7 | name::{AsName, Name}, | 8 | name::{AsName, Name}, |
8 | InFile, | 9 | InFile, |
9 | }; | 10 | }; |
@@ -12,9 +13,9 @@ use ra_prof::profile; | |||
12 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; | 13 | use ra_syntax::ast::{self, NameOwner, TypeAscriptionOwner, VisibilityOwner}; |
13 | 14 | ||
14 | use crate::{ | 15 | use crate::{ |
15 | db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, type_ref::TypeRef, | 16 | attr::Attrs, db::DefDatabase, src::HasChildSource, src::HasSource, trace::Trace, |
16 | visibility::RawVisibility, EnumId, LocalEnumVariantId, LocalStructFieldId, Lookup, StructId, | 17 | type_ref::TypeRef, visibility::RawVisibility, EnumId, HasModule, LocalEnumVariantId, |
17 | UnionId, VariantId, | 18 | LocalStructFieldId, Lookup, ModuleId, StructId, UnionId, VariantId, |
18 | }; | 19 | }; |
19 | 20 | ||
20 | /// Note that we use `StructData` for unions as well! | 21 | /// Note that we use `StructData` for unions as well! |
@@ -56,7 +57,8 @@ impl StructData { | |||
56 | let src = id.lookup(db).source(db); | 57 | let src = id.lookup(db).source(db); |
57 | 58 | ||
58 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 59 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
59 | let variant_data = VariantData::new(db, src.map(|s| s.kind())); | 60 | let variant_data = |
61 | VariantData::new(db, src.map(|s| s.kind()), id.lookup(db).container.module(db)); | ||
60 | let variant_data = Arc::new(variant_data); | 62 | let variant_data = Arc::new(variant_data); |
61 | Arc::new(StructData { name, variant_data }) | 63 | Arc::new(StructData { name, variant_data }) |
62 | } | 64 | } |
@@ -70,6 +72,7 @@ impl StructData { | |||
70 | .map(ast::StructKind::Record) | 72 | .map(ast::StructKind::Record) |
71 | .unwrap_or(ast::StructKind::Unit) | 73 | .unwrap_or(ast::StructKind::Unit) |
72 | }), | 74 | }), |
75 | id.lookup(db).container.module(db), | ||
73 | ); | 76 | ); |
74 | let variant_data = Arc::new(variant_data); | 77 | let variant_data = Arc::new(variant_data); |
75 | Arc::new(StructData { name, variant_data }) | 78 | Arc::new(StructData { name, variant_data }) |
@@ -82,7 +85,7 @@ impl EnumData { | |||
82 | let src = e.lookup(db).source(db); | 85 | let src = e.lookup(db).source(db); |
83 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 86 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
84 | let mut trace = Trace::new_for_arena(); | 87 | let mut trace = Trace::new_for_arena(); |
85 | lower_enum(db, &mut trace, &src); | 88 | lower_enum(db, &mut trace, &src, e.lookup(db).container.module(db)); |
86 | Arc::new(EnumData { name, variants: trace.into_arena() }) | 89 | Arc::new(EnumData { name, variants: trace.into_arena() }) |
87 | } | 90 | } |
88 | 91 | ||
@@ -98,7 +101,7 @@ impl HasChildSource for EnumId { | |||
98 | fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { | 101 | fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { |
99 | let src = self.lookup(db).source(db); | 102 | let src = self.lookup(db).source(db); |
100 | let mut trace = Trace::new_for_map(); | 103 | let mut trace = Trace::new_for_map(); |
101 | lower_enum(db, &mut trace, &src); | 104 | lower_enum(db, &mut trace, &src, self.lookup(db).container.module(db)); |
102 | src.with_value(trace.into_map()) | 105 | src.with_value(trace.into_map()) |
103 | } | 106 | } |
104 | } | 107 | } |
@@ -107,22 +110,23 @@ fn lower_enum( | |||
107 | db: &dyn DefDatabase, | 110 | db: &dyn DefDatabase, |
108 | trace: &mut Trace<EnumVariantData, ast::EnumVariant>, | 111 | trace: &mut Trace<EnumVariantData, ast::EnumVariant>, |
109 | ast: &InFile<ast::EnumDef>, | 112 | ast: &InFile<ast::EnumDef>, |
113 | module_id: ModuleId, | ||
110 | ) { | 114 | ) { |
111 | for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) { | 115 | for var in ast.value.variant_list().into_iter().flat_map(|it| it.variants()) { |
112 | trace.alloc( | 116 | trace.alloc( |
113 | || var.clone(), | 117 | || var.clone(), |
114 | || EnumVariantData { | 118 | || EnumVariantData { |
115 | name: var.name().map_or_else(Name::missing, |it| it.as_name()), | 119 | name: var.name().map_or_else(Name::missing, |it| it.as_name()), |
116 | variant_data: Arc::new(VariantData::new(db, ast.with_value(var.kind()))), | 120 | variant_data: Arc::new(VariantData::new(db, ast.with_value(var.kind()), module_id)), |
117 | }, | 121 | }, |
118 | ); | 122 | ); |
119 | } | 123 | } |
120 | } | 124 | } |
121 | 125 | ||
122 | impl VariantData { | 126 | impl VariantData { |
123 | fn new(db: &dyn DefDatabase, flavor: InFile<ast::StructKind>) -> Self { | 127 | fn new(db: &dyn DefDatabase, flavor: InFile<ast::StructKind>, module_id: ModuleId) -> Self { |
124 | let mut trace = Trace::new_for_arena(); | 128 | let mut trace = Trace::new_for_arena(); |
125 | match lower_struct(db, &mut trace, &flavor) { | 129 | match lower_struct(db, &mut trace, &flavor, module_id) { |
126 | StructKind::Tuple => VariantData::Tuple(trace.into_arena()), | 130 | StructKind::Tuple => VariantData::Tuple(trace.into_arena()), |
127 | StructKind::Record => VariantData::Record(trace.into_arena()), | 131 | StructKind::Record => VariantData::Record(trace.into_arena()), |
128 | StructKind::Unit => VariantData::Unit, | 132 | StructKind::Unit => VariantData::Unit, |
@@ -155,22 +159,27 @@ impl HasChildSource for VariantId { | |||
155 | type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; | 159 | type Value = Either<ast::TupleFieldDef, ast::RecordFieldDef>; |
156 | 160 | ||
157 | fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { | 161 | fn child_source(&self, db: &dyn DefDatabase) -> InFile<ArenaMap<Self::ChildId, Self::Value>> { |
158 | let src = match self { | 162 | let (src, module_id) = match self { |
159 | VariantId::EnumVariantId(it) => { | 163 | VariantId::EnumVariantId(it) => { |
160 | // I don't really like the fact that we call into parent source | 164 | // I don't really like the fact that we call into parent source |
161 | // here, this might add to more queries then necessary. | 165 | // here, this might add to more queries then necessary. |
162 | let src = it.parent.child_source(db); | 166 | let src = it.parent.child_source(db); |
163 | src.map(|map| map[it.local_id].kind()) | 167 | (src.map(|map| map[it.local_id].kind()), it.parent.lookup(db).container.module(db)) |
164 | } | 168 | } |
165 | VariantId::StructId(it) => it.lookup(db).source(db).map(|it| it.kind()), | 169 | VariantId::StructId(it) => { |
166 | VariantId::UnionId(it) => it.lookup(db).source(db).map(|it| { | 170 | (it.lookup(db).source(db).map(|it| it.kind()), it.lookup(db).container.module(db)) |
167 | it.record_field_def_list() | 171 | } |
168 | .map(ast::StructKind::Record) | 172 | VariantId::UnionId(it) => ( |
169 | .unwrap_or(ast::StructKind::Unit) | 173 | it.lookup(db).source(db).map(|it| { |
170 | }), | 174 | it.record_field_def_list() |
175 | .map(ast::StructKind::Record) | ||
176 | .unwrap_or(ast::StructKind::Unit) | ||
177 | }), | ||
178 | it.lookup(db).container.module(db), | ||
179 | ), | ||
171 | }; | 180 | }; |
172 | let mut trace = Trace::new_for_map(); | 181 | let mut trace = Trace::new_for_map(); |
173 | lower_struct(db, &mut trace, &src); | 182 | lower_struct(db, &mut trace, &src, module_id); |
174 | src.with_value(trace.into_map()) | 183 | src.with_value(trace.into_map()) |
175 | } | 184 | } |
176 | } | 185 | } |
@@ -186,10 +195,17 @@ fn lower_struct( | |||
186 | db: &dyn DefDatabase, | 195 | db: &dyn DefDatabase, |
187 | trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, | 196 | trace: &mut Trace<StructFieldData, Either<ast::TupleFieldDef, ast::RecordFieldDef>>, |
188 | ast: &InFile<ast::StructKind>, | 197 | ast: &InFile<ast::StructKind>, |
198 | module_id: ModuleId, | ||
189 | ) -> StructKind { | 199 | ) -> StructKind { |
200 | let crate_graph = db.crate_graph(); | ||
190 | match &ast.value { | 201 | match &ast.value { |
191 | ast::StructKind::Tuple(fl) => { | 202 | ast::StructKind::Tuple(fl) => { |
192 | for (i, fd) in fl.fields().enumerate() { | 203 | for (i, fd) in fl.fields().enumerate() { |
204 | let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); | ||
205 | if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { | ||
206 | continue; | ||
207 | } | ||
208 | |||
193 | trace.alloc( | 209 | trace.alloc( |
194 | || Either::Left(fd.clone()), | 210 | || Either::Left(fd.clone()), |
195 | || StructFieldData { | 211 | || StructFieldData { |
@@ -203,6 +219,11 @@ fn lower_struct( | |||
203 | } | 219 | } |
204 | ast::StructKind::Record(fl) => { | 220 | ast::StructKind::Record(fl) => { |
205 | for fd in fl.fields() { | 221 | for fd in fl.fields() { |
222 | let attrs = Attrs::new(&fd, &Hygiene::new(db.upcast(), ast.file_id)); | ||
223 | if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { | ||
224 | continue; | ||
225 | } | ||
226 | |||
206 | trace.alloc( | 227 | trace.alloc( |
207 | || Either::Right(fd.clone()), | 228 | || Either::Right(fd.clone()), |
208 | || StructFieldData { | 229 | || StructFieldData { |
diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index 71a18f5e1..7b0c506b1 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs | |||
@@ -5,6 +5,7 @@ use std::{ops, sync::Arc}; | |||
5 | use either::Either; | 5 | use either::Either; |
6 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; | 6 | use hir_expand::{hygiene::Hygiene, AstId, InFile}; |
7 | use mbe::ast_to_token_tree; | 7 | use mbe::ast_to_token_tree; |
8 | use ra_cfg::CfgOptions; | ||
8 | use ra_syntax::{ | 9 | use ra_syntax::{ |
9 | ast::{self, AstNode, AttrsOwner}, | 10 | ast::{self, AstNode, AttrsOwner}, |
10 | SmolStr, | 11 | SmolStr, |
@@ -90,6 +91,10 @@ impl Attrs { | |||
90 | pub fn by_key(&self, key: &'static str) -> AttrQuery<'_> { | 91 | pub fn by_key(&self, key: &'static str) -> AttrQuery<'_> { |
91 | AttrQuery { attrs: self, key } | 92 | AttrQuery { attrs: self, key } |
92 | } | 93 | } |
94 | |||
95 | pub(crate) fn is_cfg_enabled(&self, cfg_options: &CfgOptions) -> bool { | ||
96 | self.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false)) | ||
97 | } | ||
93 | } | 98 | } |
94 | 99 | ||
95 | #[derive(Debug, Clone, PartialEq, Eq)] | 100 | #[derive(Debug, Clone, PartialEq, Eq)] |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 5f9d53ecb..e09996c6f 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -236,7 +236,7 @@ impl Index<PatId> for Body { | |||
236 | 236 | ||
237 | impl BodySourceMap { | 237 | impl BodySourceMap { |
238 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { | 238 | pub fn expr_syntax(&self, expr: ExprId) -> Result<ExprSource, SyntheticSyntax> { |
239 | self.expr_map_back[expr] | 239 | self.expr_map_back[expr].clone() |
240 | } | 240 | } |
241 | 241 | ||
242 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { | 242 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { |
@@ -255,7 +255,7 @@ impl BodySourceMap { | |||
255 | } | 255 | } |
256 | 256 | ||
257 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { | 257 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { |
258 | self.pat_map_back[pat] | 258 | self.pat_map_back[pat].clone() |
259 | } | 259 | } |
260 | 260 | ||
261 | pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { | 261 | pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option<PatId> { |
@@ -264,6 +264,6 @@ impl BodySourceMap { | |||
264 | } | 264 | } |
265 | 265 | ||
266 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { | 266 | pub fn field_syntax(&self, expr: ExprId, field: usize) -> AstPtr<ast::RecordField> { |
267 | self.field_map[&(expr, field)] | 267 | self.field_map[&(expr, field)].clone() |
268 | } | 268 | } |
269 | } | 269 | } |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c4a5ec59c..9d6ee095e 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -4,6 +4,7 @@ | |||
4 | use either::Either; | 4 | use either::Either; |
5 | 5 | ||
6 | use hir_expand::{ | 6 | use hir_expand::{ |
7 | hygiene::Hygiene, | ||
7 | name::{name, AsName, Name}, | 8 | name::{name, AsName, Name}, |
8 | MacroDefId, MacroDefKind, | 9 | MacroDefId, MacroDefKind, |
9 | }; | 10 | }; |
@@ -20,6 +21,7 @@ use test_utils::tested_by; | |||
20 | use super::{ExprSource, PatSource}; | 21 | use super::{ExprSource, PatSource}; |
21 | use crate::{ | 22 | use crate::{ |
22 | adt::StructKind, | 23 | adt::StructKind, |
24 | attr::Attrs, | ||
23 | body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, | 25 | body::{Body, BodySourceMap, Expander, PatPtr, SyntheticSyntax}, |
24 | builtin_type::{BuiltinFloat, BuiltinInt}, | 26 | builtin_type::{BuiltinFloat, BuiltinInt}, |
25 | db::DefDatabase, | 27 | db::DefDatabase, |
@@ -31,8 +33,8 @@ use crate::{ | |||
31 | path::GenericArgs, | 33 | path::GenericArgs, |
32 | path::Path, | 34 | path::Path, |
33 | type_ref::{Mutability, TypeRef}, | 35 | type_ref::{Mutability, TypeRef}, |
34 | AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, | 36 | AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, HasModule, Intern, |
35 | StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, | 37 | ModuleDefId, StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, |
36 | }; | 38 | }; |
37 | 39 | ||
38 | pub(super) fn lower( | 40 | pub(super) fn lower( |
@@ -104,7 +106,7 @@ impl ExprCollector<'_> { | |||
104 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 106 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
105 | let ptr = Either::Left(ptr); | 107 | let ptr = Either::Left(ptr); |
106 | let src = self.expander.to_source(ptr); | 108 | let src = self.expander.to_source(ptr); |
107 | let id = self.make_expr(expr, Ok(src)); | 109 | let id = self.make_expr(expr, Ok(src.clone())); |
108 | self.source_map.expr_map.insert(src, id); | 110 | self.source_map.expr_map.insert(src, id); |
109 | id | 111 | id |
110 | } | 112 | } |
@@ -116,7 +118,7 @@ impl ExprCollector<'_> { | |||
116 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { | 118 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { |
117 | let ptr = Either::Right(ptr); | 119 | let ptr = Either::Right(ptr); |
118 | let src = self.expander.to_source(ptr); | 120 | let src = self.expander.to_source(ptr); |
119 | let id = self.make_expr(expr, Ok(src)); | 121 | let id = self.make_expr(expr, Ok(src.clone())); |
120 | self.source_map.expr_map.insert(src, id); | 122 | self.source_map.expr_map.insert(src, id); |
121 | id | 123 | id |
122 | } | 124 | } |
@@ -134,7 +136,7 @@ impl ExprCollector<'_> { | |||
134 | 136 | ||
135 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { | 137 | fn alloc_pat(&mut self, pat: Pat, ptr: PatPtr) -> PatId { |
136 | let src = self.expander.to_source(ptr); | 138 | let src = self.expander.to_source(ptr); |
137 | let id = self.make_pat(pat, Ok(src)); | 139 | let id = self.make_pat(pat, Ok(src.clone())); |
138 | self.source_map.pat_map.insert(src, id); | 140 | self.source_map.pat_map.insert(src, id); |
139 | id | 141 | id |
140 | } | 142 | } |
@@ -298,28 +300,41 @@ impl ExprCollector<'_> { | |||
298 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) | 300 | self.alloc_expr(Expr::Return { expr }, syntax_ptr) |
299 | } | 301 | } |
300 | ast::Expr::RecordLit(e) => { | 302 | ast::Expr::RecordLit(e) => { |
303 | let crate_graph = self.db.crate_graph(); | ||
301 | let path = e.path().and_then(|path| self.expander.parse_path(path)); | 304 | let path = e.path().and_then(|path| self.expander.parse_path(path)); |
302 | let mut field_ptrs = Vec::new(); | 305 | let mut field_ptrs = Vec::new(); |
303 | let record_lit = if let Some(nfl) = e.record_field_list() { | 306 | let record_lit = if let Some(nfl) = e.record_field_list() { |
304 | let fields = nfl | 307 | let fields = nfl |
305 | .fields() | 308 | .fields() |
306 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) | 309 | .inspect(|field| field_ptrs.push(AstPtr::new(field))) |
307 | .map(|field| RecordLitField { | 310 | .filter_map(|field| { |
308 | name: field | 311 | let module_id = ContainerId::DefWithBodyId(self.def).module(self.db); |
309 | .name_ref() | 312 | let attrs = Attrs::new( |
310 | .map(|nr| nr.as_name()) | 313 | &field, |
311 | .unwrap_or_else(Name::missing), | 314 | &Hygiene::new(self.db.upcast(), self.expander.current_file_id), |
312 | expr: if let Some(e) = field.expr() { | 315 | ); |
313 | self.collect_expr(e) | 316 | |
314 | } else if let Some(nr) = field.name_ref() { | 317 | if !attrs.is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) { |
315 | // field shorthand | 318 | return None; |
316 | self.alloc_expr_field_shorthand( | 319 | } |
317 | Expr::Path(Path::from_name_ref(&nr)), | 320 | |
318 | AstPtr::new(&field), | 321 | Some(RecordLitField { |
319 | ) | 322 | name: field |
320 | } else { | 323 | .name_ref() |
321 | self.missing_expr() | 324 | .map(|nr| nr.as_name()) |
322 | }, | 325 | .unwrap_or_else(Name::missing), |
326 | expr: if let Some(e) = field.expr() { | ||
327 | self.collect_expr(e) | ||
328 | } else if let Some(nr) = field.name_ref() { | ||
329 | // field shorthand | ||
330 | self.alloc_expr_field_shorthand( | ||
331 | Expr::Path(Path::from_name_ref(&nr)), | ||
332 | AstPtr::new(&field), | ||
333 | ) | ||
334 | } else { | ||
335 | self.missing_expr() | ||
336 | }, | ||
337 | }) | ||
323 | }) | 338 | }) |
324 | .collect(); | 339 | .collect(); |
325 | let spread = nfl.spread().map(|s| self.collect_expr(s)); | 340 | let spread = nfl.spread().map(|s| self.collect_expr(s)); |
@@ -357,7 +372,7 @@ impl ExprCollector<'_> { | |||
357 | } | 372 | } |
358 | ast::Expr::RefExpr(e) => { | 373 | ast::Expr::RefExpr(e) => { |
359 | let expr = self.collect_expr_opt(e.expr()); | 374 | let expr = self.collect_expr_opt(e.expr()); |
360 | let mutability = Mutability::from_mutable(e.is_mut()); | 375 | let mutability = Mutability::from_mutable(e.mut_token().is_some()); |
361 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) | 376 | self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) |
362 | } | 377 | } |
363 | ast::Expr::PrefixExpr(e) => { | 378 | ast::Expr::PrefixExpr(e) => { |
@@ -572,10 +587,8 @@ impl ExprCollector<'_> { | |||
572 | let pattern = match &pat { | 587 | let pattern = match &pat { |
573 | ast::Pat::BindPat(bp) => { | 588 | ast::Pat::BindPat(bp) => { |
574 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); | 589 | let name = bp.name().map(|nr| nr.as_name()).unwrap_or_else(Name::missing); |
575 | let annotation = BindingAnnotation::new( | 590 | let annotation = |
576 | bp.mut_kw_token().is_some(), | 591 | BindingAnnotation::new(bp.mut_token().is_some(), bp.ref_token().is_some()); |
577 | bp.ref_kw_token().is_some(), | ||
578 | ); | ||
579 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); | 592 | let subpat = bp.pat().map(|subpat| self.collect_pat(subpat)); |
580 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { | 593 | if annotation == BindingAnnotation::Unannotated && subpat.is_none() { |
581 | // This could also be a single-segment path pattern. To | 594 | // This could also be a single-segment path pattern. To |
@@ -616,7 +629,7 @@ impl ExprCollector<'_> { | |||
616 | } | 629 | } |
617 | ast::Pat::RefPat(p) => { | 630 | ast::Pat::RefPat(p) => { |
618 | let pat = self.collect_pat_opt(p.pat()); | 631 | let pat = self.collect_pat_opt(p.pat()); |
619 | let mutability = Mutability::from_mutable(p.mut_kw_token().is_some()); | 632 | let mutability = Mutability::from_mutable(p.mut_token().is_some()); |
620 | Pat::Ref { pat, mutability } | 633 | Pat::Ref { pat, mutability } |
621 | } | 634 | } |
622 | ast::Pat::PathPat(p) => { | 635 | ast::Pat::PathPat(p) => { |
@@ -655,7 +668,9 @@ impl ExprCollector<'_> { | |||
655 | }); | 668 | }); |
656 | fields.extend(iter); | 669 | fields.extend(iter); |
657 | 670 | ||
658 | Pat::Record { path, args: fields } | 671 | let ellipsis = record_field_pat_list.dotdot_token().is_some(); |
672 | |||
673 | Pat::Record { path, args: fields, ellipsis } | ||
659 | } | 674 | } |
660 | ast::Pat::SlicePat(p) => { | 675 | ast::Pat::SlicePat(p) => { |
661 | let SlicePatComponents { prefix, slice, suffix } = p.components(); | 676 | let SlicePatComponents { prefix, slice, suffix } = p.components(); |
diff --git a/crates/ra_hir_def/src/data.rs b/crates/ra_hir_def/src/data.rs index 689bb6c5c..b8fbf0ed4 100644 --- a/crates/ra_hir_def/src/data.rs +++ b/crates/ra_hir_def/src/data.rs | |||
@@ -7,7 +7,6 @@ use hir_expand::{ | |||
7 | name::{name, AsName, Name}, | 7 | name::{name, AsName, Name}, |
8 | AstId, InFile, | 8 | AstId, InFile, |
9 | }; | 9 | }; |
10 | use ra_cfg::CfgOptions; | ||
11 | use ra_prof::profile; | 10 | use ra_prof::profile; |
12 | use ra_syntax::ast::{ | 11 | use ra_syntax::ast::{ |
13 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, | 12 | self, AstNode, ImplItem, ModuleItemOwner, NameOwner, TypeAscriptionOwner, VisibilityOwner, |
@@ -75,7 +74,7 @@ impl FunctionData { | |||
75 | TypeRef::unit() | 74 | TypeRef::unit() |
76 | }; | 75 | }; |
77 | 76 | ||
78 | let ret_type = if src.value.async_kw_token().is_some() { | 77 | let ret_type = if src.value.async_token().is_some() { |
79 | let future_impl = desugar_future_path(ret_type); | 78 | let future_impl = desugar_future_path(ret_type); |
80 | let ty_bound = TypeBound::Path(future_impl); | 79 | let ty_bound = TypeBound::Path(future_impl); |
81 | TypeRef::ImplTrait(vec![ty_bound]) | 80 | TypeRef::ImplTrait(vec![ty_bound]) |
@@ -136,7 +135,7 @@ impl TraitData { | |||
136 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { | 135 | pub(crate) fn trait_data_query(db: &dyn DefDatabase, tr: TraitId) -> Arc<TraitData> { |
137 | let src = tr.lookup(db).source(db); | 136 | let src = tr.lookup(db).source(db); |
138 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); | 137 | let name = src.value.name().map_or_else(Name::missing, |n| n.as_name()); |
139 | let auto = src.value.auto_kw_token().is_some(); | 138 | let auto = src.value.auto_token().is_some(); |
140 | let ast_id_map = db.ast_id_map(src.file_id); | 139 | let ast_id_map = db.ast_id_map(src.file_id); |
141 | 140 | ||
142 | let container = AssocContainerId::TraitId(tr); | 141 | let container = AssocContainerId::TraitId(tr); |
@@ -318,10 +317,6 @@ fn collect_impl_items_in_macro( | |||
318 | } | 317 | } |
319 | } | 318 | } |
320 | 319 | ||
321 | fn is_cfg_enabled(cfg_options: &CfgOptions, attrs: &Attrs) -> bool { | ||
322 | attrs.by_key("cfg").tt_values().all(|tt| cfg_options.is_cfg_enabled(tt) != Some(false)) | ||
323 | } | ||
324 | |||
325 | fn collect_impl_items( | 320 | fn collect_impl_items( |
326 | db: &dyn DefDatabase, | 321 | db: &dyn DefDatabase, |
327 | impl_items: impl Iterator<Item = ImplItem>, | 322 | impl_items: impl Iterator<Item = ImplItem>, |
@@ -341,10 +336,11 @@ fn collect_impl_items( | |||
341 | } | 336 | } |
342 | .intern(db); | 337 | .intern(db); |
343 | 338 | ||
344 | if !is_cfg_enabled( | 339 | if !db |
345 | &crate_graph[module_id.krate].cfg_options, | 340 | .function_data(def) |
346 | &db.function_data(def).attrs, | 341 | .attrs |
347 | ) { | 342 | .is_cfg_enabled(&crate_graph[module_id.krate].cfg_options) |
343 | { | ||
348 | None | 344 | None |
349 | } else { | 345 | } else { |
350 | Some(def.into()) | 346 | Some(def.into()) |
diff --git a/crates/ra_hir_def/src/diagnostics.rs b/crates/ra_hir_def/src/diagnostics.rs index 095498429..cfa0f2f76 100644 --- a/crates/ra_hir_def/src/diagnostics.rs +++ b/crates/ra_hir_def/src/diagnostics.rs | |||
@@ -20,7 +20,7 @@ impl Diagnostic for UnresolvedModule { | |||
20 | "unresolved module".to_string() | 20 | "unresolved module".to_string() |
21 | } | 21 | } |
22 | fn source(&self) -> InFile<SyntaxNodePtr> { | 22 | fn source(&self) -> InFile<SyntaxNodePtr> { |
23 | InFile { file_id: self.file, value: self.decl.into() } | 23 | InFile { file_id: self.file, value: self.decl.clone().into() } |
24 | } | 24 | } |
25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { | 25 | fn as_any(&self) -> &(dyn Any + Send + 'static) { |
26 | self | 26 | self |
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs index 197bbe9bd..e11bdf3ec 100644 --- a/crates/ra_hir_def/src/expr.rs +++ b/crates/ra_hir_def/src/expr.rs | |||
@@ -376,35 +376,14 @@ pub enum Pat { | |||
376 | Wild, | 376 | Wild, |
377 | Tuple(Vec<PatId>), | 377 | Tuple(Vec<PatId>), |
378 | Or(Vec<PatId>), | 378 | Or(Vec<PatId>), |
379 | Record { | 379 | Record { path: Option<Path>, args: Vec<RecordFieldPat>, ellipsis: bool }, |
380 | path: Option<Path>, | 380 | Range { start: ExprId, end: ExprId }, |
381 | args: Vec<RecordFieldPat>, | 381 | Slice { prefix: Vec<PatId>, slice: Option<PatId>, suffix: Vec<PatId> }, |
382 | // FIXME: 'ellipsis' option | ||
383 | }, | ||
384 | Range { | ||
385 | start: ExprId, | ||
386 | end: ExprId, | ||
387 | }, | ||
388 | Slice { | ||
389 | prefix: Vec<PatId>, | ||
390 | slice: Option<PatId>, | ||
391 | suffix: Vec<PatId>, | ||
392 | }, | ||
393 | Path(Path), | 382 | Path(Path), |
394 | Lit(ExprId), | 383 | Lit(ExprId), |
395 | Bind { | 384 | Bind { mode: BindingAnnotation, name: Name, subpat: Option<PatId> }, |
396 | mode: BindingAnnotation, | 385 | TupleStruct { path: Option<Path>, args: Vec<PatId> }, |
397 | name: Name, | 386 | Ref { pat: PatId, mutability: Mutability }, |
398 | subpat: Option<PatId>, | ||
399 | }, | ||
400 | TupleStruct { | ||
401 | path: Option<Path>, | ||
402 | args: Vec<PatId>, | ||
403 | }, | ||
404 | Ref { | ||
405 | pat: PatId, | ||
406 | mutability: Mutability, | ||
407 | }, | ||
408 | } | 387 | } |
409 | 388 | ||
410 | impl Pat { | 389 | impl Pat { |
diff --git a/crates/ra_hir_def/src/lang_item.rs b/crates/ra_hir_def/src/lang_item.rs index 01b367278..d96ac8c0a 100644 --- a/crates/ra_hir_def/src/lang_item.rs +++ b/crates/ra_hir_def/src/lang_item.rs | |||
@@ -4,6 +4,7 @@ | |||
4 | //! features, such as Fn family of traits. | 4 | //! features, such as Fn family of traits. |
5 | use std::sync::Arc; | 5 | use std::sync::Arc; |
6 | 6 | ||
7 | use ra_prof::profile; | ||
7 | use ra_syntax::SmolStr; | 8 | use ra_syntax::SmolStr; |
8 | use rustc_hash::FxHashMap; | 9 | use rustc_hash::FxHashMap; |
9 | 10 | ||
@@ -78,6 +79,8 @@ impl LangItems { | |||
78 | 79 | ||
79 | /// Salsa query. This will look for lang items in a specific crate. | 80 | /// Salsa query. This will look for lang items in a specific crate. |
80 | pub(crate) fn crate_lang_items_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<LangItems> { | 81 | pub(crate) fn crate_lang_items_query(db: &dyn DefDatabase, krate: CrateId) -> Arc<LangItems> { |
82 | let _p = profile("crate_lang_items_query"); | ||
83 | |||
81 | let mut lang_items = LangItems::default(); | 84 | let mut lang_items = LangItems::default(); |
82 | 85 | ||
83 | let crate_def_map = db.crate_def_map(krate); | 86 | let crate_def_map = db.crate_def_map(krate); |
@@ -95,6 +98,7 @@ impl LangItems { | |||
95 | db: &dyn DefDatabase, | 98 | db: &dyn DefDatabase, |
96 | module: ModuleId, | 99 | module: ModuleId, |
97 | ) -> Option<Arc<LangItems>> { | 100 | ) -> Option<Arc<LangItems>> { |
101 | let _p = profile("module_lang_items_query"); | ||
98 | let mut lang_items = LangItems::default(); | 102 | let mut lang_items = LangItems::default(); |
99 | lang_items.collect_lang_items(db, module); | 103 | lang_items.collect_lang_items(db, module); |
100 | if lang_items.items.is_empty() { | 104 | if lang_items.items.is_empty() { |
@@ -111,6 +115,7 @@ impl LangItems { | |||
111 | start_crate: CrateId, | 115 | start_crate: CrateId, |
112 | item: SmolStr, | 116 | item: SmolStr, |
113 | ) -> Option<LangItemTarget> { | 117 | ) -> Option<LangItemTarget> { |
118 | let _p = profile("lang_item_query"); | ||
114 | let lang_items = db.crate_lang_items(start_crate); | 119 | let lang_items = db.crate_lang_items(start_crate); |
115 | let start_crate_target = lang_items.items.get(&item); | 120 | let start_crate_target = lang_items.items.get(&item); |
116 | if let Some(target) = start_crate_target { | 121 | if let Some(target) = start_crate_target { |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index e72ba52cf..afd538e4a 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -287,7 +287,7 @@ impl RawItemsCollector { | |||
287 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); | 287 | let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); |
288 | 288 | ||
289 | let ast_id = self.source_ast_id_map.ast_id(&module); | 289 | let ast_id = self.source_ast_id_map.ast_id(&module); |
290 | if module.semi_token().is_some() { | 290 | if module.semicolon_token().is_some() { |
291 | let item = | 291 | let item = |
292 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); | 292 | self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); |
293 | self.push_item(current_module, attrs, RawItemKind::Module(item)); | 293 | self.push_item(current_module, attrs, RawItemKind::Module(item)); |
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs index 7a8338937..ea29c4176 100644 --- a/crates/ra_hir_def/src/type_ref.rs +++ b/crates/ra_hir_def/src/type_ref.rs | |||
@@ -77,7 +77,7 @@ impl TypeRef { | |||
77 | } | 77 | } |
78 | ast::TypeRef::PointerType(inner) => { | 78 | ast::TypeRef::PointerType(inner) => { |
79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 79 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
80 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); | 80 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) | 81 | TypeRef::RawPtr(Box::new(inner_ty), mutability) |
82 | } | 82 | } |
83 | ast::TypeRef::ArrayType(inner) => { | 83 | ast::TypeRef::ArrayType(inner) => { |
@@ -88,7 +88,7 @@ impl TypeRef { | |||
88 | } | 88 | } |
89 | ast::TypeRef::ReferenceType(inner) => { | 89 | ast::TypeRef::ReferenceType(inner) => { |
90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); | 90 | let inner_ty = TypeRef::from_ast_opt(inner.type_ref()); |
91 | let mutability = Mutability::from_mutable(inner.mut_kw_token().is_some()); | 91 | let mutability = Mutability::from_mutable(inner.mut_token().is_some()); |
92 | TypeRef::Reference(Box::new(inner_ty), mutability) | 92 | TypeRef::Reference(Box::new(inner_ty), mutability) |
93 | } | 93 | } |
94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, | 94 | ast::TypeRef::PlaceholderType(_inner) => TypeRef::Placeholder, |