From ce0907e46e8e1aa23ee39f69e4f628f68bfbb0d7 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Thu, 11 Sep 2014 17:07:49 +1200 Subject: Add enum variants to the type namespace Change to resolve and update compiler and libs for uses. [breaking-change] Enum variants are now in both the value and type namespaces. This means that if you have a variant with the same name as a type in scope in a module, you will get a name clash and thus an error. The solution is to either rename the type or the variant. --- src/libsyntax/ext/base.rs | 6 +++--- src/libsyntax/ext/expand.rs | 6 +++--- src/libsyntax/ext/format.rs | 33 +++++++++++++++++---------------- src/libsyntax/print/pp.rs | 10 +++++----- 4 files changed, 28 insertions(+), 27 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 773daa4a4c5..30b47b916df 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -305,11 +305,11 @@ pub enum SyntaxExtension { /// based upon it. /// /// `#[deriving(...)]` is an `ItemDecorator`. - ItemDecorator(Box), + Decorator(Box), /// A syntax extension that is attached to an item and modifies it /// in-place. - ItemModifier(Box), + Modifier(Box), /// A normal, function-like syntax extension. /// @@ -387,7 +387,7 @@ fn initial_syntax_expander_table() -> SyntaxEnv { builtin_normal_expander( ext::log_syntax::expand_syntax_ext)); syntax_expanders.insert(intern("deriving"), - ItemDecorator(box ext::deriving::expand_meta_deriving)); + Decorator(box ext::deriving::expand_meta_deriving)); // Quasi-quoting expanders syntax_expanders.insert(intern("quote_tokens"), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4ff9912645a..8f5fd647dbd 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -254,7 +254,7 @@ pub fn expand_item(it: P, fld: &mut MacroExpander) match fld.cx.syntax_env.find(&intern(mname.get())) { Some(rc) => match *rc { - ItemDecorator(ref dec) => { + Decorator(ref dec) => { attr::mark_used(attr); fld.cx.bt_push(ExpnInfo { @@ -311,7 +311,7 @@ fn expand_item_modifiers(mut it: P, fld: &mut MacroExpander) // partition the attributes into ItemModifiers and others let (modifiers, other_attrs) = it.attrs.partitioned(|attr| { match fld.cx.syntax_env.find(&intern(attr.name().get())) { - Some(rc) => match *rc { ItemModifier(_) => true, _ => false }, + Some(rc) => match *rc { Modifier(_) => true, _ => false }, _ => false } }); @@ -330,7 +330,7 @@ fn expand_item_modifiers(mut it: P, fld: &mut MacroExpander) match fld.cx.syntax_env.find(&intern(mname.get())) { Some(rc) => match *rc { - ItemModifier(ref mac) => { + Modifier(ref mac) => { attr::mark_used(attr); fld.cx.bt_push(ExpnInfo { call_site: attr.span, diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 26586684309..b760c893a10 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -19,17 +19,18 @@ use parse::token; use ptr::P; use std::collections::HashMap; +use std::string; #[deriving(PartialEq)] enum ArgumentType { - Known(String), + Known(string::String), Unsigned, String, } enum Position { Exact(uint), - Named(String), + Named(string::String), } struct Context<'a, 'b:'a> { @@ -44,12 +45,12 @@ struct Context<'a, 'b:'a> { /// Note that we keep a side-array of the ordering of the named arguments /// found to be sure that we can translate them in the same order that they /// were declared in. - names: HashMap>, - name_types: HashMap, - name_ordering: Vec, + names: HashMap>, + name_types: HashMap, + name_ordering: Vec, /// The latest consecutive literal strings, or empty if there weren't any. - literal: String, + literal: string::String, /// Collection of the compiled `rt::Argument` structures pieces: Vec>, @@ -58,7 +59,7 @@ struct Context<'a, 'b:'a> { /// Stays `true` if all formatting parameters are default (as in "{}{}"). all_pieces_simple: bool, - name_positions: HashMap, + name_positions: HashMap, method_statics: Vec>, /// Updated as arguments are consumed or methods are entered @@ -81,10 +82,10 @@ pub enum Invocation { /// named arguments)) fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool, tts: &[ast::TokenTree]) - -> (Invocation, Option<(P, Vec>, Vec, - HashMap>)>) { + -> (Invocation, Option<(P, Vec>, Vec, + HashMap>)>) { let mut args = Vec::new(); - let mut names = HashMap::>::new(); + let mut names = HashMap::>::new(); let mut order = Vec::new(); let mut p = ecx.new_parser_from_tts(tts); @@ -167,7 +168,7 @@ impl<'a, 'b> Context<'a, 'b> { fn verify_piece(&mut self, p: &parse::Piece) { match *p { parse::String(..) => {} - parse::Argument(ref arg) => { + parse::NextArgument(ref arg) => { // width/precision first, if they have implicit positional // parameters it makes more sense to consume them first. self.verify_count(arg.format.width); @@ -222,7 +223,7 @@ impl<'a, 'b> Context<'a, 'b> { } } - fn describe_num_args(&self) -> String { + fn describe_num_args(&self) -> string::String { match self.args.len() { 0 => "no arguments given".to_string(), 1 => "there is 1 argument".to_string(), @@ -391,7 +392,7 @@ impl<'a, 'b> Context<'a, 'b> { self.literal.push_str(s); None } - parse::Argument(ref arg) => { + parse::NextArgument(ref arg) => { // Translate the position let pos = match arg.position { // These two have a direct mapping @@ -747,8 +748,8 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, invocation: Invocation, efmt: P, args: Vec>, - name_ordering: Vec, - names: HashMap>) + name_ordering: Vec, + names: HashMap>) -> P { let arg_types = Vec::from_fn(args.len(), |_| None); let mut cx = Context { @@ -761,7 +762,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, name_ordering: name_ordering, nest_level: 0, next_arg: 0, - literal: String::new(), + literal: string::String::new(), pieces: Vec::new(), str_pieces: Vec::new(), all_pieces_simple: true, diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 70da4e11961..f1fdc71b9c6 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -60,7 +60,7 @@ //! avoid combining it with other lines and making matters even worse. use std::io; -use std::string::String; +use std::string; #[deriving(Clone, PartialEq)] pub enum Breaks { @@ -82,7 +82,7 @@ pub struct BeginToken { #[deriving(Clone)] pub enum Token { - String(String, int), + String(string::String, int), Break(BreakToken), Begin(BeginToken), End, @@ -107,7 +107,7 @@ impl Token { } } -pub fn tok_str(t: Token) -> String { +pub fn tok_str(t: Token) -> string::String { match t { String(s, len) => return format!("STR({},{})", s, len), Break(_) => return "BREAK".to_string(), @@ -122,12 +122,12 @@ pub fn buf_str(toks: Vec, left: uint, right: uint, lim: uint) - -> String { + -> string::String { let n = toks.len(); assert_eq!(n, szs.len()); let mut i = left; let mut l = lim; - let mut s = String::from_str("["); + let mut s = string::String::from_str("["); while i != right && l != 0u { l -= 1u; if i != left { -- cgit 1.4.1-3-g733a5