Skip to content

Commit b1745d5

Browse files
committed
[experiment] Remove format_args_nl!().
1 parent 4b87ed9 commit b1745d5

File tree

76 files changed

+269
-1551
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+269
-1551
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
534534
template_str,
535535
str_style,
536536
template_snippet,
537-
false,
538537
parse::ParseMode::InlineAsm,
539538
);
540539
parser.curarg = curarg;

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,13 @@ fn parse_args<'a>(ecx: &mut ExtCtxt<'a>, sp: Span, tts: TokenStream) -> PResult<
153153
Ok(MacroInput { fmtstr, args, is_direct_literal })
154154
}
155155

156-
fn make_format_args(
157-
ecx: &mut ExtCtxt<'_>,
158-
input: MacroInput,
159-
append_newline: bool,
160-
) -> Result<FormatArgs, ()> {
156+
fn make_format_args(ecx: &mut ExtCtxt<'_>, input: MacroInput) -> Result<FormatArgs, ()> {
161157
let msg = "format argument must be a string literal";
162158
let unexpanded_fmt_span = input.fmtstr.span;
163159

164160
let MacroInput { fmtstr: efmt, mut args, is_direct_literal } = input;
165161

166162
let (fmt_str, fmt_style, fmt_span) = match expr_to_spanned_string(ecx, efmt, msg) {
167-
Ok(mut fmt) if append_newline => {
168-
fmt.0 = Symbol::intern(&format!("{}\n", fmt.0));
169-
fmt
170-
}
171163
Ok(fmt) => fmt,
172164
Err(err) => {
173165
if let Some((mut err, suggested)) = err {
@@ -196,13 +188,7 @@ fn make_format_args(
196188

197189
let fmt_str = fmt_str.as_str(); // for the suggestions below
198190
let fmt_snippet = ecx.source_map().span_to_snippet(unexpanded_fmt_span).ok();
199-
let mut parser = parse::Parser::new(
200-
fmt_str,
201-
str_style,
202-
fmt_snippet,
203-
append_newline,
204-
parse::ParseMode::Format,
205-
);
191+
let mut parser = parse::Parser::new(fmt_str, str_style, fmt_snippet, parse::ParseMode::Format);
206192

207193
let mut pieces = Vec::new();
208194
while let Some(piece) = parser.next() {
@@ -831,16 +817,15 @@ fn report_invalid_references(
831817
e.emit();
832818
}
833819

834-
fn expand_format_args_impl<'cx>(
820+
pub fn expand_format_args<'cx>(
835821
ecx: &'cx mut ExtCtxt<'_>,
836822
mut sp: Span,
837823
tts: TokenStream,
838-
nl: bool,
839824
) -> Box<dyn base::MacResult + 'cx> {
840825
sp = ecx.with_def_site_ctxt(sp);
841826
match parse_args(ecx, sp, tts) {
842827
Ok(input) => {
843-
if let Ok(format_args) = make_format_args(ecx, input, nl) {
828+
if let Ok(format_args) = make_format_args(ecx, input) {
844829
MacEager::expr(ecx.expr(sp, ExprKind::FormatArgs(P(format_args))))
845830
} else {
846831
MacEager::expr(DummyResult::raw_expr(sp, true))
@@ -852,19 +837,3 @@ fn expand_format_args_impl<'cx>(
852837
}
853838
}
854839
}
855-
856-
pub fn expand_format_args<'cx>(
857-
ecx: &'cx mut ExtCtxt<'_>,
858-
sp: Span,
859-
tts: TokenStream,
860-
) -> Box<dyn base::MacResult + 'cx> {
861-
expand_format_args_impl(ecx, sp, tts, false)
862-
}
863-
864-
pub fn expand_format_args_nl<'cx>(
865-
ecx: &'cx mut ExtCtxt<'_>,
866-
sp: Span,
867-
tts: TokenStream,
868-
) -> Box<dyn base::MacResult + 'cx> {
869-
expand_format_args_impl(ecx, sp, tts, true)
870-
}

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
8383
concat: concat::expand_concat,
8484
env: env::expand_env,
8585
file: source_util::expand_file,
86-
format_args_nl: format::expand_format_args_nl,
8786
format_args: format::expand_format_args,
8887
const_format_args: format::expand_format_args,
8988
global_asm: asm::expand_global_asm,

compiler/rustc_lint/src/non_fmt_panic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ fn check_panic_str<'tcx>(
244244
Err(_) => (None, None),
245245
};
246246

247-
let mut fmt_parser = Parser::new(fmt, style, snippet.clone(), false, ParseMode::Format);
247+
let mut fmt_parser = Parser::new(fmt, style, snippet.clone(), ParseMode::Format);
248248
let n_arguments = (&mut fmt_parser).filter(|a| matches!(a, Piece::NextArgument(_))).count();
249249

250250
if n_arguments > 0 && fmt_parser.errors.is_empty() {

compiler/rustc_parse_format/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,6 @@ pub struct Parser<'a> {
233233
width_map: Vec<InnerWidthMapping>,
234234
/// Span of the last opening brace seen, used for error reporting
235235
last_opening_brace: Option<InnerSpan>,
236-
/// Whether the source string is comes from `println!` as opposed to `format!` or `print!`
237-
append_newline: bool,
238236
/// Whether this formatting string was written directly in the source. This controls whether we
239237
/// can use spans to refer into it and give better error messages.
240238
/// N.B: This does _not_ control whether implicit argument captures can be used.
@@ -322,7 +320,6 @@ impl<'a> Parser<'a> {
322320
s: &'a str,
323321
style: Option<usize>,
324322
snippet: Option<string::String>,
325-
append_newline: bool,
326323
mode: ParseMode,
327324
) -> Parser<'a> {
328325
let input_string_kind = find_width_map_from_snippet(s, snippet, style);
@@ -341,7 +338,6 @@ impl<'a> Parser<'a> {
341338
arg_places: vec![],
342339
width_map,
343340
last_opening_brace: None,
344-
append_newline,
345341
is_source_literal,
346342
cur_line_start: 0,
347343
line_spans: vec![],
@@ -485,8 +481,7 @@ impl<'a> Parser<'a> {
485481
} else {
486482
let description = format!("expected `{c:?}` but string was terminated");
487483
// point at closing `"`
488-
let pos = self.input.len() - if self.append_newline { 1 } else { 0 };
489-
let pos = self.to_span_index(pos);
484+
let pos = self.to_span_index(self.input.len());
490485
if c == '}' {
491486
let label = format!("expected `{c:?}`");
492487
let (note, secondary_label) = if c == '}' {

compiler/rustc_parse_format/src/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::*;
22

33
#[track_caller]
44
fn same(fmt: &'static str, p: &[Piece<'static>]) {
5-
let parser = Parser::new(fmt, None, None, false, ParseMode::Format);
5+
let parser = Parser::new(fmt, None, None, ParseMode::Format);
66
assert_eq!(parser.collect::<Vec<Piece<'static>>>(), p);
77
}
88

@@ -24,7 +24,7 @@ fn fmtdflt() -> FormatSpec<'static> {
2424
}
2525

2626
fn musterr(s: &str) {
27-
let mut p = Parser::new(s, None, None, false, ParseMode::Format);
27+
let mut p = Parser::new(s, None, None, ParseMode::Format);
2828
p.next();
2929
assert!(!p.errors.is_empty());
3030
}

compiler/rustc_span/src/symbol.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,6 @@ symbols! {
734734
format_args,
735735
format_args_capture,
736736
format_args_macro,
737-
format_args_nl,
738737
format_argument,
739738
format_arguments,
740739
format_count,

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<'tcx> OnUnimplementedFormatString {
576576
let trait_name = tcx.item_name(trait_def_id);
577577
let generics = tcx.generics_of(item_def_id);
578578
let s = self.0.as_str();
579-
let parser = Parser::new(s, None, None, false, ParseMode::Format);
579+
let parser = Parser::new(s, None, None, ParseMode::Format);
580580
let mut result = Ok(());
581581
for token in parser {
582582
match token {
@@ -650,7 +650,7 @@ impl<'tcx> OnUnimplementedFormatString {
650650
let empty_string = String::new();
651651

652652
let s = self.0.as_str();
653-
let parser = Parser::new(s, None, None, false, ParseMode::Format);
653+
let parser = Parser::new(s, None, None, ParseMode::Format);
654654
let item_context = (options.get(&sym::ItemContext)).unwrap_or(&empty_string);
655655
parser
656656
.map(|p| match p {

library/core/src/macros/mod.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -549,13 +549,12 @@ macro_rules! write {
549549
#[macro_export]
550550
#[stable(feature = "rust1", since = "1.0.0")]
551551
#[cfg_attr(not(test), rustc_diagnostic_item = "writeln_macro")]
552-
#[allow_internal_unstable(format_args_nl)]
553552
macro_rules! writeln {
554553
($dst:expr $(,)?) => {
555554
$crate::write!($dst, "\n")
556555
};
557556
($dst:expr, $($arg:tt)*) => {
558-
$dst.write_fmt($crate::format_args_nl!($($arg)*))
557+
$dst.write_fmt($crate::format_args!("{}\n", $crate::format_args!($($arg)*)))
559558
};
560559
}
561560

@@ -893,21 +892,6 @@ pub(crate) mod builtin {
893892
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
894893
}
895894

896-
/// Same as [`format_args`], but adds a newline in the end.
897-
#[unstable(
898-
feature = "format_args_nl",
899-
issue = "none",
900-
reason = "`format_args_nl` is only for internal \
901-
language use and is subject to change"
902-
)]
903-
#[allow_internal_unstable(fmt_internals)]
904-
#[rustc_builtin_macro]
905-
#[macro_export]
906-
macro_rules! format_args_nl {
907-
($fmt:expr) => {{ /* compiler built-in */ }};
908-
($fmt:expr, $($args:tt)*) => {{ /* compiler built-in */ }};
909-
}
910-
911895
/// Inspects an environment variable at compile time.
912896
///
913897
/// This macro will expand to the value of the named environment variable at

library/core/src/prelude/v1.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ pub use crate::hash::macros::Hash;
5555
#[allow(deprecated)]
5656
#[doc(no_inline)]
5757
pub use crate::{
58-
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
59-
format_args_nl, include, include_bytes, include_str, line, log_syntax, module_path, option_env,
60-
stringify, trace_macros,
58+
assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args, include,
59+
include_bytes, include_str, line, log_syntax, module_path, option_env, stringify, trace_macros,
6160
};
6261

6362
#[unstable(

0 commit comments

Comments
 (0)