check_inherited(m.span, m.vis,
"unnecessary visibility");
}
- ast::Required(..) => {}
+ ast::Required(ref m) => {
+ check_inherited(m.span, m.vis,
+ "unnecessary visibility");
+ }
}
}
}
// miscellaneous, no highlighting
t::DOT | t::DOTDOT | t::DOTDOTDOT | t::COMMA | t::SEMI |
- t::COLON | t::MOD_SEP | t::LARROW | t::DARROW | t::LPAREN |
+ t::COLON | t::MOD_SEP | t::LARROW | t::LPAREN |
t::RPAREN | t::LBRACKET | t::LBRACE | t::RBRACE => "",
t::DOLLAR => {
if t::is_ident(&lexer.peek().tok) {
pub explicit_self: ExplicitSelf,
pub id: NodeId,
pub span: Span,
+ pub vis: Visibility,
}
// A trait method is either required (meaning it doesn't have an
explicit_self: m.explicit_self,
id: m.id,
span: m.span,
+ vis: m.vis,
}
}
}
MOD_SEP => "MOD_SEP",
RARROW => "RARROW",
LARROW => "LARROW",
- DARROW => "DARROW",
FAT_ARROW => "FAT_ARROW",
LPAREN => "LPAREN",
RPAREN => "RPAREN",
generics: fold_generics(&m.generics, fld),
explicit_self: fld.fold_explicit_self(&m.explicit_self),
span: fld.new_span(m.span),
+ vis: m.vis,
}
}
'<' => { return binop(rdr, token::SHL); }
'-' => {
bump(rdr);
- match rdr.curr.unwrap_or('\x00') {
- '>' => { bump(rdr); return token::DARROW; }
- _ => { return token::LARROW; }
- }
+ return token::LARROW;
}
_ => { return token::LT; }
}
/// The specific types of unsupported syntax
#[deriving(Eq, TotalEq, Hash)]
pub enum ObsoleteSyntax {
- ObsoleteSwap,
- ObsoleteUnsafeBlock,
- ObsoleteBareFnType,
- ObsoleteMultipleLocalDecl,
- ObsoleteUnsafeExternFn,
- ObsoleteTraitFuncVisibility,
- ObsoleteConstPointer,
- ObsoleteLoopAsContinue,
- ObsoleteEnumWildcard,
- ObsoleteStructWildcard,
- ObsoleteVecDotDotWildcard,
- ObsoleteMultipleImport,
- ObsoleteManagedPattern,
- ObsoleteManagedString,
- ObsoleteManagedVec,
ObsoleteOwnedType,
ObsoleteOwnedExpr,
ObsoleteOwnedPattern,
/// Reports an obsolete syntax non-fatal error.
fn obsolete(&mut self, sp: Span, kind: ObsoleteSyntax) {
let (kind_str, desc) = match kind {
- ObsoleteSwap => (
- "swap",
- "use std::mem::{swap, replace} instead"
- ),
- ObsoleteUnsafeBlock => (
- "non-standalone unsafe block",
- "use an inner `unsafe { ... }` block instead"
- ),
- ObsoleteBareFnType => (
- "bare function type",
- "use `|A| -> B` or `extern fn(A) -> B` instead"
- ),
- ObsoleteMultipleLocalDecl => (
- "declaration of multiple locals at once",
- "instead of e.g. `let a = 1, b = 2`, write \
- `let (a, b) = (1, 2)`."
- ),
- ObsoleteUnsafeExternFn => (
- "unsafe external function",
- "external functions are always unsafe; remove the `unsafe` \
- keyword"
- ),
- ObsoleteTraitFuncVisibility => (
- "visibility not necessary",
- "trait functions inherit the visibility of the trait itself"
- ),
- ObsoleteConstPointer => (
- "const pointer",
- "instead of `&const Foo` or `@const Foo`, write `&Foo` or \
- `@Foo`"
- ),
- ObsoleteLoopAsContinue => (
- "`loop` instead of `continue`",
- "`loop` is now only used for loops and `continue` is used for \
- skipping iterations"
- ),
- ObsoleteEnumWildcard => (
- "enum wildcard",
- "use `..` instead of `*` for matching all enum fields"
- ),
- ObsoleteStructWildcard => (
- "struct wildcard",
- "use `..` instead of `_` for matching trailing struct fields"
- ),
- ObsoleteVecDotDotWildcard => (
- "vec slice wildcard",
- "use `..` instead of `.._` for matching slices"
- ),
- ObsoleteMultipleImport => (
- "multiple imports",
- "only one import is allowed per `use` statement"
- ),
- ObsoleteManagedPattern => (
- "managed pointer pattern",
- "use a nested `match` expression instead of a managed box \
- pattern"
- ),
- ObsoleteManagedString => (
- "managed string",
- "use `Rc<StrBuf>` instead of a managed string"
- ),
- ObsoleteManagedVec => (
- "managed vector",
- "use `Rc<~[T]>` instead of a managed vector"
- ),
ObsoleteOwnedType => (
"`~` notation for owned pointers",
"use `Box<T>` in `std::owned` instead"
let attrs = p.parse_outer_attributes();
let lo = p.span.lo;
- let vis_span = p.span;
- let vis = p.parse_visibility();
- let style = p.parse_fn_style();
// NB: at the moment, trait methods are public by default; this
// could change.
+ let vis = p.parse_visibility();
+ let style = p.parse_fn_style();
let ident = p.parse_ident();
let generics = p.parse_generics();
token::SEMI => {
p.bump();
debug!("parse_trait_methods(): parsing required method");
- // NB: at the moment, visibility annotations on required
- // methods are ignored; this could change.
- if vis != ast::Inherited {
- p.obsolete(vis_span, ObsoleteTraitFuncVisibility);
- }
Required(TypeMethod {
ident: ident,
attrs: attrs,
generics: generics,
explicit_self: explicit_self,
id: ast::DUMMY_NODE_ID,
- span: mk_sp(lo, hi)
+ span: mk_sp(lo, hi),
+ vis: vis,
})
}
token::LBRACE => {
pub fn parse_mutability(&mut self) -> Mutability {
if self.eat_keyword(keywords::Mut) {
MutMutable
- } else if self.eat_keyword(keywords::Const) {
- self.obsolete(self.last_span, ObsoleteConstPointer);
- MutImmutable
} else {
MutImmutable
}
let e = self.parse_prefix_expr();
hi = e.span.hi;
// HACK: pretending @[] is a (removed) @-vec
- ex = match e.node {
- ExprVec(..) |
- ExprRepeat(..) => {
- self.obsolete(e.span, ObsoleteManagedVec);
- // the above error means that no-one will know we're
- // lying... hopefully.
- ExprVstore(e, ExprVstoreUniq)
- }
- ExprLit(lit) if lit_is_str(lit) => {
- self.obsolete(self.last_span, ObsoleteManagedString);
- ExprVstore(e, ExprVstoreUniq)
- }
- _ => self.mk_unary(UnBox, e)
- };
+ ex = self.mk_unary(UnBox, e);
}
token::TILDE => {
self.bump();
let assign_op = self.mk_assign_op(aop, lhs, rhs);
self.mk_expr(lo, rhs.span.hi, assign_op)
}
- token::DARROW => {
- self.obsolete(self.span, ObsoleteSwap);
- self.bump();
- // Ignore what we get, this is an error anyway
- self.parse_expr();
- self.mk_expr(lo, self.span.hi, ExprBreak(None))
- }
_ => {
lhs
}
}
pub fn parse_loop_expr(&mut self, opt_ident: Option<ast::Ident>) -> @Expr {
- // loop headers look like 'loop {' or 'loop unsafe {'
- let is_loop_header =
- self.token == token::LBRACE
- || (is_ident(&self.token)
- && self.look_ahead(1, |t| *t == token::LBRACE));
-
- if is_loop_header {
- // This is a loop body
- let lo = self.last_span.lo;
- let body = self.parse_block();
- let hi = body.span.hi;
- return self.mk_expr(lo, hi, ExprLoop(body, opt_ident));
- } else {
- // This is an obsolete 'continue' expression
- if opt_ident.is_some() {
- self.span_err(self.last_span,
- "a label may not be used with a `loop` expression");
- }
-
- self.obsolete(self.last_span, ObsoleteLoopAsContinue);
- let lo = self.span.lo;
- let ex = if Parser::token_is_lifetime(&self.token) {
- let lifetime = self.get_lifetime();
- self.bump();
- ExprAgain(Some(lifetime))
- } else {
- ExprAgain(None)
- };
- let hi = self.span.hi;
- return self.mk_expr(lo, hi, ex);
- }
+ let lo = self.last_span.lo;
+ let body = self.parse_block();
+ let hi = body.span.hi;
+ self.mk_expr(lo, hi, ExprLoop(body, opt_ident))
}
// For distingishing between struct literals and blocks
} else {
let subpat = self.parse_pat();
match *subpat {
- ast::Pat { id, node: PatWild, span } => {
- self.obsolete(self.span, ObsoleteVecDotDotWildcard);
- slice = Some(@ast::Pat {
- id: id,
- node: PatWildMulti,
- span: span
- })
- },
ast::Pat { node: PatIdent(_, _, _), .. } => {
slice = Some(subpat);
}
if self.token == token::RBRACE { break }
}
- etc = self.token == token::UNDERSCORE || self.token == token::DOTDOT;
- if self.token == token::UNDERSCORE {
- self.obsolete(self.span, ObsoleteStructWildcard);
- }
- if etc {
+ if self.token == token::DOTDOT {
self.bump();
if self.token != token::RBRACE {
let token_str = self.this_token_to_str();
span: mk_sp(lo, hi)
}
}
- // parse @pat
- token::AT => {
- self.bump();
- let sub = self.parse_pat();
- self.obsolete(self.span, ObsoleteManagedPattern);
- let hi = self.last_span.hi;
- return @ast::Pat {
- id: ast::DUMMY_NODE_ID,
- node: PatUniq(sub),
- span: mk_sp(lo, hi)
- }
- }
token::TILDE => {
// parse ~pat
self.bump();
let mut args: Vec<@Pat> = Vec::new();
match self.token {
token::LPAREN => {
- let is_star = self.look_ahead(1, |t| {
- match *t {
- token::BINOP(token::STAR) => true,
- _ => false,
- }
- });
let is_dotdot = self.look_ahead(1, |t| {
match *t {
token::DOTDOT => true,
_ => false,
}
});
- if is_star | is_dotdot {
+ if is_dotdot {
// This is a "top constructor only" pat
self.bump();
- if is_star {
- self.obsolete(self.span, ObsoleteEnumWildcard);
- }
self.bump();
self.expect(&token::RPAREN);
pat = PatEnum(enum_path, None);
fn parse_let(&mut self) -> @Decl {
let lo = self.span.lo;
let local = self.parse_local();
- while self.eat(&token::COMMA) {
- let _ = self.parse_local();
- self.obsolete(self.span, ObsoleteMultipleLocalDecl);
- }
return @spanned(lo, self.last_span.hi, DeclLocal(local));
}
maybe_whole!(no_clone self, NtBlock);
let lo = self.span.lo;
- if self.eat_keyword(keywords::Unsafe) {
- self.obsolete(self.span, ObsoleteUnsafeBlock);
- }
self.expect(&token::LBRACE);
return self.parse_block_tail_(lo, DefaultBlock, Vec::new());
maybe_whole!(pair_empty self, NtBlock);
let lo = self.span.lo;
- if self.eat_keyword(keywords::Unsafe) {
- self.obsolete(self.span, ObsoleteUnsafeBlock);
- }
self.expect(&token::LBRACE);
let (inner, next) = self.parse_inner_attrs_and_next();
fn parse_item_foreign_fn(&mut self, vis: ast::Visibility,
attrs: Vec<Attribute> ) -> @ForeignItem {
let lo = self.span.lo;
-
- // Parse obsolete purity.
- let fn_style = self.parse_fn_style();
- if fn_style != NormalFn {
- self.obsolete(self.last_span, ObsoleteUnsafeExternFn);
- }
+ self.expect_keyword(keywords::Fn);
let (ident, generics) = self.parse_fn_header();
let decl = self.parse_fn_decl(true);
// parse, e.g., "use a::b::{z,y}"
fn parse_use(&mut self) -> ViewItem_ {
- return ViewItemUse(self.parse_view_paths());
+ return ViewItemUse(self.parse_view_path());
}
ViewPathSimple(last, path, ast::DUMMY_NODE_ID));
}
- // matches view_paths = view_path | view_path , view_paths
- fn parse_view_paths(&mut self) -> @ViewPath {
- let vp = self.parse_view_path();
- while self.token == token::COMMA {
- self.bump();
- self.obsolete(self.last_span, ObsoleteMultipleImport);
- let _ = self.parse_view_path();
- }
- return vp;
- }
-
// Parses a sequence of items. Stops when it finds program
// text that can't be parsed as an item
// - mod_items uses extern_mod_allowed = true
MOD_SEP,
RARROW,
LARROW,
- DARROW,
FAT_ARROW,
LPAREN,
RPAREN,
MOD_SEP => "::".to_strbuf(),
RARROW => "->".to_strbuf(),
LARROW => "<-".to_strbuf(),
- DARROW => "<->".to_strbuf(),
FAT_ARROW => "=>".to_strbuf(),
LPAREN => "(".to_strbuf(),
RPAREN => ")".to_strbuf(),
'strict:
(9, As, "as");
(10, Break, "break");
- (11, Const, "const");
- (12, Crate, "crate");
- (13, Else, "else");
- (14, Enum, "enum");
- (15, Extern, "extern");
- (16, False, "false");
- (17, Fn, "fn");
- (18, For, "for");
- (19, If, "if");
- (20, Impl, "impl");
- (21, In, "in");
- (22, Let, "let");
- (23, Loop, "loop");
- (24, Match, "match");
- (25, Mod, "mod");
- (26, Mut, "mut");
- (27, Once, "once");
- (28, Pub, "pub");
- (29, Ref, "ref");
- (30, Return, "return");
+ (11, Crate, "crate");
+ (12, Else, "else");
+ (13, Enum, "enum");
+ (14, Extern, "extern");
+ (15, False, "false");
+ (16, Fn, "fn");
+ (17, For, "for");
+ (18, If, "if");
+ (19, Impl, "impl");
+ (20, In, "in");
+ (21, Let, "let");
+ (22, Loop, "loop");
+ (23, Match, "match");
+ (24, Mod, "mod");
+ (25, Mut, "mut");
+ (26, Once, "once");
+ (27, Pub, "pub");
+ (28, Ref, "ref");
+ (29, Return, "return");
// Static and Self are also special idents (prefill de-dupes)
(super::STATIC_KEYWORD_NAME, Static, "static");
(super::SELF_KEYWORD_NAME, Self, "self");
- (31, Struct, "struct");
- (32, Super, "super");
- (33, True, "true");
- (34, Trait, "trait");
- (35, Type, "type");
- (36, Unsafe, "unsafe");
- (37, Use, "use");
- (38, Virtual, "virtual");
- (39, While, "while");
- (40, Continue, "continue");
- (41, Proc, "proc");
- (42, Box, "box");
+ (30, Struct, "struct");
+ (31, Super, "super");
+ (32, True, "true");
+ (33, Trait, "trait");
+ (34, Type, "type");
+ (35, Unsafe, "unsafe");
+ (36, Use, "use");
+ (37, Virtual, "virtual");
+ (38, While, "while");
+ (39, Continue, "continue");
+ (40, Proc, "proc");
+ (41, Box, "box");
'reserved:
- (43, Alignof, "alignof");
- (44, Be, "be");
+ (42, Alignof, "alignof");
+ (43, Be, "be");
+ (44, Const, "const");
(45, Offsetof, "offsetof");
(46, Priv, "priv");
(47, Pure, "pure");
for (i, x) in permutations.mut_iter().enumerate() {
*x = i as i32;
}
- rng.shuffle_mut(permutations);
+ rng.shuffle(permutations);
Noise2DContext { rgradients: rgradients, permutations: permutations }
}
+++ /dev/null
-// Copyright 2013 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-fn main() {
- loop {
- loop //~ ERROR: `loop` instead of `continue`
- }
-}
+++ /dev/null
-// Copyright 2013 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 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-trait A {
- pub fn foo(); //~ ERROR: visibility not necessary
- pub fn bar(); //~ ERROR: visibility not necessary
-}
-
-fn main() { }
// except according to those terms.
pub trait E {
- pub fn foo(); //~ ERROR: obsolete syntax
+ pub fn foo(); //~ ERROR: unnecessary visibility
}
-trait F { pub fn foo(); } //~ ERROR: obsolete syntax
+trait F { pub fn foo(); } //~ ERROR: unnecessary visibility
+
+fn main() {}