Skip to content

Commit

Permalink
Auto merge of #106745 - m-ou-se:format-args-ast, r=oli-obk
Browse files Browse the repository at this point in the history
Move format_args!() into AST (and expand it during AST lowering)

Implements rust-lang/compiler-team#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.
  • Loading branch information
bors committed Jan 26, 2023
2 parents 1d9afb2 + 80d196d commit 6d13315
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(..)
Expand Down

0 comments on commit 6d13315

Please sign in to comment.