-
-
Notifications
You must be signed in to change notification settings - Fork 14.2k
MGCA: Support struct expressions without intermediary anon consts #149114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f9685d1
af8fe05
dde43f3
d6c3420
15e92c8
79aefac
762241e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2394,6 +2394,37 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | |
|
|
||
| ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Path(qpath) } | ||
| } | ||
| ExprKind::Struct(se) => { | ||
| let path = self.lower_qpath( | ||
| expr.id, | ||
| &se.qself, | ||
| &se.path, | ||
| ParamMode::Explicit, | ||
| AllowReturnTypeNotation::No, | ||
| ImplTraitContext::Disallowed(ImplTraitPosition::Path), | ||
| None, | ||
| ); | ||
|
|
||
| let fields = self.arena.alloc_from_iter(se.fields.iter().map(|f| { | ||
| let hir_id = self.lower_node_id(f.id); | ||
| self.lower_attrs(hir_id, &f.attrs, f.span, Target::ExprField); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add fixme to look into this, I expect this to be broken as it causes us to silently allow attrs |
||
|
|
||
| let expr = if let ExprKind::ConstBlock(anon_const) = &f.expr.kind { | ||
| self.lower_anon_const_to_const_arg_direct(anon_const) | ||
| } else { | ||
| self.lower_expr_to_const_arg_direct(&f.expr) | ||
|
Comment on lines
+2413
to
+2415
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this naming sucks :3 we should rename the Same with const stuff. |
||
| }; | ||
|
|
||
| &*self.arena.alloc(hir::ConstArgExprField { | ||
| hir_id, | ||
| field: self.lower_ident(f.ident), | ||
| expr: self.arena.alloc(expr), | ||
| span: self.lower_span(f.span), | ||
| }) | ||
| })); | ||
|
|
||
| ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Struct(path, fields) } | ||
| } | ||
| ExprKind::Underscore => ConstArg { | ||
| hir_id: self.lower_node_id(expr.id), | ||
| kind: hir::ConstArgKind::Infer(expr.span, ()), | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -396,6 +396,9 @@ pub trait Visitor<'v>: Sized { | |
| fn visit_expr_field(&mut self, field: &'v ExprField<'v>) -> Self::Result { | ||
| walk_expr_field(self, field) | ||
| } | ||
| fn visit_const_arg_expr_field(&mut self, field: &'v ConstArgExprField<'v>) -> Self::Result { | ||
| walk_const_arg_expr_field(self, field) | ||
| } | ||
| fn visit_pattern_type_pattern(&mut self, p: &'v TyPat<'v>) -> Self::Result { | ||
| walk_ty_pat(self, p) | ||
| } | ||
|
|
@@ -954,6 +957,17 @@ pub fn walk_expr_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v ExprField | |
| try_visit!(visitor.visit_ident(*ident)); | ||
| visitor.visit_expr(*expr) | ||
| } | ||
|
|
||
| pub fn walk_const_arg_expr_field<'v, V: Visitor<'v>>( | ||
| visitor: &mut V, | ||
| field: &'v ConstArgExprField<'v>, | ||
| ) -> V::Result { | ||
| let ConstArgExprField { hir_id, field, expr, span: _ } = field; | ||
| try_visit!(visitor.visit_id(*hir_id)); | ||
| try_visit!(visitor.visit_ident(*field)); | ||
| visitor.visit_const_arg_unambig(*expr) | ||
| } | ||
|
|
||
| /// We track whether an infer var is from a [`Ty`], [`ConstArg`], or [`GenericArg`] so that | ||
| /// HIR visitors overriding [`Visitor::visit_infer`] can determine what kind of infer is being visited | ||
| pub enum InferKind<'hir> { | ||
|
|
@@ -1067,7 +1081,17 @@ pub fn walk_const_arg<'v, V: Visitor<'v>>( | |
| ) -> V::Result { | ||
| let ConstArg { hir_id, kind } = const_arg; | ||
| try_visit!(visitor.visit_id(*hir_id)); | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why whitespace |
||
| match kind { | ||
| ConstArgKind::Struct(qpath, field_exprs) => { | ||
| try_visit!(visitor.visit_qpath(qpath, *hir_id, qpath.span())); | ||
|
|
||
| for field_expr in *field_exprs { | ||
| try_visit!(visitor.visit_const_arg_expr_field(field_expr)); | ||
| } | ||
|
|
||
| V::Result::output() | ||
| } | ||
| ConstArgKind::Path(qpath) => visitor.visit_qpath(qpath, *hir_id, qpath.span()), | ||
| ConstArgKind::Anon(anon) => visitor.visit_anon_const(*anon), | ||
| ConstArgKind::Error(_, _) => V::Result::output(), // errors and spans are not important | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add FIXME that we should use
Optionalhere and make sure theItemCtxtstill errors if u do it in a signature