Skip to content

Commit

Permalink
Delete unused "next" variants from formatting infrastructure
Browse files Browse the repository at this point in the history
The formatting infrastructure stopped emitting these a while back, and in
removing them we can simplify related code.
  • Loading branch information
Mark-Simulacrum committed Jan 20, 2020
1 parent 900811e commit fdef4f1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
19 changes: 11 additions & 8 deletions src/libcore/fmt/mod.rs
Expand Up @@ -10,7 +10,6 @@ use crate::mem;
use crate::num::flt2dec;
use crate::ops::Deref;
use crate::result;
use crate::slice;
use crate::str;

mod builders;
Expand Down Expand Up @@ -234,7 +233,6 @@ pub struct Formatter<'a> {
precision: Option<usize>,

buf: &'a mut (dyn Write + 'a),
curarg: slice::Iter<'a, ArgumentV1<'a>>,
args: &'a [ArgumentV1<'a>],
}

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

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

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

// Extract the correct argument
let value = match arg.position {
rt::v1::Position::Next => *self.curarg.next().unwrap(),
rt::v1::Position::At(i) => self.args[i],
let value = {
#[cfg(bootstrap)]
{
match arg.position {
rt::v1::Position::At(i) => self.args[i],
}
}
#[cfg(not(bootstrap))]
{
self.args[arg.position]
}
};

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

Expand Down
6 changes: 4 additions & 2 deletions src/libcore/fmt/rt/v1.rs
Expand Up @@ -7,7 +7,10 @@

#[derive(Copy, Clone)]
pub struct Argument {
#[cfg(bootstrap)]
pub position: Position,
#[cfg(not(bootstrap))]
pub position: usize,
pub format: FormatSpec,
}

Expand Down Expand Up @@ -37,12 +40,11 @@ pub enum Alignment {
pub enum Count {
Is(usize),
Param(usize),
NextParam,
Implied,
}

#[cfg(bootstrap)]
#[derive(Copy, Clone)]
pub enum Position {
Next,
At(usize),
}
13 changes: 1 addition & 12 deletions src/librustc_builtin_macros/format.rs
Expand Up @@ -590,17 +590,6 @@ impl<'a, 'b> Context<'a, 'b> {
parse::NextArgument(ref arg) => {
// Build the position
let pos = {
let pos = |c, arg| {
let mut path = Context::rtpath(self.ecx, "Position");
path.push(self.ecx.ident_of(c, sp));
match arg {
Some(i) => {
let arg = self.ecx.expr_usize(sp, i);
self.ecx.expr_call_global(sp, path, vec![arg])
}
None => self.ecx.expr_path(self.ecx.path_global(sp, path)),
}
};
match arg.position {
parse::ArgumentIs(i) | parse::ArgumentImplicitlyIs(i) => {
// Map to index in final generated argument array
Expand All @@ -615,7 +604,7 @@ impl<'a, 'b> Context<'a, 'b> {
arg_idx
}
};
pos("At", Some(arg_idx))
self.ecx.expr_usize(sp, arg_idx)
}

// should never be the case, because names are already
Expand Down

0 comments on commit fdef4f1

Please sign in to comment.