Skip to content

Commit dabf0c6

Browse files
committed
Auto merge of #24312 - rprichard:destabilize-format-args, r=alexcrichton
Fixes #22953.
2 parents 47551b5 + 8615563 commit dabf0c6

16 files changed

+61
-61
lines changed

src/libcore/fmt/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ mod num;
3838
mod float;
3939
mod builders;
4040

41-
#[stable(feature = "rust1", since = "1.0.0")]
41+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
42+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
4243
#[doc(hidden)]
4344
pub mod rt {
4445
pub mod v1;
@@ -134,7 +135,8 @@ enum Void {}
134135
/// compile time it is ensured that the function and the value have the correct
135136
/// types, and then this struct is used to canonicalize arguments to one type.
136137
#[derive(Copy)]
137-
#[stable(feature = "rust1", since = "1.0.0")]
138+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
139+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
138140
#[doc(hidden)]
139141
pub struct ArgumentV1<'a> {
140142
value: &'a Void,
@@ -154,7 +156,8 @@ impl<'a> ArgumentV1<'a> {
154156
}
155157

156158
#[doc(hidden)]
157-
#[stable(feature = "rust1", since = "1.0.0")]
159+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
160+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
158161
pub fn new<'b, T>(x: &'b T,
159162
f: fn(&T, &mut Formatter) -> Result) -> ArgumentV1<'b> {
160163
unsafe {
@@ -166,7 +169,8 @@ impl<'a> ArgumentV1<'a> {
166169
}
167170

168171
#[doc(hidden)]
169-
#[stable(feature = "rust1", since = "1.0.0")]
172+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
173+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
170174
pub fn from_usize(x: &usize) -> ArgumentV1 {
171175
ArgumentV1::new(x, ArgumentV1::show_usize)
172176
}
@@ -189,7 +193,8 @@ impl<'a> Arguments<'a> {
189193
/// When using the format_args!() macro, this function is used to generate the
190194
/// Arguments structure.
191195
#[doc(hidden)] #[inline]
192-
#[stable(feature = "rust1", since = "1.0.0")]
196+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
197+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
193198
pub fn new_v1(pieces: &'a [&'a str],
194199
args: &'a [ArgumentV1<'a>]) -> Arguments<'a> {
195200
Arguments {
@@ -206,7 +211,8 @@ impl<'a> Arguments<'a> {
206211
/// created with `argumentusize`. However, failing to do so doesn't cause
207212
/// unsafety, but will ignore invalid .
208213
#[doc(hidden)] #[inline]
209-
#[stable(feature = "rust1", since = "1.0.0")]
214+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
215+
#[cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
210216
pub fn new_v1_formatted(pieces: &'a [&'a str],
211217
args: &'a [ArgumentV1<'a>],
212218
fmt: &'a [rt::v1::Argument]) -> Arguments<'a> {

src/libcore/fmt/rt/v1.rs

+24-23
Original file line numberDiff line numberDiff line change
@@ -14,68 +14,69 @@
1414
//! These definitions are similar to their `ct` equivalents, but differ in that
1515
//! these can be statically allocated and are slightly optimized for the runtime
1616
17-
#![stable(feature = "rust1", since = "1.0.0")]
17+
#![cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
18+
#![cfg_attr(not(stage0), unstable(feature = "core", reason = "internal to format_args!"))]
1819

1920
#[derive(Copy, Clone)]
20-
#[stable(feature = "rust1", since = "1.0.0")]
21+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
2122
pub struct Argument {
22-
#[stable(feature = "rust1", since = "1.0.0")]
23+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
2324
pub position: Position,
24-
#[stable(feature = "rust1", since = "1.0.0")]
25+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
2526
pub format: FormatSpec,
2627
}
2728

2829
#[derive(Copy, Clone)]
29-
#[stable(feature = "rust1", since = "1.0.0")]
30+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
3031
pub struct FormatSpec {
31-
#[stable(feature = "rust1", since = "1.0.0")]
32+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
3233
pub fill: char,
33-
#[stable(feature = "rust1", since = "1.0.0")]
34+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
3435
pub align: Alignment,
35-
#[stable(feature = "rust1", since = "1.0.0")]
36+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
3637
pub flags: u32,
37-
#[stable(feature = "rust1", since = "1.0.0")]
38+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
3839
pub precision: Count,
39-
#[stable(feature = "rust1", since = "1.0.0")]
40+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
4041
pub width: Count,
4142
}
4243

4344
/// Possible alignments that can be requested as part of a formatting directive.
4445
#[derive(Copy, Clone, PartialEq)]
45-
#[stable(feature = "rust1", since = "1.0.0")]
46+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
4647
pub enum Alignment {
4748
/// Indication that contents should be left-aligned.
48-
#[stable(feature = "rust1", since = "1.0.0")]
49+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
4950
Left,
5051
/// Indication that contents should be right-aligned.
51-
#[stable(feature = "rust1", since = "1.0.0")]
52+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
5253
Right,
5354
/// Indication that contents should be center-aligned.
54-
#[stable(feature = "rust1", since = "1.0.0")]
55+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
5556
Center,
5657
/// No alignment was requested.
57-
#[stable(feature = "rust1", since = "1.0.0")]
58+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
5859
Unknown,
5960
}
6061

6162
#[derive(Copy, Clone)]
62-
#[stable(feature = "rust1", since = "1.0.0")]
63+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
6364
pub enum Count {
64-
#[stable(feature = "rust1", since = "1.0.0")]
65+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
6566
Is(usize),
66-
#[stable(feature = "rust1", since = "1.0.0")]
67+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
6768
Param(usize),
68-
#[stable(feature = "rust1", since = "1.0.0")]
69+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
6970
NextParam,
70-
#[stable(feature = "rust1", since = "1.0.0")]
71+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
7172
Implied,
7273
}
7374

7475
#[derive(Copy, Clone)]
75-
#[stable(feature = "rust1", since = "1.0.0")]
76+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
7677
pub enum Position {
77-
#[stable(feature = "rust1", since = "1.0.0")]
78+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
7879
Next,
79-
#[stable(feature = "rust1", since = "1.0.0")]
80+
#[cfg_attr(stage0, stable(feature = "rust1", since = "1.0.0"))]
8081
At(usize)
8182
}

src/libsyntax/ext/format.rs

+25-19
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ enum Position {
3838

3939
struct Context<'a, 'b:'a> {
4040
ecx: &'a mut ExtCtxt<'b>,
41+
/// The macro's call site. References to unstable formatting internals must
42+
/// use this span to pass the stability checker.
43+
macsp: Span,
44+
/// The span of the format string literal.
4145
fmtsp: Span,
4246

4347
/// Parsed argument expressions and the types that we've found so far for
@@ -308,7 +312,7 @@ impl<'a, 'b> Context<'a, 'b> {
308312
}
309313

310314
fn trans_count(&self, c: parse::Count) -> P<ast::Expr> {
311-
let sp = self.fmtsp;
315+
let sp = self.macsp;
312316
let count = |c, arg| {
313317
let mut path = Context::rtpath(self.ecx, "Count");
314318
path.push(self.ecx.ident_of(c));
@@ -346,7 +350,7 @@ impl<'a, 'b> Context<'a, 'b> {
346350
/// Translate a `parse::Piece` to a static `rt::Argument` or append
347351
/// to the `literal` string.
348352
fn trans_piece(&mut self, piece: &parse::Piece) -> Option<P<ast::Expr>> {
349-
let sp = self.fmtsp;
353+
let sp = self.macsp;
350354
match *piece {
351355
parse::String(s) => {
352356
self.literal.push_str(s);
@@ -442,22 +446,22 @@ impl<'a, 'b> Context<'a, 'b> {
442446
piece_ty: P<ast::Ty>,
443447
pieces: Vec<P<ast::Expr>>)
444448
-> P<ast::Expr> {
445-
let fmtsp = piece_ty.span;
446-
let ty = ecx.ty_rptr(fmtsp,
447-
ecx.ty(fmtsp, ast::TyVec(piece_ty)),
448-
Some(ecx.lifetime(fmtsp, special_idents::static_lifetime.name)),
449+
let sp = piece_ty.span;
450+
let ty = ecx.ty_rptr(sp,
451+
ecx.ty(sp, ast::TyVec(piece_ty)),
452+
Some(ecx.lifetime(sp, special_idents::static_lifetime.name)),
449453
ast::MutImmutable);
450-
let slice = ecx.expr_vec_slice(fmtsp, pieces);
454+
let slice = ecx.expr_vec_slice(sp, pieces);
451455
let st = ast::ItemStatic(ty, ast::MutImmutable, slice);
452456

453457
let name = ecx.ident_of(name);
454-
let item = ecx.item(fmtsp, name, vec![], st);
455-
let decl = respan(fmtsp, ast::DeclItem(item));
458+
let item = ecx.item(sp, name, vec![], st);
459+
let decl = respan(sp, ast::DeclItem(item));
456460

457461
// Wrap the declaration in a block so that it forms a single expression.
458-
ecx.expr_block(ecx.block(fmtsp,
459-
vec![P(respan(fmtsp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))],
460-
Some(ecx.expr_ident(fmtsp, name))))
462+
ecx.expr_block(ecx.block(sp,
463+
vec![P(respan(sp, ast::StmtDecl(P(decl), ast::DUMMY_NODE_ID)))],
464+
Some(ecx.expr_ident(sp, name))))
461465
}
462466

463467
/// Actually builds the expression which the iformat! block will be expanded
@@ -497,7 +501,7 @@ impl<'a, 'b> Context<'a, 'b> {
497501

498502
let name = self.ecx.ident_of(&format!("__arg{}", i));
499503
pats.push(self.ecx.pat_ident(e.span, name));
500-
locals.push(Context::format_arg(self.ecx, e.span, arg_ty,
504+
locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty,
501505
self.ecx.expr_ident(e.span, name)));
502506
heads.push(self.ecx.expr_addr_of(e.span, e));
503507
}
@@ -515,7 +519,7 @@ impl<'a, 'b> Context<'a, 'b> {
515519
*name));
516520
pats.push(self.ecx.pat_ident(e.span, lname));
517521
names[*self.name_positions.get(name).unwrap()] =
518-
Some(Context::format_arg(self.ecx, e.span, arg_ty,
522+
Some(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty,
519523
self.ecx.expr_ident(e.span, lname)));
520524
heads.push(self.ecx.expr_addr_of(e.span, e));
521525
}
@@ -566,7 +570,7 @@ impl<'a, 'b> Context<'a, 'b> {
566570
// Build up the static array which will store our precompiled
567571
// nonstandard placeholders, if there are any.
568572
let piece_ty = self.ecx.ty_path(self.ecx.path_global(
569-
self.fmtsp,
573+
self.macsp,
570574
Context::rtpath(self.ecx, "Argument")));
571575
let fmt = Context::static_array(self.ecx,
572576
"__STATIC_FMTARGS",
@@ -576,14 +580,14 @@ impl<'a, 'b> Context<'a, 'b> {
576580
("new_v1_formatted", vec![pieces, args_slice, fmt])
577581
};
578582

579-
self.ecx.expr_call_global(self.fmtsp, vec!(
583+
self.ecx.expr_call_global(self.macsp, vec!(
580584
self.ecx.ident_of_std("core"),
581585
self.ecx.ident_of("fmt"),
582586
self.ecx.ident_of("Arguments"),
583587
self.ecx.ident_of(fn_name)), fn_args)
584588
}
585589

586-
fn format_arg(ecx: &ExtCtxt, sp: Span,
590+
fn format_arg(ecx: &ExtCtxt, macsp: Span, sp: Span,
587591
ty: &ArgumentType, arg: P<ast::Expr>)
588592
-> P<ast::Expr> {
589593
let trait_ = match *ty {
@@ -607,7 +611,7 @@ impl<'a, 'b> Context<'a, 'b> {
607611
}
608612
}
609613
Unsigned => {
610-
return ecx.expr_call_global(sp, vec![
614+
return ecx.expr_call_global(macsp, vec![
611615
ecx.ident_of_std("core"),
612616
ecx.ident_of("fmt"),
613617
ecx.ident_of("ArgumentV1"),
@@ -620,7 +624,7 @@ impl<'a, 'b> Context<'a, 'b> {
620624
ecx.ident_of("fmt"),
621625
ecx.ident_of(trait_),
622626
ecx.ident_of("fmt")]);
623-
ecx.expr_call_global(sp, vec![
627+
ecx.expr_call_global(macsp, vec![
624628
ecx.ident_of_std("core"),
625629
ecx.ident_of("fmt"),
626630
ecx.ident_of("ArgumentV1"),
@@ -650,6 +654,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
650654
names: HashMap<String, P<ast::Expr>>)
651655
-> P<ast::Expr> {
652656
let arg_types: Vec<_> = (0..args.len()).map(|_| None).collect();
657+
let macsp = ecx.call_site();
653658
// Expand the format literal so that efmt.span will have a backtrace. This
654659
// is essential for locating a bug when the format literal is generated in
655660
// a macro. (e.g. println!("{}"), which uses concat!($fmt, "\n")).
@@ -668,6 +673,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span,
668673
pieces: Vec::new(),
669674
str_pieces: Vec::new(),
670675
all_pieces_simple: true,
676+
macsp: macsp,
671677
fmtsp: efmt.span,
672678
};
673679
let fmt = match expr_to_string(cx.ecx,

src/test/run-pass/c-stack-returning-int64.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111

12-
// pretty-expanded FIXME #23616
1312

1413
#![feature(libc, std_misc)]
1514

src/test/run-pass/capturing-logging.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// exec-env:RUST_LOG=info
1212

13-
// pretty-expanded FIXME #23616
1413

1514
#![allow(unknown_features)]
1615
#![feature(box_syntax, old_io, rustc_private, std_misc)]

src/test/run-pass/clone-with-exterior.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![allow(unknown_features)]
1413
#![feature(box_syntax, std_misc)]

src/test/run-pass/exponential-notation.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![feature(std_misc)]
1413

src/test/run-pass/float-nan.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![feature(std_misc)]
1413

src/test/run-pass/foreign-fn-linkname.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111

12-
// pretty-expanded FIXME #23616
1312

1413
#![feature(std_misc, libc)]
1514

src/test/run-pass/issue-11881.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![feature(rustc_private, old_io)]
1413

src/test/run-pass/issue-20676.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// UFCS-style calls to a method in `Trait` where `Self` was bound to a
1313
// trait object of type `Trait`. See also `ufcs-trait-object.rs`.
1414

15-
// pretty-expanded FIXME #23616
1615

1716
use std::fmt;
1817

src/test/run-pass/item-attributes.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
// for completeness since .rs files linked from .rc files support this
1313
// notation to specify their module's attributes
1414

15-
// pretty-expanded FIXME #23616
1615

1716
#![feature(custom_attribute, libc)]
1817
#![allow(unused_attribute)]

src/test/run-pass/rust-log-filter.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// exec-env:RUST_LOG=rust_log_filter/foo
1212

13-
// pretty-expanded FIXME #23616
1413

1514
#![allow(unknown_features)]
1615
#![feature(box_syntax, std_misc, rustc_private)]

src/test/run-pass/task-comm-7.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![feature(std_misc)]
1413
#![allow(dead_assignment)]

src/test/run-pass/task-spawn-move-and-copy.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![allow(unknown_features)]
1413
#![feature(box_syntax, std_misc)]

src/test/run-pass/variadic-ffi.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// pretty-expanded FIXME #23616
1211

1312
#![feature(libc, std_misc)]
1413

0 commit comments

Comments
 (0)