From e0ad0fcb95f0bd6e69e9032c23b66515a590dfe5 Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Mon, 27 Oct 2014 15:37:07 -0700 Subject: Update code with new lint names --- src/libsyntax/abi.rs | 6 +++--- src/libsyntax/ast_util.rs | 2 +- src/libsyntax/parse/token.rs | 4 ++-- src/libsyntax/print/pprust.rs | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/abi.rs b/src/libsyntax/abi.rs index 03325ad4706..dc41f3d9279 100644 --- a/src/libsyntax/abi.rs +++ b/src/libsyntax/abi.rs @@ -47,9 +47,9 @@ pub enum Architecture { Mipsel } -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] const IntelBits: u32 = (1 << (X86 as uint)) | (1 << (X86_64 as uint)); -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] const ArmBits: u32 = (1 << (Arm as uint)); pub struct AbiData { @@ -72,7 +72,7 @@ pub enum AbiArchitecture { Archs(u32) } -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] static AbiDatas: &'static [AbiData] = &[ // Platform-specific ABIs AbiData {abi: Cdecl, name: "cdecl", abi_arch: Archs(IntelBits)}, diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index d5a460dc9db..25a3a4ea3a2 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -291,7 +291,7 @@ pub fn operator_prec(op: ast::BinOp) -> uint { /// Precedence of the `as` operator, which is a binary operator /// not appearing in the prior table. -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] pub static as_prec: uint = 12u; pub fn empty_generics() -> Generics { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index fa6b0c5ad4a..769652bd23b 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -384,14 +384,14 @@ macro_rules! declare_special_idents_and_keywords {( pub mod special_idents { use ast::{Ident, Name}; $( - #[allow(non_uppercase_statics)] + #[allow(non_upper_case_globals)] pub const $si_static: Ident = Ident { name: Name($si_name), ctxt: 0 }; )* } pub mod special_names { use ast::Name; - $( #[allow(non_uppercase_statics)] pub const $si_static: Name = Name($si_name); )* + $( #[allow(non_upper_case_globals)] pub const $si_static: Name = Name($si_name); )* } /** diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 69e6d78d16a..e26848f5bb1 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -89,10 +89,10 @@ pub fn rust_printer_annotated<'a>(writer: Box, } } -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] pub const indent_unit: uint = 4u; -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] pub const default_columns: uint = 78u; /// Requires you to pass an input filename and reader so that -- cgit 1.4.1-3-g733a5 From cb5f9799421c7ae9289295acdf15546a1e68da91 Mon Sep 17 00:00:00 2001 From: gamazeps Date: Wed, 29 Oct 2014 00:59:36 +0100 Subject: Diagnostic: resolve bare fn in expected closure Closes #15273 (I did not find how to get the identifier in the message :/) Also creates the span_help! macro associated with #18126 --- src/librustc/middle/typeck/check/writeback.rs | 6 ++++-- src/libsyntax/diagnostics/macros.rs | 7 +++++++ src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs | 6 ++++-- 3 files changed, 15 insertions(+), 4 deletions(-) (limited to 'src/libsyntax') diff --git a/src/librustc/middle/typeck/check/writeback.rs b/src/librustc/middle/typeck/check/writeback.rs index 56dec61d410..b53318861b8 100644 --- a/src/librustc/middle/typeck/check/writeback.rs +++ b/src/librustc/middle/typeck/check/writeback.rs @@ -1,4 +1,4 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -282,7 +282,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { } _ => { span_err!(self.tcx().sess, reason.span(self.tcx()), E0100, - "cannot coerce non-statically resolved bare fn"); + "cannot coerce non-statically resolved bare fn to closure"); + span_help!(self.tcx().sess, reason.span(self.tcx()), + "consider embedding the function in a closure"); } } diff --git a/src/libsyntax/diagnostics/macros.rs b/src/libsyntax/diagnostics/macros.rs index c344168b62a..b4bf793d4e1 100644 --- a/src/libsyntax/diagnostics/macros.rs +++ b/src/libsyntax/diagnostics/macros.rs @@ -39,6 +39,13 @@ macro_rules! span_note( }) ) +#[macro_export] +macro_rules! span_help( + ($session:expr, $span:expr, $($message:tt)*) => ({ + ($session).span_help($span, format!($($message)*).as_slice()) + }) +) + #[macro_export] macro_rules! register_diagnostics( ($($code:tt),*) => ( diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs index c165802d61f..087ebf4e28c 100644 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs @@ -13,7 +13,9 @@ fn foo() {} fn main() { let f = foo; let f_closure: || = f; - //~^ ERROR: cannot coerce non-statically resolved bare fn + //~^ ERROR: cannot coerce non-statically resolved bare fn to closure + //~^ HELP: consider embedding the function in a closure let f_proc: proc() = f; - //~^ ERROR: cannot coerce non-statically resolved bare fn + //~^ ERROR: cannot coerce non-statically resolved bare fn to closure + //~^ HELP: consider embedding the function in a closure } -- cgit 1.4.1-3-g733a5 From 936d999b5270d186df28123a5dbd6d2bb848bb2c Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 29 Oct 2014 21:37:54 +1100 Subject: Use common variants for open and close delimiters This common representation for delimeters should make pattern matching easier. Having a separate `token::DelimToken` enum also allows us to enforce the invariant that the opening and closing delimiters must be the same in `ast::TtDelimited`, removing the need to ensure matched delimiters when working with token trees. --- src/grammar/verify.rs | 12 +- src/librustc/middle/save/span_utils.rs | 6 +- src/librustdoc/html/highlight.rs | 6 +- src/libsyntax/ast.rs | 51 ++-- src/libsyntax/ext/asm.rs | 8 +- src/libsyntax/ext/quote.rs | 32 ++- src/libsyntax/ext/tt/macro_parser.rs | 6 +- src/libsyntax/ext/tt/macro_rules.rs | 5 +- src/libsyntax/ext/tt/transcribe.rs | 14 +- src/libsyntax/fold.rs | 20 +- src/libsyntax/parse/attr.rs | 12 +- src/libsyntax/parse/lexer/mod.rs | 12 +- src/libsyntax/parse/mod.rs | 70 +++--- src/libsyntax/parse/parser.rs | 323 +++++++++++++------------ src/libsyntax/parse/token.rs | 45 ++-- src/libsyntax/print/pprust.rs | 19 +- src/test/compile-fail/removed-syntax-record.rs | 2 +- 17 files changed, 328 insertions(+), 315 deletions(-) (limited to 'src/libsyntax') diff --git a/src/grammar/verify.rs b/src/grammar/verify.rs index a4345e06164..a4641c40165 100644 --- a/src/grammar/verify.rs +++ b/src/grammar/verify.rs @@ -59,7 +59,7 @@ fn parse_token_list(file: &str) -> HashMap { "FLOAT_SUFFIX" => id(), "INT_SUFFIX" => id(), "SHL" => token::BinOp(token::Shl), - "LBRACE" => token::LBrace, + "LBRACE" => token::OpenDelim(token::Brace), "RARROW" => token::Rarrow, "LIT_STR" => token::LitStr(Name(0)), "DOTDOT" => token::DotDot, @@ -67,12 +67,12 @@ fn parse_token_list(file: &str) -> HashMap { "DOTDOTDOT" => token::DotDotDot, "NOT" => token::Not, "AND" => token::BinOp(token::And), - "LPAREN" => token::LParen, + "LPAREN" => token::OpenDelim(token::Paren), "ANDAND" => token::AndAnd, "AT" => token::At, - "LBRACKET" => token::LBracket, + "LBRACKET" => token::OpenDelim(token::Bracket), "LIT_STR_RAW" => token::LitStrRaw(Name(0), 0), - "RPAREN" => token::RParen, + "RPAREN" => token::CloseDelim(token::Paren), "SLASH" => token::BinOp(token::Slash), "COMMA" => token::Comma, "LIFETIME" => token::Lifetime(ast::Ident { name: Name(0), ctxt: 0 }), @@ -83,7 +83,7 @@ fn parse_token_list(file: &str) -> HashMap { "LIT_CHAR" => token::LitChar(Name(0)), "LIT_BYTE" => token::LitByte(Name(0)), "EQ" => token::Eq, - "RBRACKET" => token::RBracket, + "RBRACKET" => token::CloseDelim(token::Bracket), "COMMENT" => token::Comment, "DOC_COMMENT" => token::DocComment(Name(0)), "DOT" => token::Dot, @@ -91,7 +91,7 @@ fn parse_token_list(file: &str) -> HashMap { "NE" => token::Ne, "GE" => token::Ge, "PERCENT" => token::BinOp(token::Percent), - "RBRACE" => token::RBrace, + "RBRACE" => token::CloseDelim(token::Brace), "BINOP" => token::BinOp(token::Plus), "POUND" => token::Pound, "OROR" => token::OrOr, diff --git a/src/librustc/middle/save/span_utils.rs b/src/librustc/middle/save/span_utils.rs index 511d8aa5bac..93ad29cff90 100644 --- a/src/librustc/middle/save/span_utils.rs +++ b/src/librustc/middle/save/span_utils.rs @@ -145,7 +145,7 @@ impl<'a> SpanUtils<'a> { last_span = None; let mut next = toks.next_token(); - if (next.tok == token::LParen || + if (next.tok == token::OpenDelim(token::Paren) || next.tok == token::Lt) && bracket_count == 0 && prev.tok.is_ident() { @@ -164,8 +164,8 @@ impl<'a> SpanUtils<'a> { } bracket_count += match prev.tok { - token::LParen | token::Lt => 1, - token::RParen | token::Gt => -1, + token::OpenDelim(token::Paren) | token::Lt => 1, + token::CloseDelim(token::Paren) | token::Gt => -1, token::BinOp(token::Shr) => -2, _ => 0 }; diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 0441e6b791f..4797ac7c66a 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -97,8 +97,8 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, // miscellaneous, no highlighting token::Dot | token::DotDot | token::DotDotDot | token::Comma | token::Semi | - token::Colon | token::ModSep | token::LArrow | token::LParen | - token::RParen | token::LBracket | token::LBrace | token::RBrace | + token::Colon | token::ModSep | token::LArrow | token::OpenDelim(_) | + token::CloseDelim(token::Brace) | token::CloseDelim(token::Paren) | token::Question => "", token::Dollar => { if lexer.peek().tok.is_ident() { @@ -118,7 +118,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, try!(write!(out, r"#")); continue } - token::RBracket => { + token::CloseDelim(token::Bracket) => { if is_attribute { is_attribute = false; try!(write!(out, "]")); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 3bd25d245e1..a2c859cf9fd 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -595,17 +595,38 @@ pub enum CaptureClause { CaptureByRef, } -/// A token that delimits a sequence of token trees -#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] -pub struct Delimiter { - pub span: Span, - pub token: ::parse::token::Token, -} +/// A delimited sequence of token trees +#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] +pub struct Delimited { + /// The type of delimiter + pub delim: token::DelimToken, + /// The span covering the opening delimiter + pub open_span: Span, + /// The delimited sequence of token trees + pub tts: Vec, + /// The span covering the closing delimiter + pub close_span: Span, +} + +impl Delimited { + /// Returns the opening delimiter as a token. + pub fn open_token(&self) -> token::Token { + token::OpenDelim(self.delim) + } + + /// Returns the closing delimiter as a token. + pub fn close_token(&self) -> token::Token { + token::CloseDelim(self.delim) + } + + /// Returns the opening delimiter as a token tree. + pub fn open_tt(&self) -> TokenTree { + TtToken(self.open_span, self.open_token()) + } -impl Delimiter { - /// Convert the delimiter to a `TtToken` - pub fn to_tt(&self) -> TokenTree { - TtToken(self.span, self.token.clone()) + /// Returns the closing delimiter as a token tree. + pub fn close_tt(&self) -> TokenTree { + TtToken(self.close_span, self.close_token()) } } @@ -635,15 +656,15 @@ pub enum KleeneOp { #[doc="For macro invocations; parsing is delegated to the macro"] pub enum TokenTree { /// A single token - TtToken(Span, ::parse::token::Token), + TtToken(Span, token::Token), /// A delimited sequence of token trees - TtDelimited(Span, Rc<(Delimiter, Vec, Delimiter)>), + TtDelimited(Span, Rc), // These only make sense for right-hand-sides of MBE macros: /// A Kleene-style repetition sequence with an optional separator. // FIXME(eddyb) #6308 Use Rc<[TokenTree]> after DST. - TtSequence(Span, Rc>, Option<::parse::token::Token>, KleeneOp), + TtSequence(Span, Rc>, Option, KleeneOp), /// A syntactic variable that will be filled in by macro expansion. TtNonterminal(Span, Ident) } @@ -715,10 +736,10 @@ pub type Matcher = Spanned; #[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)] pub enum Matcher_ { /// Match one token - MatchTok(::parse::token::Token), + MatchTok(token::Token), /// Match repetitions of a sequence: body, separator, Kleene operator, /// lo, hi position-in-match-array used: - MatchSeq(Vec , Option<::parse::token::Token>, KleeneOp, uint, uint), + MatchSeq(Vec, Option, KleeneOp, uint, uint), /// Parse a Rust NT: name to bind, name of NT, position in match array: MatchNonterminal(Ident, Ident, uint) } diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 2b52b7feacc..d57d6e52d7f 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -84,9 +84,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let span = p.last_span; - p.expect(&token::LParen); + p.expect(&token::OpenDelim(token::Paren)); let out = p.parse_expr(); - p.expect(&token::RParen); + p.expect(&token::CloseDelim(token::Paren)); // Expands a read+write operand into two operands. // @@ -129,9 +129,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) cx.span_err(p.last_span, "input operand constraint contains '+'"); } - p.expect(&token::LParen); + p.expect(&token::OpenDelim(token::Paren)); let input = p.parse_expr(); - p.expect(&token::RParen); + p.expect(&token::CloseDelim(token::Paren)); inputs.push((constraint, input)); } diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index a95a737720a..2151f79cd7b 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -531,6 +531,15 @@ fn mk_binop(cx: &ExtCtxt, sp: Span, bop: token::BinOpToken) -> P { mk_token_path(cx, sp, name) } +fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken) -> P { + let name = match delim { + token::Paren => "Paren", + token::Bracket => "Bracket", + token::Brace => "Brace", + }; + mk_token_path(cx, sp, name) +} + #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { match *tok { @@ -542,6 +551,15 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { vec!(mk_binop(cx, sp, binop))); } + token::OpenDelim(delim) => { + return cx.expr_call(sp, mk_token_path(cx, sp, "OpenDelim"), + vec![mk_delim(cx, sp, delim)]); + } + token::CloseDelim(delim) => { + return cx.expr_call(sp, mk_token_path(cx, sp, "CloseDelim"), + vec![mk_delim(cx, sp, delim)]); + } + token::LitByte(i) => { let e_byte = mk_name(cx, sp, i.ident()); @@ -625,12 +643,6 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { token::RArrow => "RArrow", token::LArrow => "LArrow", token::FatArrow => "FatArrow", - token::LParen => "LParen", - token::RParen => "RParen", - token::LBracket => "LBracket", - token::RBracket => "RBracket", - token::LBrace => "LBrace", - token::RBrace => "RBrace", token::Pound => "Pound", token::Dollar => "Dollar", token::Underscore => "Underscore", @@ -640,7 +652,6 @@ fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { mk_token_path(cx, sp, name) } - fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec> { match *tt { ast::TtToken(sp, ref tok) => { @@ -656,10 +667,9 @@ fn mk_tt(cx: &ExtCtxt, _: Span, tt: &ast::TokenTree) -> Vec> { vec!(cx.stmt_expr(e_push)) }, ast::TtDelimited(sp, ref delimed) => { - let (ref open, ref tts, ref close) = **delimed; - mk_tt(cx, sp, &open.to_tt()).into_iter() - .chain(tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter())) - .chain(mk_tt(cx, sp, &close.to_tt()).into_iter()) + mk_tt(cx, sp, &delimed.open_tt()).into_iter() + .chain(delimed.tts.iter().flat_map(|tt| mk_tt(cx, sp, tt).into_iter())) + .chain(mk_tt(cx, sp, &delimed.close_tt()).into_iter()) .collect() }, ast::TtSequence(..) => panic!("TtSequence in quote!"), diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 9260a45adb9..bbc2cb86d00 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -355,10 +355,8 @@ pub fn parse(sess: &ParseSess, // Built-in nonterminals never start with these tokens, // so we can eliminate them from consideration. match tok { - token::RParen | - token::RBrace | - token::RBracket => {}, - _ => bb_eis.push(ei) + token::CloseDelim(_) => {}, + _ => bb_eis.push(ei), } } MatchTok(ref t) => { diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 85bd5cde304..e50d4457af2 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -172,10 +172,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, MatchedNonterminal(NtTT(ref tt)) => { match **tt { // ignore delimiters - TtDelimited(_, ref delimed) => { - let (_, ref tts, _) = **delimed; - tts.clone() - }, + TtDelimited(_, ref delimed) => delimed.tts.clone(), _ => cx.span_fatal(sp, "macro rhs must be delimited"), } }, diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 2c7b583d460..249a985a648 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -129,8 +129,7 @@ impl Add for LockstepIterSize { fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize { match *t { TtDelimited(_, ref delimed) => { - let (_, ref tts, _) = **delimed; - tts.iter().fold(LisUnconstrained, |size, tt| { + delimed.tts.iter().fold(LisUnconstrained, |size, tt| { size + lockstep_iter_size(tt, r) }) }, @@ -207,14 +206,13 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { }; match t { TtDelimited(_, ref delimed) => { - let (ref open, ref tts, ref close) = **delimed; - let mut forest = Vec::with_capacity(1 + tts.len() + 1); - forest.push(open.to_tt()); - forest.extend(tts.iter().map(|x| (*x).clone())); - forest.push(close.to_tt()); + let mut tts = Vec::with_capacity(1 + delimed.tts.len() + 1); + tts.push(delimed.open_tt()); + tts.extend(delimed.tts.iter().map(|tt| tt.clone())); + tts.push(delimed.close_tt()); r.stack.push(TtFrame { - forest: Rc::new(forest), + forest: Rc::new(tts), idx: 0, dotdotdoted: false, sep: None diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 47ca66b0b49..9a55f07e98d 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -572,18 +572,14 @@ pub fn noop_fold_tt(tt: &TokenTree, fld: &mut T) -> TokenTree { TtToken(span, ref tok) => TtToken(span, fld.fold_token(tok.clone())), TtDelimited(span, ref delimed) => { - let (ref open, ref tts, ref close) = **delimed; - TtDelimited(span, Rc::new(( - Delimiter { - span: open.span, - token: fld.fold_token(open.token.clone()) - }, - fld.fold_tts(tts.as_slice()), - Delimiter { - span: close.span, - token: fld.fold_token(close.token.clone()) - }, - ))) + TtDelimited(span, Rc::new( + Delimited { + delim: delimed.delim, + open_span: delimed.open_span, + tts: fld.fold_tts(delimed.tts.as_slice()), + close_span: delimed.close_span, + } + )) }, TtSequence(span, ref pattern, ref sep, is_optional) => TtSequence(span, diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 458a5042a7e..aefac804e4d 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -81,10 +81,10 @@ impl<'a> ParserAttr for Parser<'a> { ast::AttrOuter }; - self.expect(&token::LBracket); + self.expect(&token::OpenDelim(token::Bracket)); let meta_item = self.parse_meta_item(); let hi = self.span.hi; - self.expect(&token::RBracket); + self.expect(&token::CloseDelim(token::Bracket)); (mk_sp(lo, hi), meta_item, style) } @@ -194,7 +194,7 @@ impl<'a> ParserAttr for Parser<'a> { let hi = self.span.hi; P(spanned(lo, hi, ast::MetaNameValue(name, lit))) } - token::LParen => { + token::OpenDelim(token::Paren) => { let inner_items = self.parse_meta_seq(); let hi = self.span.hi; P(spanned(lo, hi, ast::MetaList(name, inner_items))) @@ -208,15 +208,15 @@ impl<'a> ParserAttr for Parser<'a> { /// matches meta_seq = ( COMMASEP(meta_item) ) fn parse_meta_seq(&mut self) -> Vec> { - self.parse_seq(&token::LParen, - &token::RParen, + self.parse_seq(&token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_disallowed(token::Comma), |p| p.parse_meta_item()).node } fn parse_optional_meta(&mut self) -> Vec> { match self.token { - token::LParen => self.parse_meta_seq(), + token::OpenDelim(token::Paren) => self.parse_meta_seq(), _ => Vec::new() } } diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 3a6cf610b4f..293b91111b5 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -967,12 +967,12 @@ impl<'a> StringReader<'a> { token::Dot }; } - '(' => { self.bump(); return token::LParen; } - ')' => { self.bump(); return token::RParen; } - '{' => { self.bump(); return token::LBrace; } - '}' => { self.bump(); return token::RBrace; } - '[' => { self.bump(); return token::LBracket; } - ']' => { self.bump(); return token::RBracket; } + '(' => { self.bump(); return token::OpenDelim(token::Paren); } + ')' => { self.bump(); return token::CloseDelim(token::Paren); } + '{' => { self.bump(); return token::OpenDelim(token::Brace); } + '}' => { self.bump(); return token::CloseDelim(token::Brace); } + '[' => { self.bump(); return token::OpenDelim(token::Bracket); } + ']' => { self.bump(); return token::CloseDelim(token::Bracket); } '@' => { self.bump(); return token::At; } '#' => { self.bump(); return token::Pound; } '~' => { self.bump(); return token::Tilde; } diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index c731f3965a0..83499ec54c6 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -799,29 +799,23 @@ mod test { ast::TtDelimited(_, ref macro_delimed)] if name_macro_rules.as_str() == "macro_rules" && name_zip.as_str() == "zip" => { - let (ref macro_open, ref macro_tts, ref macro_close) = **macro_delimed; - match (macro_open, macro_tts.as_slice(), macro_close) { - (&ast::Delimiter { token: token::LParen, .. }, - [ast::TtDelimited(_, ref first_delimed), - ast::TtToken(_, token::FatArrow), - ast::TtDelimited(_, ref second_delimed)], - &ast::Delimiter { token: token::RParen, .. }) => { - let (ref first_open, ref first_tts, ref first_close) = **first_delimed; - match (first_open, first_tts.as_slice(), first_close) { - (&ast::Delimiter { token: token::LParen, .. }, - [ast::TtToken(_, token::Dollar), - ast::TtToken(_, token::Ident(name, token::Plain))], - &ast::Delimiter { token: token::RParen, .. }) - if name.as_str() == "a" => {}, + match macro_delimed.tts.as_slice() { + [ast::TtDelimited(_, ref first_delimed), + ast::TtToken(_, token::FatArrow), + ast::TtDelimited(_, ref second_delimed)] + if macro_delimed.delim == token::Paren => { + match first_delimed.tts.as_slice() { + [ast::TtToken(_, token::Dollar), + ast::TtToken(_, token::Ident(name, token::Plain))] + if first_delimed.delim == token::Paren + && name.as_str() == "a" => {}, _ => panic!("value 3: {}", **first_delimed), } - let (ref second_open, ref second_tts, ref second_close) = **second_delimed; - match (second_open, second_tts.as_slice(), second_close) { - (&ast::Delimiter { token: token::LParen, .. }, - [ast::TtToken(_, token::Dollar), - ast::TtToken(_, token::Ident(name, token::Plain))], - &ast::Delimiter { token: token::RParen, .. }) - if name.as_str() == "a" => {}, + match second_delimed.tts.as_slice() { + [ast::TtToken(_, token::Dollar), + ast::TtToken(_, token::Ident(name, token::Plain))] + if second_delimed.delim == token::Paren + && name.as_str() == "a" => {}, _ => panic!("value 4: {}", **second_delimed), } }, @@ -867,12 +861,10 @@ mod test { \"variant\":\"TtDelimited\",\ \"fields\":[\ null,\ - [\ - {\ - \"span\":null,\ - \"token\":\"LParen\"\ - },\ - [\ + {\ + \"delim\":\"Paren\",\ + \"open_span\":null,\ + \"tts\":[\ {\ \"variant\":\"TtToken\",\ \"fields\":[\ @@ -907,23 +899,18 @@ mod test { ]\ }\ ],\ - {\ - \"span\":null,\ - \"token\":\"RParen\"\ - }\ - ]\ + \"close_span\":null\ + }\ ]\ },\ {\ \"variant\":\"TtDelimited\",\ \"fields\":[\ null,\ - [\ - {\ - \"span\":null,\ - \"token\":\"LBrace\"\ - },\ - [\ + {\ + \"delim\":\"Brace\",\ + \"open_span\":null,\ + \"tts\":[\ {\ \"variant\":\"TtToken\",\ \"fields\":[\ @@ -945,11 +932,8 @@ mod test { ]\ }\ ],\ - {\ - \"span\":null,\ - \"token\":\"RBrace\"\ - }\ - ]\ + \"close_span\":null\ + }\ ]\ }\ ]".to_string() diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ef3a559bf4..3911c68fa18 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -48,7 +48,7 @@ use ast::{StmtExpr, StmtSemi, StmtMac, StructDef, StructField}; use ast::{StructVariantKind, BiSub}; use ast::StrStyle; use ast::{SelfExplicit, SelfRegion, SelfStatic, SelfValue}; -use ast::{Delimiter, TokenTree, TraitItem, TraitRef, TtDelimited, TtSequence, TtToken}; +use ast::{Delimited, TokenTree, TraitItem, TraitRef, TtDelimited, TtSequence, TtToken}; use ast::{TtNonterminal, TupleVariantKind, Ty, Ty_, TyBot}; use ast::{TypeField, TyFixedLengthVec, TyClosure, TyProc, TyBareFn}; use ast::{TyTypeof, TyInfer, TypeMethod}; @@ -474,15 +474,15 @@ impl<'a> Parser<'a> { /// recover (without consuming any expected input token). Returns /// true if and only if input was consumed for recovery. pub fn check_for_erroneous_unit_struct_expecting(&mut self, expected: &[token::Token]) -> bool { - if self.token == token::LBrace - && expected.iter().all(|t| *t != token::LBrace) - && self.look_ahead(1, |t| *t == token::RBrace) { + if self.token == token::OpenDelim(token::Brace) + && expected.iter().all(|t| *t != token::OpenDelim(token::Brace)) + && self.look_ahead(1, |t| *t == token::CloseDelim(token::Brace)) { // matched; signal non-fatal error and recover. let span = self.span; self.span_err(span, "unit-like struct construction is written with no trailing `{ }`"); - self.eat(&token::LBrace); - self.eat(&token::RBrace); + self.eat(&token::OpenDelim(token::Brace)); + self.eat(&token::CloseDelim(token::Brace)); true } else { false @@ -1265,8 +1265,8 @@ impl<'a> Parser<'a> { /// Parse the items in a trait declaration pub fn parse_trait_items(&mut self) -> Vec { self.parse_unspanned_seq( - &token::LBrace, - &token::RBrace, + &token::OpenDelim(token::Brace), + &token::CloseDelim(token::Brace), seq_sep_none(), |p| { let attrs = p.parse_outer_attributes(); @@ -1319,7 +1319,7 @@ impl<'a> Parser<'a> { vis: vis, }) } - token::LBrace => { + token::OpenDelim(token::Brace) => { debug!("parse_trait_methods(): parsing provided method"); let (inner_attrs, body) = p.parse_inner_attrs_and_block(); @@ -1411,9 +1411,9 @@ impl<'a> Parser<'a> { let lo = self.span.lo; - let t = if self.token == token::LParen { + let t = if self.token == token::OpenDelim(token::Paren) { self.bump(); - if self.token == token::RParen { + if self.token == token::CloseDelim(token::Paren) { self.bump(); TyNil } else { @@ -1424,7 +1424,7 @@ impl<'a> Parser<'a> { let mut one_tuple = false; while self.token == token::Comma { self.bump(); - if self.token != token::RParen { + if self.token != token::CloseDelim(token::Paren) { ts.push(self.parse_ty(true)); } else { @@ -1433,11 +1433,11 @@ impl<'a> Parser<'a> { } if ts.len() == 1 && !one_tuple { - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); TyParen(ts.into_iter().nth(0).unwrap()) } else { let t = TyTup(ts); - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); t } } @@ -1446,7 +1446,7 @@ impl<'a> Parser<'a> { self.bump(); let last_span = self.last_span; match self.token { - token::LBracket => self.obsolete(last_span, ObsoleteOwnedVector), + token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector), _ => self.obsolete(last_span, ObsoleteOwnedType) } TyUniq(self.parse_ty(false)) @@ -1454,9 +1454,9 @@ impl<'a> Parser<'a> { // STAR POINTER (bare pointer?) self.bump(); TyPtr(self.parse_ptr()) - } else if self.token == token::LBracket { + } else if self.token == token::OpenDelim(token::Bracket) { // VECTOR - self.expect(&token::LBracket); + self.expect(&token::OpenDelim(token::Bracket)); let t = self.parse_ty(true); // Parse the `, ..e` in `[ int, ..e ]` @@ -1465,7 +1465,7 @@ impl<'a> Parser<'a> { None => TyVec(t), Some(suffix) => TyFixedLengthVec(t, suffix) }; - self.expect(&token::RBracket); + self.expect(&token::CloseDelim(token::Bracket)); t } else if self.token == token::BinOp(token::And) || self.token == token::AndAnd { @@ -1490,9 +1490,9 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(keywords::Typeof) { // TYPEOF // In order to not be ambiguous, the type must be surrounded by parens. - self.expect(&token::LParen); + self.expect(&token::OpenDelim(token::Paren)); let e = self.parse_expr(); - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); TyTypeof(e) } else if self.eat_keyword(keywords::Proc) { self.parse_proc_type() @@ -1661,7 +1661,7 @@ impl<'a> Parser<'a> { LitBinary(parse::binary_lit(i.as_str())), token::LitBinaryRaw(i, _) => LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect())), - token::LParen => { self.expect(&token::RParen); LitNil }, + token::OpenDelim(token::Paren) => { self.expect(&token::CloseDelim(token::Paren)); LitNil }, _ => { self.unexpected_last(tok); } } } @@ -2025,31 +2025,31 @@ impl<'a> Parser<'a> { let ex: Expr_; match self.token { - token::LParen => { + token::OpenDelim(token::Paren) => { self.bump(); // (e) is parenthesized e // (e,) is a tuple with only one field, e let mut trailing_comma = false; - if self.token == token::RParen { + if self.token == token::CloseDelim(token::Paren) { hi = self.span.hi; self.bump(); let lit = P(spanned(lo, hi, LitNil)); return self.mk_expr(lo, hi, ExprLit(lit)); } let mut es = vec!(self.parse_expr()); - self.commit_expr(&**es.last().unwrap(), &[], &[token::Comma, token::RParen]); + self.commit_expr(&**es.last().unwrap(), &[], &[token::Comma, token::CloseDelim(token::Paren)]); while self.token == token::Comma { self.bump(); - if self.token != token::RParen { + if self.token != token::CloseDelim(token::Paren) { es.push(self.parse_expr()); self.commit_expr(&**es.last().unwrap(), &[], - &[token::Comma, token::RParen]); + &[token::Comma, token::CloseDelim(token::Paren)]); } else { trailing_comma = true; } } hi = self.span.hi; - self.commit_expr_expecting(&**es.last().unwrap(), token::RParen); + self.commit_expr_expecting(&**es.last().unwrap(), token::CloseDelim(token::Paren)); return if es.len() == 1 && !trailing_comma { self.mk_expr(lo, hi, ExprParen(es.into_iter().nth(0).unwrap())) @@ -2057,7 +2057,7 @@ impl<'a> Parser<'a> { self.mk_expr(lo, hi, ExprTup(es)) } }, - token::LBrace => { + token::OpenDelim(token::Brace) => { self.bump(); let blk = self.parse_block_tail(lo, DefaultBlock); return self.mk_expr(blk.span.lo, blk.span.hi, @@ -2077,10 +2077,10 @@ impl<'a> Parser<'a> { ex = ExprPath(path); hi = self.last_span.hi; } - token::LBracket => { + token::OpenDelim(token::Bracket) => { self.bump(); - if self.token == token::RBracket { + if self.token == token::CloseDelim(token::Bracket) { // Empty vector. self.bump(); ex = ExprVec(Vec::new()); @@ -2093,13 +2093,13 @@ impl<'a> Parser<'a> { self.bump(); self.bump(); let count = self.parse_expr(); - self.expect(&token::RBracket); + self.expect(&token::CloseDelim(token::Bracket)); ex = ExprRepeat(first_expr, count); } else if self.token == token::Comma { // Vector with two or more elements. self.bump(); let remaining_exprs = self.parse_seq_to_end( - &token::RBracket, + &token::CloseDelim(token::Bracket), seq_sep_trailing_allowed(token::Comma), |p| p.parse_expr() ); @@ -2108,7 +2108,7 @@ impl<'a> Parser<'a> { ex = ExprVec(exprs); } else { // Vector with one element. - self.expect(&token::RBracket); + self.expect(&token::CloseDelim(token::Bracket)); ex = ExprVec(vec!(first_expr)); } } @@ -2227,7 +2227,7 @@ impl<'a> Parser<'a> { tts, EMPTY_CTXT)); } - if self.token == token::LBrace { + if self.token == token::OpenDelim(token::Brace) { // This is a struct literal, unless we're prohibited // from parsing struct literals here. if !self.restrictions.contains(RESTRICTION_NO_STRUCT_LITERAL) { @@ -2236,7 +2236,7 @@ impl<'a> Parser<'a> { let mut fields = Vec::new(); let mut base = None; - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { if self.eat(&token::DotDot) { base = Some(self.parse_expr()); break; @@ -2245,7 +2245,7 @@ impl<'a> Parser<'a> { fields.push(self.parse_field()); self.commit_expr(&*fields.last().unwrap().expr, &[token::Comma], - &[token::RBrace]); + &[token::CloseDelim(token::Brace)]); } if fields.len() == 0 && base.is_none() { @@ -2258,7 +2258,7 @@ impl<'a> Parser<'a> { } hi = self.span.hi; - self.expect(&token::RBrace); + self.expect(&token::CloseDelim(token::Brace)); ex = ExprStruct(pth, fields, base); return self.mk_expr(lo, hi, ex); } @@ -2281,7 +2281,7 @@ impl<'a> Parser<'a> { /// Parse a block or unsafe block pub fn parse_block_expr(&mut self, lo: BytePos, blk_mode: BlockCheckMode) -> P { - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let blk = self.parse_block_tail(lo, blk_mode); return self.mk_expr(blk.span.lo, blk.span.hi, ExprBlock(blk)); } @@ -2313,10 +2313,10 @@ impl<'a> Parser<'a> { // expr.f() method call match self.token { - token::LParen => { + token::OpenDelim(token::Paren) => { let mut es = self.parse_unspanned_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_expr() ); @@ -2376,10 +2376,10 @@ impl<'a> Parser<'a> { if self.expr_is_complete(&*e) { break; } match self.token { // expr(...) - token::LParen => { + token::OpenDelim(token::Paren) => { let es = self.parse_unspanned_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_expr() ); @@ -2393,7 +2393,7 @@ impl<'a> Parser<'a> { // Could be either an index expression or a slicing expression. // Any slicing non-terminal can have a mutable version with `mut` // after the opening square bracket. - token::LBracket => { + token::OpenDelim(token::Bracket) => { self.bump(); let mutbl = if self.eat_keyword(keywords::Mut) { MutMutable @@ -2402,7 +2402,7 @@ impl<'a> Parser<'a> { }; match self.token { // e[] - token::RBracket => { + token::CloseDelim(token::Bracket) => { self.bump(); hi = self.span.hi; let slice = self.mk_slice(e, None, None, mutbl); @@ -2413,7 +2413,7 @@ impl<'a> Parser<'a> { self.bump(); match self.token { // e[..] - token::RBracket => { + token::CloseDelim(token::Bracket) => { self.bump(); hi = self.span.hi; let slice = self.mk_slice(e, None, None, mutbl); @@ -2427,7 +2427,7 @@ impl<'a> Parser<'a> { _ => { hi = self.span.hi; let e2 = self.parse_expr(); - self.commit_expr_expecting(&*e2, token::RBracket); + self.commit_expr_expecting(&*e2, token::CloseDelim(token::Bracket)); let slice = self.mk_slice(e, None, Some(e2), mutbl); e = self.mk_expr(lo, hi, slice) } @@ -2442,14 +2442,14 @@ impl<'a> Parser<'a> { self.bump(); let e2 = match self.token { // e[e..] - token::RBracket => { + token::CloseDelim(token::Bracket) => { self.bump(); None } // e[e..e] _ => { let e2 = self.parse_expr(); - self.commit_expr_expecting(&*e2, token::RBracket); + self.commit_expr_expecting(&*e2, token::CloseDelim(token::Bracket)); Some(e2) } }; @@ -2464,7 +2464,7 @@ impl<'a> Parser<'a> { "`mut` keyword is invalid in index expressions"); } hi = self.span.hi; - self.commit_expr_expecting(&*ix, token::RBracket); + self.commit_expr_expecting(&*ix, token::CloseDelim(token::Bracket)); let index = self.mk_index(e, ix); e = self.mk_expr(lo, hi, index) } @@ -2525,7 +2525,7 @@ impl<'a> Parser<'a> { fn parse_non_delim_tt_tok(p: &mut Parser) -> TokenTree { maybe_whole!(deref p, NtTT); match p.token { - token::RParen | token::RBrace | token::RBracket => { + token::CloseDelim(_) => { // This is a conservative error: only report the last unclosed delimiter. The // previous unclosed delimiters could actually be closed! The parser just hasn't // gotten to them yet. @@ -2542,10 +2542,10 @@ impl<'a> Parser<'a> { p.bump(); let sp = p.span; - if p.token == token::LParen { + if p.token == token::OpenDelim(token::Paren) { let seq = p.parse_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_none(), |p| p.parse_token_tree() ); @@ -2564,8 +2564,8 @@ impl<'a> Parser<'a> { } } - match (&self.token, self.token.get_close_delimiter()) { - (&token::Eof, _) => { + match self.token { + token::Eof => { let open_braces = self.open_braces.clone(); for sp in open_braces.iter() { self.span_note(*sp, "Did you mean to close this delimiter?"); @@ -2573,36 +2573,39 @@ impl<'a> Parser<'a> { // There shouldn't really be a span, but it's easier for the test runner // if we give it one self.fatal("this file contains an un-closed delimiter "); - } - (_, Some(close_delim)) => { + }, + token::OpenDelim(delim) => { // The span for beginning of the delimited section let pre_span = self.span; // Parse the open delimiter. self.open_braces.push(self.span); - let open = Delimiter { - span: self.span, - token: self.bump_and_get(), - }; + let open_span = self.span; + self.bump(); // Parse the token trees within the delimeters let tts = self.parse_seq_to_before_end( - &close_delim, seq_sep_none(), |p| p.parse_token_tree() + &token::CloseDelim(delim), + seq_sep_none(), + |p| p.parse_token_tree() ); // Parse the close delimiter. - let close = Delimiter { - span: self.span, - token: self.bump_and_get(), - }; + let close_span = self.span; + self.bump(); self.open_braces.pop().unwrap(); // Expand to cover the entire delimited token tree let span = Span { hi: self.span.hi, ..pre_span }; - TtDelimited(span, Rc::new((open, tts, close))) - } - _ => parse_non_delim_tt_tok(self) + TtDelimited(span, Rc::new(Delimited { + delim: delim, + open_span: open_span, + tts: tts, + close_span: close_span, + })) + }, + _ => parse_non_delim_tt_tok(self), } } @@ -2641,8 +2644,8 @@ impl<'a> Parser<'a> { let mut lparens = 0u; while self.token != *ket || lparens > 0u { - if self.token == token::LParen { lparens += 1u; } - if self.token == token::RParen { lparens -= 1u; } + if self.token == token::OpenDelim(token::Paren) { lparens += 1u; } + if self.token == token::CloseDelim(token::Paren) { lparens -= 1u; } ret_val.push(self.parse_matcher(name_idx)); } @@ -2656,11 +2659,11 @@ impl<'a> Parser<'a> { let m = if self.token == token::Dollar { self.bump(); - if self.token == token::LParen { + if self.token == token::OpenDelim(token::Paren) { let name_idx_lo = *name_idx; self.bump(); let ms = self.parse_matcher_subseq_upto(name_idx, - &token::RParen); + &token::CloseDelim(token::Paren)); if ms.len() == 0u { self.fatal("repetition body must be nonempty"); } @@ -2717,7 +2720,7 @@ impl<'a> Parser<'a> { self.bump(); let last_span = self.last_span; match self.token { - token::LBracket => self.obsolete(last_span, ObsoleteOwnedVector), + token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector), _ => self.obsolete(last_span, ObsoleteOwnedExpr) } @@ -2733,11 +2736,11 @@ impl<'a> Parser<'a> { self.bump(); // Check for a place: `box(PLACE) EXPR`. - if self.eat(&token::LParen) { + if self.eat(&token::OpenDelim(token::Paren)) { // Support `box() EXPR` as the default. - if !self.eat(&token::RParen) { + if !self.eat(&token::CloseDelim(token::Paren)) { let place = self.parse_expr(); - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); let subexpression = self.parse_prefix_expr(); hi = subexpression.span.hi; ex = ExprBox(place, subexpression); @@ -2966,9 +2969,9 @@ impl<'a> Parser<'a> { fn parse_match_expr(&mut self) -> P { let lo = self.last_span.lo; let discriminant = self.parse_expr_res(RESTRICTION_NO_STRUCT_LITERAL); - self.commit_expr_expecting(&*discriminant, token::LBrace); + self.commit_expr_expecting(&*discriminant, token::OpenDelim(token::Brace)); let mut arms: Vec = Vec::new(); - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { arms.push(self.parse_arm()); } let hi = self.span.hi; @@ -2988,10 +2991,10 @@ impl<'a> Parser<'a> { let require_comma = !classify::expr_is_simple_block(&*expr) - && self.token != token::RBrace; + && self.token != token::CloseDelim(token::Brace); if require_comma { - self.commit_expr(&*expr, &[token::Comma], &[token::RBrace]); + self.commit_expr(&*expr, &[token::Comma], &[token::CloseDelim(token::Brace)]); } else { self.eat(&token::Comma); } @@ -3047,7 +3050,7 @@ impl<'a> Parser<'a> { let mut first = true; let mut before_slice = true; - while self.token != token::RBracket { + while self.token != token::CloseDelim(token::Bracket) { if first { first = false; } else { @@ -3059,7 +3062,7 @@ impl<'a> Parser<'a> { self.bump(); if self.token == token::Comma || - self.token == token::RBracket { + self.token == token::CloseDelim(token::Bracket) { slice = Some(P(ast::Pat { id: ast::DUMMY_NODE_ID, node: PatWild(PatWildMulti), @@ -3095,13 +3098,13 @@ impl<'a> Parser<'a> { let mut fields = Vec::new(); let mut etc = false; let mut first = true; - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { if first { first = false; } else { self.expect(&token::Comma); // accept trailing commas - if self.token == token::RBrace { break } + if self.token == token::CloseDelim(token::Brace) { break } } let lo = self.span.lo; @@ -3109,7 +3112,7 @@ impl<'a> Parser<'a> { if self.token == token::DotDot { self.bump(); - if self.token != token::RBrace { + if self.token != token::CloseDelim(token::Brace) { let token_str = self.this_token_to_string(); self.fatal(format!("expected `{}`, found `{}`", "}", token_str).as_slice()) @@ -3205,10 +3208,10 @@ impl<'a> Parser<'a> { span: mk_sp(lo, hi) }) } - token::LParen => { + token::OpenDelim(token::Paren) => { // parse (pat,pat,pat,...) as tuple self.bump(); - if self.token == token::RParen { + if self.token == token::CloseDelim(token::Paren) { hi = self.span.hi; self.bump(); let lit = P(codemap::Spanned { @@ -3218,15 +3221,15 @@ impl<'a> Parser<'a> { pat = PatLit(expr); } else { let mut fields = vec!(self.parse_pat()); - if self.look_ahead(1, |t| *t != token::RParen) { + if self.look_ahead(1, |t| *t != token::CloseDelim(token::Paren)) { while self.token == token::Comma { self.bump(); - if self.token == token::RParen { break; } + if self.token == token::CloseDelim(token::Paren) { break; } fields.push(self.parse_pat()); } } if fields.len() == 1 { self.expect(&token::Comma); } - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); pat = PatTup(fields); } hi = self.last_span.hi; @@ -3236,13 +3239,13 @@ impl<'a> Parser<'a> { span: mk_sp(lo, hi) }) } - token::LBracket => { + token::OpenDelim(token::Bracket) => { // parse [pat,pat,...] as vector pattern self.bump(); let (before, slice, after) = self.parse_pat_vec_elements(); - self.expect(&token::RBracket); + self.expect(&token::CloseDelim(token::Bracket)); pat = ast::PatVec(before, slice, after); hi = self.last_span.hi; return P(ast::Pat { @@ -3266,7 +3269,7 @@ impl<'a> Parser<'a> { let val = self.parse_literal_maybe_minus(); if (self.token == token::DotDotDot) && self.look_ahead(1, |t| { - *t != token::Comma && *t != token::RBracket + *t != token::Comma && *t != token::CloseDelim(token::Bracket) }) { self.bump(); let end = if self.token.is_ident() || self.token.is_path() { @@ -3303,15 +3306,14 @@ impl<'a> Parser<'a> { } else { let can_be_enum_or_struct = self.look_ahead(1, |t| { match *t { - token::LParen | token::LBracket | token::Lt | - token::LBrace | token::ModSep => true, + token::OpenDelim(_) | token::Lt | token::ModSep => true, _ => false, } }); if self.look_ahead(1, |t| *t == token::DotDotDot) && self.look_ahead(2, |t| { - *t != token::Comma && *t != token::RBracket + *t != token::Comma && *t != token::CloseDelim(token::Bracket) }) { let start = self.parse_expr_res(RESTRICTION_NO_BAR_OP); self.eat(&token::DotDotDot); @@ -3348,7 +3350,7 @@ impl<'a> Parser<'a> { let enum_path = self.parse_path(LifetimeAndTypesWithColons) .path; match self.token { - token::LBrace => { + token::OpenDelim(token::Brace) => { self.bump(); let (fields, etc) = self.parse_pat_fields(); @@ -3358,7 +3360,7 @@ impl<'a> Parser<'a> { _ => { let mut args: Vec> = Vec::new(); match self.token { - token::LParen => { + token::OpenDelim(token::Paren) => { let is_dotdot = self.look_ahead(1, |t| { match *t { token::DotDot => true, @@ -3369,12 +3371,12 @@ impl<'a> Parser<'a> { // This is a "top constructor only" pat self.bump(); self.bump(); - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); pat = PatEnum(enum_path, None); } else { args = self.parse_enum_variant_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_pat() ); @@ -3443,7 +3445,7 @@ impl<'a> Parser<'a> { // leads to a parse error. Note that if there is no explicit // binding mode then we do not end up here, because the lookahead // will direct us over to parse_enum_variant() - if self.token == token::LParen { + if self.token == token::OpenDelim(token::Paren) { let last_span = self.last_span; self.span_fatal( last_span, @@ -3632,7 +3634,7 @@ impl<'a> Parser<'a> { maybe_whole!(no_clone self, NtBlock); let lo = self.span.lo; - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); return self.parse_block_tail_(lo, DefaultBlock, Vec::new()); } @@ -3644,7 +3646,7 @@ impl<'a> Parser<'a> { maybe_whole!(pair_empty self, NtBlock); let lo = self.span.lo; - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let (inner, next) = self.parse_inner_attrs_and_next(); (inner, self.parse_block_tail_(lo, DefaultBlock, next)) @@ -3681,7 +3683,7 @@ impl<'a> Parser<'a> { let mut attributes_box = attrs_remaining; - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { // parsing items even when they're not allowed lets us give // better error messages and recover more gracefully. attributes_box.push_all(self.parse_outer_attributes().as_slice()); @@ -3695,7 +3697,7 @@ impl<'a> Parser<'a> { } self.bump(); // empty } - token::RBrace => { + token::CloseDelim(token::Brace) => { // fall through and out. } _ => { @@ -3706,7 +3708,7 @@ impl<'a> Parser<'a> { // expression without semicolon if classify::expr_requires_semi_to_be_stmt(&*e) { // Just check for errors and recover; do not eat semicolon yet. - self.commit_stmt(&[], &[token::Semi, token::RBrace]); + self.commit_stmt(&[], &[token::Semi, token::CloseDelim(token::Brace)]); } match self.token { @@ -3722,7 +3724,7 @@ impl<'a> Parser<'a> { span: span_with_semi, })); } - token::RBrace => { + token::CloseDelim(token::Brace) => { expr = Some(e); } _ => { @@ -3743,7 +3745,7 @@ impl<'a> Parser<'a> { })); self.bump(); } - token::RBrace => { + token::CloseDelim(token::Brace) => { // if a block ends in `m!(arg)` without // a `;`, it must be an expr expr = Some( @@ -3838,10 +3840,10 @@ impl<'a> Parser<'a> { token::ModSep | token::Ident(..) => { let path = self.parse_path(LifetimeAndTypesWithoutColons).path; - if self.token == token::LParen { + if self.token == token::OpenDelim(token::Paren) { self.bump(); let inputs = self.parse_seq_to_end( - &token::RParen, + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_arg_general(false)); let (return_style, output) = self.parse_ret_ty(); @@ -4035,14 +4037,14 @@ impl<'a> Parser<'a> { let sp = self.span; let mut args: Vec> = self.parse_unspanned_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| { if p.token == token::DotDotDot { p.bump(); if allow_variadic { - if p.token != token::RParen { + if p.token != token::CloseDelim(token::Paren) { let span = p.span; p.span_fatal(span, "`...` must be last in argument list for variadic function"); @@ -4154,7 +4156,7 @@ impl<'a> Parser<'a> { } } - self.expect(&token::LParen); + self.expect(&token::OpenDelim(token::Paren)); // A bit of complexity and lookahead is needed here in order to be // backwards compatible. @@ -4249,14 +4251,14 @@ impl<'a> Parser<'a> { self.bump(); let sep = seq_sep_trailing_allowed(token::Comma); let mut fn_inputs = self.parse_seq_to_before_end( - &token::RParen, + &token::CloseDelim(token::Paren), sep, parse_arg_fn ); fn_inputs.insert(0, Arg::new_self(explicit_self_sp, mutbl_self, $self_id)); fn_inputs } - token::RParen => { + token::CloseDelim(token::Paren) => { vec!(Arg::new_self(explicit_self_sp, mutbl_self, $self_id)) } _ => { @@ -4271,7 +4273,7 @@ impl<'a> Parser<'a> { let fn_inputs = match explicit_self { SelfStatic => { let sep = seq_sep_trailing_allowed(token::Comma); - self.parse_seq_to_before_end(&token::RParen, sep, parse_arg_fn) + self.parse_seq_to_before_end(&token::CloseDelim(token::Paren), sep, parse_arg_fn) } SelfValue(id) => parse_remaining_arguments!(id), SelfRegion(_,_,id) => parse_remaining_arguments!(id), @@ -4279,7 +4281,7 @@ impl<'a> Parser<'a> { }; - self.expect(&token::RParen); + self.expect(&token::CloseDelim(token::Paren)); let hi = self.span.hi; @@ -4335,8 +4337,8 @@ impl<'a> Parser<'a> { /// Parses the `(arg, arg) -> return_type` header on a procedure. fn parse_proc_decl(&mut self) -> P { let inputs = - self.parse_unspanned_seq(&token::LParen, - &token::RParen, + self.parse_unspanned_seq(&token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_fn_block_arg()); @@ -4405,8 +4407,8 @@ impl<'a> Parser<'a> { let (method_, hi, new_attrs) = { if !self.token.is_any_keyword() && self.look_ahead(1, |t| *t == token::Not) - && (self.look_ahead(2, |t| *t == token::LParen) - || self.look_ahead(2, |t| *t == token::LBrace)) { + && (self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren)) + || self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) { // method macro. let pth = self.parse_path(NoTypesAllowed).path; self.expect(&token::Not); @@ -4484,10 +4486,10 @@ impl<'a> Parser<'a> { fn parse_impl_items(&mut self) -> (Vec, Vec) { let mut impl_items = Vec::new(); - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let (inner_attrs, mut method_attrs) = self.parse_inner_attrs_and_next(); - while !self.eat(&token::RBrace) { + while !self.eat(&token::CloseDelim(token::Brace)) { method_attrs.extend(self.parse_outer_attributes().into_iter()); let vis = self.parse_visibility(); if self.eat_keyword(keywords::Type) { @@ -4513,7 +4515,7 @@ impl<'a> Parser<'a> { // Special case: if the next identifier that follows is '(', don't // allow this to be parsed as a trait. - let could_be_trait = self.token != token::LParen; + let could_be_trait = self.token != token::OpenDelim(token::Paren); // Parse the trait. let mut ty = self.parse_ty(true); @@ -4571,11 +4573,11 @@ impl<'a> Parser<'a> { let mut fields: Vec; let is_tuple_like; - if self.eat(&token::LBrace) { + if self.eat(&token::OpenDelim(token::Brace)) { // It's a record-like struct. is_tuple_like = false; fields = Vec::new(); - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { fields.push(self.parse_struct_decl_field()); } if fields.len() == 0 { @@ -4584,12 +4586,12 @@ impl<'a> Parser<'a> { token::get_ident(class_name)).as_slice()); } self.bump(); - } else if self.token == token::LParen { + } else if self.token == token::OpenDelim(token::Paren) { // It's a tuple-like struct. is_tuple_like = true; fields = self.parse_unspanned_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| { let attrs = p.parse_outer_attributes(); @@ -4639,7 +4641,7 @@ impl<'a> Parser<'a> { token::Comma => { self.bump(); } - token::RBrace => {} + token::CloseDelim(token::Brace) => {} _ => { let span = self.span; let token_str = self.this_token_to_string(); @@ -4771,13 +4773,13 @@ impl<'a> Parser<'a> { (id, m, Some(attrs)) } else { self.push_mod_path(id, outer_attrs); - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let mod_inner_lo = self.span.lo; let old_owns_directory = self.owns_directory; self.owns_directory = true; let (inner, next) = self.parse_inner_attrs_and_next(); - let m = self.parse_mod_items(token::RBrace, next, mod_inner_lo); - self.expect(&token::RBrace); + let m = self.parse_mod_items(token::CloseDelim(token::Brace), next, mod_inner_lo); + self.expect(&token::CloseDelim(token::Brace)); self.owns_directory = old_owns_directory; self.pop_mod_path(); (id, ItemMod(m), Some(inner)) @@ -4978,7 +4980,7 @@ impl<'a> Parser<'a> { self.span_err(last_span, Parser::expected_item_err(attrs_remaining.as_slice())); } - assert!(self.token == token::RBrace); + assert!(self.token == token::CloseDelim(token::Brace)); ast::ForeignMod { abi: abi, view_items: view_items, @@ -5065,13 +5067,13 @@ impl<'a> Parser<'a> { attrs: Vec ) -> ItemOrViewItem { - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let abi = opt_abi.unwrap_or(abi::C); let (inner, next) = self.parse_inner_attrs_and_next(); let m = self.parse_foreign_mod_items(abi, next); - self.expect(&token::RBrace); + self.expect(&token::CloseDelim(token::Brace)); let last_span = self.last_span; let item = self.mk_item(lo, @@ -5098,7 +5100,7 @@ impl<'a> Parser<'a> { /// this should probably be renamed or refactored... fn parse_struct_def(&mut self) -> P { let mut fields: Vec = Vec::new(); - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { fields.push(self.parse_struct_decl_field()); } self.bump(); @@ -5114,7 +5116,7 @@ impl<'a> Parser<'a> { let mut variants = Vec::new(); let mut all_nullary = true; let mut any_disr = None; - while self.token != token::RBrace { + while self.token != token::CloseDelim(token::Brace) { let variant_attrs = self.parse_outer_attributes(); let vlo = self.span.lo; @@ -5125,15 +5127,15 @@ impl<'a> Parser<'a> { let mut args = Vec::new(); let mut disr_expr = None; ident = self.parse_ident(); - if self.eat(&token::LBrace) { + if self.eat(&token::OpenDelim(token::Brace)) { // Parse a struct variant. all_nullary = false; kind = StructVariantKind(self.parse_struct_def()); - } else if self.token == token::LParen { + } else if self.token == token::OpenDelim(token::Paren) { all_nullary = false; let arg_tys = self.parse_enum_variant_seq( - &token::LParen, - &token::RParen, + &token::OpenDelim(token::Paren), + &token::CloseDelim(token::Paren), seq_sep_trailing_allowed(token::Comma), |p| p.parse_ty(true) ); @@ -5164,7 +5166,7 @@ impl<'a> Parser<'a> { if !self.eat(&token::Comma) { break; } } - self.expect(&token::RBrace); + self.expect(&token::CloseDelim(token::Brace)); match any_disr { Some(disr_span) if !all_nullary => self.span_err(disr_span, @@ -5180,7 +5182,7 @@ impl<'a> Parser<'a> { let id = self.parse_ident(); let mut generics = self.parse_generics(); self.parse_where_clause(&mut generics); - self.expect(&token::LBrace); + self.expect(&token::OpenDelim(token::Brace)); let enum_definition = self.parse_enum_def(&generics); (id, ItemEnum(enum_definition, generics), None) @@ -5188,7 +5190,7 @@ impl<'a> Parser<'a> { fn fn_expr_lookahead(tok: &token::Token) -> bool { match *tok { - token::LParen | token::At | token::Tilde | token::BinOp(_) => true, + token::OpenDelim(token::Paren) | token::At | token::Tilde | token::BinOp(_) => true, _ => false } } @@ -5291,7 +5293,7 @@ impl<'a> Parser<'a> { visibility, maybe_append(attrs, extra_attrs)); return IoviItem(item); - } else if self.token == token::LBrace { + } else if self.token == token::OpenDelim(token::Brace) { return self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs); } @@ -5356,7 +5358,7 @@ impl<'a> Parser<'a> { return IoviItem(item); } if self.token.is_keyword(keywords::Unsafe) - && self.look_ahead(1u, |t| *t != token::LBrace) { + && self.look_ahead(1u, |t| *t != token::OpenDelim(token::Brace)) { // UNSAFE FUNCTION ITEM self.bump(); let abi = if self.eat_keyword(keywords::Extern) { @@ -5486,8 +5488,8 @@ impl<'a> Parser<'a> { if macros_allowed && !self.token.is_any_keyword() && self.look_ahead(1, |t| *t == token::Not) && (self.look_ahead(2, |t| t.is_plain_ident()) - || self.look_ahead(2, |t| *t == token::LParen) - || self.look_ahead(2, |t| *t == token::LBrace)) { + || self.look_ahead(2, |t| *t == token::OpenDelim(token::Paren)) + || self.look_ahead(2, |t| *t == token::OpenDelim(token::Brace))) { // MACRO INVOCATION ITEM // item macro. @@ -5573,10 +5575,11 @@ impl<'a> Parser<'a> { fn parse_view_path(&mut self) -> P { let lo = self.span.lo; - if self.token == token::LBrace { + if self.token == token::OpenDelim(token::Brace) { // use {foo,bar} let idents = self.parse_unspanned_seq( - &token::LBrace, &token::RBrace, + &token::OpenDelim(token::Brace), + &token::CloseDelim(token::Brace), seq_sep_trailing_allowed(token::Comma), |p| p.parse_path_list_item()); let path = ast::Path { @@ -5631,10 +5634,10 @@ impl<'a> Parser<'a> { } // foo::bar::{a,b,c} - token::LBrace => { + token::OpenDelim(token::Brace) => { let idents = self.parse_unspanned_seq( - &token::LBrace, - &token::RBrace, + &token::OpenDelim(token::Brace), + &token::CloseDelim(token::Brace), seq_sep_trailing_allowed(token::Comma), |p| p.parse_path_list_item() ); @@ -5793,7 +5796,7 @@ impl<'a> Parser<'a> { loop { match self.parse_foreign_item(attrs, macros_allowed) { IoviNone(returned_attrs) => { - if self.token == token::RBrace { + if self.token == token::CloseDelim(token::Brace) { attrs = returned_attrs; break } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 9ed8e4bc3a7..cc4fdcf01b4 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -56,12 +56,6 @@ use std::rc::Rc; #[cfg(stage0)] pub use self::RArrow as RARROW; #[cfg(stage0)] pub use self::LArrow as LARROW; #[cfg(stage0)] pub use self::FatArrow as FAT_ARROW; -#[cfg(stage0)] pub use self::LParen as LPAREN; -#[cfg(stage0)] pub use self::RParen as RPAREN; -#[cfg(stage0)] pub use self::LBracket as LBRACKET; -#[cfg(stage0)] pub use self::RBracket as RBRACKET; -#[cfg(stage0)] pub use self::LBrace as LBRACE; -#[cfg(stage0)] pub use self::RBrace as RBRACE; #[cfg(stage0)] pub use self::Pound as POUND; #[cfg(stage0)] pub use self::Dollar as DOLLAR; #[cfg(stage0)] pub use self::Question as QUESTION; @@ -82,6 +76,12 @@ use std::rc::Rc; #[cfg(stage0)] pub use self::Comment as COMMENT; #[cfg(stage0)] pub use self::Shebang as SHEBANG; #[cfg(stage0)] pub use self::Eof as EOF; +#[cfg(stage0)] pub const LPAREN: Token = OpenDelim(Paren); +#[cfg(stage0)] pub const RPAREN: Token = CloseDelim(Paren); +#[cfg(stage0)] pub const LBRACKET: Token = OpenDelim(Bracket); +#[cfg(stage0)] pub const RBRACKET: Token = CloseDelim(Bracket); +#[cfg(stage0)] pub const LBRACE: Token = OpenDelim(Brace); +#[cfg(stage0)] pub const RBRACE: Token = CloseDelim(Brace); #[allow(non_camel_case_types)] #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] @@ -98,6 +98,17 @@ pub enum BinOpToken { Shr, } +/// A delimeter token +#[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] +pub enum DelimToken { + /// A round parenthesis: `(` or `)` + Paren, + /// A square bracket: `[` or `]` + Bracket, + /// A curly brace: `{` or `}` + Brace, +} + #[cfg(stage0)] #[allow(non_uppercase_statics)] pub const ModName: bool = true; @@ -143,15 +154,13 @@ pub enum Token { RArrow, LArrow, FatArrow, - LParen, - RParen, - LBracket, - RBracket, - LBrace, - RBrace, Pound, Dollar, Question, + /// An opening delimeter, eg. `{` + OpenDelim(DelimToken), + /// A closing delimeter, eg. `}` + CloseDelim(DelimToken), /* Literals */ LitByte(ast::Name), @@ -192,9 +201,7 @@ impl Token { /// Returns `true` if the token can appear at the start of an expression. pub fn can_begin_expr(&self) -> bool { match *self { - LParen => true, - LBrace => true, - LBracket => true, + OpenDelim(_) => true, Ident(_, _) => true, Underscore => true, Tilde => true, @@ -227,10 +234,10 @@ impl Token { /// otherwise `None`. pub fn get_close_delimiter(&self) -> Option { match *self { - LParen => Some(RParen), - LBrace => Some(RBrace), - LBracket => Some(RBracket), - _ => None, + OpenDelim(Paren) => Some(CloseDelim(Paren)), + OpenDelim(Brace) => Some(CloseDelim(Brace)), + OpenDelim(Bracket) => Some(CloseDelim(Bracket)), + _ => None, } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index d347d0199a7..6df9fff0e6b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -225,12 +225,12 @@ pub fn token_to_string(tok: &Token) -> String { token::RArrow => "->".into_string(), token::LArrow => "<-".into_string(), token::FatArrow => "=>".into_string(), - token::LParen => "(".into_string(), - token::RParen => ")".into_string(), - token::LBracket => "[".into_string(), - token::RBracket => "]".into_string(), - token::LBrace => "{".into_string(), - token::RBrace => "}".into_string(), + token::OpenDelim(token::Paren) => "(".into_string(), + token::CloseDelim(token::Paren) => ")".into_string(), + token::OpenDelim(token::Bracket) => "[".into_string(), + token::CloseDelim(token::Bracket) => "]".into_string(), + token::OpenDelim(token::Brace) => "{".into_string(), + token::CloseDelim(token::Brace) => "}".into_string(), token::Pound => "#".into_string(), token::Dollar => "$".into_string(), token::Question => "?".into_string(), @@ -1121,12 +1121,11 @@ impl<'a> State<'a> { pub fn print_tt(&mut self, tt: &ast::TokenTree) -> IoResult<()> { match *tt { ast::TtDelimited(_, ref delimed) => { - let (ref open, ref tts, ref close) = **delimed; - try!(word(&mut self.s, token_to_string(&open.token).as_slice())); + try!(word(&mut self.s, token_to_string(&delimed.open_token()).as_slice())); try!(space(&mut self.s)); - try!(self.print_tts(tts.as_slice())); + try!(self.print_tts(delimed.tts.as_slice())); try!(space(&mut self.s)); - word(&mut self.s, token_to_string(&close.token).as_slice()) + word(&mut self.s, token_to_string(&delimed.close_token()).as_slice()) }, ast::TtToken(_, ref tk) => { try!(word(&mut self.s, token_to_string(tk).as_slice())); diff --git a/src/test/compile-fail/removed-syntax-record.rs b/src/test/compile-fail/removed-syntax-record.rs index b3fa04d8025..b31e2538ab9 100644 --- a/src/test/compile-fail/removed-syntax-record.rs +++ b/src/test/compile-fail/removed-syntax-record.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -type t = { f: () }; //~ ERROR expected type, found token LBrace +type t = { f: () }; //~ ERROR expected type, found token OpenDelim(Brace) -- cgit 1.4.1-3-g733a5 From 1ab50f3600ff52dcf97f0cd2b32f632988540b97 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 30 Oct 2014 01:47:53 +1100 Subject: Remove Token::get_close_delimiter We can simplify these usages due to the new delimiter representation. `Parser::expect_open_delim` has been added for convenience. --- src/libsyntax/parse/parser.rs | 80 ++++++++++++++++++------------------------- src/libsyntax/parse/token.rs | 11 ------ 2 files changed, 33 insertions(+), 58 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3911c68fa18..8bd984b60ed 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2013,6 +2013,16 @@ impl<'a> Parser<'a> { }) } + fn expect_open_delim(&mut self) -> token::DelimToken { + match self.token { + token::OpenDelim(delim) => { + self.bump(); + delim + }, + _ => self.fatal("expected open delimiter"), + } + } + /// At the bottom (top?) of the precedence hierarchy, /// parse things like parenthesized exprs, /// macros, return, etc. @@ -2209,14 +2219,9 @@ impl<'a> Parser<'a> { // MACRO INVOCATION expression self.bump(); - let ket = self.token.get_close_delimiter() - .unwrap_or_else(|| { - self.fatal("expected open delimiter") - }); - self.bump(); - + let delim = self.expect_open_delim(); let tts = self.parse_seq_to_end( - &ket, + &token::CloseDelim(delim), seq_sep_none(), |p| p.parse_token_tree()); let hi = self.span.hi; @@ -2624,13 +2629,8 @@ impl<'a> Parser<'a> { // the interpolation of Matcher's maybe_whole!(self, NtMatchers); let mut name_idx = 0u; - match self.token.get_close_delimiter() { - Some(other_delimiter) => { - self.bump(); - self.parse_matcher_subseq_upto(&mut name_idx, &other_delimiter) - } - None => self.fatal("expected open delimiter") - } + let delim = self.expect_open_delim(); + self.parse_matcher_subseq_upto(&mut name_idx, &token::CloseDelim(delim)) } /// This goofy function is necessary to correctly match parens in Matcher's. @@ -3325,11 +3325,8 @@ impl<'a> Parser<'a> { let pth1 = codemap::Spanned{span:id_span, node: id}; if self.eat(&token::Not) { // macro invocation - let ket = self.token.get_close_delimiter() - .unwrap_or_else(|| self.fatal("expected open delimiter")); - self.bump(); - - let tts = self.parse_seq_to_end(&ket, + let delim = self.expect_open_delim(); + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), seq_sep_none(), |p| p.parse_token_tree()); @@ -3545,18 +3542,17 @@ impl<'a> Parser<'a> { let pth = self.parse_path(NoTypesAllowed).path; self.bump(); - let id = if self.token.get_close_delimiter().is_some() { - token::special_idents::invalid // no special identifier - } else { - self.parse_ident() + let id = match self.token { + token::OpenDelim(_) => token::special_idents::invalid, // no special identifier + _ => self.parse_ident(), }; // check that we're pointing at delimiters (need to check // again after the `if`, because of `parse_ident` // consuming more tokens). - let (bra, ket) = match self.token.get_close_delimiter() { - Some(ket) => (self.token.clone(), ket), - None => { + let delim = match self.token { + token::OpenDelim(delim) => delim, + _ => { // we only expect an ident if we didn't parse one // above. let ident_str = if id.name == token::special_idents::invalid.name { @@ -3568,12 +3564,12 @@ impl<'a> Parser<'a> { self.fatal(format!("expected {}`(` or `{{`, found `{}`", ident_str, tok_str).as_slice()) - } + }, }; let tts = self.parse_unspanned_seq( - &bra, - &ket, + &token::OpenDelim(delim), + &token::CloseDelim(delim), seq_sep_none(), |p| p.parse_token_tree() ); @@ -4414,15 +4410,10 @@ impl<'a> Parser<'a> { self.expect(&token::Not); // eat a matched-delimiter token tree: - let tts = match self.token.get_close_delimiter() { - Some(ket) => { - self.bump(); - self.parse_seq_to_end(&ket, - seq_sep_none(), - |p| p.parse_token_tree()) - } - None => self.fatal("expected open delimiter") - }; + let delim = self.expect_open_delim(); + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), + seq_sep_none(), + |p| p.parse_token_tree()); let m_ = ast::MacInvocTT(pth, tts, EMPTY_CTXT); let m: ast::Mac = codemap::Spanned { node: m_, span: mk_sp(self.span.lo, @@ -5505,15 +5496,10 @@ impl<'a> Parser<'a> { token::special_idents::invalid // no special identifier }; // eat a matched-delimiter token tree: - let tts = match self.token.get_close_delimiter() { - Some(ket) => { - self.bump(); - self.parse_seq_to_end(&ket, - seq_sep_none(), - |p| p.parse_token_tree()) - } - None => self.fatal("expected open delimiter") - }; + let delim = self.expect_open_delim(); + let tts = self.parse_seq_to_end(&token::CloseDelim(delim), + seq_sep_none(), + |p| p.parse_token_tree()); // single-variant-enum... : let m = ast::MacInvocTT(pth, tts, EMPTY_CTXT); let m: ast::Mac = codemap::Spanned { node: m, diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index cc4fdcf01b4..2025b65835e 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -230,17 +230,6 @@ impl Token { } } - /// Returns the matching close delimiter if this is an open delimiter, - /// otherwise `None`. - pub fn get_close_delimiter(&self) -> Option { - match *self { - OpenDelim(Paren) => Some(CloseDelim(Paren)), - OpenDelim(Brace) => Some(CloseDelim(Brace)), - OpenDelim(Bracket) => Some(CloseDelim(Bracket)), - _ => None, - } - } - /// Returns `true` if the token is any literal pub fn is_lit(&self) -> bool { match *self { -- cgit 1.4.1-3-g733a5 From 98a4770a981b779c06a08c642ccefc6c6b5c16a9 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Thu, 30 Oct 2014 08:44:41 +1100 Subject: Formatting fixes --- src/libsyntax/parse/parser.rs | 18 +++++++++++++----- src/libsyntax/parse/token.rs | 16 ++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8bd984b60ed..54730391d56 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1661,7 +1661,10 @@ impl<'a> Parser<'a> { LitBinary(parse::binary_lit(i.as_str())), token::LitBinaryRaw(i, _) => LitBinary(Rc::new(i.as_str().as_bytes().iter().map(|&x| x).collect())), - token::OpenDelim(token::Paren) => { self.expect(&token::CloseDelim(token::Paren)); LitNil }, + token::OpenDelim(token::Paren) => { + self.expect(&token::CloseDelim(token::Paren)); + LitNil + }, _ => { self.unexpected_last(tok); } } } @@ -2047,7 +2050,8 @@ impl<'a> Parser<'a> { return self.mk_expr(lo, hi, ExprLit(lit)); } let mut es = vec!(self.parse_expr()); - self.commit_expr(&**es.last().unwrap(), &[], &[token::Comma, token::CloseDelim(token::Paren)]); + self.commit_expr(&**es.last().unwrap(), &[], + &[token::Comma, token::CloseDelim(token::Paren)]); while self.token == token::Comma { self.bump(); if self.token != token::CloseDelim(token::Paren) { @@ -2454,7 +2458,8 @@ impl<'a> Parser<'a> { // e[e..e] _ => { let e2 = self.parse_expr(); - self.commit_expr_expecting(&*e2, token::CloseDelim(token::Bracket)); + self.commit_expr_expecting(&*e2, + token::CloseDelim(token::Bracket)); Some(e2) } }; @@ -2720,7 +2725,9 @@ impl<'a> Parser<'a> { self.bump(); let last_span = self.last_span; match self.token { - token::OpenDelim(token::Bracket) => self.obsolete(last_span, ObsoleteOwnedVector), + token::OpenDelim(token::Bracket) => { + self.obsolete(last_span, ObsoleteOwnedVector) + }, _ => self.obsolete(last_span, ObsoleteOwnedExpr) } @@ -3704,7 +3711,8 @@ impl<'a> Parser<'a> { // expression without semicolon if classify::expr_requires_semi_to_be_stmt(&*e) { // Just check for errors and recover; do not eat semicolon yet. - self.commit_stmt(&[], &[token::Semi, token::CloseDelim(token::Brace)]); + self.commit_stmt(&[], &[token::Semi, + token::CloseDelim(token::Brace)]); } match self.token { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 2025b65835e..641e3817949 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -267,7 +267,7 @@ impl Token { pub fn is_plain_ident(&self) -> bool { match *self { Ident(_, Plain) => true, - _ => false, + _ => false, } } @@ -392,20 +392,20 @@ impl Token { #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash)] /// For interpolation during macro expansion. pub enum Nonterminal { - NtItem( P), + NtItem(P), NtBlock(P), - NtStmt( P), - NtPat( P), - NtExpr( P), - NtTy( P), + NtStmt(P), + NtPat(P), + NtExpr(P), + NtTy(P), #[cfg(stage0)] NtIdent(Box, bool), #[cfg(not(stage0))] NtIdent(Box, IdentStyle), /// Stuff inside brackets for attributes - NtMeta( P), + NtMeta(P), NtPath(Box), - NtTT( P), // needs P'ed to break a circularity + NtTT(P), // needs P'ed to break a circularity NtMatchers(Vec) } -- cgit 1.4.1-3-g733a5 From fb00015246824313e8882935c9ba175ea6daf9d4 Mon Sep 17 00:00:00 2001 From: P1start Date: Sun, 26 Oct 2014 12:07:54 +1300 Subject: Improve the error message for parenthesised box expressions Closes #15386. --- src/libsyntax/parse/parser.rs | 14 ++++++++++++++ src/test/compile-fail/parenthesized-box-expr-message.rs | 14 ++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/compile-fail/parenthesized-box-expr-message.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8ef3a559bf4..d9dd37fcb4f 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2730,6 +2730,8 @@ impl<'a> Parser<'a> { return self.parse_dot_or_call_expr(); } + let lo = self.span.lo; + self.bump(); // Check for a place: `box(PLACE) EXPR`. @@ -2738,6 +2740,18 @@ impl<'a> Parser<'a> { if !self.eat(&token::RParen) { let place = self.parse_expr(); self.expect(&token::RParen); + // Give a suggestion to use `box()` when a parenthesised expression is used + if !self.token.can_begin_expr() { + let span = self.span; + let this_token_to_string = self.this_token_to_string(); + self.span_err(span, + format!("expected expression, found `{}`", + this_token_to_string).as_slice()); + let box_span = mk_sp(lo, self.last_span.hi); + self.span_help(box_span, + "perhaps you meant `box() (foo)` instead?"); + self.abort_if_errors(); + } let subexpression = self.parse_prefix_expr(); hi = subexpression.span.hi; ex = ExprBox(place, subexpression); diff --git a/src/test/compile-fail/parenthesized-box-expr-message.rs b/src/test/compile-fail/parenthesized-box-expr-message.rs new file mode 100644 index 00000000000..05bbaec37af --- /dev/null +++ b/src/test/compile-fail/parenthesized-box-expr-message.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + box(1 + 1) //~ HELP perhaps you meant `box() (foo)` instead? + ; //~ ERROR expected expression, found `;` +} -- cgit 1.4.1-3-g733a5 From 14398f29290b0d96dbe60f329b69062442eefb33 Mon Sep 17 00:00:00 2001 From: P1start Date: Mon, 27 Oct 2014 17:43:38 +1300 Subject: Add a message for when a `.` follows a macro invocation --- src/libsyntax/parse/parser.rs | 10 ++++++++++ src/test/compile-fail/macro-invocation-dot-help.rs | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/compile-fail/macro-invocation-dot-help.rs (limited to 'src/libsyntax') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d9dd37fcb4f..f04f9efd7a7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3592,6 +3592,16 @@ impl<'a> Parser<'a> { let hi = self.span.hi; if id.name == token::special_idents::invalid.name { + if self.token == token::Dot { + let span = self.span; + let token_string = self.this_token_to_string(); + self.span_err(span, + format!("expected statement, found `{}`", + token_string).as_slice()); + let mac_span = mk_sp(lo, hi); + self.span_help(mac_span, "try parenthesizing this macro invocation"); + self.abort_if_errors(); + } P(spanned(lo, hi, StmtMac( spanned(lo, hi, MacInvocTT(pth, tts, EMPTY_CTXT)), false))) } else { diff --git a/src/test/compile-fail/macro-invocation-dot-help.rs b/src/test/compile-fail/macro-invocation-dot-help.rs new file mode 100644 index 00000000000..bd45b76dd5a --- /dev/null +++ b/src/test/compile-fail/macro-invocation-dot-help.rs @@ -0,0 +1,14 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + foo!() //~ HELP try parenthesizing this macro invocation + .bar //~ ERROR expected statement +} -- cgit 1.4.1-3-g733a5 From 1d356624a1c03363be37886ffdad7dcf25ee81f6 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 23 Oct 2014 08:42:21 -0700 Subject: collections: Enable IndexMut for some collections This commit enables implementations of IndexMut for a number of collections, including Vec, RingBuf, SmallIntMap, TrieMap, TreeMap, and HashMap. At the same time this deprecates the `get_mut` methods on vectors in favor of using the indexing notation. cc #18424 --- src/compiletest/runtest.rs | 2 +- src/libcollections/bitv.rs | 21 ++--- src/libcollections/btree/map.rs | 6 ++ src/libcollections/priority_queue.rs | 26 +++--- src/libcollections/ringbuf.rs | 33 ++++---- src/libcollections/smallintmap.rs | 11 ++- src/libcollections/str.rs | 8 +- src/libcollections/treemap.rs | 4 +- src/libcollections/trie.rs | 5 +- src/libcollections/vec.rs | 16 +--- src/libcore/intrinsics.rs | 97 ---------------------- src/libgetopts/lib.rs | 12 +-- src/libregex/compile.rs | 6 +- src/libregex/parse.rs | 2 +- src/libregex/vm.rs | 10 +-- src/librustc/metadata/encoder.rs | 2 +- src/librustc/middle/borrowck/move_data.rs | 4 +- src/librustc/middle/dependency_format.rs | 2 +- src/librustc/middle/graph.rs | 8 +- src/librustc/middle/liveness.rs | 18 ++-- src/librustc/middle/resolve.rs | 4 +- src/librustc/middle/trans/_match.rs | 2 +- src/librustc/middle/trans/cleanup.rs | 2 +- src/librustc/middle/trans/expr.rs | 2 +- src/librustc/middle/trans/type_.rs | 2 +- src/librustc/middle/typeck/check/method.rs | 2 +- src/librustc/middle/typeck/check/mod.rs | 2 +- src/librustc/middle/typeck/check/regionck.rs | 4 +- .../middle/typeck/infer/region_inference/mod.rs | 2 +- src/librustc/middle/typeck/infer/type_variable.rs | 6 +- src/librustc/middle/typeck/variance.rs | 2 +- src/librustc/util/snapshot_vec.rs | 8 +- src/libserialize/json.rs | 2 +- src/libstd/collections/hashmap/map.rs | 32 ++++--- src/libstd/io/fs.rs | 2 +- src/libstd/num/strconv.rs | 4 +- src/libstd/path/windows.rs | 6 +- src/libstd/rand/mod.rs | 2 +- src/libsync/comm/sync.rs | 4 +- src/libsync/raw.rs | 2 +- src/libsyntax/ast_map/mod.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/format.rs | 4 +- src/libsyntax/ext/tt/macro_parser.rs | 10 +-- src/libsyntax/print/pp.rs | 29 ++++--- src/libtest/stats.rs | 4 +- 46 files changed, 165 insertions(+), 271 deletions(-) (limited to 'src/libsyntax') diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index a9edad3add6..a40913a5db2 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -1013,7 +1013,7 @@ fn check_expected_errors(expected_errors: Vec , if prefix_matches(line, prefixes[i].as_slice()) && line.contains(ee.kind.as_slice()) && line.contains(ee.msg.as_slice()) { - *found_flags.get_mut(i) = true; + found_flags[i] = true; was_expected = true; break; } diff --git a/src/libcollections/bitv.rs b/src/libcollections/bitv.rs index 1e081ae8a4b..1b12fdcb8dc 100644 --- a/src/libcollections/bitv.rs +++ b/src/libcollections/bitv.rs @@ -243,7 +243,7 @@ impl Bitv { let used_bits = bitv.nbits % u32::BITS; if init && used_bits != 0 { let largest_used_word = (bitv.nbits + u32::BITS - 1) / u32::BITS - 1; - *bitv.storage.get_mut(largest_used_word) &= (1 << used_bits) - 1; + bitv.storage[largest_used_word] &= (1 << used_bits) - 1; } bitv @@ -297,8 +297,9 @@ impl Bitv { let w = i / u32::BITS; let b = i % u32::BITS; let flag = 1 << b; - *self.storage.get_mut(w) = if x { self.storage[w] | flag } - else { self.storage[w] & !flag }; + let val = if x { self.storage[w] | flag } + else { self.storage[w] & !flag }; + self.storage[w] = val; } /// Sets all bits to 1. @@ -617,7 +618,7 @@ impl Bitv { self.storage.truncate(word_len); if len % u32::BITS > 0 { let mask = (1 << len % u32::BITS) - 1; - *self.storage.get_mut(word_len - 1) &= mask; + self.storage[word_len - 1] &= mask; } } } @@ -681,15 +682,15 @@ impl Bitv { let overhang = self.nbits % u32::BITS; // # of already-used bits let mask = !((1 << overhang) - 1); // e.g. 5 unused bits => 111110....0 if value { - *self.storage.get_mut(old_last_word) |= mask; + self.storage[old_last_word] |= mask; } else { - *self.storage.get_mut(old_last_word) &= !mask; + self.storage[old_last_word] &= !mask; } } // Fill in words after the old tail word let stop_idx = cmp::min(self.storage.len(), new_nwords); for idx in range(old_last_word + 1, stop_idx) { - *self.storage.get_mut(idx) = full_value; + self.storage[idx] = full_value; } // Allocate new words, if needed if new_nwords > self.storage.len() { @@ -700,7 +701,7 @@ impl Bitv { if value { let tail_word = new_nwords - 1; let used_bits = new_nbits % u32::BITS; - *self.storage.get_mut(tail_word) &= (1 << used_bits) - 1; + self.storage[tail_word] &= (1 << used_bits) - 1; } } // Adjust internal bit count @@ -728,7 +729,7 @@ impl Bitv { let ret = self.get(self.nbits - 1); // If we are unusing a whole word, make sure it is zeroed out if self.nbits % u32::BITS == 1 { - *self.storage.get_mut(self.nbits / u32::BITS) = 0; + self.storage[self.nbits / u32::BITS] = 0; } self.nbits -= 1; ret @@ -1184,7 +1185,7 @@ impl BitvSet { for (i, w) in other_words { let old = self_bitv.storage[i]; let new = f(old, w); - *self_bitv.storage.get_mut(i) = new; + self_bitv.storage[i] = new; } } diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 77fb6d4a120..dc7d935619f 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -690,6 +690,12 @@ impl Index for BTreeMap { } } +impl IndexMut for BTreeMap { + fn index_mut(&mut self, key: &K) -> &mut V { + self.find_mut(key).expect("no entry found for key") + } +} + /// Genericises over how to get the correct type of iterator from the correct type /// of Node ownership. trait Traverse { diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 16e04b93777..fbadbb0ffc9 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -71,7 +71,7 @@ //! let mut pq = PriorityQueue::new(); //! //! // We're at `start`, with a zero cost -//! *dist.get_mut(start) = 0u; +//! dist[start] = 0u; //! pq.push(State { cost: 0u, position: start }); //! //! // Examine the frontier with lower cost nodes first (min-heap) @@ -96,7 +96,7 @@ //! if next.cost < dist[next.position] { //! pq.push(next); //! // Relaxation, we have now found a better way -//! *dist.get_mut(next.position) = next.cost; +//! dist[next.position] = next.cost; //! } //! } //! } @@ -330,7 +330,7 @@ impl PriorityQueue { None => { None } Some(mut item) => { if !self.is_empty() { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); } Some(item) @@ -378,7 +378,7 @@ impl PriorityQueue { /// ``` pub fn push_pop(&mut self, mut item: T) -> T { if !self.is_empty() && *self.top().unwrap() > item { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); } item @@ -402,7 +402,7 @@ impl PriorityQueue { /// ``` pub fn replace(&mut self, mut item: T) -> Option { if !self.is_empty() { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); Some(item) } else { @@ -462,26 +462,26 @@ impl PriorityQueue { // compared to using swaps, which involves twice as many moves. fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { - let new = replace(self.data.get_mut(pos), zeroed()); + let new = replace(&mut self.data[pos], zeroed()); while pos > start { let parent = (pos - 1) >> 1; if new > self.data[parent] { - let x = replace(self.data.get_mut(parent), zeroed()); - ptr::write(self.data.get_mut(pos), x); + let x = replace(&mut self.data[parent], zeroed()); + ptr::write(&mut self.data[pos], x); pos = parent; continue } break } - ptr::write(self.data.get_mut(pos), new); + ptr::write(&mut self.data[pos], new); } } fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; - let new = replace(self.data.get_mut(pos), zeroed()); + let new = replace(&mut self.data[pos], zeroed()); let mut child = 2 * pos + 1; while child < end { @@ -489,13 +489,13 @@ impl PriorityQueue { if right < end && !(self.data[child] > self.data[right]) { child = right; } - let x = replace(self.data.get_mut(child), zeroed()); - ptr::write(self.data.get_mut(pos), x); + let x = replace(&mut self.data[child], zeroed()); + ptr::write(&mut self.data[pos], x); pos = child; child = 2 * pos + 1; } - ptr::write(self.data.get_mut(pos), new); + ptr::write(&mut self.data[pos], new); self.siftup(start, pos); } } diff --git a/src/libcollections/ringbuf.rs b/src/libcollections/ringbuf.rs index 5f05ab7a906..81e4361ec39 100644 --- a/src/libcollections/ringbuf.rs +++ b/src/libcollections/ringbuf.rs @@ -58,7 +58,7 @@ impl Deque for RingBuf { /// Returns a mutable reference to the first element in the `RingBuf`. fn front_mut<'a>(&'a mut self) -> Option<&'a mut T> { - if self.nelts > 0 { Some(self.get_mut(0)) } else { None } + if self.nelts > 0 { Some(&mut self[0]) } else { None } } /// Returns a reference to the last element in the `RingBuf`. @@ -69,13 +69,13 @@ impl Deque for RingBuf { /// Returns a mutable reference to the last element in the `RingBuf`. fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> { let nelts = self.nelts; - if nelts > 0 { Some(self.get_mut(nelts - 1)) } else { None } + if nelts > 0 { Some(&mut self[nelts - 1]) } else { None } } /// Removes and returns the first element in the `RingBuf`, or `None` if it /// is empty. fn pop_front(&mut self) -> Option { - let result = self.elts.get_mut(self.lo).take(); + let result = self.elts[self.lo].take(); if result.is_some() { self.lo = (self.lo + 1u) % self.elts.len(); self.nelts -= 1u; @@ -91,7 +91,7 @@ impl Deque for RingBuf { if self.lo == 0u { self.lo = self.elts.len() - 1u; } else { self.lo -= 1u; } - *self.elts.get_mut(self.lo) = Some(t); + self.elts[self.lo] = Some(t); self.nelts += 1u; } } @@ -102,14 +102,14 @@ impl MutableSeq for RingBuf { grow(self.nelts, &mut self.lo, &mut self.elts); } let hi = self.raw_index(self.nelts); - *self.elts.get_mut(hi) = Some(t); + self.elts[hi] = Some(t); self.nelts += 1u; } fn pop(&mut self) -> Option { if self.nelts > 0 { self.nelts -= 1; let hi = self.raw_index(self.nelts); - self.elts.get_mut(hi).take() + self.elts[hi].take() } else { None } @@ -140,6 +140,7 @@ impl RingBuf { /// # Example /// /// ```rust + /// # #![allow(deprecated)] /// use std::collections::RingBuf; /// /// let mut buf = RingBuf::new(); @@ -149,12 +150,9 @@ impl RingBuf { /// *buf.get_mut(1) = 7; /// assert_eq!(buf[1], 7); /// ``` + #[deprecated = "use indexing instead: `buf[index] = value`"] pub fn get_mut<'a>(&'a mut self, i: uint) -> &'a mut T { - let idx = self.raw_index(i); - match *self.elts.get_mut(idx) { - None => panic!(), - Some(ref mut v) => v - } + &mut self[i] } /// Swaps elements at indices `i` and `j`. @@ -466,13 +464,16 @@ impl Index for RingBuf { } } -// FIXME(#12825) Indexing will always try IndexMut first and that causes issues. -/*impl IndexMut for RingBuf { +impl IndexMut for RingBuf { #[inline] - fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut A { - self.get_mut(*index) + fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A { + let idx = self.raw_index(*i); + match *(&mut self.elts[idx]) { + None => panic!(), + Some(ref mut v) => v + } } -}*/ +} impl FromIterator for RingBuf { fn from_iter>(iterator: T) -> RingBuf { diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index 3b509f37c47..22bb4574f9c 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -100,7 +100,7 @@ impl MutableMap for SmallIntMap { /// Returns a mutable reference to the value corresponding to the key. fn find_mut<'a>(&'a mut self, key: &uint) -> Option<&'a mut V> { if *key < self.v.len() { - match *self.v.get_mut(*key) { + match *self.v.index_mut(key) { Some(ref mut value) => Some(value), None => None } @@ -118,7 +118,7 @@ impl MutableMap for SmallIntMap { if len <= key { self.v.grow_fn(key - len + 1, |_| None); } - *self.v.get_mut(key) = Some(value); + self.v[key] = Some(value); !exists } @@ -145,7 +145,7 @@ impl MutableMap for SmallIntMap { if *key >= self.v.len() { return None; } - self.v.get_mut(*key).take() + self.v[*key].take() } } @@ -405,13 +405,12 @@ impl Index for SmallIntMap { } } -// FIXME(#12825) Indexing will always try IndexMut first and that causes issues. -/*impl IndexMut for SmallIntMap { +impl IndexMut for SmallIntMap { #[inline] fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V { self.find_mut(i).expect("key not present") } -}*/ +} macro_rules! iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index 5dd3be4ec8f..7d882ae5383 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -692,17 +692,17 @@ pub trait StrAllocating: Str { for (i, sc) in me.chars().enumerate() { let mut current = i; - *dcol.get_mut(0) = current + 1; + dcol[0] = current + 1; for (j, tc) in t.chars().enumerate() { let next = dcol[j + 1]; if sc == tc { - *dcol.get_mut(j + 1) = current; + dcol[j + 1] = current; } else { - *dcol.get_mut(j + 1) = cmp::min(current, next); - *dcol.get_mut(j + 1) = cmp::min(dcol[j + 1], dcol[j]) + 1; + dcol[j + 1] = cmp::min(current, next); + dcol[j + 1] = cmp::min(dcol[j + 1], dcol[j]) + 1; } current = next; diff --git a/src/libcollections/treemap.rs b/src/libcollections/treemap.rs index feb4c11a061..ea4d541aab9 100644 --- a/src/libcollections/treemap.rs +++ b/src/libcollections/treemap.rs @@ -257,12 +257,12 @@ impl Index for TreeMap { } } -/*impl IndexMut for TreeMap { +impl IndexMut for TreeMap { #[inline] fn index_mut<'a>(&'a mut self, i: &K) -> &'a mut V { self.find_mut(i).expect("no entry found for key") } -}*/ +} impl TreeMap { /// Creates an empty `TreeMap`. diff --git a/src/libcollections/trie.rs b/src/libcollections/trie.rs index d02190e0824..8c18a6488ba 100644 --- a/src/libcollections/trie.rs +++ b/src/libcollections/trie.rs @@ -515,13 +515,12 @@ impl Index for TrieMap { } } -// FIXME(#12825) Indexing will always try IndexMut first and that causes issues. -/*impl IndexMut for TrieMap { +impl IndexMut for TrieMap { #[inline] fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut T { self.find_mut(i).expect("key not present") } -}*/ +} /// A set implemented as a radix trie. /// diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 759f9ec7d3f..ea03873ee83 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -46,7 +46,7 @@ use slice::{Items, MutItems}; /// assert_eq!(vec.pop(), Some(2)); /// assert_eq!(vec.len(), 1); /// -/// *vec.get_mut(0) = 7i; +/// vec[0] = 7i; /// assert_eq!(vec[0], 7); /// /// vec.push_all([1, 2, 3]); @@ -414,11 +414,10 @@ impl Index for Vec { } } -#[cfg(not(stage0))] impl IndexMut for Vec { #[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { - self.get_mut(*index) + &mut self.as_mut_slice()[*index] } } @@ -712,14 +711,6 @@ impl Vec { } } - /// Deprecated, use `.extend(other.into_iter())` - #[inline] - #[deprecated = "use .extend(other.into_iter())"] - #[cfg(stage0)] - pub fn push_all_move(&mut self, other: Vec) { - self.extend(other.into_iter()); - } - /// Returns a mutable slice of the elements of `self`. /// /// # Example @@ -799,12 +790,13 @@ impl Vec { /// # Example /// /// ``` + /// # #![allow(deprecated)] /// let mut vec = vec![1i, 2, 3]; /// *vec.get_mut(1) = 4; /// assert_eq!(vec, vec![1i, 4, 3]); /// ``` #[inline] - #[unstable = "this is likely to be moved to actual indexing"] + #[deprecated = "use `foo[index] = bar` instead"] pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut T { &mut self.as_mut_slice()[index] } diff --git a/src/libcore/intrinsics.rs b/src/libcore/intrinsics.rs index 68b3ca96de1..cd0b72d50c9 100644 --- a/src/libcore/intrinsics.rs +++ b/src/libcore/intrinsics.rs @@ -57,107 +57,10 @@ pub struct TyDesc { // Called when a value of type `T` is no longer needed pub drop_glue: GlueFn, - // Called by reflection visitor to visit a value of type `T` - #[cfg(stage0)] - pub visit_glue: GlueFn, - // Name corresponding to the type pub name: &'static str, } -#[cfg(stage0)] -#[lang="opaque"] -pub enum Opaque { } - -#[cfg(stage0)] -pub type Disr = u64; - -#[cfg(stage0)] -#[lang="ty_visitor"] -pub trait TyVisitor { - fn visit_bot(&mut self) -> bool; - fn visit_nil(&mut self) -> bool; - fn visit_bool(&mut self) -> bool; - - fn visit_int(&mut self) -> bool; - fn visit_i8(&mut self) -> bool; - fn visit_i16(&mut self) -> bool; - fn visit_i32(&mut self) -> bool; - fn visit_i64(&mut self) -> bool; - - fn visit_uint(&mut self) -> bool; - fn visit_u8(&mut self) -> bool; - fn visit_u16(&mut self) -> bool; - fn visit_u32(&mut self) -> bool; - fn visit_u64(&mut self) -> bool; - - fn visit_f32(&mut self) -> bool; - fn visit_f64(&mut self) -> bool; - - fn visit_char(&mut self) -> bool; - - fn visit_estr_slice(&mut self) -> bool; - - fn visit_box(&mut self, mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_uniq(&mut self, mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_ptr(&mut self, mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_rptr(&mut self, mtbl: uint, inner: *const TyDesc) -> bool; - - fn visit_evec_slice(&mut self, mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_evec_fixed(&mut self, n: uint, sz: uint, align: uint, - inner: *const TyDesc) -> bool; - - fn visit_enter_rec(&mut self, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_rec_field(&mut self, i: uint, name: &str, - mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_leave_rec(&mut self, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_class(&mut self, name: &str, named_fields: bool, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_class_field(&mut self, i: uint, name: &str, named: bool, - mtbl: uint, inner: *const TyDesc) -> bool; - fn visit_leave_class(&mut self, name: &str, named_fields: bool, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_tup(&mut self, n_fields: uint, - sz: uint, align: uint) -> bool; - fn visit_tup_field(&mut self, i: uint, inner: *const TyDesc) -> bool; - fn visit_leave_tup(&mut self, n_fields: uint, - sz: uint, align: uint) -> bool; - - fn visit_enter_enum(&mut self, n_variants: uint, - get_disr: unsafe extern fn(ptr: *const Opaque) -> Disr, - sz: uint, align: uint) -> bool; - fn visit_enter_enum_variant(&mut self, variant: uint, - disr_val: Disr, - n_fields: uint, - name: &str) -> bool; - fn visit_enum_variant_field(&mut self, i: uint, offset: uint, - inner: *const TyDesc) -> bool; - fn visit_leave_enum_variant(&mut self, variant: uint, - disr_val: Disr, - n_fields: uint, - name: &str) -> bool; - fn visit_leave_enum(&mut self, n_variants: uint, - get_disr: unsafe extern fn(ptr: *const Opaque) -> Disr, - sz: uint, align: uint) -> bool; - - fn visit_enter_fn(&mut self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool; - fn visit_fn_input(&mut self, i: uint, mode: uint, - inner: *const TyDesc) -> bool; - fn visit_fn_output(&mut self, retstyle: uint, variadic: bool, - converging: bool, inner: *const TyDesc) -> bool; - fn visit_leave_fn(&mut self, purity: uint, proto: uint, - n_inputs: uint, retstyle: uint) -> bool; - - fn visit_trait(&mut self, name: &str) -> bool; - fn visit_param(&mut self, i: uint) -> bool; - fn visit_self(&mut self) -> bool; -} - extern "rust-intrinsic" { // NB: These intrinsics take unsafe pointers because they mutate aliased diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index 24b78020974..12851713af2 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -614,29 +614,29 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result { if name_pos == names.len() && !i_arg.is_none() { return Err(UnexpectedArgument(nm.to_string())); } - vals.get_mut(optid).push(Given); + vals[optid].push(Given); } Maybe => { if !i_arg.is_none() { - vals.get_mut(optid) + vals[optid] .push(Val((i_arg.clone()) .unwrap())); } else if name_pos < names.len() || i + 1 == l || is_arg(args[i + 1].as_slice()) { - vals.get_mut(optid).push(Given); + vals[optid].push(Given); } else { i += 1; - vals.get_mut(optid).push(Val(args[i].clone())); + vals[optid].push(Val(args[i].clone())); } } Yes => { if !i_arg.is_none() { - vals.get_mut(optid).push(Val(i_arg.clone().unwrap())); + vals[optid].push(Val(i_arg.clone().unwrap())); } else if i + 1 == l { return Err(ArgumentMissing(nm.to_string())); } else { i += 1; - vals.get_mut(optid).push(Val(args[i].clone())); + vals[optid].push(Val(args[i].clone())); } } } diff --git a/src/libregex/compile.rs b/src/libregex/compile.rs index 53d2ea62a2a..2b82b620e39 100644 --- a/src/libregex/compile.rs +++ b/src/libregex/compile.rs @@ -157,7 +157,7 @@ impl<'r> Compiler<'r> { if cap >= len { self.names.grow(10 + cap - len, None) } - *self.names.get_mut(cap) = name; + self.names[cap] = name; self.push(Save(2 * cap)); self.compile(*x); @@ -243,7 +243,7 @@ impl<'r> Compiler<'r> { /// `panic!` is called. #[inline] fn set_split(&mut self, i: InstIdx, pc1: InstIdx, pc2: InstIdx) { - let split = self.insts.get_mut(i); + let split = &mut self.insts[i]; match *split { Split(_, _) => *split = Split(pc1, pc2), _ => panic!("BUG: Invalid split index."), @@ -263,7 +263,7 @@ impl<'r> Compiler<'r> { /// `panic!` is called. #[inline] fn set_jump(&mut self, i: InstIdx, pc: InstIdx) { - let jmp = self.insts.get_mut(i); + let jmp = &mut self.insts[i]; match *jmp { Jump(_) => *jmp = Jump(pc), _ => panic!("BUG: Invalid jump index."), diff --git a/src/libregex/parse.rs b/src/libregex/parse.rs index d71cc9cb511..3115161682f 100644 --- a/src/libregex/parse.rs +++ b/src/libregex/parse.rs @@ -978,7 +978,7 @@ fn combine_ranges(unordered: Vec<(char, char)>) -> Vec<(char, char)> { } match which { None => ordered.push((us, ue)), - Some(i) => *ordered.get_mut(i) = (us, ue), + Some(i) => ordered[i] = (us, ue), } } ordered.sort(); diff --git a/src/libregex/vm.rs b/src/libregex/vm.rs index 0a4dca9125a..ce06828e764 100644 --- a/src/libregex/vm.rs +++ b/src/libregex/vm.rs @@ -461,13 +461,13 @@ impl Threads { } fn add(&mut self, pc: uint, groups: &[Option], empty: bool) { - let t = self.queue.get_mut(self.size); + let t = &mut self.queue[self.size]; t.pc = pc; match (empty, self.which) { (_, Exists) | (true, _) => {}, (false, Location) => { - *t.groups.get_mut(0) = groups[0]; - *t.groups.get_mut(1) = groups[1]; + t.groups[0] = groups[0]; + t.groups[1] = groups[1]; } (false, Submatches) => { for (slot, val) in t.groups.iter_mut().zip(groups.iter()) { @@ -475,7 +475,7 @@ impl Threads { } } } - *self.sparse.get_mut(pc) = self.size; + self.sparse[pc] = self.size; self.size += 1; } @@ -497,7 +497,7 @@ impl Threads { #[inline] fn groups<'r>(&'r mut self, i: uint) -> &'r mut [Option] { - self.queue.get_mut(i).groups.as_mut_slice() + self.queue[i].groups.as_mut_slice() } } diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 6fe14a2d12a..6f5d5f6925c 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -1619,7 +1619,7 @@ fn encode_index(rbml_w: &mut Encoder, index: Vec>, let mut buckets: Vec>> = Vec::from_fn(256, |_| Vec::new()); for elt in index.into_iter() { let h = hash::hash(&elt.val) as uint; - buckets.get_mut(h % 256).push(elt); + buckets[h % 256].push(elt); } rbml_w.start_tag(tag_index); diff --git a/src/librustc/middle/borrowck/move_data.rs b/src/librustc/middle/borrowck/move_data.rs index 5f3c46fcf4c..dbdac39a6aa 100644 --- a/src/librustc/middle/borrowck/move_data.rs +++ b/src/librustc/middle/borrowck/move_data.rs @@ -214,13 +214,13 @@ impl MoveData { fn set_path_first_move(&self, index: MovePathIndex, first_move: MoveIndex) { - self.paths.borrow_mut().get_mut(index.get()).first_move = first_move + (*self.paths.borrow_mut())[index.get()].first_move = first_move } fn set_path_first_child(&self, index: MovePathIndex, first_child: MovePathIndex) { - self.paths.borrow_mut().get_mut(index.get()).first_child = first_child + (*self.paths.borrow_mut())[index.get()].first_child = first_child } fn move_next_move(&self, index: MoveIndex) -> MoveIndex { diff --git a/src/librustc/middle/dependency_format.rs b/src/librustc/middle/dependency_format.rs index 8e2d4d0dc5a..3baa8eb0cc0 100644 --- a/src/librustc/middle/dependency_format.rs +++ b/src/librustc/middle/dependency_format.rs @@ -161,7 +161,7 @@ fn calculate_type(sess: &session::Session, if src.dylib.is_none() && !formats.contains_key(&cnum) { assert!(src.rlib.is_some()); add_library(sess, cnum, cstore::RequireStatic, &mut formats); - *ret.get_mut(cnum as uint - 1) = Some(cstore::RequireStatic); + ret[cnum as uint - 1] = Some(cstore::RequireStatic); debug!("adding staticlib: {}", data.name); } }); diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 4775f945f5c..783b94238e2 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -142,7 +142,7 @@ impl Graph { } pub fn mut_node_data<'a>(&'a mut self, idx: NodeIndex) -> &'a mut N { - &mut self.nodes.get_mut(idx.get()).data + &mut self.nodes[idx.get()].data } pub fn node_data<'a>(&'a self, idx: NodeIndex) -> &'a N { @@ -182,14 +182,14 @@ impl Graph { }); // adjust the firsts for each node target be the next object. - self.nodes.get_mut(source.get()).first_edge[Outgoing.repr] = idx; - self.nodes.get_mut(target.get()).first_edge[Incoming.repr] = idx; + self.nodes[source.get()].first_edge[Outgoing.repr] = idx; + self.nodes[target.get()].first_edge[Incoming.repr] = idx; return idx; } pub fn mut_edge_data<'a>(&'a mut self, idx: EdgeIndex) -> &'a mut E { - &mut self.edges.get_mut(idx.get()).data + &mut self.edges[idx.get()].data } pub fn edge_data<'a>(&'a self, idx: EdgeIndex) -> &'a E { diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index f9810120d21..80eba56ea6c 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -756,7 +756,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn init_empty(&mut self, ln: LiveNode, succ_ln: LiveNode) { - *self.successors.get_mut(ln.get()) = succ_ln; + self.successors[ln.get()] = succ_ln; // It is not necessary to initialize the // values to empty because this is the value @@ -770,10 +770,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn init_from_succ(&mut self, ln: LiveNode, succ_ln: LiveNode) { // more efficient version of init_empty() / merge_from_succ() - *self.successors.get_mut(ln.get()) = succ_ln; + self.successors[ln.get()] = succ_ln; self.indices2(ln, succ_ln, |this, idx, succ_idx| { - *this.users.get_mut(idx) = this.users[succ_idx] + this.users[idx] = this.users[succ_idx] }); debug!("init_from_succ(ln={}, succ={})", self.ln_str(ln), self.ln_str(succ_ln)); @@ -789,11 +789,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { let mut changed = false; self.indices2(ln, succ_ln, |this, idx, succ_idx| { changed |= copy_if_invalid(this.users[succ_idx].reader, - &mut this.users.get_mut(idx).reader); + &mut this.users[idx].reader); changed |= copy_if_invalid(this.users[succ_idx].writer, - &mut this.users.get_mut(idx).writer); + &mut this.users[idx].writer); if this.users[succ_idx].used && !this.users[idx].used { - this.users.get_mut(idx).used = true; + this.users[idx].used = true; changed = true; } }); @@ -817,8 +817,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { // this) so we just clear out all the data. fn define(&mut self, writer: LiveNode, var: Variable) { let idx = self.idx(writer, var); - self.users.get_mut(idx).reader = invalid_node(); - self.users.get_mut(idx).writer = invalid_node(); + self.users[idx].reader = invalid_node(); + self.users[idx].writer = invalid_node(); debug!("{} defines {} (idx={}): {}", writer.to_string(), var.to_string(), idx, self.ln_str(writer)); @@ -830,7 +830,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { ln.to_string(), acc, var.to_string(), self.ln_str(ln)); let idx = self.idx(ln, var); - let user = self.users.get_mut(idx); + let user = &mut self.users[idx]; if (acc & ACC_WRITE) != 0 { user.reader = invalid_node(); diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 7af4739d409..63b5e52f8b8 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -2596,7 +2596,7 @@ impl<'a> Resolver<'a> { // We've successfully resolved the import. Write the results in. let mut import_resolutions = module_.import_resolutions.borrow_mut(); - let import_resolution = import_resolutions.get_mut(&target); + let import_resolution = &mut (*import_resolutions)[target]; match value_result { BoundResult(ref target_module, ref name_bindings) => { @@ -5697,7 +5697,7 @@ impl<'a> Resolver<'a> { let mut smallest = 0; for (i, other) in maybes.iter().enumerate() { - *values.get_mut(i) = name.lev_distance(other.get()); + values[i] = name.lev_distance(other.get()); if values[i] <= values[smallest] { smallest = i; diff --git a/src/librustc/middle/trans/_match.rs b/src/librustc/middle/trans/_match.rs index f53b5331edd..70aef4504f0 100644 --- a/src/librustc/middle/trans/_match.rs +++ b/src/librustc/middle/trans/_match.rs @@ -403,7 +403,7 @@ fn expand_nested_bindings<'a, 'p, 'blk, 'tcx>(bcx: Block<'blk, 'tcx>, } let mut pats = br.pats.clone(); - *pats.get_mut(col) = pat; + pats[col] = pat; Match { pats: pats, data: &*br.data, diff --git a/src/librustc/middle/trans/cleanup.rs b/src/librustc/middle/trans/cleanup.rs index e5825d7a38f..5a4979d9dcd 100644 --- a/src/librustc/middle/trans/cleanup.rs +++ b/src/librustc/middle/trans/cleanup.rs @@ -469,7 +469,7 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> { assert!(self.is_valid_custom_scope(custom_scope)); let mut scopes = self.scopes.borrow_mut(); - let scope = scopes.get_mut(custom_scope.index); + let scope = &mut (*scopes)[custom_scope.index]; scope.cleanups.push(cleanup); scope.clear_cached_exits(); } diff --git a/src/librustc/middle/trans/expr.rs b/src/librustc/middle/trans/expr.rs index 4d004c85f6e..24c03cb5d42 100644 --- a/src/librustc/middle/trans/expr.rs +++ b/src/librustc/middle/trans/expr.rs @@ -1331,7 +1331,7 @@ fn trans_struct<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, field_ty.name == field.ident.node.name); match opt_pos { Some(i) => { - *need_base.get_mut(i) = false; + need_base[i] = false; (i, &*field.expr) } None => { diff --git a/src/librustc/middle/trans/type_.rs b/src/librustc/middle/trans/type_.rs index f08fd20314a..d53fb8dfcf1 100644 --- a/src/librustc/middle/trans/type_.rs +++ b/src/librustc/middle/trans/type_.rs @@ -284,7 +284,7 @@ impl Type { return Vec::new(); } let mut elts = Vec::from_elem(n_elts, 0 as TypeRef); - llvm::LLVMGetStructElementTypes(self.to_ref(), elts.get_mut(0)); + llvm::LLVMGetStructElementTypes(self.to_ref(), &mut elts[0]); mem::transmute(elts) } } diff --git a/src/librustc/middle/typeck/check/method.rs b/src/librustc/middle/typeck/check/method.rs index 7527160c825..6ae1bc82bb4 100644 --- a/src/librustc/middle/typeck/check/method.rs +++ b/src/librustc/middle/typeck/check/method.rs @@ -650,7 +650,7 @@ impl<'a, 'tcx> LookupContext<'a, 'tcx> { ByValueExplicitSelfCategory => { let mut n = (*m).clone(); let self_ty = n.fty.sig.inputs[0]; - *n.fty.sig.inputs.get_mut(0) = ty::mk_uniq(tcx, self_ty); + n.fty.sig.inputs[0] = ty::mk_uniq(tcx, self_ty); m = Rc::new(n); } _ => { } diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 8843be3cf81..4d4ac114937 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -5455,7 +5455,7 @@ pub fn check_bounds_are_used(ccx: &CrateCtxt, match ty::get(t).sty { ty::ty_param(ParamTy {idx, ..}) => { debug!("Found use of ty param num {}", idx); - *tps_used.get_mut(idx) = true; + tps_used[idx] = true; } _ => () } diff --git a/src/librustc/middle/typeck/check/regionck.rs b/src/librustc/middle/typeck/check/regionck.rs index bcade1e74ca..d0338333bad 100644 --- a/src/librustc/middle/typeck/check/regionck.rs +++ b/src/librustc/middle/typeck/check/regionck.rs @@ -1757,7 +1757,7 @@ fn adjust_upvar_borrow_kind_for_mut(rcx: &Rcx, // is inferred to mutable if necessary let mut upvar_borrow_map = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); - let ub = upvar_borrow_map.get_mut(upvar_id); + let ub = &mut (*upvar_borrow_map)[*upvar_id]; return adjust_upvar_borrow_kind(rcx, *upvar_id, ub, ty::MutBorrow); } @@ -1807,7 +1807,7 @@ fn adjust_upvar_borrow_kind_for_unique(rcx: &Rcx, cmt: mc::cmt) { // borrow_kind of the upvar to make sure it // is inferred to unique if necessary let mut ub = rcx.fcx.inh.upvar_borrow_map.borrow_mut(); - let ub = ub.get_mut(upvar_id); + let ub = &mut (*ub)[*upvar_id]; return adjust_upvar_borrow_kind(rcx, *upvar_id, ub, ty::UniqueImmBorrow); } diff --git a/src/librustc/middle/typeck/infer/region_inference/mod.rs b/src/librustc/middle/typeck/infer/region_inference/mod.rs index 80213d43ec4..ff1ded726c5 100644 --- a/src/librustc/middle/typeck/infer/region_inference/mod.rs +++ b/src/librustc/middle/typeck/infer/region_inference/mod.rs @@ -261,7 +261,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> { if snapshot.length == 0 { undo_log.truncate(0); } else { - *undo_log.get_mut(snapshot.length) = CommitedSnapshot; + (*undo_log)[snapshot.length] = CommitedSnapshot; } } diff --git a/src/librustc/middle/typeck/infer/type_variable.rs b/src/librustc/middle/typeck/infer/type_variable.rs index 63094ceaabd..1383f7aa4dc 100644 --- a/src/librustc/middle/typeck/infer/type_variable.rs +++ b/src/librustc/middle/typeck/infer/type_variable.rs @@ -159,12 +159,12 @@ impl sv::SnapshotVecDelegate for Delegate { action: UndoEntry) { match action { SpecifyVar(vid, relations) => { - values.get_mut(vid.index).value = Bounded(relations); + values[vid.index].value = Bounded(relations); } Relate(a, b) => { - relations(values.get_mut(a.index)).pop(); - relations(values.get_mut(b.index)).pop(); + relations(&mut (*values)[a.index]).pop(); + relations(&mut (*values)[b.index]).pop(); } } } diff --git a/src/librustc/middle/typeck/variance.rs b/src/librustc/middle/typeck/variance.rs index c8214a743de..21bd876a5c9 100644 --- a/src/librustc/middle/typeck/variance.rs +++ b/src/librustc/middle/typeck/variance.rs @@ -994,7 +994,7 @@ impl<'a, 'tcx> SolveContext<'a, 'tcx> { new_value, term.to_string()); - *self.solutions.get_mut(inferred) = new_value; + self.solutions[inferred] = new_value; changed = true; } } diff --git a/src/librustc/util/snapshot_vec.rs b/src/librustc/util/snapshot_vec.rs index 8885d86d4da..6d99fc7156c 100644 --- a/src/librustc/util/snapshot_vec.rs +++ b/src/librustc/util/snapshot_vec.rs @@ -105,7 +105,7 @@ impl> SnapshotVec { * action. */ - self.values.get_mut(index) + &mut self.values[index] } pub fn set(&mut self, index: uint, new_elem: T) { @@ -114,7 +114,7 @@ impl> SnapshotVec { * saved (and perhaps restored) if a snapshot is active. */ - let old_elem = mem::replace(self.values.get_mut(index), new_elem); + let old_elem = mem::replace(&mut self.values[index], new_elem); if self.in_snapshot() { self.undo_log.push(SetElem(index, old_elem)); } @@ -162,7 +162,7 @@ impl> SnapshotVec { } SetElem(i, v) => { - *self.values.get_mut(i) = v; + self.values[i] = v; } Other(u) => { @@ -189,7 +189,7 @@ impl> SnapshotVec { // The root snapshot. self.undo_log.truncate(0); } else { - *self.undo_log.get_mut(snapshot.length) = CommittedSnapshot; + self.undo_log[snapshot.length] = CommittedSnapshot; } } } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 99c60dde0ac..dc14a993016 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1231,7 +1231,7 @@ impl Stack { InternalIndex(i) => { i + 1 } _ => { panic!(); } }; - *self.stack.get_mut(len - 1) = InternalIndex(idx); + self.stack[len - 1] = InternalIndex(idx); } } diff --git a/src/libstd/collections/hashmap/map.rs b/src/libstd/collections/hashmap/map.rs index 6562a644988..cb47c28f8be 100644 --- a/src/libstd/collections/hashmap/map.rs +++ b/src/libstd/collections/hashmap/map.rs @@ -14,19 +14,14 @@ use clone::Clone; use cmp::{max, Eq, Equiv, PartialEq}; use collections::{Collection, Mutable, MutableSet, Map, MutableMap}; use default::Default; -use fmt::Show; -use fmt; +use fmt::{mod, Show}; use hash::{Hash, Hasher, RandomSipHasher}; -use iter::{Iterator, FromIterator, Extendable}; -use iter; -use mem::replace; -use mem; +use iter::{mod, Iterator, FromIterator, Extendable}; +use mem::{mod, replace}; use num; -use ops::Deref; +use ops::{Deref, Index, IndexMut}; use option::{Some, None, Option}; -use result::{Ok, Err}; -use ops::Index; -use core::result::Result; +use result::{Result, Ok, Err}; use super::table; use super::table::{ @@ -837,6 +832,7 @@ impl, V, S, H: Hasher> HashMap { /// # Example /// /// ``` + /// # #![allow(deprecated)] /// use std::collections::HashMap; /// /// let mut map = HashMap::new(); @@ -852,11 +848,9 @@ impl, V, S, H: Hasher> HashMap { /// *map.get_mut(&"a") = -2; /// assert_eq!(map["a"], -2); /// ``` + #[deprecated = "use indexing instead: `&mut map[key]`"] pub fn get_mut<'a>(&'a mut self, k: &K) -> &'a mut V { - match self.find_mut(k) { - Some(v) => v, - None => panic!("no entry found for key") - } + &mut self[*k] } /// Return true if the map contains a value for the specified key, @@ -1194,13 +1188,15 @@ impl, V, S, H: Hasher> Index for HashMap { } } -// FIXME(#12825) Indexing will always try IndexMut first and that causes issues. -/*impl, V, S, H: Hasher> ops::IndexMut for HashMap { +impl, V, S, H: Hasher> IndexMut for HashMap { #[inline] fn index_mut<'a>(&'a mut self, index: &K) -> &'a mut V { - self.get_mut(index) + match self.find_mut(index) { + Some(v) => v, + None => panic!("no entry found for key") + } } -}*/ +} /// HashMap iterator pub struct Entries<'a, K: 'a, V: 'a> { diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs index f749d6c823e..f193ce8cffa 100644 --- a/src/libstd/io/fs.rs +++ b/src/libstd/io/fs.rs @@ -963,7 +963,7 @@ mod test { macro_rules! error( ($e:expr, $s:expr) => ( match $e { - Ok(val) => panic!("Unexpected success. Should've been: {}", $s), + Ok(_) => panic!("Unexpected success. Should've been: {}", $s), Err(ref err) => assert!(err.to_string().as_slice().contains($s.as_slice()), format!("`{}` did not contain `{}`", err, $s)) } diff --git a/src/libstd/num/strconv.rs b/src/libstd/num/strconv.rs index 6e0d81a63c9..f79cda0195e 100644 --- a/src/libstd/num/strconv.rs +++ b/src/libstd/num/strconv.rs @@ -424,10 +424,10 @@ pub fn float_to_str_bytes_common, R: Rng>(rng: &mut R, for (i, elem) in iter.enumerate() { let k = rng.gen_range(0, i + 1 + amount); if k < amount { - *reservoir.get_mut(k) = elem; + reservoir[k] = elem; } } return reservoir; diff --git a/src/libsync/comm/sync.rs b/src/libsync/comm/sync.rs index bbb4813f5f9..42de6f66289 100644 --- a/src/libsync/comm/sync.rs +++ b/src/libsync/comm/sync.rs @@ -426,7 +426,7 @@ impl Buffer { fn enqueue(&mut self, t: T) { let pos = (self.start + self.size) % self.buf.len(); self.size += 1; - let prev = mem::replace(self.buf.get_mut(pos), Some(t)); + let prev = mem::replace(&mut self.buf[pos], Some(t)); assert!(prev.is_none()); } @@ -434,7 +434,7 @@ impl Buffer { let start = self.start; self.size -= 1; self.start = (self.start + 1) % self.buf.len(); - self.buf.get_mut(start).take().unwrap() + self.buf[start].take().unwrap() } fn size(&self) -> uint { self.size } diff --git a/src/libsync/raw.rs b/src/libsync/raw.rs index 4fd62ac3a1d..1410091b924 100644 --- a/src/libsync/raw.rs +++ b/src/libsync/raw.rs @@ -308,7 +308,7 @@ impl<'a> Condvar<'a> { // To avoid :broadcast_heavy, we make a new waitqueue, // swap it out with the old one, and broadcast on the // old one outside of the little-lock. - queue = Some(mem::replace(state.blocked.get_mut(condvar_id), + queue = Some(mem::replace(&mut state.blocked[condvar_id], WaitQueue::new())); } else { out_of_bounds = Some(state.blocked.len()); diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs index 915c2d1b318..fa36577ebdb 100644 --- a/src/libsyntax/ast_map/mod.rs +++ b/src/libsyntax/ast_map/mod.rs @@ -712,7 +712,7 @@ impl<'ast> NodeCollector<'ast> { if id as uint >= len { self.map.grow(id as uint - len + 1, NotPresent); } - *self.map.get_mut(id as uint) = entry; + self.map[id as uint] = entry; } fn insert(&mut self, id: NodeId, node: Node<'ast>) { diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index a8326e79ef3..e641abbfeee 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -785,6 +785,6 @@ impl SyntaxEnv { pub fn info<'a>(&'a mut self) -> &'a mut BlockInfo { let last_chain_index = self.chain.len() - 1; - &mut self.chain.get_mut(last_chain_index).info + &mut self.chain[last_chain_index].info } } diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 1b12ae67ee5..fa9a844233a 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -247,7 +247,7 @@ impl<'a, 'b> Context<'a, 'b> { self.verify_same(self.args[arg].span, &ty, arg_type); } if self.arg_types[arg].is_none() { - *self.arg_types.get_mut(arg) = Some(ty); + self.arg_types[arg] = Some(ty); } } @@ -567,7 +567,7 @@ impl<'a, 'b> Context<'a, 'b> { let lname = self.ecx.ident_of(format!("__arg{}", *name).as_slice()); pats.push(self.ecx.pat_ident(e.span, lname)); - *names.get_mut(self.name_positions[*name]) = + names[self.name_positions[*name]] = Some(Context::format_arg(self.ecx, e.span, arg_ty, self.ecx.expr_ident(e.span, lname))); heads.push(self.ecx.expr_addr_of(e.span, e)); diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 9260a45adb9..4de20420148 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -288,8 +288,7 @@ pub fn parse(sess: &ParseSess, // Only touch the binders we have actually bound for idx in range(ei.match_lo, ei.match_hi) { let sub = (ei.matches[idx]).clone(); - new_pos.matches - .get_mut(idx) + new_pos.matches[idx] .push(Rc::new(MatchedSeq(sub, mk_sp(ei.sp_lo, sp.hi)))); } @@ -331,8 +330,7 @@ pub fn parse(sess: &ParseSess, new_ei.idx += 1u; //we specifically matched zero repeats. for idx in range(match_idx_lo, match_idx_hi) { - new_ei.matches - .get_mut(idx) + new_ei.matches[idx] .push(Rc::new(MatchedSeq(Vec::new(), sp))); } @@ -376,7 +374,7 @@ pub fn parse(sess: &ParseSess, if token_name_eq(&tok, &token::Eof) { if eof_eis.len() == 1u { let mut v = Vec::new(); - for dv in eof_eis.get_mut(0).matches.iter_mut() { + for dv in eof_eis[0].matches.iter_mut() { v.push(dv.pop().unwrap()); } return Success(nameize(sess, ms, v.as_slice())); @@ -417,7 +415,7 @@ pub fn parse(sess: &ParseSess, match ei.elts[ei.idx].node { MatchNonterminal(_, name, idx) => { let name_string = token::get_ident(name); - ei.matches.get_mut(idx).push(Rc::new(MatchedNonterminal( + ei.matches[idx].push(Rc::new(MatchedNonterminal( parse_nt(&mut rust_parser, name_string.get())))); ei.idx += 1u; } diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 57c72ca77c6..5523f85aceb 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -303,7 +303,7 @@ impl Printer { } // be very careful with this! pub fn replace_last_token(&mut self, t: Token) { - *self.token.get_mut(self.right) = t; + self.token[self.right] = t; } pub fn pretty_print(&mut self, t: Token) -> io::IoResult<()> { debug!("pp ~[{},{}]", self.left, self.right); @@ -327,8 +327,8 @@ impl Printer { } else { self.advance_right(); } debug!("pp Begin({})/buffer ~[{},{}]", b.offset, self.left, self.right); - *self.token.get_mut(self.right) = t; - *self.size.get_mut(self.right) = -self.right_total; + self.token[self.right] = t; + self.size[self.right] = -self.right_total; let right = self.right; self.scan_push(right); Ok(()) @@ -340,8 +340,8 @@ impl Printer { } else { debug!("pp End/buffer ~[{},{}]", self.left, self.right); self.advance_right(); - *self.token.get_mut(self.right) = t; - *self.size.get_mut(self.right) = -1; + self.token[self.right] = t; + self.size[self.right] = -1; let right = self.right; self.scan_push(right); Ok(()) @@ -359,8 +359,8 @@ impl Printer { self.check_stack(0); let right = self.right; self.scan_push(right); - *self.token.get_mut(self.right) = t; - *self.size.get_mut(self.right) = -self.right_total; + self.token[self.right] = t; + self.size[self.right] = -self.right_total; self.right_total += b.blank_space; Ok(()) } @@ -373,8 +373,8 @@ impl Printer { debug!("pp String('{}')/buffer ~[{},{}]", *s, self.left, self.right); self.advance_right(); - *self.token.get_mut(self.right) = t.clone(); - *self.size.get_mut(self.right) = len; + self.token[self.right] = t.clone(); + self.size[self.right] = len; self.right_total += len; self.check_stream() } @@ -391,7 +391,7 @@ impl Printer { if self.left == self.scan_stack[self.bottom] { debug!("setting {} to infinity and popping", self.left); let scanned = self.scan_pop_bottom(); - *self.size.get_mut(scanned) = SIZE_INFINITY; + self.size[scanned] = SIZE_INFINITY; } } let left = self.token[self.left].clone(); @@ -412,7 +412,7 @@ impl Printer { self.top %= self.buf_len; assert!((self.top != self.bottom)); } - *self.scan_stack.get_mut(self.top) = x; + self.scan_stack[self.top] = x; } pub fn scan_pop(&mut self) -> uint { assert!((!self.scan_stack_empty)); @@ -474,20 +474,19 @@ impl Printer { Begin(_) => { if k > 0 { let popped = self.scan_pop(); - *self.size.get_mut(popped) = self.size[x] + - self.right_total; + self.size[popped] = self.size[x] + self.right_total; self.check_stack(k - 1); } } End => { // paper says + not =, but that makes no sense. let popped = self.scan_pop(); - *self.size.get_mut(popped) = 1; + self.size[popped] = 1; self.check_stack(k + 1); } _ => { let popped = self.scan_pop(); - *self.size.get_mut(popped) = self.size[x] + self.right_total; + self.size[popped] = self.size[x] + self.right_total; if k > 0 { self.check_stack(k); } diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index 72c61f3afc7..21cf1d11e80 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -185,7 +185,7 @@ impl<'a, T: FloatMath + FromPrimitive> Stats for &'a [T] { let hi = x + y; let lo = y - (hi - x); if !lo.is_zero() { - *partials.get_mut(j) = lo; + partials[j] = lo; j += 1; } x = hi; @@ -193,7 +193,7 @@ impl<'a, T: FloatMath + FromPrimitive> Stats for &'a [T] { if j >= partials.len() { partials.push(x); } else { - *partials.get_mut(j) = x; + partials[j] = x; partials.truncate(j+1); } } -- cgit 1.4.1-3-g733a5 From 6fcba8826fd26028341a35d88b07208378ac05ea Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 30 Oct 2014 09:13:02 -0700 Subject: Test fixes and rebase conflicts --- src/libcore/panicking.rs | 6 +++--- src/libnative/io/timer_windows.rs | 2 +- src/librustc/lint/context.rs | 2 +- src/libstd/dynamic_lib.rs | 1 + src/libstd/os.rs | 2 +- src/libsyntax/ext/quote.rs | 2 +- src/libsyntax/parse/token.rs | 14 +++++++------- .../compile-fail/coerce-bare-fn-to-closure-and-proc.rs | 4 ++-- 8 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src/libsyntax') diff --git a/src/libcore/panicking.rs b/src/libcore/panicking.rs index 62c9d907cb2..39de04c27ce 100644 --- a/src/libcore/panicking.rs +++ b/src/libcore/panicking.rs @@ -28,7 +28,7 @@ //! one function. Currently, the actual symbol is declared in the standard //! library, but the location of this may change over time. -#![allow(dead_code, missing_doc)] +#![allow(dead_code, missing_docs)] use fmt; use intrinsics; @@ -63,7 +63,7 @@ fn panic_bounds_check(file_line: &(&'static str, uint), #[cfg(stage0)] #[cold] #[inline(never)] pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { - #[allow(ctypes)] + #[allow(improper_ctypes)] extern { #[lang = "fail_fmt"] fn panic_impl(fmt: &fmt::Arguments, file: &'static str, @@ -104,7 +104,7 @@ fn panic_bounds_check(file_line: &(&'static str, uint), #[cfg(not(stage0))] #[cold] #[inline(never)] pub fn panic_fmt(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! { - #[allow(ctypes)] + #[allow(improper_ctypes)] extern { #[lang = "panic_fmt"] fn panic_impl(fmt: &fmt::Arguments, file: &'static str, diff --git a/src/libnative/io/timer_windows.rs b/src/libnative/io/timer_windows.rs index 421cc28e157..c17c541fc01 100644 --- a/src/libnative/io/timer_windows.rs +++ b/src/libnative/io/timer_windows.rs @@ -79,7 +79,7 @@ fn helper(input: libc::HANDLE, messages: Receiver, _: ()) { } } else { let remove = { - match chans.get_mut(idx as uint - 1) { + match &mut chans[idx as uint - 1] { &(ref mut c, oneshot) => { c.call(); oneshot } } }; diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index a75b98a5470..aa8e1ed2703 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -254,7 +254,7 @@ impl LintStore { } - #[allow(unused_variable)] + #[allow(unused_variables)] fn find_lint(&self, lint_name: &str, sess: &Session, span: Option) -> Option { diff --git a/src/libstd/dynamic_lib.rs b/src/libstd/dynamic_lib.rs index 23cae2443c3..ec6eef07c95 100644 --- a/src/libstd/dynamic_lib.rs +++ b/src/libstd/dynamic_lib.rs @@ -286,6 +286,7 @@ pub mod dl { use os; use ptr; use result::{Ok, Err, Result}; + use slice::ImmutableSlice; use str::StrSlice; use str; use string::String; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 6e1eb82768c..d4e6251cebe 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -144,7 +144,7 @@ pub mod windows { use option::{None, Option}; use option; use os::TMPBUF_SZ; - use slice::MutableSlice; + use slice::{MutableSlice, ImmutableSlice}; use string::String; use str::StrSlice; use vec::Vec; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 2151f79cd7b..f751655c9ff 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -540,7 +540,7 @@ fn mk_delim(cx: &ExtCtxt, sp: Span, delim: token::DelimToken) -> P { mk_token_path(cx, sp, name) } -#[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot +#[allow(non_upper_case_globals)] fn mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { match *tok { token::BinOp(binop) => { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index c1720766ff3..d56aa8da72a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -110,10 +110,10 @@ pub enum DelimToken { } #[cfg(stage0)] -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] pub const ModName: bool = true; #[cfg(stage0)] -#[allow(non_uppercase_statics)] +#[allow(non_upper_case_globals)] pub const Plain: bool = false; #[deriving(Clone, Encodable, Decodable, PartialEq, Eq, Hash, Show)] @@ -263,7 +263,7 @@ impl Token { /// Returns `true` if the token is a path that is not followed by a `::` /// token. - #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot + #[allow(non_upper_case_globals)] pub fn is_plain_ident(&self) -> bool { match *self { Ident(_, Plain) => true, @@ -311,7 +311,7 @@ impl Token { } /// Returns `true` if the token is a given keyword, `kw`. - #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot + #[allow(non_upper_case_globals)] pub fn is_keyword(&self, kw: keywords::Keyword) -> bool { match *self { Ident(sid, Plain) => kw.to_name() == sid.name, @@ -321,7 +321,7 @@ impl Token { /// Returns `true` if the token is either a special identifier, or a strict /// or reserved keyword. - #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot + #[allow(non_upper_case_globals)] pub fn is_any_keyword(&self) -> bool { match *self { Ident(sid, Plain) => { @@ -338,7 +338,7 @@ impl Token { } /// Returns `true` if the token may not appear as an identifier. - #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot + #[allow(non_upper_case_globals)] pub fn is_strict_keyword(&self) -> bool { match *self { Ident(sid, Plain) => { @@ -364,7 +364,7 @@ impl Token { /// Returns `true` if the token is a keyword that has been reserved for /// possible future use. - #[allow(non_uppercase_statics)] // NOTE(stage0): remove this attribute after the next snapshot + #[allow(non_upper_case_globals)] pub fn is_reserved_keyword(&self) -> bool { match *self { Ident(sid, Plain) => { diff --git a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs index 087ebf4e28c..9f258aee746 100644 --- a/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs +++ b/src/test/compile-fail/coerce-bare-fn-to-closure-and-proc.rs @@ -14,8 +14,8 @@ fn main() { let f = foo; let f_closure: || = f; //~^ ERROR: cannot coerce non-statically resolved bare fn to closure - //~^ HELP: consider embedding the function in a closure + //~^^ HELP: consider embedding the function in a closure let f_proc: proc() = f; //~^ ERROR: cannot coerce non-statically resolved bare fn to closure - //~^ HELP: consider embedding the function in a closure + //~^^ HELP: consider embedding the function in a closure } -- cgit 1.4.1-3-g733a5