From 60f4d7bd8c0ecb9f23557464e824140a2be8f41a Mon Sep 17 00:00:00 2001 From: Luca Barbieri Date: Fri, 3 Apr 2020 21:12:09 +0200 Subject: Provide more complete AST accessors to support usage in rustc --- crates/ra_hir_def/src/body/lower.rs | 10 +++++++--- crates/ra_hir_def/src/nameres/raw.rs | 4 ++++ crates/ra_hir_def/src/path/lower.rs | 2 +- crates/ra_hir_def/src/path/lower/lower_use.rs | 2 +- crates/ra_hir_def/src/visibility.rs | 4 ++++ 5 files changed, 17 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 8d4b8b0f0..8338414fa 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -482,14 +482,17 @@ impl ExprCollector<'_> { self.collect_block_items(&block); let statements = block .statements() - .map(|s| match s { + .filter_map(|s| match s { ast::Stmt::LetStmt(stmt) => { let pat = self.collect_pat_opt(stmt.pat()); let type_ref = stmt.ascribed_type().map(TypeRef::from_ast); let initializer = stmt.initializer().map(|e| self.collect_expr(e)); - Statement::Let { pat, type_ref, initializer } + Some(Statement::Let { pat, type_ref, initializer }) } - ast::Stmt::ExprStmt(stmt) => Statement::Expr(self.collect_expr_opt(stmt.expr())), + ast::Stmt::ExprStmt(stmt) => { + Some(Statement::Expr(self.collect_expr_opt(stmt.expr()))) + } + ast::Stmt::ModuleItem(_) => None, }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); @@ -541,6 +544,7 @@ impl ExprCollector<'_> { let ast_id = self.expander.ast_id(&def); (TraitLoc { container, ast_id }.intern(self.db).into(), def.name()) } + ast::ModuleItem::ExternBlock(_) => continue, // FIXME: collect from extern blocks ast::ModuleItem::ImplDef(_) | ast::ModuleItem::UseItem(_) | ast::ModuleItem::ExternCrateItem(_) diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 8f190e7f9..a9dff3a5d 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -266,6 +266,10 @@ impl RawItemsCollector { self.add_macro(current_module, it); return; } + ast::ModuleItem::ExternBlock(_) => { + // FIXME: add extern block + return; + } }; if let Some(name) = name { let name = name.as_name(); diff --git a/crates/ra_hir_def/src/path/lower.rs b/crates/ra_hir_def/src/path/lower.rs index 4900000fe..3c13cb2c7 100644 --- a/crates/ra_hir_def/src/path/lower.rs +++ b/crates/ra_hir_def/src/path/lower.rs @@ -28,7 +28,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option loop { let segment = path.segment()?; - if segment.has_colon_colon() { + if segment.coloncolon().is_some() { kind = PathKind::Abs; } diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index 278d5196e..6ec944228 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs @@ -34,7 +34,7 @@ pub(crate) fn lower_use_tree( let alias = tree.alias().map(|a| { a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) }); - let is_glob = tree.has_star(); + let is_glob = tree.star().is_some(); if let Some(ast_path) = tree.path() { // Handle self in a path. // E.g. `use something::{self, <...>}` diff --git a/crates/ra_hir_def/src/visibility.rs b/crates/ra_hir_def/src/visibility.rs index 62513873e..1482d3be0 100644 --- a/crates/ra_hir_def/src/visibility.rs +++ b/crates/ra_hir_def/src/visibility.rs @@ -84,6 +84,10 @@ impl RawVisibility { let path = ModPath { kind: PathKind::Super(1), segments: Vec::new() }; RawVisibility::Module(path) } + ast::VisibilityKind::PubSelf => { + let path = ModPath { kind: PathKind::Plain, segments: Vec::new() }; + RawVisibility::Module(path) + } ast::VisibilityKind::Pub => RawVisibility::Public, } } -- cgit v1.2.3 From 689661c95968cb438f8bd1f10ce0ee096287741b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 9 Apr 2020 13:00:09 +0200 Subject: Scale back to only two traits --- crates/ra_hir_def/src/body/lower.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'crates/ra_hir_def/src') diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 8338414fa..b02de5d67 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -492,7 +492,6 @@ impl ExprCollector<'_> { ast::Stmt::ExprStmt(stmt) => { Some(Statement::Expr(self.collect_expr_opt(stmt.expr()))) } - ast::Stmt::ModuleItem(_) => None, }) .collect(); let tail = block.expr().map(|e| self.collect_expr(e)); -- cgit v1.2.3