aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_def/src/body
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_def/src/body')
-rw-r--r--crates/hir_def/src/body/lower.rs28
1 files changed, 17 insertions, 11 deletions
diff --git a/crates/hir_def/src/body/lower.rs b/crates/hir_def/src/body/lower.rs
index 820d5c17e..9f278d35b 100644
--- a/crates/hir_def/src/body/lower.rs
+++ b/crates/hir_def/src/body/lower.rs
@@ -40,23 +40,25 @@ use crate::{
40 40
41use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource}; 41use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource};
42 42
43pub struct LowerCtx { 43pub struct LowerCtx<'a> {
44 pub db: &'a dyn DefDatabase,
44 hygiene: Hygiene, 45 hygiene: Hygiene,
45 file_id: Option<HirFileId>, 46 file_id: Option<HirFileId>,
46 source_ast_id_map: Option<Arc<AstIdMap>>, 47 source_ast_id_map: Option<Arc<AstIdMap>>,
47} 48}
48 49
49impl LowerCtx { 50impl<'a> LowerCtx<'a> {
50 pub fn new(db: &dyn DefDatabase, file_id: HirFileId) -> Self { 51 pub fn new(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
51 LowerCtx { 52 LowerCtx {
53 db,
52 hygiene: Hygiene::new(db.upcast(), file_id), 54 hygiene: Hygiene::new(db.upcast(), file_id),
53 file_id: Some(file_id), 55 file_id: Some(file_id),
54 source_ast_id_map: Some(db.ast_id_map(file_id)), 56 source_ast_id_map: Some(db.ast_id_map(file_id)),
55 } 57 }
56 } 58 }
57 59
58 pub fn with_hygiene(hygiene: &Hygiene) -> Self { 60 pub fn with_hygiene(db: &'a dyn DefDatabase, hygiene: &Hygiene) -> Self {
59 LowerCtx { hygiene: hygiene.clone(), file_id: None, source_ast_id_map: None } 61 LowerCtx { db, hygiene: hygiene.clone(), file_id: None, source_ast_id_map: None }
60 } 62 }
61 63
62 pub(crate) fn hygiene(&self) -> &Hygiene { 64 pub(crate) fn hygiene(&self) -> &Hygiene {
@@ -145,7 +147,7 @@ impl ExprCollector<'_> {
145 (self.body, self.source_map) 147 (self.body, self.source_map)
146 } 148 }
147 149
148 fn ctx(&self) -> LowerCtx { 150 fn ctx(&self) -> LowerCtx<'_> {
149 LowerCtx::new(self.db, self.expander.current_file_id) 151 LowerCtx::new(self.db, self.expander.current_file_id)
150 } 152 }
151 153
@@ -376,7 +378,7 @@ impl ExprCollector<'_> {
376 ast::Expr::PathExpr(e) => { 378 ast::Expr::PathExpr(e) => {
377 let path = e 379 let path = e
378 .path() 380 .path()
379 .and_then(|path| self.expander.parse_path(path)) 381 .and_then(|path| self.expander.parse_path(self.db, path))
380 .map(Expr::Path) 382 .map(Expr::Path)
381 .unwrap_or(Expr::Missing); 383 .unwrap_or(Expr::Missing);
382 self.alloc_expr(path, syntax_ptr) 384 self.alloc_expr(path, syntax_ptr)
@@ -408,7 +410,8 @@ impl ExprCollector<'_> {
408 self.alloc_expr(Expr::Yield { expr }, syntax_ptr) 410 self.alloc_expr(Expr::Yield { expr }, syntax_ptr)
409 } 411 }
410 ast::Expr::RecordExpr(e) => { 412 ast::Expr::RecordExpr(e) => {
411 let path = e.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); 413 let path =
414 e.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
412 let record_lit = if let Some(nfl) = e.record_expr_field_list() { 415 let record_lit = if let Some(nfl) = e.record_expr_field_list() {
413 let fields = nfl 416 let fields = nfl
414 .fields() 417 .fields()
@@ -801,7 +804,8 @@ impl ExprCollector<'_> {
801 } 804 }
802 } 805 }
803 ast::Pat::TupleStructPat(p) => { 806 ast::Pat::TupleStructPat(p) => {
804 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); 807 let path =
808 p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
805 let (args, ellipsis) = self.collect_tuple_pat(p.fields()); 809 let (args, ellipsis) = self.collect_tuple_pat(p.fields());
806 Pat::TupleStruct { path, args, ellipsis } 810 Pat::TupleStruct { path, args, ellipsis }
807 } 811 }
@@ -811,7 +815,8 @@ impl ExprCollector<'_> {
811 Pat::Ref { pat, mutability } 815 Pat::Ref { pat, mutability }
812 } 816 }
813 ast::Pat::PathPat(p) => { 817 ast::Pat::PathPat(p) => {
814 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); 818 let path =
819 p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
815 path.map(Pat::Path).unwrap_or(Pat::Missing) 820 path.map(Pat::Path).unwrap_or(Pat::Missing)
816 } 821 }
817 ast::Pat::OrPat(p) => { 822 ast::Pat::OrPat(p) => {
@@ -825,7 +830,8 @@ impl ExprCollector<'_> {
825 } 830 }
826 ast::Pat::WildcardPat(_) => Pat::Wild, 831 ast::Pat::WildcardPat(_) => Pat::Wild,
827 ast::Pat::RecordPat(p) => { 832 ast::Pat::RecordPat(p) => {
828 let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); 833 let path =
834 p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
829 let args: Vec<_> = p 835 let args: Vec<_> = p
830 .record_pat_field_list() 836 .record_pat_field_list()
831 .expect("every struct should have a field list") 837 .expect("every struct should have a field list")