Skip to content

Commit fdef4f1

Browse files
Delete unused "next" variants from formatting infrastructure
The formatting infrastructure stopped emitting these a while back, and in removing them we can simplify related code.
1 parent 900811e commit fdef4f1

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

src/libcore/fmt/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::mem;
1010
use crate::num::flt2dec;
1111
use crate::ops::Deref;
1212
use crate::result;
13-
use crate::slice;
1413
use crate::str;
1514

1615
mod builders;
@@ -234,7 +233,6 @@ pub struct Formatter<'a> {
234233
precision: Option<usize>,
235234

236235
buf: &'a mut (dyn Write + 'a),
237-
curarg: slice::Iter<'a, ArgumentV1<'a>>,
238236
args: &'a [ArgumentV1<'a>],
239237
}
240238

@@ -1044,7 +1042,6 @@ pub fn write(output: &mut dyn Write, args: Arguments<'_>) -> Result {
10441042
align: rt::v1::Alignment::Unknown,
10451043
fill: ' ',
10461044
args: args.args,
1047-
curarg: args.args.iter(),
10481045
};
10491046

10501047
let mut idx = 0;
@@ -1117,7 +1114,6 @@ impl<'a> Formatter<'a> {
11171114

11181115
// These only exist in the struct for the `run` method,
11191116
// which won’t be used together with this method.
1120-
curarg: self.curarg.clone(),
11211117
args: self.args,
11221118
}
11231119
}
@@ -1134,9 +1130,17 @@ impl<'a> Formatter<'a> {
11341130
self.precision = self.getcount(&arg.format.precision);
11351131

11361132
// Extract the correct argument
1137-
let value = match arg.position {
1138-
rt::v1::Position::Next => *self.curarg.next().unwrap(),
1139-
rt::v1::Position::At(i) => self.args[i],
1133+
let value = {
1134+
#[cfg(bootstrap)]
1135+
{
1136+
match arg.position {
1137+
rt::v1::Position::At(i) => self.args[i],
1138+
}
1139+
}
1140+
#[cfg(not(bootstrap))]
1141+
{
1142+
self.args[arg.position]
1143+
}
11401144
};
11411145

11421146
// Then actually do some printing
@@ -1148,7 +1152,6 @@ impl<'a> Formatter<'a> {
11481152
rt::v1::Count::Is(n) => Some(n),
11491153
rt::v1::Count::Implied => None,
11501154
rt::v1::Count::Param(i) => self.args[i].as_usize(),
1151-
rt::v1::Count::NextParam => self.curarg.next()?.as_usize(),
11521155
}
11531156
}
11541157

src/libcore/fmt/rt/v1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
#[derive(Copy, Clone)]
99
pub struct Argument {
10+
#[cfg(bootstrap)]
1011
pub position: Position,
12+
#[cfg(not(bootstrap))]
13+
pub position: usize,
1114
pub format: FormatSpec,
1215
}
1316

@@ -37,12 +40,11 @@ pub enum Alignment {
3740
pub enum Count {
3841
Is(usize),
3942
Param(usize),
40-
NextParam,
4143
Implied,
4244
}
4345

46+
#[cfg(bootstrap)]
4447
#[derive(Copy, Clone)]
4548
pub enum Position {
46-
Next,
4749
At(usize),
4850
}

src/librustc_builtin_macros/format.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -590,17 +590,6 @@ impl<'a, 'b> Context<'a, 'b> {
590590
parse::NextArgument(ref arg) => {
591591
// Build the position
592592
let pos = {
593-
let pos = |c, arg| {
594-
let mut path = Context::rtpath(self.ecx, "Position");
595-
path.push(self.ecx.ident_of(c, sp));
596-
match arg {
597-
Some(i) => {
598-
let arg = self.ecx.expr_usize(sp, i);
599-
self.ecx.expr_call_global(sp, path, vec![arg])
600-
}
601-
None => self.ecx.expr_path(self.ecx.path_global(sp, path)),
602-
}
603-
};
604593
match arg.position {
605594
parse::ArgumentIs(i) | parse::ArgumentImplicitlyIs(i) => {
606595
// Map to index in final generated argument array
@@ -615,7 +604,7 @@ impl<'a, 'b> Context<'a, 'b> {
615604
arg_idx
616605
}
617606
};
618-
pos("At", Some(arg_idx))
607+
self.ecx.expr_usize(sp, arg_idx)
619608
}
620609

621610
// should never be the case, because names are already

0 commit comments

Comments
 (0)