diff options
Diffstat (limited to 'crates/hir_def/src/body/lower.rs')
-rw-r--r-- | crates/hir_def/src/body/lower.rs | 28 |
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 c11da30d2..75dc19c11 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 | ||
41 | use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource}; | 41 | use super::{diagnostics::BodyDiagnostic, ExprSource, PatSource}; |
42 | 42 | ||
43 | pub struct LowerCtx { | 43 | pub 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 | ||
49 | impl LowerCtx { | 50 | impl<'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() |
@@ -791,7 +794,8 @@ impl ExprCollector<'_> { | |||
791 | } | 794 | } |
792 | } | 795 | } |
793 | ast::Pat::TupleStructPat(p) => { | 796 | ast::Pat::TupleStructPat(p) => { |
794 | let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); | 797 | let path = |
798 | p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new); | ||
795 | let (args, ellipsis) = self.collect_tuple_pat(p.fields()); | 799 | let (args, ellipsis) = self.collect_tuple_pat(p.fields()); |
796 | Pat::TupleStruct { path, args, ellipsis } | 800 | Pat::TupleStruct { path, args, ellipsis } |
797 | } | 801 | } |
@@ -801,7 +805,8 @@ impl ExprCollector<'_> { | |||
801 | Pat::Ref { pat, mutability } | 805 | Pat::Ref { pat, mutability } |
802 | } | 806 | } |
803 | ast::Pat::PathPat(p) => { | 807 | ast::Pat::PathPat(p) => { |
804 | let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); | 808 | let path = |
809 | p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new); | ||
805 | path.map(Pat::Path).unwrap_or(Pat::Missing) | 810 | path.map(Pat::Path).unwrap_or(Pat::Missing) |
806 | } | 811 | } |
807 | ast::Pat::OrPat(p) => { | 812 | ast::Pat::OrPat(p) => { |
@@ -815,7 +820,8 @@ impl ExprCollector<'_> { | |||
815 | } | 820 | } |
816 | ast::Pat::WildcardPat(_) => Pat::Wild, | 821 | ast::Pat::WildcardPat(_) => Pat::Wild, |
817 | ast::Pat::RecordPat(p) => { | 822 | ast::Pat::RecordPat(p) => { |
818 | let path = p.path().and_then(|path| self.expander.parse_path(path)).map(Box::new); | 823 | let path = |
824 | p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new); | ||
819 | let args: Vec<_> = p | 825 | let args: Vec<_> = p |
820 | .record_pat_field_list() | 826 | .record_pat_field_list() |
821 | .expect("every struct should have a field list") | 827 | .expect("every struct should have a field list") |