From b74663e027521d351b5920e6ce95d5c58221cef5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 26 Sep 2013 13:44:54 -0700 Subject: Remove the notion of an "unknown format" As mentioned in #9456, the format! syntax extension would previously consider an empty format as a 'Unknown' format which could then also get coerced into a different style of format on another argument. This is unusual behavior because `{}` is a very common format and if you have `{0} {0:?}` you wouldn't expect them both to be coereced to the `Poly` formatter. This commit removes this coercion, but still retains the requirement that each argument has exactly one format specified for it (an empty format now counts as well). Perhaps at a later date we can add support for multiple formats of one argument, but this puts us in at least a backwards-compatible situation if we decide to do that. --- src/libsyntax/ext/format.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index d33ae069112..ef3879f56ae 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -22,7 +22,6 @@ use std::vec; #[deriving(Eq)] enum ArgumentType { - Unknown, Known(@str), Unsigned, String, @@ -153,14 +152,13 @@ impl Context { parse::ArgumentIs(i) => Left(i), parse::ArgumentNamed(s) => Right(s.to_managed()), }; - let ty = if arg.format.ty == "" { - Unknown - } else { Known(arg.format.ty.to_managed()) }; - self.verify_arg_type(pos, ty); // and finally the method being applied match arg.method { - None => {} + None => { + let ty = Known(arg.format.ty.to_managed()); + self.verify_arg_type(pos, ty); + } Some(ref method) => { self.verify_method(pos, *method); } } } @@ -253,7 +251,7 @@ impl Context { return; } self.verify_same(self.args[arg].span, ty, self.arg_types[arg]); - if ty != Unknown || self.arg_types[arg].is_none() { + if self.arg_types[arg].is_none() { self.arg_types[arg] = Some(ty); } } @@ -269,7 +267,7 @@ impl Context { }; self.verify_same(span, ty, self.name_types.find(&name).map(|&x| *x)); - if ty != Unknown || !self.name_types.contains_key(&name) { + if !self.name_types.contains_key(&name) { self.name_types.insert(name, ty); } // Assign this named argument a slot in the arguments array if @@ -292,9 +290,8 @@ impl Context { /// that: `Some(None) == Some(Some(x))` fn verify_same(&self, sp: Span, ty: ArgumentType, before: Option) { - if ty == Unknown { return } let cur = match before { - Some(Unknown) | None => return, + None => return, Some(t) => t, }; if ty == cur { return } @@ -649,9 +646,9 @@ impl Context { }; let fmt_trait = match ty { - Unknown => "Default", Known(tyname) => { match tyname.as_slice() { + "" => "Default", "?" => "Poly", "b" => "Bool", "c" => "Char", -- cgit 1.4.1-3-g733a5