From 434f108adad75b7c5e25db745a9f9fefa5cdaa31 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 24 Nov 2019 18:48:29 +0300 Subject: Simplify --- crates/ra_hir_def/src/body.rs | 28 ++++++---------------------- crates/ra_hir_def/src/body/scope.rs | 4 ++-- crates/ra_hir_def/src/nameres.rs | 2 +- crates/ra_hir_def/src/nameres/tests.rs | 2 +- 4 files changed, 10 insertions(+), 26 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index c06997cf1..45a36d793 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -20,7 +20,7 @@ use crate::{ DefWithBodyId, HasModule, HasSource, Lookup, ModuleId, }; -pub struct Expander { +struct Expander { crate_def_map: Arc, current_file_id: HirFileId, hygiene: Hygiene, @@ -28,7 +28,7 @@ pub struct Expander { } impl Expander { - pub fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { + fn new(db: &impl DefDatabase, current_file_id: HirFileId, module: ModuleId) -> Expander { let crate_def_map = db.crate_def_map(module.krate); let hygiene = Hygiene::new(db, current_file_id); Expander { crate_def_map, current_file_id, hygiene, module } @@ -101,17 +101,17 @@ impl Drop for Mark { /// The body of an item (function, const etc.). #[derive(Debug, Eq, PartialEq)] pub struct Body { - exprs: Arena, - pats: Arena, + pub exprs: Arena, + pub pats: Arena, /// The patterns for the function's parameters. While the parameter types are /// part of the function signature, the patterns are not (they don't change /// the external type of the function). /// /// If this `Body` is for the body of a constant, this will just be /// empty. - params: Vec, + pub params: Vec, /// The `ExprId` of the actual body expression. - body_expr: ExprId, + pub body_expr: ExprId, } pub type ExprPtr = Either, AstPtr>; @@ -182,22 +182,6 @@ impl Body { ) -> (Body, BodySourceMap) { lower::lower(db, expander, params, body) } - - pub fn params(&self) -> &[PatId] { - &self.params - } - - pub fn body_expr(&self) -> ExprId { - self.body_expr - } - - pub fn exprs(&self) -> impl Iterator { - self.exprs.iter() - } - - pub fn pats(&self) -> impl Iterator { - self.pats.iter() - } } impl Index for Body { diff --git a/crates/ra_hir_def/src/body/scope.rs b/crates/ra_hir_def/src/body/scope.rs index 20d707bc4..5240a59d5 100644 --- a/crates/ra_hir_def/src/body/scope.rs +++ b/crates/ra_hir_def/src/body/scope.rs @@ -54,8 +54,8 @@ impl ExprScopes { let mut scopes = ExprScopes { scopes: Arena::default(), scope_by_expr: FxHashMap::default() }; let root = scopes.root_scope(); - scopes.add_params_bindings(body, root, body.params()); - compute_expr_scopes(body.body_expr(), body, &mut scopes, root); + scopes.add_params_bindings(body, root, &body.params); + compute_expr_scopes(body.body_expr, body, &mut scopes, root); scopes } diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 9476fb1ad..2359386c2 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -81,13 +81,13 @@ use crate::{ #[derive(Debug, PartialEq, Eq)] pub struct CrateDefMap { pub root: LocalModuleId, + pub modules: Arena, pub(crate) krate: CrateId, /// The prelude module for this crate. This either comes from an import /// marked with the `prelude_import` attribute, or (in the normal case) from /// a dependency (`std` or `core`). pub(crate) prelude: Option, pub(crate) extern_prelude: FxHashMap, - pub(crate) modules: Arena, edition: Edition, diagnostics: Vec, diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index f0b86af7c..f502f1cb3 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -25,7 +25,7 @@ fn compute_crate_def_map(fixture: &str) -> Arc { fn render_crate_def_map(map: &CrateDefMap) -> String { let mut buf = String::new(); - go(&mut buf, map, "\ncrate", map.root()); + go(&mut buf, map, "\ncrate", map.root); return buf.trim().to_string(); fn go(buf: &mut String, map: &CrateDefMap, path: &str, module: LocalModuleId) { -- cgit v1.2.3