Skip to content

Commit aab063a

Browse files
committed
Use Cow<str> in describe_num_args
1 parent c7646d5 commit aab063a

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/libsyntax_ext/format.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use self::Position::*;
1414
use fmt_macros as parse;
1515

1616
use syntax::ast;
17-
use syntax::ext::base;
18-
use syntax::ext::base::*;
17+
use syntax::ext::base::{self, *};
1918
use syntax::ext::build::AstBuilder;
2019
use syntax::feature_gate;
2120
use syntax::parse::token;
@@ -24,6 +23,7 @@ use syntax::symbol::Symbol;
2423
use syntax::tokenstream;
2524
use syntax_pos::{MultiSpan, Span, DUMMY_SP};
2625

26+
use std::borrow::Cow;
2727
use std::collections::hash_map::Entry;
2828
use std::collections::{HashMap, HashSet};
2929

@@ -143,8 +143,10 @@ fn parse_args(ecx: &mut ExtCtxt,
143143
ecx.span_err(sp, "requires at least a format string argument");
144144
return None;
145145
}
146+
146147
let fmtstr = panictry!(p.parse_expr());
147148
let mut named = false;
149+
148150
while p.token != token::Eof {
149151
if !p.eat(&token::Comma) {
150152
ecx.span_err(p.span, "expected token: `,`");
@@ -264,11 +266,11 @@ impl<'a, 'b> Context<'a, 'b> {
264266
}
265267
}
266268

267-
fn describe_num_args(&self) -> String {
269+
fn describe_num_args(&self) -> Cow<str> {
268270
match self.args.len() {
269-
0 => "no arguments were given".to_string(),
270-
1 => "there is 1 argument".to_string(),
271-
x => format!("there are {} arguments", x),
271+
0 => "no arguments were given".into(),
272+
1 => "there is 1 argument".into(),
273+
x => format!("there are {} arguments", x).into(),
272274
}
273275
}
274276

0 commit comments

Comments
 (0)