Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/body/lower.rs')
-rw-r--r--crates/hir-def/src/body/lower.rs64
1 files changed, 26 insertions, 38 deletions
diff --git a/crates/hir-def/src/body/lower.rs b/crates/hir-def/src/body/lower.rs
index 6117664c64..0b108b54e6 100644
--- a/crates/hir-def/src/body/lower.rs
+++ b/crates/hir-def/src/body/lower.rs
@@ -12,7 +12,7 @@ use hir_expand::{
span_map::{ExpansionSpanMap, SpanMap},
InFile, MacroDefId,
};
-use intern::{sym, Interned, Symbol};
+use intern::{sym, Symbol};
use rustc_hash::FxHashMap;
use span::AstIdMap;
use stdx::never;
@@ -274,8 +274,8 @@ impl ExprCollector<'_> {
(self.body, self.source_map)
}
- fn ctx(&self) -> LowerCtx<'_> {
- self.expander.ctx(self.db)
+ fn ctx(&mut self) -> LowerCtx<'_> {
+ self.expander.ctx(self.db, &mut self.body.types, &mut self.source_map.types)
}
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
@@ -436,7 +436,7 @@ impl ExprCollector<'_> {
}
ast::Expr::PathExpr(e) => {
let (path, hygiene) = self
- .collect_expr_path(&e)
+ .collect_expr_path(e)
.map(|(path, hygiene)| (Expr::Path(path), hygiene))
.unwrap_or((Expr::Missing, HygieneId::ROOT));
let expr_id = self.alloc_expr(path, syntax_ptr);
@@ -486,8 +486,7 @@ impl ExprCollector<'_> {
self.alloc_expr(Expr::Yeet { expr }, syntax_ptr)
}
ast::Expr::RecordExpr(e) => {
- let path =
- e.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
+ let path = e.path().and_then(|path| self.parse_path(path)).map(Box::new);
let record_lit = if let Some(nfl) = e.record_expr_field_list() {
let fields = nfl
.fields()
@@ -534,7 +533,7 @@ impl ExprCollector<'_> {
ast::Expr::TryExpr(e) => self.collect_try_operator(syntax_ptr, e),
ast::Expr::CastExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
- let type_ref = Interned::new(TypeRef::from_ast_opt(&self.ctx(), e.ty()));
+ let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
}
ast::Expr::RefExpr(e) => {
@@ -573,16 +572,13 @@ impl ExprCollector<'_> {
arg_types.reserve_exact(num_params);
for param in pl.params() {
let pat = this.collect_pat_top(param.pat());
- let type_ref =
- param.ty().map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
+ let type_ref = param.ty().map(|it| TypeRef::from_ast(&this.ctx(), it));
args.push(pat);
arg_types.push(type_ref);
}
}
- let ret_type = e
- .ret_type()
- .and_then(|r| r.ty())
- .map(|it| Interned::new(TypeRef::from_ast(&this.ctx(), it)));
+ let ret_type =
+ e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&this.ctx(), it));
let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
let prev_try_block_label = this.current_try_block_label.take();
@@ -709,7 +705,7 @@ impl ExprCollector<'_> {
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
ast::Expr::AsmExpr(e) => self.lower_inline_asm(e, syntax_ptr),
ast::Expr::OffsetOfExpr(e) => {
- let container = Interned::new(TypeRef::from_ast_opt(&self.ctx(), e.ty()));
+ let container = TypeRef::from_ast_opt(&self.ctx(), e.ty());
let fields = e.fields().map(|it| it.as_name()).collect();
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
}
@@ -717,15 +713,15 @@ impl ExprCollector<'_> {
})
}
- fn collect_expr_path(&mut self, e: &ast::PathExpr) -> Option<(Path, HygieneId)> {
+ fn parse_path(&mut self, path: ast::Path) -> Option<Path> {
+ self.expander.parse_path(self.db, path, &mut self.body.types, &mut self.source_map.types)
+ }
+
+ fn collect_expr_path(&mut self, e: ast::PathExpr) -> Option<(Path, HygieneId)> {
e.path().and_then(|path| {
- let path = self.expander.parse_path(self.db, path)?;
- let Path::Normal { type_anchor, mod_path, generic_args } = &path else {
- panic!("path parsing produced a non-normal path");
- };
+ let path = self.parse_path(path)?;
// Need to enable `mod_path.len() < 1` for `self`.
- let may_be_variable =
- type_anchor.is_none() && mod_path.len() <= 1 && generic_args.is_none();
+ let may_be_variable = matches!(&path, Path::BarePath(mod_path) if mod_path.len() <= 1);
let hygiene = if may_be_variable {
self.hygiene_id_for(e.syntax().text_range().start())
} else {
@@ -790,17 +786,14 @@ impl ExprCollector<'_> {
}
ast::Expr::CallExpr(e) => {
let path = collect_path(self, e.expr()?)?;
- let path = path
- .path()
- .and_then(|path| self.expander.parse_path(self.db, path))
- .map(Box::new);
+ let path = path.path().and_then(|path| self.parse_path(path)).map(Box::new);
let (ellipsis, args) = collect_tuple(self, e.arg_list()?.args());
self.alloc_pat_from_expr(Pat::TupleStruct { path, args, ellipsis }, syntax_ptr)
}
ast::Expr::PathExpr(e) => {
let (path, hygiene) = self
- .collect_expr_path(e)
- .map(|(path, hygiene)| (Pat::Path(Box::new(path)), hygiene))
+ .collect_expr_path(e.clone())
+ .map(|(path, hygiene)| (Pat::Path(path), hygiene))
.unwrap_or((Pat::Missing, HygieneId::ROOT));
let pat_id = self.alloc_pat_from_expr(path, syntax_ptr);
if !hygiene.is_root() {
@@ -819,8 +812,7 @@ impl ExprCollector<'_> {
id
}
ast::Expr::RecordExpr(e) => {
- let path =
- e.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
+ let path = e.path().and_then(|path| self.parse_path(path)).map(Box::new);
let record_field_list = e.record_expr_field_list()?;
let ellipsis = record_field_list.dotdot_token().is_some();
// FIXME: Report an error here if `record_field_list.spread().is_some()`.
@@ -1063,7 +1055,7 @@ impl ExprCollector<'_> {
syntax_ptr,
);
let none_arm = MatchArm {
- pat: self.alloc_pat_desugared(Pat::Path(Box::new(option_none))),
+ pat: self.alloc_pat_desugared(Pat::Path(option_none)),
guard: None,
expr: self.alloc_expr(Expr::Break { expr: None, label: None }, syntax_ptr),
};
@@ -1325,8 +1317,7 @@ impl ExprCollector<'_> {
return;
}
let pat = self.collect_pat_top(stmt.pat());
- let type_ref =
- stmt.ty().map(|it| Interned::new(TypeRef::from_ast(&self.ctx(), it)));
+ let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
let else_branch = stmt
.let_else()
@@ -1552,8 +1543,7 @@ impl ExprCollector<'_> {
return pat;
}
ast::Pat::TupleStructPat(p) => {
- let path =
- p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
+ let path = p.path().and_then(|path| self.parse_path(path)).map(Box::new);
let (args, ellipsis) = self.collect_tuple_pat(
p.fields(),
comma_follows_token(p.l_paren_token()),
@@ -1567,8 +1557,7 @@ impl ExprCollector<'_> {
Pat::Ref { pat, mutability }
}
ast::Pat::PathPat(p) => {
- let path =
- p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
+ let path = p.path().and_then(|path| self.parse_path(path));
path.map(Pat::Path).unwrap_or(Pat::Missing)
}
ast::Pat::OrPat(p) => 'b: {
@@ -1615,8 +1604,7 @@ impl ExprCollector<'_> {
}
ast::Pat::WildcardPat(_) => Pat::Wild,
ast::Pat::RecordPat(p) => {
- let path =
- p.path().and_then(|path| self.expander.parse_path(self.db, path)).map(Box::new);
+ let path = p.path().and_then(|path| self.parse_path(path)).map(Box::new);
let record_pat_field_list =
&p.record_pat_field_list().expect("every struct should have a field list");
let args = record_pat_field_list