Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/expr_store/lower.rs')
-rw-r--r--crates/hir-def/src/expr_store/lower.rs88
1 files changed, 34 insertions, 54 deletions
diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs
index 4e877748ca..3b9281ffb9 100644
--- a/crates/hir-def/src/expr_store/lower.rs
+++ b/crates/hir-def/src/expr_store/lower.rs
@@ -960,38 +960,29 @@ impl ExprCollector<'_> {
impl_trait_lower_fn: ImplTraitLowerFn<'_>,
) -> TypeBound {
match node.kind() {
- ast::TypeBoundKind::PathType(path_type) => {
+ ast::TypeBoundKind::PathType(binder, path_type) => {
+ let binder = match binder.and_then(|it| it.generic_param_list()) {
+ Some(gpl) => gpl
+ .lifetime_params()
+ .flat_map(|lp| lp.lifetime().map(|lt| Name::new_lifetime(&lt.text())))
+ .collect(),
+ None => ThinVec::default(),
+ };
let m = match node.question_mark_token() {
Some(_) => TraitBoundModifier::Maybe,
None => TraitBoundModifier::None,
};
self.lower_path_type(&path_type, impl_trait_lower_fn)
.map(|p| {
- TypeBound::Path(self.alloc_path(p, AstPtr::new(&path_type).upcast()), m)
+ let path = self.alloc_path(p, AstPtr::new(&path_type).upcast());
+ if binder.is_empty() {
+ TypeBound::Path(path, m)
+ } else {
+ TypeBound::ForLifetime(binder, path)
+ }
})
.unwrap_or(TypeBound::Error)
}
- ast::TypeBoundKind::ForType(for_type) => {
- let lt_refs = match for_type.generic_param_list() {
- Some(gpl) => gpl
- .lifetime_params()
- .flat_map(|lp| lp.lifetime().map(|lt| Name::new_lifetime(&lt.text())))
- .collect(),
- None => ThinVec::default(),
- };
- let path = for_type.ty().and_then(|ty| match &ty {
- ast::Type::PathType(path_type) => {
- self.lower_path_type(path_type, impl_trait_lower_fn).map(|p| (p, ty))
- }
- _ => None,
- });
- match path {
- Some((p, ty)) => {
- TypeBound::ForLifetime(lt_refs, self.alloc_path(p, AstPtr::new(&ty)))
- }
- None => TypeBound::Error,
- }
- }
ast::TypeBoundKind::Use(gal) => TypeBound::Use(
gal.use_bound_generic_args()
.map(|p| match p {
@@ -1496,13 +1487,13 @@ impl ExprCollector<'_> {
ast::Expr::UnderscoreExpr(_) => self.alloc_pat_from_expr(Pat::Wild, syntax_ptr),
ast::Expr::ParenExpr(e) => {
// We special-case `(..)` for consistency with patterns.
- if let Some(ast::Expr::RangeExpr(range)) = e.expr() {
- if range.is_range_full() {
- return Some(self.alloc_pat_from_expr(
- Pat::Tuple { args: Box::default(), ellipsis: Some(0) },
- syntax_ptr,
- ));
- }
+ if let Some(ast::Expr::RangeExpr(range)) = e.expr()
+ && range.is_range_full()
+ {
+ return Some(self.alloc_pat_from_expr(
+ Pat::Tuple { args: Box::default(), ellipsis: Some(0) },
+ syntax_ptr,
+ ));
}
return e.expr().and_then(|expr| self.maybe_collect_expr_as_pat(&expr));
}
@@ -1981,13 +1972,7 @@ impl ExprCollector<'_> {
return collector(self, None);
}
};
- if record_diagnostics {
- if let Some(err) = res.err {
- self.store
- .diagnostics
- .push(ExpressionStoreDiagnostics::MacroError { node: macro_call_ptr, err });
- }
- }
+ // No need to push macro and parsing errors as they'll be recreated from `macro_calls()`.
match res.value {
Some((mark, expansion)) => {
@@ -1997,10 +1982,6 @@ impl ExprCollector<'_> {
self.store.expansions.insert(macro_call_ptr, macro_file);
}
- if record_diagnostics {
- // FIXME: Report parse errors here
- }
-
let id = collector(self, expansion.map(|it| it.tree()));
self.expander.exit(mark);
id
@@ -2588,19 +2569,18 @@ impl ExprCollector<'_> {
}
}
RibKind::MacroDef(macro_id) => {
- if let Some((parent_ctx, label_macro_id)) = hygiene_info {
- if label_macro_id == **macro_id {
- // A macro is allowed to refer to labels from before its declaration.
- // Therefore, if we got to the rib of its declaration, give up its hygiene
- // and use its parent expansion.
-
- hygiene_id =
- HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
- hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
- let expansion = self.db.lookup_intern_macro_call(expansion.into());
- (parent_ctx.parent(self.db), expansion.def)
- });
- }
+ if let Some((parent_ctx, label_macro_id)) = hygiene_info
+ && label_macro_id == **macro_id
+ {
+ // A macro is allowed to refer to labels from before its declaration.
+ // Therefore, if we got to the rib of its declaration, give up its hygiene
+ // and use its parent expansion.
+
+ hygiene_id = HygieneId::new(parent_ctx.opaque_and_semitransparent(self.db));
+ hygiene_info = parent_ctx.outer_expn(self.db).map(|expansion| {
+ let expansion = self.db.lookup_intern_macro_call(expansion.into());
+ (parent_ctx.parent(self.db), expansion.def)
+ });
}
}
_ => {}