diff options
| author | bors <bors@rust-lang.org> | 2015-02-03 03:44:05 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-02-03 03:44:05 +0000 |
| commit | 7858cb432d3f2efc0374424cb2b51518f697c172 (patch) | |
| tree | bccd460a861e61f758d2d459cb9da02b1ad8792b /src/libsyntax | |
| parent | eaf4c5c784637f3df8bdebc6ec21dbd4bc69420a (diff) | |
| parent | 9ece22ee00033cdf0b6b418c451112c92c8ad922 (diff) | |
| download | rust-7858cb432d3f2efc0374424cb2b51518f697c172.tar.gz rust-7858cb432d3f2efc0374424cb2b51518f697c172.zip | |
Auto merge of #21872 - alexcrichton:rollup, r=alexcrichton
Diffstat (limited to 'src/libsyntax')
32 files changed, 419 insertions, 369 deletions
diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 2325b3778c7..de3fa1135b1 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -24,6 +24,7 @@ pub enum Os { OsFreebsd, OsiOS, OsDragonfly, + OsOpenbsd, } #[derive(PartialEq, Eq, Hash, RustcEncodable, RustcDecodable, Clone, Copy, Debug)] @@ -134,7 +135,8 @@ impl fmt::Display for Os { OsiOS => "ios".fmt(f), OsAndroid => "android".fmt(f), OsFreebsd => "freebsd".fmt(f), - OsDragonfly => "dragonfly".fmt(f) + OsDragonfly => "dragonfly".fmt(f), + OsOpenbsd => "openbsd".fmt(f), } } } diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 8546e03cc87..5535e5911e0 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -730,7 +730,7 @@ impl<'ast> NodeCollector<'ast> { } fn visit_fn_decl(&mut self, decl: &'ast FnDecl) { - for a in decl.inputs.iter() { + for a in &decl.inputs { self.insert(a.id, NodeArg(&*a.pat)); } } @@ -743,7 +743,7 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { self.parent = i.id; match i.node { ItemImpl(_, _, _, _, _, ref impl_items) => { - for impl_item in impl_items.iter() { + for impl_item in impl_items { match *impl_item { MethodImplItem(ref m) => { self.insert(m.id, NodeImplItem(impl_item)); @@ -755,12 +755,12 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { } } ItemEnum(ref enum_definition, _) => { - for v in enum_definition.variants.iter() { + for v in &enum_definition.variants { self.insert(v.node.id, NodeVariant(&**v)); } } ItemForeignMod(ref nm) => { - for nitem in nm.items.iter() { + for nitem in &nm.items { self.insert(nitem.id, NodeForeignItem(&**nitem)); } } @@ -774,13 +774,13 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> { } } ItemTrait(_, _, ref bounds, ref trait_items) => { - for b in bounds.iter() { + for b in &**bounds { if let TraitTyParamBound(ref t, TraitBoundModifier::None) = *b { self.insert(t.trait_ref.ref_id, NodeItem(i)); } } - for tm in trait_items.iter() { + for tm in trait_items { match *tm { RequiredMethod(ref m) => { self.insert(m.id, NodeTraitItem(tm)); diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 7f1264ac9a1..c62f76564a7 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -102,6 +102,20 @@ pub fn is_by_value_binop(b: BinOp_) -> bool { } } +/// Returns `true` if the binary operator is symmetric in the sense that LHS +/// and RHS must have the same type. So the type of LHS can serve as an hint +/// for the type of RHS and vice versa. +pub fn is_symmetric_binop(b: BinOp_) -> bool { + match b { + BiAdd | BiSub | BiMul | BiDiv | BiRem | + BiBitXor | BiBitAnd | BiBitOr | + BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => { + true + } + _ => false + } +} + /// Returns `true` if the unary operator takes its argument by value pub fn is_by_value_unop(u: UnOp) -> bool { match u { @@ -302,7 +316,7 @@ pub fn split_trait_methods(trait_methods: &[TraitItem]) -> (Vec<TypeMethod>, Vec<P<Method>> ) { let mut reqd = Vec::new(); let mut provd = Vec::new(); - for trt_method in trait_methods.iter() { + for trt_method in trait_methods { match *trt_method { RequiredMethod(ref tm) => reqd.push((*tm).clone()), ProvidedMethod(ref m) => provd.push((*m).clone()), @@ -322,21 +336,21 @@ pub fn struct_field_visibility(field: ast::StructField) -> Visibility { pub fn operator_prec(op: ast::BinOp_) -> usize { match op { // 'as' sits here with 12 - BiMul | BiDiv | BiRem => 11us, - BiAdd | BiSub => 10us, - BiShl | BiShr => 9us, - BiBitAnd => 8us, - BiBitXor => 7us, - BiBitOr => 6us, - BiLt | BiLe | BiGe | BiGt | BiEq | BiNe => 3us, - BiAnd => 2us, - BiOr => 1us + BiMul | BiDiv | BiRem => 11, + BiAdd | BiSub => 10, + BiShl | BiShr => 9, + BiBitAnd => 8, + BiBitXor => 7, + BiBitOr => 6, + BiLt | BiLe | BiGe | BiGt | BiEq | BiNe => 3, + BiAnd => 2, + BiOr => 1 } } /// Precedence of the `as` operator, which is a binary operator /// not appearing in the prior table. -pub const AS_PREC: usize = 12us; +pub const AS_PREC: usize = 12; pub fn empty_generics() -> Generics { Generics { @@ -391,10 +405,10 @@ pub struct IdVisitor<'a, O:'a> { impl<'a, O: IdVisitingOperation> IdVisitor<'a, O> { fn visit_generics_helper(&mut self, generics: &Generics) { - for type_parameter in generics.ty_params.iter() { + for type_parameter in &*generics.ty_params { self.operation.visit_id(type_parameter.id) } - for lifetime in generics.lifetimes.iter() { + for lifetime in &generics.lifetimes { self.operation.visit_id(lifetime.lifetime.id) } } @@ -430,14 +444,14 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { ViewPathSimple(_, _) | ViewPathGlob(_) => {} ViewPathList(_, ref paths) => { - for path in paths.iter() { + for path in paths { self.operation.visit_id(path.node.id()) } } } } ItemEnum(ref enum_definition, _) => { - for variant in enum_definition.variants.iter() { + for variant in &enum_definition.variants { self.operation.visit_id(variant.node.id) } } @@ -511,7 +525,7 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> { visit::FkFnBlock => {} } - for argument in function_declaration.inputs.iter() { + for argument in &function_declaration.inputs { self.operation.visit_id(argument.id) } diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs index 4427a7aaf02..301a18892d8 100644 --- a/src/libsyntax/attr.rs +++ b/src/libsyntax/attr.rs @@ -373,7 +373,7 @@ impl fmt::Display for StabilityLevel { fn find_stability_generic<'a, AM: AttrMetaMethods, I: Iterator<Item=&'a AM>> - (diagnostic: &SpanHandler, mut attrs: I, item_sp: Span) + (diagnostic: &SpanHandler, attrs: I, item_sp: Span) -> (Option<Stability>, Vec<&'a AM>) { let mut stab: Option<Stability> = None; @@ -394,7 +394,7 @@ fn find_stability_generic<'a, let mut feature = None; let mut since = None; let mut reason = None; - for meta in metas.iter() { + for meta in metas { if meta.name().get() == "feature" { match meta.value_str() { Some(v) => feature = Some(v), @@ -490,13 +490,13 @@ fn find_stability_generic<'a, pub fn find_stability(diagnostic: &SpanHandler, attrs: &[Attribute], item_sp: Span) -> Option<Stability> { let (s, used) = find_stability_generic(diagnostic, attrs.iter(), item_sp); - for used in used.into_iter() { mark_used(used) } + for used in used { mark_used(used) } return s; } pub fn require_unique_names(diagnostic: &SpanHandler, metas: &[P<MetaItem>]) { let mut set = HashSet::new(); - for meta in metas.iter() { + for meta in metas { let name = meta.name(); if !set.insert(name.clone()) { @@ -518,7 +518,7 @@ pub fn find_repr_attrs(diagnostic: &SpanHandler, attr: &Attribute) -> Vec<ReprAt match attr.node.value.node { ast::MetaList(ref s, ref items) if *s == "repr" => { mark_used(attr); - for item in items.iter() { + for item in items { match item.node { ast::MetaWord(ref word) => { let hint = match word.get() { diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index 8adb9b24222..00857d10f43 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -431,7 +431,7 @@ impl CodeMap { let lo = self.lookup_char_pos(sp.lo); let hi = self.lookup_char_pos(sp.hi); let mut lines = Vec::new(); - for i in lo.line - 1us..hi.line as usize { + for i in lo.line - 1..hi.line as usize { lines.push(i); }; FileLines {file: lo.file, lines: lines} @@ -453,7 +453,7 @@ impl CodeMap { } pub fn get_filemap(&self, filename: &str) -> Rc<FileMap> { - for fm in self.files.borrow().iter() { + for fm in &*self.files.borrow() { if filename == fm.name { return fm.clone(); } @@ -477,7 +477,7 @@ impl CodeMap { // The number of extra bytes due to multibyte chars in the FileMap let mut total_extra_bytes = 0; - for mbc in map.multibyte_chars.borrow().iter() { + for mbc in &*map.multibyte_chars.borrow() { debug!("{}-byte char at {:?}", mbc.bytes, mbc.pos); if mbc.pos < bpos { // every character is at least one byte, so we only @@ -499,10 +499,10 @@ impl CodeMap { let files = self.files.borrow(); let files = &*files; let len = files.len(); - let mut a = 0us; + let mut a = 0; let mut b = len; - while b - a > 1us { - let m = (a + b) / 2us; + while b - a > 1 { + let m = (a + b) / 2; if files[m].start_pos > pos { b = m; } else { @@ -538,12 +538,12 @@ impl CodeMap { let files = self.files.borrow(); let f = (*files)[idx].clone(); - let mut a = 0us; + let mut a = 0; { let lines = f.lines.borrow(); let mut b = lines.len(); - while b - a > 1us { - let m = (a + b) / 2us; + while b - a > 1 { + let m = (a + b) / 2; if (*lines)[m] > pos { b = m; } else { a = m; } } } @@ -552,7 +552,7 @@ impl CodeMap { fn lookup_pos(&self, pos: BytePos) -> Loc { let FileMapAndLine {fm: f, line: a} = self.lookup_line(pos); - let line = a + 1us; // Line numbers start at 1 + let line = a + 1; // Line numbers start at 1 let chpos = self.bytepos_to_file_charpos(pos); let linebpos = (*f.lines.borrow())[a]; let linechpos = self.bytepos_to_file_charpos(linebpos); @@ -763,7 +763,7 @@ mod test { assert_eq!(file_lines.file.name, "blork.rs"); assert_eq!(file_lines.lines.len(), 1); - assert_eq!(file_lines.lines[0], 1us); + assert_eq!(file_lines.lines[0], 1); } #[test] diff --git a/src/libsyntax/diagnostic.rs b/src/libsyntax/diagnostic.rs index 821ac8e2f89..d22054d8ed0 100644 --- a/src/libsyntax/diagnostic.rs +++ b/src/libsyntax/diagnostic.rs @@ -25,7 +25,7 @@ use term::WriterWrapper; use term; /// maximum number of lines we will print for each error; arbitrary. -static MAX_LINES: usize = 6us; +static MAX_LINES: usize = 6; #[derive(Clone, Copy)] pub enum RenderSpan { @@ -155,19 +155,19 @@ impl Handler { self.bump_err_count(); } pub fn bump_err_count(&self) { - self.err_count.set(self.err_count.get() + 1us); + self.err_count.set(self.err_count.get() + 1); } pub fn err_count(&self) -> usize { self.err_count.get() } pub fn has_errors(&self) -> bool { - self.err_count.get() > 0us + self.err_count.get() > 0 } pub fn abort_if_errors(&self) { let s; match self.err_count.get() { - 0us => return, - 1us => s = "aborting due to previous error".to_string(), + 0 => return, + 1 => s = "aborting due to previous error".to_string(), _ => { s = format!("aborting due to {} previous errors", self.err_count.get()); @@ -457,43 +457,43 @@ fn highlight_lines(err: &mut EmitterWriter, let mut elided = false; let mut display_lines = &lines.lines[]; if display_lines.len() > MAX_LINES { - display_lines = &display_lines[0us..MAX_LINES]; + display_lines = &display_lines[0..MAX_LINES]; elided = true; } // Print the offending lines - for &line_number in display_lines.iter() { + for &line_number in display_lines { if let Some(line) = fm.get_line(line_number) { try!(write!(&mut err.dst, "{}:{} {}\n", fm.name, line_number + 1, line)); } } if elided { - let last_line = display_lines[display_lines.len() - 1us]; - let s = format!("{}:{} ", fm.name, last_line + 1us); + let last_line = display_lines[display_lines.len() - 1]; + let s = format!("{}:{} ", fm.name, last_line + 1); try!(write!(&mut err.dst, "{0:1$}...\n", "", s.len())); } // FIXME (#3260) // If there's one line at fault we can easily point to the problem - if lines.lines.len() == 1us { + if lines.lines.len() == 1 { let lo = cm.lookup_char_pos(sp.lo); - let mut digits = 0us; - let mut num = (lines.lines[0] + 1us) / 10us; + let mut digits = 0; + let mut num = (lines.lines[0] + 1) / 10; // how many digits must be indent past? - while num > 0us { num /= 10us; digits += 1us; } + while num > 0 { num /= 10; digits += 1; } // indent past |name:## | and the 0-offset column location - let left = fm.name.len() + digits + lo.col.to_usize() + 3us; + let left = fm.name.len() + digits + lo.col.to_usize() + 3; let mut s = String::new(); // Skip is the number of characters we need to skip because they are // part of the 'filename:line ' part of the previous line. - let skip = fm.name.len() + digits + 3us; + let skip = fm.name.len() + digits + 3; for _ in 0..skip { s.push(' '); } if let Some(orig) = fm.get_line(lines.lines[0]) { - for pos in 0us..left - skip { + for pos in 0..left - skip { let cur_char = orig.as_bytes()[pos] as char; // Whenever a tab occurs on the previous line, we insert one on // the error-point-squiggly-line as well (instead of a space). @@ -511,7 +511,7 @@ fn highlight_lines(err: &mut EmitterWriter, let hi = cm.lookup_char_pos(sp.hi); if hi.col != lo.col { // the ^ already takes up one space - let num_squigglies = hi.col.to_usize() - lo.col.to_usize() - 1us; + let num_squigglies = hi.col.to_usize() - lo.col.to_usize() - 1; for _ in 0..num_squigglies { s.push('~'); } @@ -550,7 +550,7 @@ fn custom_highlight_lines(w: &mut EmitterWriter, last_line_number + 1, last_line)); } } else { - for &line_number in lines.iter() { + for &line_number in lines { if let Some(line) = fm.get_line(line_number) { try!(write!(&mut w.dst, "{}:{} {}\n", fm.name, line_number + 1, line)); diff --git a/src/libsyntax/ext/concat.rs b/src/libsyntax/ext/concat.rs index 39895a3946a..4e10cc9aacc 100644 --- a/src/libsyntax/ext/concat.rs +++ b/src/libsyntax/ext/concat.rs @@ -25,7 +25,7 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, None => return base::DummyResult::expr(sp) }; let mut accumulator = String::new(); - for e in es.into_iter() { + for e in es { match e.node { ast::ExprLit(ref lit) => { match lit.node { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 1b84d93738d..02982039be0 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -427,7 +427,7 @@ impl<'a> TraitDef<'a> { bounds.push(cx.typarambound(trait_path.clone())); // also add in any bounds from the declaration - for declared_bound in ty_param.bounds.iter() { + for declared_bound in &*ty_param.bounds { bounds.push((*declared_bound).clone()); } @@ -770,7 +770,7 @@ impl<'a> MethodDef<'a> { let mut raw_fields = Vec::new(); // ~[[fields of self], // [fields of next Self arg], [etc]] let mut patterns = Vec::new(); - for i in 0us..self_args.len() { + for i in 0..self_args.len() { let struct_path= cx.path(DUMMY_SP, vec!( type_ident )); let (pat, ident_expr) = trait_.create_struct_pattern(cx, @@ -859,8 +859,8 @@ impl<'a> MethodDef<'a> { /// (&A2(ref __self_0), /// &A2(ref __arg_1_0)) => (*__self_0).eq(&(*__arg_1_0)), /// _ => { - /// let __self_vi = match *self { A1(..) => 0us, A2(..) => 1us }; - /// let __arg_1_vi = match *__arg_1 { A1(..) => 0us, A2(..) => 1us }; + /// let __self_vi = match *self { A1(..) => 0, A2(..) => 1 }; + /// let __arg_1_vi = match *__arg_1 { A1(..) => 0, A2(..) => 1 }; /// false /// } /// } @@ -904,8 +904,8 @@ impl<'a> MethodDef<'a> { /// (Variant2, Variant2, Variant2) => ... // delegate Matching on Variant2 /// ... /// _ => { - /// let __this_vi = match this { Variant1 => 0us, Variant2 => 1us, ... }; - /// let __that_vi = match that { Variant1 => 0us, Variant2 => 1us, ... }; + /// let __this_vi = match this { Variant1 => 0, Variant2 => 1, ... }; + /// let __that_vi = match that { Variant1 => 0, Variant2 => 1, ... }; /// ... // catch-all remainder can inspect above variant index values. /// } /// } @@ -974,7 +974,7 @@ impl<'a> MethodDef<'a> { subpats.push(p); idents }; - for self_arg_name in self_arg_names.tail().iter() { + for self_arg_name in self_arg_names.tail() { let (p, idents) = mk_self_pat(cx, &self_arg_name[]); subpats.push(p); self_pats_idents.push(idents); @@ -1067,13 +1067,13 @@ impl<'a> MethodDef<'a> { // // ``` // let __self0_vi = match self { - // A => 0us, B(..) => 1us, C(..) => 2us + // A => 0, B(..) => 1, C(..) => 2 // }; // let __self1_vi = match __arg1 { - // A => 0us, B(..) => 1us, C(..) => 2us + // A => 0, B(..) => 1, C(..) => 2 // }; // let __self2_vi = match __arg2 { - // A => 0us, B(..) => 1us, C(..) => 2us + // A => 0, B(..) => 1, C(..) => 2 // }; // ``` let mut index_let_stmts: Vec<P<ast::Stmt>> = Vec::new(); diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index e7f546b2691..efd93226618 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -100,7 +100,7 @@ fn hash_substructure(cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure) _ => cx.span_bug(trait_span, "impossible substructure in `derive(Hash)`") }; - for &FieldInfo { ref self_, span, .. } in fields.iter() { + for &FieldInfo { ref self_, span, .. } in fields { stmts.push(call_hash(span, self_.clone())); } diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index c694b054ba3..ae7b20f7853 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -93,7 +93,7 @@ fn cs_from(name: &str, cx: &mut ExtCtxt, trait_span: Span, substr: &Substructure let mut arms = Vec::new(); - for variant in enum_def.variants.iter() { + for variant in &enum_def.variants { match variant.node.kind { ast::TupleVariantKind(ref args) => { if !args.is_empty() { diff --git a/src/libsyntax/ext/env.rs b/src/libsyntax/ext/env.rs index 9f6bf352b04..9aa454ae8d5 100644 --- a/src/libsyntax/ext/env.rs +++ b/src/libsyntax/ext/env.rs @@ -21,7 +21,7 @@ use ext::base; use ext::build::AstBuilder; use parse::token; -use std::os; +use std::env; pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box<base::MacResult+'cx> { @@ -30,8 +30,8 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT Some(v) => v }; - let e = match os::getenv(&var[]) { - None => { + let e = match env::var_string(&var[]) { + Err(..) => { cx.expr_path(cx.path_all(sp, true, vec!(cx.ident_of("std"), @@ -48,7 +48,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenT ast::MutImmutable)), Vec::new())) } - Some(s) => { + Ok(s) => { cx.expr_call_global(sp, vec!(cx.ident_of("std"), cx.ident_of("option"), @@ -101,12 +101,12 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } - let e = match os::getenv(var.get()) { - None => { + let e = match env::var_string(var.get()) { + Err(..) => { cx.span_err(sp, msg.get()); cx.expr_usize(sp, 0) } - Some(s) => cx.expr_str(sp, token::intern_and_get_ident(&s[])) + Ok(s) => cx.expr_str(sp, token::intern_and_get_ident(&s[])) }; MacExpr::new(e) } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 5736400313e..6eacb344018 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -362,7 +362,7 @@ fn expand_mac_invoc<T, F, G>(mac: ast::Mac, span: codemap::Span, // in this file. // Token-tree macros: MacInvocTT(pth, tts, _) => { - if pth.segments.len() > 1us { + if pth.segments.len() > 1 { fld.cx.span_err(pth.span, "expected macro name without module \ separators"); @@ -504,7 +504,7 @@ fn expand_item_modifiers(mut it: P<ast::Item>, fld: &mut MacroExpander) return it.expect_item(); } - for attr in modifiers.iter() { + for attr in &modifiers { let mname = attr.name(); match fld.cx.syntax_env.find(&intern(mname.get())) { @@ -552,7 +552,7 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite // does this attribute list contain "macro_use" ? fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool { - for attr in attrs.iter() { + for attr in attrs { let mut is_use = attr.check_name("macro_use"); if attr.check_name("macro_escape") { fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use"); @@ -853,7 +853,7 @@ impl<'v> Visitor<'v> for PatIdentFinder { ast::Pat { id: _, node: ast::PatIdent(_, ref path1, ref inner), span: _ } => { self.ident_accumulator.push(path1.node); // visit optional subpattern of PatIdent: - for subpat in inner.iter() { + if let Some(ref subpat) = *inner { self.visit_pat(&**subpat) } } @@ -873,7 +873,7 @@ fn pattern_bindings(pat: &ast::Pat) -> Vec<ast::Ident> { /// find the PatIdent paths in a fn fn_decl_arg_bindings(fn_decl: &ast::FnDecl) -> Vec<ast::Ident> { let mut pat_idents = PatIdentFinder{ident_accumulator:Vec::new()}; - for arg in fn_decl.inputs.iter() { + for arg in &fn_decl.inputs { pat_idents.visit_pat(&*arg.pat); } pat_idents.ident_accumulator @@ -931,7 +931,7 @@ fn expand_pat(p: P<ast::Pat>, fld: &mut MacroExpander) -> P<ast::Pat> { }, _ => unreachable!() }; - if pth.segments.len() > 1us { + if pth.segments.len() > 1 { fld.cx.span_err(pth.span, "expected macro name without module separators"); return DummyResult::raw_pat(span); } @@ -1063,7 +1063,7 @@ fn expand_annotatable(a: Annotatable, let mut decorator_items = SmallVector::zero(); let mut new_attrs = Vec::new(); - for attr in a.attrs().iter() { + for attr in a.attrs() { let mname = attr.name(); match fld.cx.syntax_env.find(&intern(mname.get())) { @@ -1218,7 +1218,7 @@ fn expand_item_multi_modifier(mut it: Annotatable, return it } - for attr in modifiers.iter() { + for attr in &modifiers { let mname = attr.name(); match fld.cx.syntax_env.find(&intern(mname.get())) { @@ -1420,11 +1420,11 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); let mut expander = MacroExpander::new(&mut cx); - for def in imported_macros.into_iter() { + for def in imported_macros { expander.cx.insert_macro(def); } - for (name, extension) in user_exts.into_iter() { + for (name, extension) in user_exts { expander.cx.syntax_env.insert(name, extension); } diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 36dbf117604..16aaccb0207 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -499,7 +499,7 @@ impl<'a, 'b> Context<'a, 'b> { self.ecx.expr_ident(e.span, name))); heads.push(self.ecx.expr_addr_of(e.span, e)); } - for name in self.name_ordering.iter() { + for name in &self.name_ordering { let e = match self.names.remove(name) { Some(e) => e, None => continue @@ -706,7 +706,7 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, cx.ecx.span_err(cx.args[i].span, "argument never used"); } } - for (name, e) in cx.names.iter() { + for (name, e) in &cx.names { if !cx.name_types.contains_key(name) { cx.ecx.span_err(e.span, "named argument never used"); } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 0f617302c92..9092169e182 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -694,7 +694,7 @@ fn mk_tt(cx: &ExtCtxt, tt: &ast::TokenTree) -> Vec<P<ast::Stmt>> { fn mk_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> Vec<P<ast::Stmt>> { let mut ss = Vec::new(); - for tt in tts.iter() { + for tt in tts { ss.extend(mk_tt(cx, tt).into_iter()); } ss @@ -709,7 +709,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // try removing it when enough of them are gone. let mut p = cx.new_parser_from_tts(tts); - p.quote_depth += 1us; + p.quote_depth += 1; let cx_expr = p.parse_expr(); if !p.eat(&token::Comma) { diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index e3211c7c337..823efdd3eed 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -171,11 +171,11 @@ pub fn initial_matcher_pos(ms: Rc<Vec<TokenTree>>, sep: Option<Token>, lo: ByteP stack: vec![], top_elts: TtSeq(ms), sep: sep, - idx: 0us, + idx: 0, up: None, matches: matches, - match_lo: 0us, - match_cur: 0us, + match_lo: 0, + match_cur: 0, match_hi: match_idx_hi, sp_lo: lo } @@ -209,12 +209,12 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>]) ret_val: &mut HashMap<Ident, Rc<NamedMatch>>, idx: &mut usize) { match m { &TtSequence(_, ref seq) => { - for next_m in seq.tts.iter() { + for next_m in &seq.tts { n_rec(p_s, next_m, res, ret_val, idx) } } &TtDelimited(_, ref delim) => { - for next_m in delim.tts.iter() { + for next_m in &delim.tts { n_rec(p_s, next_m, res, ret_val, idx) } } @@ -238,8 +238,8 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc<NamedMatch>]) } } let mut ret_val = HashMap::new(); - let mut idx = 0us; - for m in ms.iter() { n_rec(p_s, m, res, &mut ret_val, &mut idx) } + let mut idx = 0; + for m in ms { n_rec(p_s, m, res, &mut ret_val, &mut idx) } ret_val } @@ -383,7 +383,7 @@ pub fn parse(sess: &ParseSess, if seq.op == ast::ZeroOrMore { let mut new_ei = ei.clone(); new_ei.match_cur += seq.num_captures; - new_ei.idx += 1us; + new_ei.idx += 1; //we specifically matched zero repeats. for idx in ei.match_cur..ei.match_cur + seq.num_captures { (&mut new_ei.matches[idx]).push(Rc::new(MatchedSeq(vec![], sp))); @@ -398,7 +398,7 @@ pub fn parse(sess: &ParseSess, cur_eis.push(box MatcherPos { stack: vec![], sep: seq.separator.clone(), - idx: 0us, + idx: 0, matches: matches, match_lo: ei_t.match_cur, match_cur: ei_t.match_cur, @@ -442,20 +442,20 @@ pub fn parse(sess: &ParseSess, /* error messages here could be improved with links to orig. rules */ if token_name_eq(&tok, &token::Eof) { - if eof_eis.len() == 1us { + if eof_eis.len() == 1 { let mut v = Vec::new(); - for dv in (&mut eof_eis[0]).matches.iter_mut() { + for dv in &mut (&mut eof_eis[0]).matches { v.push(dv.pop().unwrap()); } return Success(nameize(sess, ms, &v[])); - } else if eof_eis.len() > 1us { + } else if eof_eis.len() > 1 { return Error(sp, "ambiguity: multiple successful parses".to_string()); } else { return Failure(sp, "unexpected end of macro invocation".to_string()); } } else { - if (bb_eis.len() > 0us && next_eis.len() > 0us) - || bb_eis.len() > 1us { + if (bb_eis.len() > 0 && next_eis.len() > 0) + || bb_eis.len() > 1 { let nts = bb_eis.iter().map(|ei| { match ei.top_elts.get_tt(ei.idx) { TtToken(_, MatchNt(bind, name, _, _)) => { @@ -469,12 +469,12 @@ pub fn parse(sess: &ParseSess, "local ambiguity: multiple parsing options: \ built-in NTs {} or {} other options.", nts, next_eis.len()).to_string()); - } else if bb_eis.len() == 0us && next_eis.len() == 0us { + } else if bb_eis.len() == 0 && next_eis.len() == 0 { return Failure(sp, format!("no rules expected the token `{}`", pprust::token_to_string(&tok)).to_string()); - } else if next_eis.len() > 0us { + } else if next_eis.len() > 0 { /* Now process the next token */ - while next_eis.len() > 0us { + while next_eis.len() > 0 { cur_eis.push(next_eis.pop().unwrap()); } rdr.next_token(); @@ -488,7 +488,7 @@ pub fn parse(sess: &ParseSess, let match_cur = ei.match_cur; (&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal( parse_nt(&mut rust_parser, span, name_string.get())))); - ei.idx += 1us; + ei.idx += 1; ei.match_cur += 1; } _ => panic!() @@ -501,16 +501,16 @@ pub fn parse(sess: &ParseSess, } } - assert!(cur_eis.len() > 0us); + assert!(cur_eis.len() > 0); } } pub fn parse_nt(p: &mut Parser, sp: Span, name: &str) -> Nonterminal { match name { "tt" => { - p.quote_depth += 1us; //but in theory, non-quoted tts might be useful + p.quote_depth += 1; //but in theory, non-quoted tts might be useful let res = token::NtTT(P(p.parse_token_tree())); - p.quote_depth -= 1us; + p.quote_depth -= 1; return res; } _ => {} diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 666281ac6b6..ac9f375e0a4 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -259,7 +259,7 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, _ => cx.span_bug(def.span, "wrong-structured lhs") }; - for lhs in lhses.iter() { + for lhs in &lhses { check_lhs_nt_follows(cx, &**lhs, def.span); } diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 0bf20b8f3e1..83234e3b7a5 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -223,7 +223,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { r.repeat_len.pop(); } } else { /* repeat */ - *r.repeat_idx.last_mut().unwrap() += 1us; + *r.repeat_idx.last_mut().unwrap() += 1; r.stack.last_mut().unwrap().idx = 0; match r.stack.last().unwrap().sep.clone() { Some(tk) => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 775cfede70d..4e76359e930 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -253,7 +253,7 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { } fn visit_item(&mut self, i: &ast::Item) { - for attr in i.attrs.iter() { + for attr in &i.attrs { if attr.name() == "thread_local" { self.gate_feature("thread_local", i.span, "`#[thread_local]` is an experimental feature, and does not \ @@ -508,7 +508,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C let mut unknown_features = Vec::new(); - for attr in krate.attrs.iter() { + for attr in &krate.attrs { if !attr.check_name("feature") { continue } @@ -519,7 +519,7 @@ fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::C expected #![feature(...)]"); } Some(list) => { - for mi in list.iter() { + for mi in list { let name = match mi.node { ast::MetaWord(ref word) => (*word).clone(), _ => { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index a1362f5382c..9012ec2114d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -37,7 +37,7 @@ pub trait MoveMap<T> { impl<T> MoveMap<T> for Vec<T> { fn move_map<F>(mut self, mut f: F) -> Vec<T> where F: FnMut(T) -> T { - for p in self.iter_mut() { + for p in &mut self { unsafe { // FIXME(#5016) this shouldn't need to zero to be safe. ptr::write(p, f(ptr::read_and_zero(p))); @@ -1117,7 +1117,7 @@ pub fn noop_fold_crate<T: Folder>(Crate {module, attrs, config, mut exported_mac }, vec![], span) }; - for def in exported_macros.iter_mut() { + for def in &mut exported_macros { def.id = folder.new_id(def.id); } diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 73424136cfb..08e795ef80d 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -23,16 +23,14 @@ html_favicon_url = "http://www.rust-lang.org/favicon.ico", html_root_url = "http://doc.rust-lang.org/nightly/")] -#![cfg_attr(not(stage0), allow(unused_mut))] // NOTE: remove after stage0 snap - #![feature(box_syntax)] #![feature(collections)] #![feature(core)] +#![feature(env)] #![feature(hash)] #![feature(int_uint)] #![feature(io)] #![feature(libc)] -#![feature(os)] #![feature(path)] #![feature(quote, unsafe_destructor)] #![feature(rustc_private)] diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 54ec9c7b146..06e8728d236 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -13,7 +13,7 @@ use ast; use codemap::{spanned, Spanned, mk_sp, Span}; use parse::common::*; //resolve bug? use parse::token; -use parse::parser::Parser; +use parse::parser::{Parser, TokenType}; use ptr::P; /// A parser that can parse attributes. @@ -69,7 +69,9 @@ impl<'a> ParserAttr for Parser<'a> { let lo = self.span.lo; self.bump(); - let style = if self.eat(&token::Not) { + if permit_inner { self.expected_tokens.push(TokenType::Token(token::Not)); } + let style = if self.token == token::Not { + self.bump(); if !permit_inner { let span = self.span; self.span_err(span, @@ -96,7 +98,8 @@ impl<'a> ParserAttr for Parser<'a> { } }; - if permit_inner && self.eat(&token::Semi) { + if permit_inner && self.token == token::Semi { + self.bump(); self.span_warn(span, "this inner attribute syntax is deprecated. \ The new syntax is `#![foo]`, with a bang and no semicolon"); style = ast::AttrInner; diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index 926385ccd11..b17fc7fe82e 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -62,7 +62,7 @@ pub fn doc_comment_style(comment: &str) -> ast::AttrStyle { pub fn strip_doc_comment_decoration(comment: &str) -> String { /// remove whitespace-only lines from the start/end of lines fn vertical_trim(lines: Vec<String> ) -> Vec<String> { - let mut i = 0us; + let mut i = 0; let mut j = lines.len(); // first line of all-stars should be omitted if lines.len() > 0 && @@ -90,7 +90,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { let mut i = usize::MAX; let mut can_trim = true; let mut first = true; - for line in lines.iter() { + for line in &lines { for (j, c) in line.chars().enumerate() { if j > i || !"* \t".contains_char(c) { can_trim = false; @@ -125,7 +125,7 @@ pub fn strip_doc_comment_decoration(comment: &str) -> String { // one-line comments lose their prefix static ONLINERS: &'static [&'static str] = &["///!", "///", "//!", "//"]; - for prefix in ONLINERS.iter() { + for prefix in ONLINERS { if comment.starts_with(*prefix) { return (&comment[prefix.len()..]).to_string(); } @@ -158,7 +158,7 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut Vec<Comment>) { fn consume_whitespace_counting_blank_lines(rdr: &mut StringReader, comments: &mut Vec<Comment>) { while is_whitespace(rdr.curr) && !rdr.is_eof() { - if rdr.col == CharPos(0us) && rdr.curr_is('\n') { + if rdr.col == CharPos(0) && rdr.curr_is('\n') { push_blank_line_comment(rdr, &mut *comments); } rdr.bump(); @@ -305,7 +305,7 @@ fn read_block_comment(rdr: &mut StringReader, let mut style = if code_to_the_left { Trailing } else { Isolated }; rdr.consume_non_eol_whitespace(); - if !rdr.is_eof() && !rdr.curr_is('\n') && lines.len() == 1us { + if !rdr.is_eof() && !rdr.curr_is('\n') && lines.len() == 1 { style = Mixed; } debug!("<<< block comment"); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 2cf6058a433..e6da47304ce 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -279,7 +279,7 @@ impl<'a> StringReader<'a> { /// Converts CRLF to LF in the given string, raising an error on bare CR. fn translate_crlf<'b>(&self, start: BytePos, s: &'b str, errmsg: &'b str) -> CowString<'b> { - let mut i = 0us; + let mut i = 0; while i < s.len() { let str::CharRange { ch, next } = s.char_range_at(i); if ch == '\r' { @@ -331,10 +331,10 @@ impl<'a> StringReader<'a> { let byte_offset_diff = next.next - current_byte_offset; self.pos = self.pos + Pos::from_usize(byte_offset_diff); self.curr = Some(next.ch); - self.col = self.col + CharPos(1us); + self.col = self.col + CharPos(1); if last_char == '\n' { self.filemap.next_line(self.last_pos); - self.col = CharPos(0us); + self.col = CharPos(0); } if byte_offset_diff > 1 { @@ -472,7 +472,7 @@ impl<'a> StringReader<'a> { cmap.files.borrow_mut().push(self.filemap.clone()); let loc = cmap.lookup_char_pos_adj(self.last_pos); debug!("Skipping a shebang"); - if loc.line == 1us && loc.col == CharPos(0us) { + if loc.line == 1 && loc.col == CharPos(0) { // FIXME: Add shebang "token", return it let start = self.last_pos; while !self.curr_is('\n') && !self.is_eof() { self.bump(); } @@ -646,7 +646,7 @@ impl<'a> StringReader<'a> { /// Scan through any digits (base `radix`) or underscores, and return how /// many digits there were. fn scan_digits(&mut self, radix: usize) -> usize { - let mut len = 0us; + let mut len = 0; loop { let c = self.curr; if c == Some('_') { debug!("skipping a _"); self.bump(); continue; } @@ -799,14 +799,14 @@ impl<'a> StringReader<'a> { if self.curr == Some('{') { self.scan_unicode_escape(delim) } else { - let res = self.scan_hex_digits(4us, delim, false); + let res = self.scan_hex_digits(4, delim, false); let sp = codemap::mk_sp(escaped_pos, self.last_pos); self.old_escape_warning(sp); res } } 'U' if !ascii_only => { - let res = self.scan_hex_digits(8us, delim, false); + let res = self.scan_hex_digits(8, delim, false); let sp = codemap::mk_sp(escaped_pos, self.last_pos); self.old_escape_warning(sp); res @@ -877,7 +877,7 @@ impl<'a> StringReader<'a> { fn scan_unicode_escape(&mut self, delim: char) -> bool { self.bump(); // past the { let start_bpos = self.last_pos; - let mut count = 0us; + let mut count = 0; let mut accum_int = 0; while !self.curr_is('}') && count <= 6 { @@ -937,10 +937,10 @@ impl<'a> StringReader<'a> { /// error if it isn't. fn check_float_base(&mut self, start_bpos: BytePos, last_bpos: BytePos, base: usize) { match base { - 16us => self.err_span_(start_bpos, last_bpos, "hexadecimal float literal is not \ + 16 => self.err_span_(start_bpos, last_bpos, "hexadecimal float literal is not \ supported"), - 8us => self.err_span_(start_bpos, last_bpos, "octal float literal is not supported"), - 2us => self.err_span_(start_bpos, last_bpos, "binary float literal is not supported"), + 8 => self.err_span_(start_bpos, last_bpos, "octal float literal is not supported"), + 2 => self.err_span_(start_bpos, last_bpos, "binary float literal is not supported"), _ => () } } @@ -1189,7 +1189,7 @@ impl<'a> StringReader<'a> { 'r' => { let start_bpos = self.last_pos; self.bump(); - let mut hash_count = 0us; + let mut hash_count = 0; while self.curr_is('#') { self.bump(); hash_count += 1; @@ -1374,7 +1374,7 @@ impl<'a> StringReader<'a> { fn scan_raw_byte_string(&mut self) -> token::Lit { let start_bpos = self.last_pos; self.bump(); - let mut hash_count = 0us; + let mut hash_count = 0; while self.curr_is('#') { self.bump(); hash_count += 1; @@ -1526,7 +1526,7 @@ mod test { // check that the given reader produces the desired stream // of tokens (stop checking after exhausting the expected vec) fn check_tokenization (mut string_reader: StringReader, expected: Vec<token::Token> ) { - for expected_tok in expected.iter() { + for expected_tok in &expected { assert_eq!(&string_reader.next_token().tok, expected_tok); } } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8ac5b6e5274..eecd7d87185 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -181,7 +181,7 @@ pub fn parse_tts_from_source_str(name: String, name, source ); - p.quote_depth += 1us; + p.quote_depth += 1; // right now this is re-creating the token trees from ... token trees. maybe_aborted(p.parse_all_token_trees(),p) } @@ -324,7 +324,7 @@ pub mod with_hygiene { name, source ); - p.quote_depth += 1us; + p.quote_depth += 1; // right now this is re-creating the token trees from ... token trees. maybe_aborted(p.parse_all_token_trees(),p) } @@ -436,7 +436,7 @@ pub fn str_lit(lit: &str) -> String { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a>(it: &mut iter::Peekable<(usize, char), str::CharIndices<'a>>) { + fn eat<'a>(it: &mut iter::Peekable<str::CharIndices<'a>>) { loop { match it.peek().map(|x| x.1) { Some(' ') | Some('\n') | Some('\r') | Some('\t') => { @@ -605,7 +605,7 @@ pub fn binary_lit(lit: &str) -> Rc<Vec<u8>> { let error = |&: i| format!("lexer should have rejected {} at {}", lit, i); /// Eat everything up to a non-whitespace - fn eat<'a, I: Iterator<Item=(usize, u8)>>(it: &mut iter::Peekable<(usize, u8), I>) { + fn eat<'a, I: Iterator<Item=(usize, u8)>>(it: &mut iter::Peekable<I>) { loop { match it.peek().map(|x| x.1) { Some(b' ') | Some(b'\n') | Some(b'\r') | Some(b'\t') => { @@ -683,9 +683,9 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) -> match suffix { Some(suf) if looks_like_width_suffix(&['f'], suf) => { match base { - 16us => sd.span_err(sp, "hexadecimal float literal is not supported"), - 8us => sd.span_err(sp, "octal float literal is not supported"), - 2us => sd.span_err(sp, "binary float literal is not supported"), + 16 => sd.span_err(sp, "hexadecimal float literal is not supported"), + 8 => sd.span_err(sp, "octal float literal is not supported"), + 2 => sd.span_err(sp, "binary float literal is not supported"), _ => () } let ident = token::intern_and_get_ident(&*s); @@ -755,6 +755,7 @@ mod test { use ast; use abi; use attr::{first_attr_value_str_by_name, AttrMetaMethods}; + use parse; use parse::parser::Parser; use parse::token::{str_to_ident}; use print::pprust::item_to_string; @@ -1163,7 +1164,7 @@ mod test { "impl z { fn a (self: Foo, &myarg: i32) {} }", ]; - for &src in srcs.iter() { + for &src in &srcs { let spans = get_spans_of_pat_idents(src); let Span{ lo, hi, .. } = spans[0]; assert!("self" == &src[lo.to_usize()..hi.to_usize()], @@ -1214,4 +1215,26 @@ mod test { let doc = first_attr_value_str_by_name(item.attrs.as_slice(), "doc").unwrap(); assert_eq!(doc.get(), "/** doc comment\n * with CRLF */"); } + + #[test] + fn ttdelim_span() { + let sess = parse::new_parse_sess(); + let expr = parse::parse_expr_from_source_str("foo".to_string(), + "foo!( fn main() { body } )".to_string(), vec![], &sess); + + let tts = match expr.node { + ast::ExprMac(ref mac) => { + let ast::MacInvocTT(_, ref tts, _) = mac.node; + tts.clone() + } + _ => panic!("not a macro"), + }; + + let span = tts.iter().rev().next().unwrap().get_span(); + + match sess.span_diagnostic.cm.span_to_snippet(span) { + Some(s) => assert_eq!(&s[], "{ body }"), + None => panic!("could not get snippet"), + } + } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d99095eeba3..c3182602a4b 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -290,6 +290,7 @@ pub struct Parser<'a> { #[derive(PartialEq, Eq, Clone)] pub enum TokenType { Token(token::Token), + Keyword(keywords::Keyword), Operator, } @@ -298,6 +299,7 @@ impl TokenType { match *self { TokenType::Token(ref t) => format!("`{}`", Parser::token_to_string(t)), TokenType::Operator => "an operator".to_string(), + TokenType::Keyword(kw) => format!("`{}`", token::get_name(kw.to_name())), } } } @@ -365,9 +367,9 @@ impl<'a> Parser<'a> { token_str)[]); } - pub fn unexpected(&self) -> ! { - let this_token = self.this_token_to_string(); - self.fatal(&format!("unexpected token: `{}`", this_token)[]); + pub fn unexpected(&mut self) -> ! { + self.expect_one_of(&[], &[]); + unreachable!() } /// Expect and consume the token t. Signal an error if @@ -425,10 +427,13 @@ impl<'a> Parser<'a> { let expect = tokens_to_string(&expected[]); let actual = self.this_token_to_string(); self.fatal( - &(if expected.len() != 1 { + &(if expected.len() > 1 { (format!("expected one of {}, found `{}`", expect, actual)) + } else if expected.len() == 0 { + (format!("unexpected token: `{}`", + actual)) } else { (format!("expected {}, found `{}`", expect, @@ -515,7 +520,7 @@ impl<'a> Parser<'a> { pub fn parse_path_list_item(&mut self) -> ast::PathListItem { let lo = self.span.lo; - let node = if self.eat_keyword(keywords::Mod) { + let node = if self.eat_keyword_noexpect(keywords::Mod) { let span = self.last_span; self.span_warn(span, "deprecated syntax; use the `self` keyword now"); ast::PathListMod { id: ast::DUMMY_NODE_ID } @@ -547,9 +552,23 @@ impl<'a> Parser<'a> { is_present } + pub fn check_keyword(&mut self, kw: keywords::Keyword) -> bool { + self.expected_tokens.push(TokenType::Keyword(kw)); + self.token.is_keyword(kw) + } + /// If the next token is the given keyword, eat it and return /// true. Otherwise, return false. pub fn eat_keyword(&mut self, kw: keywords::Keyword) -> bool { + if self.check_keyword(kw) { + self.bump(); + true + } else { + false + } + } + + pub fn eat_keyword_noexpect(&mut self, kw: keywords::Keyword) -> bool { if self.token.is_keyword(kw) { self.bump(); true @@ -563,10 +582,7 @@ impl<'a> Parser<'a> { /// Otherwise, eat it. pub fn expect_keyword(&mut self, kw: keywords::Keyword) { if !self.eat_keyword(kw) { - let id_interned_str = token::get_name(kw.to_name()); - let token_str = self.this_token_to_string(); - self.fatal(&format!("expected `{}`, found `{}`", - id_interned_str, token_str)[]) + self.expect_one_of(&[], &[]); } } @@ -593,6 +609,7 @@ impl<'a> Parser<'a> { /// Expect and consume an `&`. If `&&` is seen, replace it with a single /// `&` and continue. If an `&` is not seen, signal an error. fn expect_and(&mut self) { + self.expected_tokens.push(TokenType::Token(token::BinOp(token::And))); match self.token { token::BinOp(token::And) => self.bump(), token::AndAnd => { @@ -601,12 +618,7 @@ impl<'a> Parser<'a> { self.replace_token(token::BinOp(token::And), lo, span.hi) } _ => { - let token_str = self.this_token_to_string(); - let found_token = - Parser::token_to_string(&token::BinOp(token::And)); - self.fatal(&format!("expected `{}`, found `{}`", - found_token, - token_str)[]) + self.expect_one_of(&[], &[]); } } } @@ -614,6 +626,7 @@ impl<'a> Parser<'a> { /// Expect and consume a `|`. If `||` is seen, replace it with a single /// `|` and continue. If a `|` is not seen, signal an error. fn expect_or(&mut self) { + self.expected_tokens.push(TokenType::Token(token::BinOp(token::Or))); match self.token { token::BinOp(token::Or) => self.bump(), token::OrOr => { @@ -622,12 +635,7 @@ impl<'a> Parser<'a> { self.replace_token(token::BinOp(token::Or), lo, span.hi) } _ => { - let found_token = self.this_token_to_string(); - let token_str = - Parser::token_to_string(&token::BinOp(token::Or)); - self.fatal(&format!("expected `{}`, found `{}`", - token_str, - found_token)[]) + self.expect_one_of(&[], &[]); } } } @@ -652,6 +660,7 @@ impl<'a> Parser<'a> { /// This is meant to be used when parsing generics on a path to get the /// starting token. fn eat_lt(&mut self) -> bool { + self.expected_tokens.push(TokenType::Token(token::Lt)); match self.token { token::Lt => { self.bump(); true } token::BinOp(token::Shl) => { @@ -666,11 +675,7 @@ impl<'a> Parser<'a> { fn expect_lt(&mut self) { if !self.eat_lt() { - let found_token = self.this_token_to_string(); - let token_str = Parser::token_to_string(&token::Lt); - self.fatal(&format!("expected `{}`, found `{}`", - token_str, - found_token)[]) + self.expect_one_of(&[], &[]); } } @@ -700,6 +705,7 @@ impl<'a> Parser<'a> { /// with a single > and continue. If a GT is not seen, /// signal an error. pub fn expect_gt(&mut self) { + self.expected_tokens.push(TokenType::Token(token::Gt)); match self.token { token::Gt => self.bump(), token::BinOp(token::Shr) => { @@ -740,7 +746,7 @@ impl<'a> Parser<'a> { // would encounter a `>` and stop. This lets the parser handle trailing // commas in generic parameters, because it can stop either after // parsing a type or after parsing a comma. - for i in iter::count(0us, 1) { + for i in iter::count(0, 1) { if self.check(&token::Gt) || self.token == token::BinOp(token::Shr) || self.token == token::Ge @@ -917,7 +923,7 @@ impl<'a> Parser<'a> { }; self.span = next.sp; self.token = next.tok; - self.tokens_consumed += 1us; + self.tokens_consumed += 1; self.expected_tokens.clear(); // check after each token self.check_unknown_macro_variable(); @@ -998,14 +1004,14 @@ impl<'a> Parser<'a> { /// Is the current token one of the keywords that signals a bare function /// type? pub fn token_is_bare_fn_keyword(&mut self) -> bool { - self.token.is_keyword(keywords::Fn) || - self.token.is_keyword(keywords::Unsafe) || - self.token.is_keyword(keywords::Extern) + self.check_keyword(keywords::Fn) || + self.check_keyword(keywords::Unsafe) || + self.check_keyword(keywords::Extern) } /// Is the current token one of the keywords that signals a closure type? pub fn token_is_closure_keyword(&mut self) -> bool { - self.token.is_keyword(keywords::Unsafe) + self.check_keyword(keywords::Unsafe) } pub fn get_lifetime(&mut self) -> ast::Ident { @@ -1035,7 +1041,7 @@ impl<'a> Parser<'a> { let lifetime_defs = self.parse_late_bound_lifetime_defs(); // examine next token to decide to do - if self.eat_keyword(keywords::Proc) { + if self.eat_keyword_noexpect(keywords::Proc) { self.parse_proc_type(lifetime_defs) } else if self.token_is_bare_fn_keyword() || self.token_is_closure_keyword() { self.parse_ty_bare_fn_or_ty_closure(lifetime_defs) @@ -1166,11 +1172,11 @@ impl<'a> Parser<'a> { // Closure: [unsafe] <'lt> |S| [:Bounds] -> T // Fn: [unsafe] [extern "ABI"] fn <'lt> (S) -> T - if self.token.is_keyword(keywords::Fn) { + if self.check_keyword(keywords::Fn) { self.parse_ty_bare_fn(lifetime_defs) - } else if self.token.is_keyword(keywords::Extern) { + } else if self.check_keyword(keywords::Extern) { self.parse_ty_bare_fn(lifetime_defs) - } else if self.token.is_keyword(keywords::Unsafe) { + } else if self.check_keyword(keywords::Unsafe) { if self.look_ahead(1, |t| t.is_keyword(keywords::Fn) || t.is_keyword(keywords::Extern)) { self.parse_ty_bare_fn(lifetime_defs) @@ -1480,7 +1486,7 @@ impl<'a> Parser<'a> { // BORROWED POINTER self.expect_and(); self.parse_borrowed_pointee() - } else if self.token.is_keyword(keywords::For) { + } else if self.check_keyword(keywords::For) { self.parse_for_in_type() } else if self.token_is_bare_fn_keyword() || self.token_is_closure_keyword() { @@ -1494,14 +1500,14 @@ impl<'a> Parser<'a> { })) { // CLOSURE self.parse_ty_closure(Vec::new()) - } else if self.eat_keyword(keywords::Typeof) { + } else if self.eat_keyword_noexpect(keywords::Typeof) { // TYPEOF // In order to not be ambiguous, the type must be surrounded by parens. self.expect(&token::OpenDelim(token::Paren)); let e = self.parse_expr(); self.expect(&token::CloseDelim(token::Paren)); TyTypeof(e) - } else if self.eat_keyword(keywords::Proc) { + } else if self.eat_keyword_noexpect(keywords::Proc) { self.parse_proc_type(Vec::new()) } else if self.eat_lt() { // QUALIFIED PATH `<TYPE as TRAIT_REF>::item` @@ -2092,6 +2098,7 @@ impl<'a> Parser<'a> { } fn expect_open_delim(&mut self) -> token::DelimToken { + self.expected_tokens.push(TokenType::Token(token::Gt)); match self.token { token::OpenDelim(delim) => { self.bump(); @@ -2233,7 +2240,7 @@ impl<'a> Parser<'a> { if self.eat_keyword(keywords::Move) { return self.parse_lambda_expr(CaptureByValue); } - if self.eat_keyword(keywords::Proc) { + if self.eat_keyword_noexpect(keywords::Proc) { let span = self.last_span; let _ = self.parse_proc_decl(); let _ = self.parse_expr(); @@ -2307,8 +2314,8 @@ impl<'a> Parser<'a> { hi = self.span.hi; } else if self.check(&token::ModSep) || self.token.is_ident() && - !self.token.is_keyword(keywords::True) && - !self.token.is_keyword(keywords::False) { + !self.check_keyword(keywords::True) && + !self.check_keyword(keywords::False) { let pth = self.parse_path(LifetimeAndTypesWithColons); @@ -2625,7 +2632,7 @@ impl<'a> Parser<'a> { } pub fn check_unknown_macro_variable(&mut self) { - if self.quote_depth == 0us { + if self.quote_depth == 0 { match self.token { token::SubstNt(name, _) => self.fatal(&format!("unknown macro variable `{}`", @@ -2694,7 +2701,7 @@ impl<'a> Parser<'a> { token_str)[]) }, /* we ought to allow different depths of unquotation */ - token::Dollar | token::SubstNt(..) if p.quote_depth > 0us => { + token::Dollar | token::SubstNt(..) if p.quote_depth > 0 => { p.parse_unquoted() } _ => { @@ -2706,7 +2713,7 @@ impl<'a> Parser<'a> { match self.token { token::Eof => { let open_braces = self.open_braces.clone(); - for sp in open_braces.iter() { + for sp in &open_braces { self.span_help(*sp, "did you mean to close this delimiter?"); } // There shouldn't really be a span, but it's easier for the test runner @@ -2735,7 +2742,7 @@ impl<'a> Parser<'a> { self.open_braces.pop().unwrap(); // Expand to cover the entire delimited token tree - let span = Span { hi: self.span.hi, ..pre_span }; + let span = Span { hi: close_span.hi, ..pre_span }; TtDelimited(span, Rc::new(Delimited { delim: delim, @@ -2792,7 +2799,7 @@ impl<'a> Parser<'a> { ex = ExprAddrOf(m, e); } token::Ident(_, _) => { - if !self.token.is_keyword(keywords::Box) { + if !self.check_keyword(keywords::Box) { return self.parse_dot_or_call_expr(); } @@ -2879,7 +2886,7 @@ impl<'a> Parser<'a> { } } None => { - if AS_PREC >= min_prec && self.eat_keyword(keywords::As) { + if AS_PREC >= min_prec && self.eat_keyword_noexpect(keywords::As) { let rhs = self.parse_ty(); let _as = self.mk_expr(lhs.span.lo, rhs.span.hi, @@ -3002,7 +3009,7 @@ impl<'a> Parser<'a> { /// Parse an 'if' or 'if let' expression ('if' token already eaten) pub fn parse_if_expr(&mut self) -> P<Expr> { - if self.token.is_keyword(keywords::Let) { + if self.check_keyword(keywords::Let) { return self.parse_if_let_expr(); } let lo = self.last_span.lo; @@ -3655,7 +3662,7 @@ impl<'a> Parser<'a> { } let lo = self.span.lo; - if self.token.is_keyword(keywords::Let) { + if self.check_keyword(keywords::Let) { check_expected_item(self, &item_attrs[]); self.expect_keyword(keywords::Let); let decl = self.parse_let(); @@ -5200,7 +5207,7 @@ impl<'a> Parser<'a> { Some(i) => { let mut err = String::from_str("circular modules: "); let len = included_mod_stack.len(); - for p in included_mod_stack[i.. len].iter() { + for p in &included_mod_stack[i.. len] { err.push_str(&p.display().as_cow()[]); err.push_str(" -> "); } @@ -5302,7 +5309,7 @@ impl<'a> Parser<'a> { let (maybe_path, ident) = match self.token { token::Ident(..) => { let the_ident = self.parse_ident(); - let path = if self.eat_keyword(keywords::As) { + let path = if self.eat_keyword_noexpect(keywords::As) { // skip the ident if there is one if self.token.is_ident() { self.bump(); } @@ -5445,7 +5452,7 @@ impl<'a> Parser<'a> { seq_sep_trailing_allowed(token::Comma), |p| p.parse_ty_sum() ); - for ty in arg_tys.into_iter() { + for ty in arg_tys { args.push(ast::VariantArg { ty: ty, id: ast::DUMMY_NODE_ID, @@ -5595,14 +5602,13 @@ impl<'a> Parser<'a> { token_str)[]); } - if self.eat_keyword(keywords::Virtual) { + if self.eat_keyword_noexpect(keywords::Virtual) { let span = self.span; self.span_err(span, "`virtual` structs have been removed from the language"); } - if self.token.is_keyword(keywords::Static) { + if self.eat_keyword(keywords::Static) { // STATIC ITEM - self.bump(); let m = if self.eat_keyword(keywords::Mut) {MutMutable} else {MutImmutable}; let (ident, item_, extra_attrs) = self.parse_item_const(Some(m)); let last_span = self.last_span; @@ -5614,9 +5620,8 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(item); } - if self.token.is_keyword(keywords::Const) { + if self.eat_keyword(keywords::Const) { // CONST ITEM - self.bump(); if self.eat_keyword(keywords::Mut) { let last_span = self.last_span; self.span_err(last_span, "const globals cannot be mutable"); @@ -5632,8 +5637,8 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(item); } - if self.token.is_keyword(keywords::Unsafe) && - self.look_ahead(1us, |t| t.is_keyword(keywords::Trait)) + if self.check_keyword(keywords::Unsafe) && + self.look_ahead(1, |t| t.is_keyword(keywords::Trait)) { // UNSAFE TRAIT ITEM self.expect_keyword(keywords::Unsafe); @@ -5649,8 +5654,8 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(item); } - if self.token.is_keyword(keywords::Unsafe) && - self.look_ahead(1us, |t| t.is_keyword(keywords::Impl)) + if self.check_keyword(keywords::Unsafe) && + self.look_ahead(1, |t| t.is_keyword(keywords::Impl)) { // IMPL ITEM self.expect_keyword(keywords::Unsafe); @@ -5665,7 +5670,7 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(item); } - if self.token.is_keyword(keywords::Fn) { + if self.check_keyword(keywords::Fn) { // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = @@ -5679,8 +5684,8 @@ impl<'a> Parser<'a> { maybe_append(attrs, extra_attrs)); return Ok(item); } - if self.token.is_keyword(keywords::Unsafe) - && self.look_ahead(1us, |t| *t != token::OpenDelim(token::Brace)) { + if self.check_keyword(keywords::Unsafe) + && self.look_ahead(1, |t| *t != token::OpenDelim(token::Brace)) { // UNSAFE FUNCTION ITEM self.bump(); let abi = if self.eat_keyword(keywords::Extern) { @@ -5784,11 +5789,11 @@ impl<'a> Parser<'a> { let visibility = self.parse_visibility(); - if self.token.is_keyword(keywords::Static) { + if self.check_keyword(keywords::Static) { // FOREIGN STATIC ITEM return Ok(self.parse_item_foreign_static(visibility, attrs)); } - if self.token.is_keyword(keywords::Fn) || self.token.is_keyword(keywords::Unsafe) { + if self.check_keyword(keywords::Fn) || self.check_keyword(keywords::Unsafe) { // FOREIGN FUNCTION ITEM return Ok(self.parse_item_foreign_fn(visibility, attrs)); } @@ -5912,9 +5917,9 @@ impl<'a> Parser<'a> { self.bump(); match self.token { - token::Ident(i, _) => { - self.bump(); - path.push(i); + token::Ident(..) => { + let ident = self.parse_ident(); + path.push(ident); } // foo::bar::{a,b,c} @@ -5954,11 +5959,16 @@ impl<'a> Parser<'a> { return P(spanned(lo, self.span.hi, ViewPathGlob(path))); } + // fall-through for case foo::bar::; + token::Semi => { + self.span_err(self.span, "expected identifier or `{` or `*`, found `;`"); + } + _ => break } } } - let mut rename_to = path[path.len() - 1us]; + let mut rename_to = path[path.len() - 1]; let path = ast::Path { span: mk_sp(lo, self.last_span.hi), global: false, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 5531ce7b119..5c3892e49c0 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -456,7 +456,7 @@ macro_rules! declare_special_idents_and_keywords {( pub use self::Keyword::*; use ast; - #[derive(Copy)] + #[derive(Copy, Clone, PartialEq, Eq)] pub enum Keyword { $( $sk_variant, )* $( $rk_variant, )* diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 70d6a5f695a..707b3c72ecd 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -132,15 +132,15 @@ pub fn buf_str(toks: &[Token], let mut i = left; let mut l = lim; let mut s = string::String::from_str("["); - while i != right && l != 0us { - l -= 1us; + while i != right && l != 0 { + l -= 1; if i != left { s.push_str(", "); } s.push_str(&format!("{}={}", szs[i], tok_str(&toks[i]))[]); - i += 1us; + i += 1; i %= n; } s.push(']'); @@ -326,8 +326,8 @@ impl Printer { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; - self.left = 0us; - self.right = 0us; + self.left = 0; + self.right = 0; } else { self.advance_right(); } debug!("pp Begin({})/buffer ~[{},{}]", b.offset, self.left, self.right); @@ -355,8 +355,8 @@ impl Printer { if self.scan_stack_empty { self.left_total = 1; self.right_total = 1; - self.left = 0us; - self.right = 0us; + self.left = 0; + self.right = 0; } else { self.advance_right(); } debug!("pp Break({})/buffer ~[{},{}]", b.offset, self.left, self.right); @@ -410,7 +410,7 @@ impl Printer { if self.scan_stack_empty { self.scan_stack_empty = false; } else { - self.top += 1us; + self.top += 1; self.top %= self.buf_len; assert!((self.top != self.bottom)); } @@ -422,7 +422,7 @@ impl Printer { if self.top == self.bottom { self.scan_stack_empty = true; } else { - self.top += self.buf_len - 1us; self.top %= self.buf_len; + self.top += self.buf_len - 1; self.top %= self.buf_len; } return x; } @@ -436,12 +436,12 @@ impl Printer { if self.top == self.bottom { self.scan_stack_empty = true; } else { - self.bottom += 1us; self.bottom %= self.buf_len; + self.bottom += 1; self.bottom %= self.buf_len; } return x; } pub fn advance_right(&mut self) { - self.right += 1us; + self.right += 1; self.right %= self.buf_len; assert!((self.right != self.left)); } @@ -471,7 +471,7 @@ impl Printer { break; } - self.left += 1us; + self.left += 1; self.left %= self.buf_len; left_size = self.size[self.left]; @@ -520,7 +520,7 @@ impl Printer { pub fn get_top(&mut self) -> PrintStackElem { let print_stack = &mut self.print_stack; let n = print_stack.len(); - if n != 0us { + if n != 0 { (*print_stack)[n - 1] } else { PrintStackElem { @@ -565,7 +565,7 @@ impl Printer { Token::End => { debug!("print End -> pop End"); let print_stack = &mut self.print_stack; - assert!((print_stack.len() != 0us)); + assert!((print_stack.len() != 0)); print_stack.pop().unwrap(); Ok(()) } @@ -667,11 +667,11 @@ pub fn spaces(p: &mut Printer, n: usize) -> old_io::IoResult<()> { } pub fn zerobreak(p: &mut Printer) -> old_io::IoResult<()> { - spaces(p, 0us) + spaces(p, 0) } pub fn space(p: &mut Printer) -> old_io::IoResult<()> { - spaces(p, 1us) + spaces(p, 1) } pub fn hardbreak(p: &mut Printer) -> old_io::IoResult<()> { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 5367ccc1357..e6d895a49fc 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -92,10 +92,10 @@ pub fn rust_printer_annotated<'a>(writer: Box<old_io::Writer+'static>, } #[allow(non_upper_case_globals)] -pub const indent_unit: usize = 4us; +pub const indent_unit: usize = 4; #[allow(non_upper_case_globals)] -pub const default_columns: usize = 78us; +pub const default_columns: usize = 78; /// Requires you to pass an input filename and reader so that /// it can scan the input text for comments and literals to @@ -377,7 +377,7 @@ pub fn block_to_string(blk: &ast::Block) -> String { // containing cbox, will be closed by print-block at } try!(s.cbox(indent_unit)); // head-ibox, will be closed by print-block after { - try!(s.ibox(0us)); + try!(s.ibox(0)); s.print_block(blk) }) } @@ -516,7 +516,7 @@ impl<'a> State<'a> { pub fn bclose_maybe_open (&mut self, span: codemap::Span, indented: usize, close_box: bool) -> IoResult<()> { try!(self.maybe_print_comment(span.hi)); - try!(self.break_offset_if_not_bol(1us, -(indented as isize))); + try!(self.break_offset_if_not_bol(1, -(indented as isize))); try!(word(&mut self.s, "}")); if close_box { try!(self.end()); // close the outer-box @@ -591,9 +591,9 @@ impl<'a> State<'a> { pub fn commasep<T, F>(&mut self, b: Breaks, elts: &[T], mut op: F) -> IoResult<()> where F: FnMut(&mut State, &T) -> IoResult<()>, { - try!(self.rbox(0us, b)); + try!(self.rbox(0, b)); let mut first = true; - for elt in elts.iter() { + for elt in elts { if first { first = false; } else { try!(self.word_space(",")); } try!(op(self, elt)); } @@ -609,13 +609,13 @@ impl<'a> State<'a> { F: FnMut(&mut State, &T) -> IoResult<()>, G: FnMut(&T) -> codemap::Span, { - try!(self.rbox(0us, b)); + try!(self.rbox(0, b)); let len = elts.len(); - let mut i = 0us; - for elt in elts.iter() { + let mut i = 0; + for elt in elts { try!(self.maybe_print_comment(get_span(elt).hi)); try!(op(self, elt)); - i += 1us; + i += 1; if i < len { try!(word(&mut self.s, ",")); try!(self.maybe_print_trailing_comment(get_span(elt), @@ -634,7 +634,7 @@ impl<'a> State<'a> { pub fn print_mod(&mut self, _mod: &ast::Mod, attrs: &[ast::Attribute]) -> IoResult<()> { try!(self.print_inner_attributes(attrs)); - for item in _mod.items.iter() { + for item in &_mod.items { try!(self.print_item(&**item)); } Ok(()) @@ -643,7 +643,7 @@ impl<'a> State<'a> { pub fn print_foreign_mod(&mut self, nmod: &ast::ForeignMod, attrs: &[ast::Attribute]) -> IoResult<()> { try!(self.print_inner_attributes(attrs)); - for item in nmod.items.iter() { + for item in &nmod.items { try!(self.print_foreign_item(&**item)); } Ok(()) @@ -651,8 +651,8 @@ impl<'a> State<'a> { pub fn print_opt_lifetime(&mut self, lifetime: &Option<ast::Lifetime>) -> IoResult<()> { - for l in lifetime.iter() { - try!(self.print_lifetime(l)); + if let Some(l) = *lifetime { + try!(self.print_lifetime(&l)); try!(self.nbsp()); } Ok(()) @@ -660,7 +660,7 @@ impl<'a> State<'a> { pub fn print_type(&mut self, ty: &ast::Ty) -> IoResult<()> { try!(self.maybe_print_comment(ty.span.lo)); - try!(self.ibox(0us)); + try!(self.ibox(0)); match ty.node { ast::TyVec(ref ty) => { try!(word(&mut self.s, "[")); @@ -799,7 +799,7 @@ impl<'a> State<'a> { ast::ItemExternCrate(ref optional_path) => { try!(self.head(&visibility_qualified(item.vis, "extern crate")[])); - for &(ref p, style) in optional_path.iter() { + if let Some((ref p, style)) = *optional_path { try!(self.print_string(p.get(), style)); try!(space(&mut self.s)); try!(word(&mut self.s, "as")); @@ -880,7 +880,7 @@ impl<'a> State<'a> { } ast::ItemTy(ref ty, ref params) => { try!(self.ibox(indent_unit)); - try!(self.ibox(0us)); + try!(self.ibox(0)); try!(self.word_nbsp(&visibility_qualified(item.vis, "type")[])); try!(self.print_ident(item.ident)); try!(self.print_generics(params)); @@ -945,7 +945,7 @@ impl<'a> State<'a> { try!(space(&mut self.s)); try!(self.bopen()); try!(self.print_inner_attributes(&item.attrs[])); - for impl_item in impl_items.iter() { + for impl_item in impl_items { match *impl_item { ast::MethodImplItem(ref meth) => { try!(self.print_method(&**meth)); @@ -966,7 +966,7 @@ impl<'a> State<'a> { try!(self.print_generics(generics)); let bounds: Vec<_> = bounds.iter().map(|b| b.clone()).collect(); let mut real_bounds = Vec::with_capacity(bounds.len()); - for b in bounds.into_iter() { + for b in bounds { if let TraitTyParamBound(ref ptr, ast::TraitBoundModifier::Maybe) = b { try!(space(&mut self.s)); try!(self.word_space("for ?")); @@ -979,7 +979,7 @@ impl<'a> State<'a> { try!(self.print_where_clause(generics)); try!(word(&mut self.s, " ")); try!(self.bopen()); - for meth in methods.iter() { + for meth in methods { try!(self.print_trait_method(meth)); } try!(self.bclose(item.span)); @@ -1010,7 +1010,7 @@ impl<'a> State<'a> { if !t.bound_lifetimes.is_empty() { try!(word(&mut self.s, "for<")); let mut comma = false; - for lifetime_def in t.bound_lifetimes.iter() { + for lifetime_def in &t.bound_lifetimes { if comma { try!(self.word_space(",")) } @@ -1039,7 +1039,7 @@ impl<'a> State<'a> { variants: &[P<ast::Variant>], span: codemap::Span) -> IoResult<()> { try!(self.bopen()); - for v in variants.iter() { + for v in variants { try!(self.space_if_not_bol()); try!(self.maybe_print_comment(v.span.lo)); try!(self.print_outer_attributes(&v.node.attrs[])); @@ -1094,7 +1094,7 @@ impl<'a> State<'a> { try!(self.bopen()); try!(self.hardbreak_if_not_bol()); - for field in struct_def.fields.iter() { + for field in &struct_def.fields { match field.node.kind { ast::UnnamedField(..) => panic!("unexpected unnamed field"), ast::NamedField(ident, visibility) => { @@ -1141,7 +1141,7 @@ impl<'a> State<'a> { }, ast::TtSequence(_, ref seq) => { try!(word(&mut self.s, "$(")); - for tt_elt in seq.tts.iter() { + for tt_elt in &seq.tts { try!(self.print_tt(tt_elt)); } try!(word(&mut self.s, ")")); @@ -1277,8 +1277,8 @@ impl<'a> State<'a> { pub fn print_outer_attributes(&mut self, attrs: &[ast::Attribute]) -> IoResult<()> { - let mut count = 0us; - for attr in attrs.iter() { + let mut count = 0; + for attr in attrs { match attr.node.style { ast::AttrOuter => { try!(self.print_attribute(attr)); @@ -1295,8 +1295,8 @@ impl<'a> State<'a> { pub fn print_inner_attributes(&mut self, attrs: &[ast::Attribute]) -> IoResult<()> { - let mut count = 0us; - for attr in attrs.iter() { + let mut count = 0; + for attr in attrs { match attr.node.style { ast::AttrInner => { try!(self.print_attribute(attr)); @@ -1395,7 +1395,7 @@ impl<'a> State<'a> { try!(self.print_inner_attributes(attrs)); - for st in blk.stmts.iter() { + for st in &blk.stmts { try!(self.print_stmt(&**st)); } match blk.expr { @@ -1416,8 +1416,8 @@ impl<'a> State<'a> { match _else.node { // "another else-if" ast::ExprIf(ref i, ref then, ref e) => { - try!(self.cbox(indent_unit - 1us)); - try!(self.ibox(0us)); + try!(self.cbox(indent_unit - 1)); + try!(self.ibox(0)); try!(word(&mut self.s, " else if ")); try!(self.print_expr(&**i)); try!(space(&mut self.s)); @@ -1426,8 +1426,8 @@ impl<'a> State<'a> { } // "another else-if-let" ast::ExprIfLet(ref pat, ref expr, ref then, ref e) => { - try!(self.cbox(indent_unit - 1us)); - try!(self.ibox(0us)); + try!(self.cbox(indent_unit - 1)); + try!(self.ibox(0)); try!(word(&mut self.s, " else if let ")); try!(self.print_pat(&**pat)); try!(space(&mut self.s)); @@ -1439,8 +1439,8 @@ impl<'a> State<'a> { } // "final else" ast::ExprBlock(ref b) => { - try!(self.cbox(indent_unit - 1us)); - try!(self.ibox(0us)); + try!(self.cbox(indent_unit - 1)); + try!(self.ibox(0)); try!(word(&mut self.s, " else ")); self.print_block(&**b) } @@ -1606,7 +1606,7 @@ impl<'a> State<'a> { try!(self.print_expr(&*args[0])); try!(word(&mut self.s, ".")); try!(self.print_ident(ident.node)); - if tys.len() > 0us { + if tys.len() > 0 { try!(word(&mut self.s, "::<")); try!(self.commasep(Inconsistent, tys, |s, ty| s.print_type(&**ty))); @@ -1691,8 +1691,8 @@ impl<'a> State<'a> { try!(self.print_if_let(&**pat, &**expr, &** blk, elseopt.as_ref().map(|e| &**e))); } ast::ExprWhile(ref test, ref blk, opt_ident) => { - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(self.word_space(":")); } try!(self.head("while")); @@ -1701,8 +1701,8 @@ impl<'a> State<'a> { try!(self.print_block(&**blk)); } ast::ExprWhileLet(ref pat, ref expr, ref blk, opt_ident) => { - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(self.word_space(":")); } try!(self.head("while let")); @@ -1714,8 +1714,8 @@ impl<'a> State<'a> { try!(self.print_block(&**blk)); } ast::ExprForLoop(ref pat, ref iter, ref blk, opt_ident) => { - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(self.word_space(":")); } try!(self.head("for")); @@ -1727,8 +1727,8 @@ impl<'a> State<'a> { try!(self.print_block(&**blk)); } ast::ExprLoop(ref blk, opt_ident) => { - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(self.word_space(":")); } try!(self.head("loop")); @@ -1742,7 +1742,7 @@ impl<'a> State<'a> { try!(self.print_expr(&**expr)); try!(space(&mut self.s)); try!(self.bopen()); - for arm in arms.iter() { + for arm in arms { try!(self.print_arm(arm)); } try!(self.bclose_(expr.span, indent_unit)); @@ -1777,7 +1777,7 @@ impl<'a> State<'a> { // containing cbox, will be closed by print-block at } try!(self.cbox(indent_unit)); // head-box, will be closed by print-block after { - try!(self.ibox(0us)); + try!(self.ibox(0)); try!(self.print_block(&**blk)); } ast::ExprAssign(ref lhs, ref rhs) => { @@ -1825,16 +1825,16 @@ impl<'a> State<'a> { ast::ExprBreak(opt_ident) => { try!(word(&mut self.s, "break")); try!(space(&mut self.s)); - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(space(&mut self.s)); } } ast::ExprAgain(opt_ident) => { try!(word(&mut self.s, "continue")); try!(space(&mut self.s)); - for ident in opt_ident.iter() { - try!(self.print_ident(*ident)); + if let Some(ident) = opt_ident { + try!(self.print_ident(ident)); try!(space(&mut self.s)) } } @@ -1991,7 +1991,7 @@ impl<'a> State<'a> { } let mut first = true; - for segment in path.segments.iter() { + for segment in &path.segments { if first { first = false } else { @@ -2040,7 +2040,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, "<")); let mut comma = false; - for lifetime in data.lifetimes.iter() { + for lifetime in &data.lifetimes { if comma { try!(self.word_space(",")) } @@ -2059,7 +2059,7 @@ impl<'a> State<'a> { comma = true; } - for binding in data.bindings.iter() { + for binding in &*data.bindings { if comma { try!(self.word_space(",")) } @@ -2154,7 +2154,7 @@ impl<'a> State<'a> { }, |f| f.node.pat.span)); if etc { - if fields.len() != 0us { try!(self.word_space(",")); } + if fields.len() != 0 { try!(self.word_space(",")); } try!(word(&mut self.s, "..")); } try!(space(&mut self.s)); @@ -2193,7 +2193,7 @@ impl<'a> State<'a> { try!(self.commasep(Inconsistent, &before[], |s, p| s.print_pat(&**p))); - for p in slice.iter() { + if let Some(ref p) = *slice { if !before.is_empty() { try!(self.word_space(",")); } try!(self.print_pat(&**p)); match **p { @@ -2221,10 +2221,10 @@ impl<'a> State<'a> { try!(space(&mut self.s)); } try!(self.cbox(indent_unit)); - try!(self.ibox(0us)); + try!(self.ibox(0)); try!(self.print_outer_attributes(&arm.attrs[])); let mut first = true; - for p in arm.pats.iter() { + for p in &arm.pats { if first { first = false; } else { @@ -2307,9 +2307,9 @@ impl<'a> State<'a> { -> IoResult<()> { // It is unfortunate to duplicate the commasep logic, but we want the // self type and the args all in the same box. - try!(self.rbox(0us, Inconsistent)); + try!(self.rbox(0, Inconsistent)); let mut first = true; - for &explicit_self in opt_explicit_self.iter() { + if let Some(explicit_self) = opt_explicit_self { let m = match explicit_self { &ast::SelfStatic => ast::MutImmutable, _ => match decl.inputs[0].pat.node { @@ -2327,7 +2327,7 @@ impl<'a> State<'a> { &decl.inputs[1..] }; - for arg in args.iter() { + for arg in args { if first { first = false; } else { try!(self.word_space(",")); } try!(self.print_arg(arg)); } @@ -2397,7 +2397,7 @@ impl<'a> State<'a> { if !bounds.is_empty() { try!(word(&mut self.s, prefix)); let mut first = true; - for bound in bounds.iter() { + for bound in bounds { try!(self.nbsp()); if first { first = false; @@ -2437,7 +2437,7 @@ impl<'a> State<'a> { { try!(self.print_lifetime(&lifetime.lifetime)); let mut sep = ":"; - for v in lifetime.bounds.iter() { + for v in &lifetime.bounds { try!(word(&mut self.s, sep)); try!(self.print_lifetime(v)); sep = "+"; @@ -2457,7 +2457,7 @@ impl<'a> State<'a> { try!(word(&mut self.s, "<")); let mut ints = Vec::new(); - for i in 0us..total { + for i in 0..total { ints.push(i); } @@ -2707,7 +2707,7 @@ impl<'a> State<'a> { if span.hi < (*cmnt).pos && (*cmnt).pos < next && span_line.line == comment_line.line { try!(self.print_comment(cmnt)); - self.cur_cmnt_and_lit.cur_cmnt += 1us; + self.cur_cmnt_and_lit.cur_cmnt += 1; } } _ => () @@ -2725,7 +2725,7 @@ impl<'a> State<'a> { match self.next_comment() { Some(ref cmnt) => { try!(self.print_comment(cmnt)); - self.cur_cmnt_and_lit.cur_cmnt += 1us; + self.cur_cmnt_and_lit.cur_cmnt += 1; } _ => break } @@ -2792,7 +2792,7 @@ impl<'a> State<'a> { } ast::LitBinary(ref v) => { let mut escaped: String = String::new(); - for &ch in v.iter() { + for &ch in &**v { ascii::escape_default(ch as u8, |ch| escaped.push(ch as char)); } @@ -2807,7 +2807,7 @@ impl<'a> State<'a> { while self.cur_cmnt_and_lit.cur_lit < lits.len() { let ltrl = (*lits)[self.cur_cmnt_and_lit.cur_lit].clone(); if ltrl.pos > pos { return None; } - self.cur_cmnt_and_lit.cur_lit += 1us; + self.cur_cmnt_and_lit.cur_lit += 1; if ltrl.pos == pos { return Some(ltrl); } } None @@ -2822,7 +2822,7 @@ impl<'a> State<'a> { Some(ref cmnt) => { if (*cmnt).pos < pos { try!(self.print_comment(cmnt)); - self.cur_cmnt_and_lit.cur_cmnt += 1us; + self.cur_cmnt_and_lit.cur_cmnt += 1; } else { break; } } _ => break @@ -2835,14 +2835,14 @@ impl<'a> State<'a> { cmnt: &comments::Comment) -> IoResult<()> { match cmnt.style { comments::Mixed => { - assert_eq!(cmnt.lines.len(), 1us); + assert_eq!(cmnt.lines.len(), 1); try!(zerobreak(&mut self.s)); try!(word(&mut self.s, &cmnt.lines[0][])); zerobreak(&mut self.s) } comments::Isolated => { try!(self.hardbreak_if_not_bol()); - for line in cmnt.lines.iter() { + for line in &cmnt.lines { // Don't print empty lines because they will end up as trailing // whitespace if !line.is_empty() { @@ -2854,12 +2854,12 @@ impl<'a> State<'a> { } comments::Trailing => { try!(word(&mut self.s, " ")); - if cmnt.lines.len() == 1us { + if cmnt.lines.len() == 1 { try!(word(&mut self.s, &cmnt.lines[0][])); hardbreak(&mut self.s) } else { - try!(self.ibox(0us)); - for line in cmnt.lines.iter() { + try!(self.ibox(0)); + for line in &cmnt.lines { if !line.is_empty() { try!(word(&mut self.s, &line[])); } diff --git a/src/libsyntax/test.rs b/src/libsyntax/test.rs index a7679adca2e..61ce664d2c7 100644 --- a/src/libsyntax/test.rs +++ b/src/libsyntax/test.rs @@ -356,8 +356,8 @@ fn is_bench_fn(cx: &TestCtxt, i: &ast::Item) -> bool { let tparm_cnt = generics.ty_params.len(); // NB: inadequate check, but we're running // well before resolve, can't get too deep. - input_cnt == 1us - && no_output && tparm_cnt == 0us + input_cnt == 1 + && no_output && tparm_cnt == 0 } _ => false } diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs index 1b35b1b04a3..51144267519 100644 --- a/src/libsyntax/util/interner.rs +++ b/src/libsyntax/util/interner.rs @@ -40,7 +40,7 @@ impl<T: Eq + Hash<Hasher> + Clone + 'static> Interner<T> { pub fn prefill(init: &[T]) -> Interner<T> { let rv = Interner::new(); - for v in init.iter() { + for v in init { rv.intern((*v).clone()); } rv @@ -158,7 +158,7 @@ impl StrInterner { pub fn prefill(init: &[&str]) -> StrInterner { let rv = StrInterner::new(); - for &v in init.iter() { rv.intern(v); } + for &v in init { rv.intern(v); } rv } diff --git a/src/libsyntax/util/small_vector.rs b/src/libsyntax/util/small_vector.rs index 12f871b2782..a6c92c03743 100644 --- a/src/libsyntax/util/small_vector.rs +++ b/src/libsyntax/util/small_vector.rs @@ -38,7 +38,7 @@ impl<T> FromIterator<T> for SmallVector<T> { } impl<T> Extend<T> for SmallVector<T> { - fn extend<I: Iterator<Item=T>>(&mut self, mut iter: I) { + fn extend<I: Iterator<Item=T>>(&mut self, iter: I) { for val in iter { self.push(val); } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index eb906788aa7..bd84306fe17 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -159,13 +159,13 @@ pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem) pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) { visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID); - for attr in krate.attrs.iter() { + for attr in &krate.attrs { visitor.visit_attribute(attr); } } pub fn walk_mod<'v, V: Visitor<'v>>(visitor: &mut V, module: &'v Mod) { - for item in module.items.iter() { + for item in &module.items { visitor.visit_item(&**item) } } @@ -179,7 +179,7 @@ pub fn walk_local<'v, V: Visitor<'v>>(visitor: &mut V, local: &'v Local) { pub fn walk_lifetime_def<'v, V: Visitor<'v>>(visitor: &mut V, lifetime_def: &'v LifetimeDef) { visitor.visit_name(lifetime_def.lifetime.span, lifetime_def.lifetime.name); - for bound in lifetime_def.bounds.iter() { + for bound in &lifetime_def.bounds { visitor.visit_lifetime_bound(bound); } } @@ -239,7 +239,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_path(path, item.id); } ViewPathList(ref prefix, ref list) => { - for id in list.iter() { + for id in list { match id.node { PathListIdent { name, .. } => { visitor.visit_ident(id.span, name); @@ -270,7 +270,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_mod(module, item.span, item.id) } ItemForeignMod(ref foreign_module) => { - for foreign_item in foreign_module.items.iter() { + for foreign_item in &foreign_module.items { visitor.visit_foreign_item(&**foreign_item) } } @@ -293,7 +293,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { None => () } visitor.visit_ty(&**typ); - for impl_item in impl_items.iter() { + for impl_item in impl_items { match *impl_item { MethodImplItem(ref method) => { walk_method_helper(visitor, &**method) @@ -315,13 +315,13 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { ItemTrait(_, ref generics, ref bounds, ref methods) => { visitor.visit_generics(generics); walk_ty_param_bounds_helper(visitor, bounds); - for method in methods.iter() { + for method in methods { visitor.visit_trait_item(method) } } ItemMac(ref mac) => visitor.visit_mac(mac), } - for attr in item.attrs.iter() { + for attr in &item.attrs { visitor.visit_attribute(attr); } } @@ -329,7 +329,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { pub fn walk_enum_def<'v, V: Visitor<'v>>(visitor: &mut V, enum_definition: &'v EnumDef, generics: &'v Generics) { - for variant in enum_definition.variants.iter() { + for variant in &enum_definition.variants { visitor.visit_variant(&**variant, generics); } } @@ -341,7 +341,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, match variant.node.kind { TupleVariantKind(ref variant_arguments) => { - for variant_argument in variant_arguments.iter() { + for variant_argument in variant_arguments { visitor.visit_ty(&*variant_argument.ty) } } @@ -356,7 +356,7 @@ pub fn walk_variant<'v, V: Visitor<'v>>(visitor: &mut V, Some(ref expr) => visitor.visit_expr(&**expr), None => () } - for attr in variant.node.attrs.iter() { + for attr in &variant.node.attrs { visitor.visit_attribute(attr); } } @@ -385,12 +385,12 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { visitor.visit_ty(&*mutable_type.ty) } TyTup(ref tuple_element_types) => { - for tuple_element_type in tuple_element_types.iter() { + for tuple_element_type in tuple_element_types { visitor.visit_ty(&**tuple_element_type) } } TyBareFn(ref function_declaration) => { - for argument in function_declaration.decl.inputs.iter() { + for argument in &function_declaration.decl.inputs { visitor.visit_ty(&*argument.ty) } walk_fn_ret_ty(visitor, &function_declaration.decl.output); @@ -422,13 +422,13 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty) { pub fn walk_lifetime_decls_helper<'v, V: Visitor<'v>>(visitor: &mut V, lifetimes: &'v Vec<LifetimeDef>) { - for l in lifetimes.iter() { + for l in lifetimes { visitor.visit_lifetime_def(l); } } pub fn walk_path<'v, V: Visitor<'v>>(visitor: &mut V, path: &'v Path) { - for segment in path.segments.iter() { + for segment in &path.segments { visitor.visit_path_segment(path.span, segment); } } @@ -453,21 +453,21 @@ pub fn walk_path_parameters<'v, V: Visitor<'v>>(visitor: &mut V, path_parameters: &'v PathParameters) { match *path_parameters { ast::AngleBracketedParameters(ref data) => { - for typ in data.types.iter() { + for typ in &*data.types { visitor.visit_ty(&**typ); } - for lifetime in data.lifetimes.iter() { + for lifetime in &data.lifetimes { visitor.visit_lifetime_ref(lifetime); } - for binding in data.bindings.iter() { + for binding in &*data.bindings { visitor.visit_assoc_type_binding(&**binding); } } ast::ParenthesizedParameters(ref data) => { - for typ in data.inputs.iter() { + for typ in &data.inputs { visitor.visit_ty(&**typ); } - for typ in data.output.iter() { + if let Some(ref typ) = data.output { visitor.visit_ty(&**typ); } } @@ -484,20 +484,20 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { match pattern.node { PatEnum(ref path, ref children) => { visitor.visit_path(path, pattern.id); - for children in children.iter() { - for child in children.iter() { - visitor.visit_pat(&**child) + if let Some(ref children) = *children { + for child in children { + visitor.visit_pat(&*child) } } } PatStruct(ref path, ref fields, _) => { visitor.visit_path(path, pattern.id); - for field in fields.iter() { + for field in fields { visitor.visit_pat(&*field.node.pat) } } PatTup(ref tuple_elements) => { - for tuple_element in tuple_elements.iter() { + for tuple_element in tuple_elements { visitor.visit_pat(&**tuple_element) } } @@ -519,13 +519,13 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { } PatWild(_) => (), PatVec(ref prepattern, ref slice_pattern, ref postpatterns) => { - for prepattern in prepattern.iter() { + for prepattern in prepattern { visitor.visit_pat(&**prepattern) } - for slice_pattern in slice_pattern.iter() { + if let Some(ref slice_pattern) = *slice_pattern { visitor.visit_pat(&**slice_pattern) } - for postpattern in postpatterns.iter() { + for postpattern in postpatterns { visitor.visit_pat(&**postpattern) } } @@ -545,14 +545,14 @@ pub fn walk_foreign_item<'v, V: Visitor<'v>>(visitor: &mut V, ForeignItemStatic(ref typ, _) => visitor.visit_ty(&**typ), } - for attr in foreign_item.attrs.iter() { + for attr in &foreign_item.attrs { visitor.visit_attribute(attr); } } pub fn walk_ty_param_bounds_helper<'v, V: Visitor<'v>>(visitor: &mut V, bounds: &'v OwnedSlice<TyParamBound>) { - for bound in bounds.iter() { + for bound in &**bounds { visitor.visit_ty_param_bound(bound) } } @@ -576,11 +576,11 @@ pub fn walk_ty_param<'v, V: Visitor<'v>>(visitor: &mut V, param: &'v TyParam) { } pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics) { - for type_parameter in generics.ty_params.iter() { + for type_parameter in &*generics.ty_params { walk_ty_param(visitor, type_parameter); } walk_lifetime_decls_helper(visitor, &generics.lifetimes); - for predicate in generics.where_clause.predicates.iter() { + for predicate in &generics.where_clause.predicates { match predicate { &ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate{ref bounded_ty, ref bounds, @@ -593,7 +593,7 @@ pub fn walk_generics<'v, V: Visitor<'v>>(visitor: &mut V, generics: &'v Generics ..}) => { visitor.visit_lifetime_ref(lifetime); - for bound in bounds.iter() { + for bound in bounds { visitor.visit_lifetime_ref(bound); } } @@ -615,7 +615,7 @@ pub fn walk_fn_ret_ty<'v, V: Visitor<'v>>(visitor: &mut V, ret_ty: &'v FunctionR } pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &'v FnDecl) { - for argument in function_declaration.inputs.iter() { + for argument in &function_declaration.inputs { visitor.visit_pat(&*argument.pat); visitor.visit_ty(&*argument.ty) } @@ -635,7 +635,7 @@ pub fn walk_method_helper<'v, V: Visitor<'v>>(visitor: &mut V, method: &'v Metho &**body, method.span, method.id); - for attr in method.attrs.iter() { + for attr in &method.attrs { visitor.visit_attribute(attr); } @@ -673,12 +673,12 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V, pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v TypeMethod) { visitor.visit_ident(method_type.span, method_type.ident); visitor.visit_explicit_self(&method_type.explicit_self); - for argument_type in method_type.decl.inputs.iter() { + for argument_type in &method_type.decl.inputs { visitor.visit_ty(&*argument_type.ty) } visitor.visit_generics(&method_type.generics); walk_fn_ret_ty(visitor, &method_type.decl.output); - for attr in method_type.attrs.iter() { + for attr in &method_type.attrs { visitor.visit_attribute(attr); } } @@ -695,7 +695,7 @@ pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v Tr pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &'v StructDef) { - for field in struct_definition.fields.iter() { + for field in &struct_definition.fields { visitor.visit_struct_field(field) } } @@ -708,13 +708,13 @@ pub fn walk_struct_field<'v, V: Visitor<'v>>(visitor: &mut V, visitor.visit_ty(&*struct_field.node.ty); - for attr in struct_field.node.attrs.iter() { + for attr in &struct_field.node.attrs { visitor.visit_attribute(attr); } } pub fn walk_block<'v, V: Visitor<'v>>(visitor: &mut V, block: &'v Block) { - for statement in block.stmts.iter() { + for statement in &block.stmts { visitor.visit_stmt(&**statement) } walk_expr_opt(visitor, &block.expr) @@ -746,7 +746,7 @@ pub fn walk_expr_opt<'v, V: Visitor<'v>>(visitor: &mut V, } pub fn walk_exprs<'v, V: Visitor<'v>>(visitor: &mut V, expressions: &'v [P<Expr>]) { - for expression in expressions.iter() { + for expression in expressions { visitor.visit_expr(&**expression) } } @@ -770,25 +770,25 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } ExprStruct(ref path, ref fields, ref optional_base) => { visitor.visit_path(path, expression.id); - for field in fields.iter() { + for field in fields { visitor.visit_expr(&*field.expr) } walk_expr_opt(visitor, optional_base) } ExprTup(ref subexpressions) => { - for subexpression in subexpressions.iter() { + for subexpression in subexpressions { visitor.visit_expr(&**subexpression) } } ExprCall(ref callee_expression, ref arguments) => { - for argument in arguments.iter() { + for argument in arguments { visitor.visit_expr(&**argument) } visitor.visit_expr(&**callee_expression) } ExprMethodCall(_, ref types, ref arguments) => { walk_exprs(visitor, arguments.as_slice()); - for typ in types.iter() { + for typ in types { visitor.visit_ty(&**typ) } } @@ -832,7 +832,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprLoop(ref block, _) => visitor.visit_block(&**block), ExprMatch(ref subexpression, ref arms, _) => { visitor.visit_expr(&**subexpression); - for arm in arms.iter() { + for arm in arms { visitor.visit_arm(arm) } } @@ -881,11 +881,11 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr(&**subexpression) } ExprInlineAsm(ref ia) => { - for input in ia.inputs.iter() { + for input in &ia.inputs { let (_, ref input) = *input; visitor.visit_expr(&**input) } - for output in ia.outputs.iter() { + for output in &ia.outputs { let (_, ref output, _) = *output; visitor.visit_expr(&**output) } @@ -896,12 +896,12 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { } pub fn walk_arm<'v, V: Visitor<'v>>(visitor: &mut V, arm: &'v Arm) { - for pattern in arm.pats.iter() { + for pattern in &arm.pats { visitor.visit_pat(&**pattern) } walk_expr_opt(visitor, &arm.guard); visitor.visit_expr(&*arm.body); - for attr in arm.attrs.iter() { + for attr in &arm.attrs { visitor.visit_attribute(attr); } } |
