Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk

Move format_args!() into AST (and expand it during AST lowering)

Implements https://github.com/rust-lang/compiler-team/issues/541

This moves FormatArgs from rustc_builtin_macros to rustc_ast_lowering. For now, the end result is the same. But this allows for future changes to do smarter things with format_args!(). It also allows Clippy to directly access the ast::FormatArgs, making things a lot easier.

This change turns the format args types into lang items. The builtin macro used to refer to them by their path. After this change, the path is no longer relevant, making it easier to make changes in `core`.

This updates clippy to use the new language items, but this doesn't yet make clippy use the ast::FormatArgs structure that's now available. That should be done after this is merged.
This commit is contained in:
bors 2023-01-26 12:44:47 +00:00
commit 6d133152f8
2 changed files with 5 additions and 1 deletions

View File

@ -400,7 +400,10 @@ pub(crate) fn format_expr(
}
}
ast::ExprKind::Underscore => Some("_".to_owned()),
ast::ExprKind::IncludedBytes(..) => unreachable!(),
ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) => {
// These do not occur in the AST because macros aren't expanded.
unreachable!()
}
ast::ExprKind::Err => None,
};

View File

@ -463,6 +463,7 @@ pub(crate) fn first_line_ends_with(s: &str, c: char) -> bool {
pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr: &str) -> bool {
match expr.kind {
ast::ExprKind::MacCall(..)
| ast::ExprKind::FormatArgs(..)
| ast::ExprKind::Call(..)
| ast::ExprKind::MethodCall(..)
| ast::ExprKind::Array(..)