未验证 提交 9f6d0cb0 编写于 作者: M Matthias Krüger 提交者: GitHub

Rollup merge of #93463 - dtolnay:_args, r=cjgillot

Rename _args -> args in format_args expansion

As observed in https://github.com/rust-lang/rust/pull/91359#discussion_r786058960, prior to that PR this variable was sometimes never used, such as in the case of:

```rust
println!("");

// used to expand to:
::std::io::_print(
    ::core::fmt::Arguments::new_v1(
        &["\n"],
        &match () {
            _args => [],
        },
    ),
);
```

so the leading underscore in `_args` was used to suppress an unused variable lint. However after #91359 the variable is always used when present, as the unused case would instead expand to:

```rust
::std::io::_print(::core::fmt::Arguments::new_v1(&["\n"], &[]));
```
......@@ -791,7 +791,7 @@ fn into_expr(self) -> P<ast::Expr> {
// Thus in the not nicely ordered case we emit the following instead:
//
// match (&$arg0, &$arg1, …) {
// _args => [ArgumentV1::new(_args.$i, …), ArgumentV1::new(_args.$j, …), …]
// args => [ArgumentV1::new(args.$i, …), ArgumentV1::new(args.$j, …), …]
// }
//
// for the sequence of indices $i, $j, … governed by fmt_arg_index_and_ty.
......@@ -804,7 +804,7 @@ fn into_expr(self) -> P<ast::Expr> {
self.ecx.expr_addr_of(expansion_span, P(e.take()))
} else {
let def_site = self.ecx.with_def_site_ctxt(span);
let args_tuple = self.ecx.expr_ident(def_site, Ident::new(sym::_args, def_site));
let args_tuple = self.ecx.expr_ident(def_site, Ident::new(sym::args, def_site));
let member = Ident::new(sym::integer(arg_index), def_site);
self.ecx.expr(def_site, ast::ExprKind::Field(args_tuple, member))
};
......@@ -828,7 +828,7 @@ fn into_expr(self) -> P<ast::Expr> {
.map(|e| self.ecx.expr_addr_of(e.span.with_ctxt(self.macsp.ctxt()), e))
.collect();
let pat = self.ecx.pat_ident(self.macsp, Ident::new(sym::_args, self.macsp));
let pat = self.ecx.pat_ident(self.macsp, Ident::new(sym::args, self.macsp));
let arm = self.ecx.arm(self.macsp, pat, args_array);
let head = self.ecx.expr(self.macsp, ast::ExprKind::Tup(heads));
self.ecx.expr_match(self.macsp, head, vec![arm])
......
......@@ -272,7 +272,6 @@
__H,
__S,
__try_var,
_args,
_d,
_e,
_task_context,
......@@ -324,6 +323,7 @@
append_const_msg,
arbitrary_enum_discriminant,
arbitrary_self_types,
args,
arith_offset,
arm,
arm_target_feature,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册