Skip to content

Commit 995e57b

Browse files
committed
Gate fmt args flattening behind -Zflatten-format-args.
1 parent 1d59081 commit 995e57b

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

compiler/rustc_ast_lowering/src/format.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
1616
// Never call the const constructor of `fmt::Arguments` if the
1717
// format_args!() had any arguments _before_ flattening/inlining.
1818
let allow_const = fmt.arguments.all_args().is_empty();
19-
let fmt = flatten_format_args(Cow::Borrowed(fmt));
20-
let fmt = inline_literals(fmt);
19+
let mut fmt = Cow::Borrowed(fmt);
20+
if self.tcx.sess.opts.unstable_opts.flatten_format_args {
21+
fmt = flatten_format_args(fmt);
22+
fmt = inline_literals(fmt);
23+
}
2124
expand_format_args(self, sp, &fmt, allow_const)
2225
}
2326
}

compiler/rustc_interface/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ fn test_unstable_options_tracking_hash() {
744744
tracked!(emit_thin_lto, false);
745745
tracked!(export_executable_symbols, true);
746746
tracked!(fewer_names, Some(true));
747+
tracked!(flatten_format_args, true);
747748
tracked!(force_unstable_if_unmarked, true);
748749
tracked!(fuel, Some(("abc".to_string(), 99)));
749750
tracked!(function_sections, Some(false));

compiler/rustc_session/src/options.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1422,6 +1422,9 @@ options! {
14221422
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
14231423
"reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR) \
14241424
(default: no)"),
1425+
flatten_format_args: bool = (false, parse_bool, [TRACKED],
1426+
"flatten nested format_args!() and literals into a simplified format_args!() call \
1427+
(default: no)"),
14251428
force_unstable_if_unmarked: bool = (false, parse_bool, [TRACKED],
14261429
"force all crates to be `rustc_private` unstable (default: no)"),
14271430
fuel: Option<(String, u64)> = (None, parse_optimization_fuel, [TRACKED],

0 commit comments

Comments
 (0)