diff options
Diffstat (limited to 'crates/ra_hir_def')
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 13 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 30 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 5 |
3 files changed, 10 insertions, 38 deletions
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 7fac6ce66..eafaf48c1 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -9,6 +9,8 @@ use drop_bomb::DropBomb; | |||
9 | use either::Either; | 9 | use either::Either; |
10 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; | 10 | use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; |
11 | use ra_arena::{map::ArenaMap, Arena}; | 11 | use ra_arena::{map::ArenaMap, Arena}; |
12 | use ra_cfg::CfgOptions; | ||
13 | use ra_db::CrateId; | ||
12 | use ra_prof::profile; | 14 | use ra_prof::profile; |
13 | use ra_syntax::{ast, AstNode, AstPtr}; | 15 | use ra_syntax::{ast, AstNode, AstPtr}; |
14 | use rustc_hash::FxHashMap; | 16 | use rustc_hash::FxHashMap; |
@@ -24,8 +26,6 @@ use crate::{ | |||
24 | src::HasSource, | 26 | src::HasSource, |
25 | AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, | 27 | AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, |
26 | }; | 28 | }; |
27 | use ra_cfg::CfgOptions; | ||
28 | use ra_db::CrateId; | ||
29 | 29 | ||
30 | /// A subser of Exander that only deals with cfg attributes. We only need it to | 30 | /// A subser of Exander that only deals with cfg attributes. We only need it to |
31 | /// avoid cyclic queries in crate def map during enum processing. | 31 | /// avoid cyclic queries in crate def map during enum processing. |
@@ -187,7 +187,7 @@ pub struct Body { | |||
187 | pub item_scope: ItemScope, | 187 | pub item_scope: ItemScope, |
188 | } | 188 | } |
189 | 189 | ||
190 | pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>; | 190 | pub type ExprPtr = AstPtr<ast::Expr>; |
191 | pub type ExprSource = InFile<ExprPtr>; | 191 | pub type ExprSource = InFile<ExprPtr>; |
192 | 192 | ||
193 | pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; | 193 | pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; |
@@ -285,7 +285,7 @@ impl BodySourceMap { | |||
285 | } | 285 | } |
286 | 286 | ||
287 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { | 287 | pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> { |
288 | let src = node.map(|it| Either::Left(AstPtr::new(it))); | 288 | let src = node.map(|it| AstPtr::new(it)); |
289 | self.expr_map.get(&src).cloned() | 289 | self.expr_map.get(&src).cloned() |
290 | } | 290 | } |
291 | 291 | ||
@@ -294,11 +294,6 @@ impl BodySourceMap { | |||
294 | self.expansions.get(&src).cloned() | 294 | self.expansions.get(&src).cloned() |
295 | } | 295 | } |
296 | 296 | ||
297 | pub fn field_init_shorthand_expr(&self, node: InFile<&ast::RecordField>) -> Option<ExprId> { | ||
298 | let src = node.map(|it| Either::Right(AstPtr::new(it))); | ||
299 | self.expr_map.get(&src).cloned() | ||
300 | } | ||
301 | |||
302 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { | 297 | pub fn pat_syntax(&self, pat: PatId) -> Result<PatSource, SyntheticSyntax> { |
303 | self.pat_map_back[pat].clone() | 298 | self.pat_map_back[pat].clone() |
304 | } | 299 | } |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index c1d7eb826..cc2532e88 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -27,7 +27,6 @@ use crate::{ | |||
27 | }, | 27 | }, |
28 | item_scope::BuiltinShadowMode, | 28 | item_scope::BuiltinShadowMode, |
29 | path::GenericArgs, | 29 | path::GenericArgs, |
30 | path::Path, | ||
31 | type_ref::{Mutability, TypeRef}, | 30 | type_ref::{Mutability, TypeRef}, |
32 | AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, | 31 | AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, |
33 | StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, | 32 | StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, |
@@ -102,7 +101,6 @@ impl ExprCollector<'_> { | |||
102 | } | 101 | } |
103 | 102 | ||
104 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { | 103 | fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId { |
105 | let ptr = Either::Left(ptr); | ||
106 | let src = self.expander.to_source(ptr); | 104 | let src = self.expander.to_source(ptr); |
107 | let id = self.make_expr(expr, Ok(src.clone())); | 105 | let id = self.make_expr(expr, Ok(src.clone())); |
108 | self.source_map.expr_map.insert(src, id); | 106 | self.source_map.expr_map.insert(src, id); |
@@ -113,13 +111,6 @@ impl ExprCollector<'_> { | |||
113 | fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { | 111 | fn alloc_expr_desugared(&mut self, expr: Expr) -> ExprId { |
114 | self.make_expr(expr, Err(SyntheticSyntax)) | 112 | self.make_expr(expr, Err(SyntheticSyntax)) |
115 | } | 113 | } |
116 | fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr<ast::RecordField>) -> ExprId { | ||
117 | let ptr = Either::Right(ptr); | ||
118 | let src = self.expander.to_source(ptr); | ||
119 | let id = self.make_expr(expr, Ok(src.clone())); | ||
120 | self.source_map.expr_map.insert(src, id); | ||
121 | id | ||
122 | } | ||
123 | fn empty_block(&mut self) -> ExprId { | 114 | fn empty_block(&mut self) -> ExprId { |
124 | self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) | 115 | self.alloc_expr_desugared(Expr::Block { statements: Vec::new(), tail: None }) |
125 | } | 116 | } |
@@ -289,7 +280,7 @@ impl ExprCollector<'_> { | |||
289 | ast::Expr::ParenExpr(e) => { | 280 | ast::Expr::ParenExpr(e) => { |
290 | let inner = self.collect_expr_opt(e.expr()); | 281 | let inner = self.collect_expr_opt(e.expr()); |
291 | // make the paren expr point to the inner expression as well | 282 | // make the paren expr point to the inner expression as well |
292 | let src = self.expander.to_source(Either::Left(syntax_ptr)); | 283 | let src = self.expander.to_source(syntax_ptr); |
293 | self.source_map.expr_map.insert(src, inner); | 284 | self.source_map.expr_map.insert(src, inner); |
294 | inner | 285 | inner |
295 | } | 286 | } |
@@ -309,22 +300,13 @@ impl ExprCollector<'_> { | |||
309 | if !self.expander.is_cfg_enabled(&attrs) { | 300 | if !self.expander.is_cfg_enabled(&attrs) { |
310 | return None; | 301 | return None; |
311 | } | 302 | } |
303 | let name = field.field_name()?.as_name(); | ||
312 | 304 | ||
313 | Some(RecordLitField { | 305 | Some(RecordLitField { |
314 | name: field | 306 | name, |
315 | .name_ref() | 307 | expr: match field.expr() { |
316 | .map(|nr| nr.as_name()) | 308 | Some(e) => self.collect_expr(e), |
317 | .unwrap_or_else(Name::missing), | 309 | None => self.missing_expr(), |
318 | expr: if let Some(e) = field.expr() { | ||
319 | self.collect_expr(e) | ||
320 | } else if let Some(nr) = field.name_ref() { | ||
321 | // field shorthand | ||
322 | self.alloc_expr_field_shorthand( | ||
323 | Expr::Path(Path::from_name_ref(&nr)), | ||
324 | AstPtr::new(&field), | ||
325 | ) | ||
326 | } else { | ||
327 | self.missing_expr() | ||
328 | }, | 310 | }, |
329 | }) | 311 | }) |
330 | }) | 312 | }) |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 904080341..91c7b3e09 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -134,11 +134,6 @@ impl Path { | |||
134 | lower::lower_path(path, hygiene) | 134 | lower::lower_path(path, hygiene) |
135 | } | 135 | } |
136 | 136 | ||
137 | /// Converts an `ast::NameRef` into a single-identifier `Path`. | ||
138 | pub(crate) fn from_name_ref(name_ref: &ast::NameRef) -> Path { | ||
139 | Path { type_anchor: None, mod_path: name_ref.as_name().into(), generic_args: vec![None] } | ||
140 | } | ||
141 | |||
142 | /// Converts a known mod path to `Path`. | 137 | /// Converts a known mod path to `Path`. |
143 | pub(crate) fn from_known_path( | 138 | pub(crate) fn from_known_path( |
144 | path: ModPath, | 139 | path: ModPath, |