Rollup merge of #124637 - fmease:ast-pretty-ty-asc-builtin-syn, r=compiler-errors
AST pretty: Use `builtin_syntax` for type ascription Follow-up to #122806. CC #124619.
This commit is contained in:
commit
e6c82d9b59
@ -1390,7 +1390,7 @@ pub struct StructExpr {
|
|||||||
// Adding a new variant? Please update `test_expr` in `tests/ui/macros/stringify.rs`.
|
// Adding a new variant? Please update `test_expr` in `tests/ui/macros/stringify.rs`.
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub enum ExprKind {
|
pub enum ExprKind {
|
||||||
/// An array (`[a, b, c, d]`)
|
/// An array (e.g, `[a, b, c, d]`).
|
||||||
Array(ThinVec<P<Expr>>),
|
Array(ThinVec<P<Expr>>),
|
||||||
/// Allow anonymous constants from an inline `const` block
|
/// Allow anonymous constants from an inline `const` block
|
||||||
ConstBlock(AnonConst),
|
ConstBlock(AnonConst),
|
||||||
@ -1401,7 +1401,7 @@ pub enum ExprKind {
|
|||||||
/// This also represents calling the constructor of
|
/// This also represents calling the constructor of
|
||||||
/// tuple-like ADTs such as tuple structs and enum variants.
|
/// tuple-like ADTs such as tuple structs and enum variants.
|
||||||
Call(P<Expr>, ThinVec<P<Expr>>),
|
Call(P<Expr>, ThinVec<P<Expr>>),
|
||||||
/// A method call (e.g. `x.foo::<Bar, Baz>(a, b, c)`).
|
/// A method call (e.g., `x.foo::<Bar, Baz>(a, b, c)`).
|
||||||
MethodCall(Box<MethodCall>),
|
MethodCall(Box<MethodCall>),
|
||||||
/// A tuple (e.g., `(a, b, c, d)`).
|
/// A tuple (e.g., `(a, b, c, d)`).
|
||||||
Tup(ThinVec<P<Expr>>),
|
Tup(ThinVec<P<Expr>>),
|
||||||
@ -1413,7 +1413,10 @@ pub enum ExprKind {
|
|||||||
Lit(token::Lit),
|
Lit(token::Lit),
|
||||||
/// A cast (e.g., `foo as f64`).
|
/// A cast (e.g., `foo as f64`).
|
||||||
Cast(P<Expr>, P<Ty>),
|
Cast(P<Expr>, P<Ty>),
|
||||||
/// A type ascription (e.g., `42: usize`).
|
/// A type ascription (e.g., `builtin # type_ascribe(42, usize)`).
|
||||||
|
///
|
||||||
|
/// Usually not written directly in user code but
|
||||||
|
/// indirectly via the macro `type_ascribe!(...)`.
|
||||||
Type(P<Expr>, P<Ty>),
|
Type(P<Expr>, P<Ty>),
|
||||||
/// A `let pat = expr` expression that is only semantically allowed in the condition
|
/// A `let pat = expr` expression that is only semantically allowed in the condition
|
||||||
/// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`).
|
/// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`).
|
||||||
@ -1488,7 +1491,10 @@ pub enum ExprKind {
|
|||||||
/// Output of the `asm!()` macro.
|
/// Output of the `asm!()` macro.
|
||||||
InlineAsm(P<InlineAsm>),
|
InlineAsm(P<InlineAsm>),
|
||||||
|
|
||||||
/// Output of the `offset_of!()` macro.
|
/// An `offset_of` expression (e.g., `builtin # offset_of(Struct, field)`).
|
||||||
|
///
|
||||||
|
/// Usually not written directly in user code but
|
||||||
|
/// indirectly via the macro `core::mem::offset_of!(...)`.
|
||||||
OffsetOf(P<Ty>, P<[Ident]>),
|
OffsetOf(P<Ty>, P<[Ident]>),
|
||||||
|
|
||||||
/// A macro invocation; pre-expansion.
|
/// A macro invocation; pre-expansion.
|
||||||
|
@ -422,7 +422,8 @@ pub(super) fn print_expr_outer_attr_style(
|
|||||||
self.print_type(ty);
|
self.print_type(ty);
|
||||||
}
|
}
|
||||||
ast::ExprKind::Type(expr, ty) => {
|
ast::ExprKind::Type(expr, ty) => {
|
||||||
self.word("type_ascribe!(");
|
self.word("builtin # type_ascribe");
|
||||||
|
self.popen();
|
||||||
self.ibox(0);
|
self.ibox(0);
|
||||||
self.print_expr(expr, FixupContext::default());
|
self.print_expr(expr, FixupContext::default());
|
||||||
|
|
||||||
@ -431,7 +432,7 @@ pub(super) fn print_expr_outer_attr_style(
|
|||||||
self.print_type(ty);
|
self.print_type(ty);
|
||||||
|
|
||||||
self.end();
|
self.end();
|
||||||
self.word(")");
|
self.pclose();
|
||||||
}
|
}
|
||||||
ast::ExprKind::Let(pat, scrutinee, _, _) => {
|
ast::ExprKind::Let(pat, scrutinee, _, _) => {
|
||||||
self.print_let(pat, scrutinee, fixup);
|
self.print_let(pat, scrutinee, fixup);
|
||||||
@ -657,15 +658,15 @@ pub(super) fn print_expr_outer_attr_style(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
ast::ExprKind::InlineAsm(a) => {
|
ast::ExprKind::InlineAsm(a) => {
|
||||||
// FIXME: This should have its own syntax, distinct from a macro invocation.
|
// FIXME: Print `builtin # asm` once macro `asm` uses `builtin_syntax`.
|
||||||
self.word("asm!");
|
self.word("asm!");
|
||||||
self.print_inline_asm(a);
|
self.print_inline_asm(a);
|
||||||
}
|
}
|
||||||
ast::ExprKind::FormatArgs(fmt) => {
|
ast::ExprKind::FormatArgs(fmt) => {
|
||||||
// FIXME: This should have its own syntax, distinct from a macro invocation.
|
// FIXME: Print `builtin # format_args` once macro `format_args` uses `builtin_syntax`.
|
||||||
self.word("format_args!");
|
self.word("format_args!");
|
||||||
self.popen();
|
self.popen();
|
||||||
self.rbox(0, Inconsistent);
|
self.ibox(0);
|
||||||
self.word(reconstruct_format_args_template_string(&fmt.template));
|
self.word(reconstruct_format_args_template_string(&fmt.template));
|
||||||
for arg in fmt.arguments.all_args() {
|
for arg in fmt.arguments.all_args() {
|
||||||
self.word_space(",");
|
self.word_space(",");
|
||||||
@ -677,7 +678,7 @@ pub(super) fn print_expr_outer_attr_style(
|
|||||||
ast::ExprKind::OffsetOf(container, fields) => {
|
ast::ExprKind::OffsetOf(container, fields) => {
|
||||||
self.word("builtin # offset_of");
|
self.word("builtin # offset_of");
|
||||||
self.popen();
|
self.popen();
|
||||||
self.rbox(0, Inconsistent);
|
self.ibox(0);
|
||||||
self.print_type(container);
|
self.print_type(container);
|
||||||
self.word(",");
|
self.word(",");
|
||||||
self.space();
|
self.space();
|
||||||
@ -690,8 +691,8 @@ pub(super) fn print_expr_outer_attr_style(
|
|||||||
self.print_ident(field);
|
self.print_ident(field);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.pclose();
|
|
||||||
self.end();
|
self.end();
|
||||||
|
self.pclose();
|
||||||
}
|
}
|
||||||
ast::ExprKind::MacCall(m) => self.print_mac(m),
|
ast::ExprKind::MacCall(m) => self.print_mac(m),
|
||||||
ast::ExprKind::Paren(e) => {
|
ast::ExprKind::Paren(e) => {
|
||||||
|
@ -238,6 +238,7 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
|
|||||||
self.bclose(item.span, empty);
|
self.bclose(item.span, empty);
|
||||||
}
|
}
|
||||||
ast::ItemKind::GlobalAsm(asm) => {
|
ast::ItemKind::GlobalAsm(asm) => {
|
||||||
|
// FIXME: Print `builtin # global_asm` once macro `global_asm` uses `builtin_syntax`.
|
||||||
self.head(visibility_qualified(&item.vis, "global_asm!"));
|
self.head(visibility_qualified(&item.vis, "global_asm!"));
|
||||||
self.print_inline_asm(asm);
|
self.print_inline_asm(asm);
|
||||||
self.word(";");
|
self.word(";");
|
||||||
|
Loading…
Reference in New Issue
Block a user