Skip to content

Commit

Permalink
Use Cow<str> in describe_num_args
Browse files Browse the repository at this point in the history
  • Loading branch information
ljedrz committed Aug 9, 2018
1 parent c7646d5 commit aab063a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/libsyntax_ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use self::Position::*;
use fmt_macros as parse;

use syntax::ast;
use syntax::ext::base;
use syntax::ext::base::*;
use syntax::ext::base::{self, *};
use syntax::ext::build::AstBuilder;
use syntax::feature_gate;
use syntax::parse::token;
Expand All @@ -24,6 +23,7 @@ use syntax::symbol::Symbol;
use syntax::tokenstream;
use syntax_pos::{MultiSpan, Span, DUMMY_SP};

use std::borrow::Cow;
use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};

Expand Down Expand Up @@ -143,8 +143,10 @@ fn parse_args(ecx: &mut ExtCtxt,
ecx.span_err(sp, "requires at least a format string argument");
return None;
}

let fmtstr = panictry!(p.parse_expr());
let mut named = false;

while p.token != token::Eof {
if !p.eat(&token::Comma) {
ecx.span_err(p.span, "expected token: `,`");
Expand Down Expand Up @@ -264,11 +266,11 @@ impl<'a, 'b> Context<'a, 'b> {
}
}

fn describe_num_args(&self) -> String {
fn describe_num_args(&self) -> Cow<str> {
match self.args.len() {
0 => "no arguments were given".to_string(),
1 => "there is 1 argument".to_string(),
x => format!("there are {} arguments", x),
0 => "no arguments were given".into(),
1 => "there is 1 argument".into(),
x => format!("there are {} arguments", x).into(),
}
}

Expand Down

0 comments on commit aab063a

Please sign in to comment.