From 8dbf8f5f0a26a8f80f895294532ad567c156beb3 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Apr 2016 04:10:59 +0300 Subject: syntax: Don't rely on token::IdentStyle in the parser --- src/test/compile-fail/use-mod-4.rs | 14 ++++++++++++++ src/test/parse-fail/use-mod-4.rs | 16 ---------------- 2 files changed, 14 insertions(+), 16 deletions(-) create mode 100644 src/test/compile-fail/use-mod-4.rs delete mode 100644 src/test/parse-fail/use-mod-4.rs (limited to 'src/test') diff --git a/src/test/compile-fail/use-mod-4.rs b/src/test/compile-fail/use-mod-4.rs new file mode 100644 index 00000000000..146d37f41d6 --- /dev/null +++ b/src/test/compile-fail/use-mod-4.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. + +use foo::self; //~ ERROR unresolved import `foo::self` +//~^ ERROR `self` imports are only allowed within a { } list + +fn main() {} diff --git a/src/test/parse-fail/use-mod-4.rs b/src/test/parse-fail/use-mod-4.rs deleted file mode 100644 index bcafa4e9fde..00000000000 --- a/src/test/parse-fail/use-mod-4.rs +++ /dev/null @@ -1,16 +0,0 @@ -// 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. - -// compile-flags: -Z parse-only - -use foo::self; -//~^ ERROR expected identifier, found keyword `self` - -fn main() {} -- cgit 1.4.1-3-g733a5 From 546c052d225d41cd31f610e87a20f15cd0fa8e3c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Apr 2016 04:12:02 +0300 Subject: syntax: Get rid of token::IdentStyle --- src/librustdoc/html/highlight.rs | 2 +- src/libsyntax/ast.rs | 12 ++++---- src/libsyntax/diagnostics/plugin.rs | 10 +++---- src/libsyntax/ext/quote.rs | 25 ++++------------ src/libsyntax/ext/tt/macro_parser.rs | 12 ++++---- src/libsyntax/ext/tt/macro_rules.rs | 22 +++++++------- src/libsyntax/ext/tt/transcribe.rs | 12 ++++---- src/libsyntax/fold.rs | 17 ++++------- src/libsyntax/parse/lexer/mod.rs | 35 +++++++--------------- src/libsyntax/parse/mod.rs | 34 +++++++--------------- src/libsyntax/parse/parser.rs | 32 +++++++++------------ src/libsyntax/parse/token.rs | 56 ++++++++++++++++-------------------- src/libsyntax/print/pprust.rs | 19 ++++-------- src/libsyntax_ext/concat_idents.rs | 2 +- src/libsyntax_ext/format.rs | 2 +- src/test/auxiliary/roman_numerals.rs | 2 +- 16 files changed, 111 insertions(+), 183 deletions(-) (limited to 'src/test') diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index 7ca4703a2e1..2f0ae540fbf 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -147,7 +147,7 @@ fn write_source(sess: &parse::ParseSess, } // keywords are also included in the identifier set - token::Ident(ident, _is_mod_sep) => { + token::Ident(ident) => { match &*ident.name.as_str() { "ref" | "mut" => "kw-2", diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index df9f935446d..0e825b8c2fe 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1206,8 +1206,7 @@ impl TokenTree { TokenTree::Delimited(sp, Rc::new(Delimited { delim: token::Bracket, open_span: sp, - tts: vec![TokenTree::Token(sp, token::Ident(token::str_to_ident("doc"), - token::Plain)), + tts: vec![TokenTree::Token(sp, token::Ident(token::str_to_ident("doc"))), TokenTree::Token(sp, token::Eq), TokenTree::Token(sp, token::Literal( token::StrRaw(token::intern(&stripped), num_of_hashes), None))], @@ -1225,14 +1224,13 @@ impl TokenTree { } (&TokenTree::Token(sp, token::SpecialVarNt(var)), _) => { let v = [TokenTree::Token(sp, token::Dollar), - TokenTree::Token(sp, token::Ident(token::str_to_ident(var.as_str()), - token::Plain))]; + TokenTree::Token(sp, token::Ident(token::str_to_ident(var.as_str())))]; v[index].clone() } - (&TokenTree::Token(sp, token::MatchNt(name, kind, name_st, kind_st)), _) => { - let v = [TokenTree::Token(sp, token::SubstNt(name, name_st)), + (&TokenTree::Token(sp, token::MatchNt(name, kind)), _) => { + let v = [TokenTree::Token(sp, token::SubstNt(name)), TokenTree::Token(sp, token::Colon), - TokenTree::Token(sp, token::Ident(kind, kind_st))]; + TokenTree::Token(sp, token::Ident(kind))]; v[index].clone() } (&TokenTree::Sequence(_, ref seq), _) => { diff --git a/src/libsyntax/diagnostics/plugin.rs b/src/libsyntax/diagnostics/plugin.rs index 43b4a201afc..26088b1242e 100644 --- a/src/libsyntax/diagnostics/plugin.rs +++ b/src/libsyntax/diagnostics/plugin.rs @@ -54,7 +54,7 @@ pub fn expand_diagnostic_used<'cx>(ecx: &'cx mut ExtCtxt, token_tree: &[TokenTree]) -> Box { let code = match (token_tree.len(), token_tree.get(0)) { - (1, Some(&TokenTree::Token(_, token::Ident(code, _)))) => code, + (1, Some(&TokenTree::Token(_, token::Ident(code)))) => code, _ => unreachable!() }; @@ -92,10 +92,10 @@ pub fn expand_register_diagnostic<'cx>(ecx: &'cx mut ExtCtxt, token_tree.get(1), token_tree.get(2) ) { - (1, Some(&TokenTree::Token(_, token::Ident(ref code, _))), None, None) => { + (1, Some(&TokenTree::Token(_, token::Ident(ref code))), None, None) => { (code, None) }, - (3, Some(&TokenTree::Token(_, token::Ident(ref code, _))), + (3, Some(&TokenTree::Token(_, token::Ident(ref code))), Some(&TokenTree::Token(_, token::Comma)), Some(&TokenTree::Token(_, token::Literal(token::StrRaw(description, _), None)))) => { (code, Some(description)) @@ -160,9 +160,9 @@ pub fn expand_build_diagnostic_array<'cx>(ecx: &'cx mut ExtCtxt, let (crate_name, name) = match (&token_tree[0], &token_tree[2]) { ( // Crate name. - &TokenTree::Token(_, token::Ident(ref crate_name, _)), + &TokenTree::Token(_, token::Ident(ref crate_name)), // DIAGNOSTICS ident. - &TokenTree::Token(_, token::Ident(ref name, _)) + &TokenTree::Token(_, token::Ident(ref name)) ) => (*&crate_name, name), _ => unreachable!() }; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 77aeaf8459a..9734b49ba7c 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -72,7 +72,7 @@ pub mod rt { impl ToTokens for ast::Ident { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![TokenTree::Token(DUMMY_SP, token::Ident(*self, token::Plain))] + vec![TokenTree::Token(DUMMY_SP, token::Ident(*self))] } } @@ -646,14 +646,10 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { cx.expr_usize(sp, n)) } - token::Ident(ident, style) => { + token::Ident(ident) => { return cx.expr_call(sp, mk_token_path(cx, sp, "Ident"), - vec![mk_ident(cx, sp, ident), - match style { - ModName => mk_token_path(cx, sp, "ModName"), - Plain => mk_token_path(cx, sp, "Plain"), - }]); + vec![mk_ident(cx, sp, ident)]); } token::Lifetime(ident) => { @@ -668,19 +664,10 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { vec!(mk_name(cx, sp, ast::Ident::with_empty_ctxt(ident)))); } - token::MatchNt(name, kind, namep, kindp) => { + token::MatchNt(name, kind) => { return cx.expr_call(sp, mk_token_path(cx, sp, "MatchNt"), - vec!(mk_ident(cx, sp, name), - mk_ident(cx, sp, kind), - match namep { - ModName => mk_token_path(cx, sp, "ModName"), - Plain => mk_token_path(cx, sp, "Plain"), - }, - match kindp { - ModName => mk_token_path(cx, sp, "ModName"), - Plain => mk_token_path(cx, sp, "Plain"), - })); + vec![mk_ident(cx, sp, name), mk_ident(cx, sp, kind)]); } token::Interpolated(_) => panic!("quote! with interpolated token"), @@ -722,7 +709,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P { fn statements_mk_tt(cx: &ExtCtxt, tt: &TokenTree, matcher: bool) -> Vec { match *tt { - TokenTree::Token(sp, SubstNt(ident, _)) => { + TokenTree::Token(sp, SubstNt(ident)) => { // tt.extend($ident.to_tokens(ext_cx)) let e_to_toks = diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 4e4c644776a..8b33bbd3700 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -216,7 +216,7 @@ pub fn nameize(p_s: &ParseSess, ms: &[TokenTree], res: &[Rc]) n_rec(p_s, next_m, res, ret_val, idx)?; } } - TokenTree::Token(sp, MatchNt(bind_name, _, _, _)) => { + TokenTree::Token(sp, MatchNt(bind_name, _)) => { match ret_val.entry(bind_name.name) { Vacant(spot) => { spot.insert(res[*idx].clone()); @@ -263,7 +263,7 @@ pub type PositionalParseResult = ParseResult>>; /// unhygienic comparison) pub fn token_name_eq(t1 : &Token, t2 : &Token) -> bool { match (t1,t2) { - (&token::Ident(id1,_),&token::Ident(id2,_)) + (&token::Ident(id1),&token::Ident(id2)) | (&token::Lifetime(id1),&token::Lifetime(id2)) => id1.name == id2.name, _ => *t1 == *t2 @@ -451,7 +451,7 @@ pub fn parse(sess: &ParseSess, if (!bb_eis.is_empty() && !next_eis.is_empty()) || bb_eis.len() > 1 { let nts = bb_eis.iter().map(|ei| match ei.top_elts.get_tt(ei.idx) { - TokenTree::Token(_, MatchNt(bind, name, _, _)) => { + TokenTree::Token(_, MatchNt(bind, name)) => { format!("{} ('{}')", name, bind) } _ => panic!() @@ -479,7 +479,7 @@ pub fn parse(sess: &ParseSess, let mut ei = bb_eis.pop().unwrap(); match ei.top_elts.get_tt(ei.idx) { - TokenTree::Token(span, MatchNt(_, ident, _, _)) => { + TokenTree::Token(span, MatchNt(_, ident)) => { let match_cur = ei.match_cur; (&mut ei.matches[match_cur]).push(Rc::new(MatchedNonterminal( parse_nt(&mut rust_parser, span, &ident.name.as_str())))); @@ -534,9 +534,9 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { "ty" => token::NtTy(panictry!(p.parse_ty())), // this could be handled like a token, since it is one "ident" => match p.token { - token::Ident(sn,b) => { + token::Ident(sn) => { p.bump(); - token::NtIdent(Box::new(Spanned::{node: sn, span: p.span}),b) + token::NtIdent(Box::new(Spanned::{node: sn, span: p.span})) } _ => { let token_str = pprust::token_to_string(&p.token); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 87ab3dad50c..abb17de47ea 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -244,8 +244,8 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, // $( $lhs:tt => $rhs:tt );+ // ...quasiquoting this would be nice. // These spans won't matter, anyways - let match_lhs_tok = MatchNt(lhs_nm, special_idents::tt, token::Plain, token::Plain); - let match_rhs_tok = MatchNt(rhs_nm, special_idents::tt, token::Plain, token::Plain); + let match_lhs_tok = MatchNt(lhs_nm, special_idents::tt); + let match_rhs_tok = MatchNt(rhs_nm, special_idents::tt); let argument_gram = vec!( TokenTree::Sequence(DUMMY_SP, Rc::new(ast::SequenceRepetition { @@ -415,7 +415,7 @@ fn check_matcher_old<'a, I>(cx: &mut ExtCtxt, matcher: I, follow: &Token, on_fai let mut tokens = matcher.peekable(); while let Some(token) = tokens.next() { last = match *token { - TokenTree::Token(sp, MatchNt(ref name, ref frag_spec, _, _)) => { + TokenTree::Token(sp, MatchNt(ref name, ref frag_spec)) => { // ii. If T is a simple NT, look ahead to the next token T' in // M. If T' is in the set FOLLOW(NT), continue. Else; reject. if can_be_followed_by_any(&frag_spec.name.as_str()) { @@ -881,7 +881,7 @@ fn check_matcher_core(cx: &mut ExtCtxt, // Now `last` holds the complete set of NT tokens that could // end the sequence before SUFFIX. Check that every one works with `suffix`. 'each_last: for &(_sp, ref t) in &last.tokens { - if let MatchNt(ref name, ref frag_spec, _, _) = *t { + if let MatchNt(ref name, ref frag_spec) = *t { for &(sp, ref next_token) in &suffix_first.tokens { match is_in_follow(cx, next_token, &frag_spec.name.as_str()) { Err(msg) => { @@ -917,9 +917,8 @@ fn check_matcher_core(cx: &mut ExtCtxt, last } - fn token_can_be_followed_by_any(tok: &Token) -> bool { - if let &MatchNt(_, ref frag_spec, _, _) = tok { + if let &MatchNt(_, ref frag_spec) = tok { frag_can_be_followed_by_any(&frag_spec.name.as_str()) } else { // (Non NT's can always be followed by anthing in matchers.) @@ -1005,8 +1004,8 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result { "pat" => { match *tok { FatArrow | Comma | Eq | BinOp(token::Or) => Ok(true), - Ident(i, _) if (i.name.as_str() == "if" || - i.name.as_str() == "in") => Ok(true), + Ident(i) if (i.name.as_str() == "if" || + i.name.as_str() == "in") => Ok(true), _ => Ok(false) } }, @@ -1014,9 +1013,8 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result { match *tok { OpenDelim(token::DelimToken::Brace) | OpenDelim(token::DelimToken::Bracket) | Comma | FatArrow | Colon | Eq | Gt | Semi | BinOp(token::Or) => Ok(true), - MatchNt(_, ref frag, _, _) if frag.name.as_str() == "block" => Ok(true), - Ident(i, _) if (i.name.as_str() == "as" || - i.name.as_str() == "where") => Ok(true), + MatchNt(_, ref frag) if frag.name.as_str() == "block" => Ok(true), + Ident(i) if i.name.as_str() == "as" || i.name.as_str() == "where" => Ok(true), _ => Ok(false) } }, @@ -1036,7 +1034,7 @@ fn is_in_follow(_: &ExtCtxt, tok: &Token, frag: &str) -> Result { fn has_legal_fragment_specifier(tok: &Token) -> Result<(), String> { debug!("has_legal_fragment_specifier({:?})", tok); - if let &MatchNt(_, ref frag_spec, _, _) = tok { + if let &MatchNt(_, ref frag_spec) = tok { let s = &frag_spec.name.as_str(); if !is_legal_fragment_specifier(s) { return Err(s.to_string()); diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index ae99fe81739..7f53d0f412c 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -161,7 +161,7 @@ fn lockstep_iter_size(t: &TokenTree, r: &TtReader) -> LockstepIterSize { size + lockstep_iter_size(tt, r) }) }, - TokenTree::Token(_, SubstNt(name, _)) | TokenTree::Token(_, MatchNt(name, _, _, _)) => + TokenTree::Token(_, SubstNt(name)) | TokenTree::Token(_, MatchNt(name, _)) => match lookup_cur_matched(r, name) { Some(matched) => match *matched { MatchedNonterminal(_) => LisUnconstrained, @@ -186,7 +186,7 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { None => (), Some(sp) => { r.cur_span = sp; - r.cur_tok = token::Ident(r.imported_from.unwrap(), token::Plain); + r.cur_tok = token::Ident(r.imported_from.unwrap()); return ret_val; }, } @@ -278,12 +278,12 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { } } // FIXME #2887: think about span stuff here - TokenTree::Token(sp, SubstNt(ident, namep)) => { + TokenTree::Token(sp, SubstNt(ident)) => { r.stack.last_mut().unwrap().idx += 1; match lookup_cur_matched(r, ident) { None => { r.cur_span = sp; - r.cur_tok = SubstNt(ident, namep); + r.cur_tok = SubstNt(ident); return ret_val; // this can't be 0 length, just like TokenTree::Delimited } @@ -292,9 +292,9 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { // sidestep the interpolation tricks for ident because // (a) idents can be in lots of places, so it'd be a pain // (b) we actually can, since it's a token. - MatchedNonterminal(NtIdent(ref sn, b)) => { + MatchedNonterminal(NtIdent(ref sn)) => { r.cur_span = sn.span; - r.cur_tok = token::Ident(sn.node, b); + r.cur_tok = token::Ident(sn.node); return ret_val; } MatchedNonterminal(ref other_whole_nt) => { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 89451e79550..69c420902c8 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -610,17 +610,11 @@ pub fn noop_fold_tts(tts: &[TokenTree], fld: &mut T) -> Vec(t: token::Token, fld: &mut T) -> token::Token { match t { - token::Ident(id, followed_by_colons) => { - token::Ident(fld.fold_ident(id), followed_by_colons) - } + token::Ident(id) => token::Ident(fld.fold_ident(id)), token::Lifetime(id) => token::Lifetime(fld.fold_ident(id)), token::Interpolated(nt) => token::Interpolated(fld.fold_interpolated(nt)), - token::SubstNt(ident, namep) => { - token::SubstNt(fld.fold_ident(ident), namep) - } - token::MatchNt(name, kind, namep, kindp) => { - token::MatchNt(fld.fold_ident(name), fld.fold_ident(kind), namep, kindp) - } + token::SubstNt(ident) => token::SubstNt(fld.fold_ident(ident)), + token::MatchNt(name, kind) => token::MatchNt(fld.fold_ident(name), fld.fold_ident(kind)), _ => t } } @@ -664,9 +658,8 @@ pub fn noop_fold_interpolated(nt: token::Nonterminal, fld: &mut T) token::NtPat(pat) => token::NtPat(fld.fold_pat(pat)), token::NtExpr(expr) => token::NtExpr(fld.fold_expr(expr)), token::NtTy(ty) => token::NtTy(fld.fold_ty(ty)), - token::NtIdent(id, is_mod_name) => - token::NtIdent(Box::new(Spanned::{node: fld.fold_ident(id.node), .. *id}), - is_mod_name), + token::NtIdent(id) => + token::NtIdent(Box::new(Spanned::{node: fld.fold_ident(id.node), ..*id})), token::NtMeta(meta_item) => token::NtMeta(fld.fold_meta_item(meta_item)), token::NtPath(path) => token::NtPath(Box::new(fld.fold_path(*path))), token::NtTT(tt) => token::NtTT(P(fld.fold_tt(&tt))), diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index a5cb5c7117e..265a432ae82 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -1039,11 +1039,7 @@ impl<'a> StringReader<'a> { token::Underscore } else { // FIXME: perform NFKC normalization here. (Issue #2253) - if self.curr_is(':') && self.nextch_is(':') { - token::Ident(str_to_ident(string), token::ModName) - } else { - token::Ident(str_to_ident(string), token::Plain) - } + token::Ident(str_to_ident(string)) } }); } @@ -1231,8 +1227,7 @@ impl<'a> StringReader<'a> { let keyword_checking_ident = self.with_str_from(start, |lifetime_name| { str_to_ident(lifetime_name) }); - let keyword_checking_token = &token::Ident(keyword_checking_ident, - token::Plain); + let keyword_checking_token = &token::Ident(keyword_checking_ident); let last_bpos = self.last_pos; if keyword_checking_token.is_keyword(token::keywords::SelfValue) { self.err_span_(start, @@ -1687,7 +1682,7 @@ mod tests { assert_eq!(string_reader.next_token().tok, token::Whitespace); let tok1 = string_reader.next_token(); let tok2 = TokenAndSpan { - tok: token::Ident(id, token::Plain), + tok: token::Ident(id), sp: Span { lo: BytePos(21), hi: BytePos(23), @@ -1701,7 +1696,7 @@ mod tests { // read another token: let tok3 = string_reader.next_token(); let tok4 = TokenAndSpan { - tok: token::Ident(str_to_ident("main"), token::Plain), + tok: token::Ident(str_to_ident("main")), sp: Span { lo: BytePos(24), hi: BytePos(28), @@ -1722,8 +1717,8 @@ mod tests { } // make the identifier by looking up the string in the interner - fn mk_ident(id: &str, style: token::IdentStyle) -> token::Token { - token::Ident(str_to_ident(id), style) + fn mk_ident(id: &str) -> token::Token { + token::Ident(str_to_ident(id)) } #[test] @@ -1731,9 +1726,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a b".to_string()), - vec![mk_ident("a", token::Plain), - token::Whitespace, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::Whitespace, mk_ident("b")]); } #[test] @@ -1741,9 +1734,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a::b".to_string()), - vec![mk_ident("a", token::ModName), - token::ModSep, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::ModSep, mk_ident("b")]); } #[test] @@ -1751,10 +1742,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a ::b".to_string()), - vec![mk_ident("a", token::Plain), - token::Whitespace, - token::ModSep, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::Whitespace, token::ModSep, mk_ident("b")]); } #[test] @@ -1762,10 +1750,7 @@ mod tests { let cm = Rc::new(CodeMap::new()); let sh = mk_sh(cm.clone()); check_tokenization(setup(&cm, &sh, "a:: b".to_string()), - vec![mk_ident("a", token::ModName), - token::ModSep, - token::Whitespace, - mk_ident("b", token::Plain)]); + vec![mk_ident("a"), token::ModSep, token::Whitespace, mk_ident("b")]); } #[test] diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 29b1d5b9aff..7534683a206 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -734,9 +734,9 @@ mod tests { match (tts.len(), tts.get(0), tts.get(1), tts.get(2), tts.get(3)) { ( 4, - Some(&TokenTree::Token(_, token::Ident(name_macro_rules, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(name_macro_rules))), Some(&TokenTree::Token(_, token::Not)), - Some(&TokenTree::Token(_, token::Ident(name_zip, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(name_zip))), Some(&TokenTree::Delimited(_, ref macro_delimed)), ) if name_macro_rules.name.as_str() == "macro_rules" @@ -755,7 +755,7 @@ mod tests { ( 2, Some(&TokenTree::Token(_, token::Dollar)), - Some(&TokenTree::Token(_, token::Ident(ident, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(ident))), ) if first_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, @@ -766,7 +766,7 @@ mod tests { ( 2, Some(&TokenTree::Token(_, token::Dollar)), - Some(&TokenTree::Token(_, token::Ident(ident, token::Plain))), + Some(&TokenTree::Token(_, token::Ident(ident))), ) if second_delimed.delim == token::Paren && ident.name.as_str() == "a" => {}, @@ -785,26 +785,17 @@ mod tests { let tts = string_to_tts("fn a (b : i32) { b; }".to_string()); let expected = vec![ - TokenTree::Token(sp(0, 2), - token::Ident(str_to_ident("fn"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(3, 4), - token::Ident(str_to_ident("a"), - token::IdentStyle::Plain)), + TokenTree::Token(sp(0, 2), token::Ident(str_to_ident("fn"))), + TokenTree::Token(sp(3, 4), token::Ident(str_to_ident("a"))), TokenTree::Delimited( sp(5, 14), Rc::new(ast::Delimited { delim: token::DelimToken::Paren, open_span: sp(5, 6), tts: vec![ - TokenTree::Token(sp(6, 7), - token::Ident(str_to_ident("b"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(8, 9), - token::Colon), - TokenTree::Token(sp(10, 13), - token::Ident(str_to_ident("i32"), - token::IdentStyle::Plain)), + TokenTree::Token(sp(6, 7), token::Ident(str_to_ident("b"))), + TokenTree::Token(sp(8, 9), token::Colon), + TokenTree::Token(sp(10, 13), token::Ident(str_to_ident("i32"))), ], close_span: sp(13, 14), })), @@ -814,11 +805,8 @@ mod tests { delim: token::DelimToken::Brace, open_span: sp(15, 16), tts: vec![ - TokenTree::Token(sp(17, 18), - token::Ident(str_to_ident("b"), - token::IdentStyle::Plain)), - TokenTree::Token(sp(18, 19), - token::Semi) + TokenTree::Token(sp(17, 18), token::Ident(str_to_ident("b"))), + TokenTree::Token(sp(18, 19), token::Semi), ], close_span: sp(20, 21), })) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b81ee67c214..71f059de041 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -567,7 +567,7 @@ impl<'a> Parser<'a> { } self.check_reserved_keywords(); match self.token { - token::Ident(i, _) => { + token::Ident(i) => { self.bump(); Ok(i) } @@ -629,9 +629,8 @@ impl<'a> Parser<'a> { } pub fn check_contextual_keyword(&mut self, ident: Ident) -> bool { - let tok = token::Ident(ident, token::Plain); - self.expected_tokens.push(TokenType::Token(tok)); - if let token::Ident(ref cur_ident, _) = self.token { + self.expected_tokens.push(TokenType::Token(token::Ident(ident))); + if let token::Ident(ref cur_ident) = self.token { cur_ident.name == ident.name } else { false @@ -1699,7 +1698,7 @@ impl<'a> Parser<'a> { pub fn parse_path_segment_ident(&mut self) -> PResult<'a, ast::Ident> { match self.token { - token::Ident(sid, _) if self.token.is_path_segment_keyword() => { + token::Ident(sid) if self.token.is_path_segment_keyword() => { self.bump(); Ok(sid) } @@ -2564,7 +2563,7 @@ impl<'a> Parser<'a> { // expr.f if self.eat(&token::Dot) { match self.token { - token::Ident(i, _) => { + token::Ident(i) => { let dot_pos = self.last_span.hi; hi = self.span.hi; self.bump(); @@ -2661,7 +2660,7 @@ impl<'a> Parser<'a> { // Parse unquoted tokens after a `$` in a token tree fn parse_unquoted(&mut self) -> PResult<'a, TokenTree> { let mut sp = self.span; - let (name, namep) = match self.token { + let name = match self.token { token::Dollar => { self.bump(); @@ -2686,14 +2685,12 @@ impl<'a> Parser<'a> { return Ok(TokenTree::Token(sp, SpecialVarNt(SpecialMacroVar::CrateMacroVar))); } else { sp = mk_sp(sp.lo, self.span.hi); - let namep = match self.token { token::Ident(_, p) => p, _ => token::Plain }; - let name = self.parse_ident()?; - (name, namep) + self.parse_ident()? } } - token::SubstNt(name, namep) => { + token::SubstNt(name) => { self.bump(); - (name, namep) + name } _ => unreachable!() }; @@ -2703,18 +2700,17 @@ impl<'a> Parser<'a> { !t.is_reserved_keyword()) { self.bump(); sp = mk_sp(sp.lo, self.span.hi); - let kindp = match self.token { token::Ident(_, p) => p, _ => token::Plain }; let nt_kind = self.parse_ident()?; - Ok(TokenTree::Token(sp, MatchNt(name, nt_kind, namep, kindp))) + Ok(TokenTree::Token(sp, MatchNt(name, nt_kind))) } else { - Ok(TokenTree::Token(sp, SubstNt(name, namep))) + Ok(TokenTree::Token(sp, SubstNt(name))) } } pub fn check_unknown_macro_variable(&mut self) { if self.quote_depth == 0 { match self.token { - token::SubstNt(name, _) => + token::SubstNt(name) => self.fatal(&format!("unknown macro variable `{}`", name)).emit(), _ => {} } @@ -4614,7 +4610,7 @@ impl<'a> Parser<'a> { fn expect_self_ident(&mut self) -> PResult<'a, ast::Ident> { match self.token { - token::Ident(id, _) if id.name == special_idents::self_.name => { + token::Ident(id) if id.name == special_idents::self_.name => { self.bump(); Ok(id) }, @@ -4927,7 +4923,7 @@ impl<'a> Parser<'a> { Visibility::Inherited => (), _ => { let is_macro_rules: bool = match self.token { - token::Ident(sid, _) => sid.name == intern("macro_rules"), + token::Ident(sid) => sid.name == intern("macro_rules"), _ => false, }; if is_macro_rules { diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 46cf79ba336..76bd0f66cd8 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -11,7 +11,6 @@ pub use self::BinOpToken::*; pub use self::Nonterminal::*; pub use self::DelimToken::*; -pub use self::IdentStyle::*; pub use self::Lit::*; pub use self::Token::*; @@ -51,13 +50,6 @@ pub enum DelimToken { Brace, } -#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] -pub enum IdentStyle { - /// `::` follows the identifier with no whitespace in-between. - ModName, - Plain, -} - #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] pub enum SpecialMacroVar { /// `$crate` will be filled in with the name of the crate a macro was @@ -139,7 +131,7 @@ pub enum Token { Literal(Lit, Option), /* Name components */ - Ident(ast::Ident, IdentStyle), + Ident(ast::Ident), Underscore, Lifetime(ast::Ident), @@ -150,10 +142,10 @@ pub enum Token { DocComment(ast::Name), // In left-hand-sides of MBE macros: /// Parse a nonterminal (name to bind, name of NT, styles of their idents) - MatchNt(ast::Ident, ast::Ident, IdentStyle, IdentStyle), + MatchNt(ast::Ident, ast::Ident), // In right-hand-sides of MBE macros: /// A syntactic variable that will be filled in by macro expansion. - SubstNt(ast::Ident, IdentStyle), + SubstNt(ast::Ident), /// A macro variable with special meaning. SpecialVarNt(SpecialMacroVar), @@ -279,16 +271,16 @@ impl Token { /// Returns `true` if the token is a given keyword, `kw`. pub fn is_keyword(&self, kw: keywords::Keyword) -> bool { match *self { - Ident(id, _) => id.name == kw.to_name(), + Ident(id) => id.name == kw.to_name(), _ => false, } } pub fn is_path_segment_keyword(&self) -> bool { match *self { - Ident(id, _) => id.name == SUPER_KEYWORD_NAME || - id.name == SELF_KEYWORD_NAME || - id.name == SELF_TYPE_KEYWORD_NAME, + Ident(id) => id.name == SUPER_KEYWORD_NAME || + id.name == SELF_KEYWORD_NAME || + id.name == SELF_TYPE_KEYWORD_NAME, _ => false, } } @@ -296,12 +288,12 @@ impl Token { /// Returns `true` if the token is either a strict or reserved keyword. pub fn is_any_keyword(&self) -> bool { match *self { - Ident(id, _) => id.name == SELF_KEYWORD_NAME || - id.name == STATIC_KEYWORD_NAME || - id.name == SUPER_KEYWORD_NAME || - id.name == SELF_TYPE_KEYWORD_NAME || - id.name >= STRICT_KEYWORD_START && - id.name <= RESERVED_KEYWORD_FINAL, + Ident(id) => id.name == SELF_KEYWORD_NAME || + id.name == STATIC_KEYWORD_NAME || + id.name == SUPER_KEYWORD_NAME || + id.name == SELF_TYPE_KEYWORD_NAME || + id.name >= STRICT_KEYWORD_START && + id.name <= RESERVED_KEYWORD_FINAL, _ => false } } @@ -309,12 +301,12 @@ impl Token { /// Returns `true` if the token is either a strict keyword. pub fn is_strict_keyword(&self) -> bool { match *self { - Ident(id, _) => id.name == SELF_KEYWORD_NAME || - id.name == STATIC_KEYWORD_NAME || - id.name == SUPER_KEYWORD_NAME || - id.name == SELF_TYPE_KEYWORD_NAME || - id.name >= STRICT_KEYWORD_START && - id.name <= STRICT_KEYWORD_FINAL, + Ident(id) => id.name == SELF_KEYWORD_NAME || + id.name == STATIC_KEYWORD_NAME || + id.name == SUPER_KEYWORD_NAME || + id.name == SELF_TYPE_KEYWORD_NAME || + id.name >= STRICT_KEYWORD_START && + id.name <= STRICT_KEYWORD_FINAL, _ => false, } } @@ -322,8 +314,8 @@ impl Token { /// Returns `true` if the token is either a keyword reserved for possible future use. pub fn is_reserved_keyword(&self) -> bool { match *self { - Ident(id, _) => id.name >= RESERVED_KEYWORD_START && - id.name <= RESERVED_KEYWORD_FINAL, + Ident(id) => id.name >= RESERVED_KEYWORD_START && + id.name <= RESERVED_KEYWORD_FINAL, _ => false, } } @@ -333,7 +325,7 @@ impl Token { /// See `styntax::ext::mtwt`. pub fn mtwt_eq(&self, other : &Token) -> bool { match (self, other) { - (&Ident(id1,_), &Ident(id2,_)) | (&Lifetime(id1), &Lifetime(id2)) => + (&Ident(id1), &Ident(id2)) | (&Lifetime(id1), &Lifetime(id2)) => mtwt::resolve(id1) == mtwt::resolve(id2), _ => *self == *other } @@ -349,7 +341,7 @@ pub enum Nonterminal { NtPat(P), NtExpr(P), NtTy(P), - NtIdent(Box, IdentStyle), + NtIdent(Box), /// Stuff inside brackets for attributes NtMeta(P), NtPath(Box), @@ -743,6 +735,6 @@ mod tests { assert!(Gt.mtwt_eq(&Gt)); let a = str_to_ident("bac"); let a1 = mark_ident(a,92); - assert!(Ident(a, ModName).mtwt_eq(&Ident(a1, Plain))); + assert!(Ident(a).mtwt_eq(&Ident(a1))); } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 95f1b63168b..4fe076b3a7b 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -270,14 +270,14 @@ pub fn token_to_string(tok: &Token) -> String { } /* Name components */ - token::Ident(s, _) => s.to_string(), + token::Ident(s) => s.to_string(), token::Lifetime(s) => s.to_string(), token::Underscore => "_".to_string(), /* Other */ token::DocComment(s) => s.to_string(), - token::SubstNt(s, _) => format!("${}", s), - token::MatchNt(s, t, _, _) => format!("${}:{}", s, t), + token::SubstNt(s) => format!("${}", s), + token::MatchNt(s, t) => format!("${}:{}", s, t), token::Eof => "".to_string(), token::Whitespace => " ".to_string(), token::Comment => "/* */".to_string(), @@ -294,7 +294,7 @@ pub fn token_to_string(tok: &Token) -> String { token::NtBlock(ref e) => block_to_string(&e), token::NtStmt(ref e) => stmt_to_string(&e), token::NtPat(ref e) => pat_to_string(&e), - token::NtIdent(ref e, _) => ident_to_string(e.node), + token::NtIdent(ref e) => ident_to_string(e.node), token::NtTT(ref e) => tt_to_string(&e), token::NtArm(ref e) => arm_to_string(&e), token::NtImplItem(ref e) => impl_item_to_string(&e), @@ -1488,20 +1488,11 @@ impl<'a> State<'a> { pub fn print_tts(&mut self, tts: &[ast::TokenTree]) -> io::Result<()> { self.ibox(0)?; - let mut suppress_space = false; for (i, tt) in tts.iter().enumerate() { - if i != 0 && !suppress_space { + if i != 0 { space(&mut self.s)?; } self.print_tt(tt)?; - // There should be no space between the module name and the following `::` in paths, - // otherwise imported macros get re-parsed from crate metadata incorrectly (#20701) - suppress_space = match *tt { - TokenTree::Token(_, token::Ident(_, token::ModName)) | - TokenTree::Token(_, token::MatchNt(_, _, _, token::ModName)) | - TokenTree::Token(_, token::SubstNt(_, token::ModName)) => true, - _ => false - } } self.end() } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 85453f6dfcb..dce808756cf 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -40,7 +40,7 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) } } else { match *e { - TokenTree::Token(_, token::Ident(ident, _)) => { + TokenTree::Token(_, token::Ident(ident)) => { res_str.push_str(&ident.name.as_str()) }, _ => { diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index fd68ba73427..c8341a057a1 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -106,7 +106,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) if named || (p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq)) { named = true; let ident = match p.token { - token::Ident(i, _) => { + token::Ident(i) => { p.bump(); i } diff --git a/src/test/auxiliary/roman_numerals.rs b/src/test/auxiliary/roman_numerals.rs index c262b0dba25..839ece49c3e 100644 --- a/src/test/auxiliary/roman_numerals.rs +++ b/src/test/auxiliary/roman_numerals.rs @@ -48,7 +48,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree]) } let text = match args[0] { - TokenTree::Token(_, token::Ident(s, _)) => s.to_string(), + TokenTree::Token(_, token::Ident(s)) => s.to_string(), _ => { cx.span_err(sp, "argument should be a single identifier"); return DummyResult::any(sp); -- cgit 1.4.1-3-g733a5 From 923001ebb7980ec425e6df561575bccaf5f90240 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 16 Apr 2016 21:53:40 +0300 Subject: Add tests --- src/test/compile-fail/qualified-path-params-2.rs | 31 ++++++++++++++++++++++ src/test/compile-fail/qualified-path-params.rs | 33 ++++++++++++++++++++++++ src/test/compile-fail/use-keyword.rs | 23 +++++++++++++++++ src/test/run-pass/use-keyword-2.rs | 30 +++++++++++++++++++++ 4 files changed, 117 insertions(+) create mode 100644 src/test/compile-fail/qualified-path-params-2.rs create mode 100644 src/test/compile-fail/qualified-path-params.rs create mode 100644 src/test/compile-fail/use-keyword.rs create mode 100644 src/test/run-pass/use-keyword-2.rs (limited to 'src/test') diff --git a/src/test/compile-fail/qualified-path-params-2.rs b/src/test/compile-fail/qualified-path-params-2.rs new file mode 100644 index 00000000000..5c661bfcdc0 --- /dev/null +++ b/src/test/compile-fail/qualified-path-params-2.rs @@ -0,0 +1,31 @@ +// Copyright 2016 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. + +// Check that qualified paths with type parameters +// fail during type checking and not during parsing + +struct S; + +trait Tr { + type A; +} + +impl Tr for S { + type A = S; +} + +impl S { + fn f() {} +} + +type A = ::A::f; //~ ERROR type parameters are not allowed on this type +//~^ ERROR ambiguous associated type; specify the type using the syntax `<::A as Trait>::f` + +fn main() {} diff --git a/src/test/compile-fail/qualified-path-params.rs b/src/test/compile-fail/qualified-path-params.rs new file mode 100644 index 00000000000..002080f4cb4 --- /dev/null +++ b/src/test/compile-fail/qualified-path-params.rs @@ -0,0 +1,33 @@ +// Copyright 2016 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. + +// Check that qualified paths with type parameters +// fail during type checking and not during parsing + +struct S; + +trait Tr { + type A; +} + +impl Tr for S { + type A = S; +} + +impl S { + fn f() {} +} + +fn main() { + match 10 { + ::A::f:: => {} //~ ERROR `f` is not an associated const + 0 ... ::A::f:: => {} //~ ERROR only char and numeric types are allowed in range + } +} diff --git a/src/test/compile-fail/use-keyword.rs b/src/test/compile-fail/use-keyword.rs new file mode 100644 index 00000000000..040db025567 --- /dev/null +++ b/src/test/compile-fail/use-keyword.rs @@ -0,0 +1,23 @@ +// Copyright 2016 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. + +// Check that imports with nakes super and self don't fail during parsing +// FIXME: this shouldn't fail during name resolution either + +mod a { + mod b { + use self as A; //~ ERROR `self` imports are only allowed within a { } list + //~^ ERROR unresolved import `self`. There is no `self` in the crate root + use super as B; //~ ERROR unresolved import `super`. There is no `super` in the crate root + use super::{self as C}; //~ERROR unresolved import `super`. There is no `super` in the crate + } +} + +fn main() {} diff --git a/src/test/run-pass/use-keyword-2.rs b/src/test/run-pass/use-keyword-2.rs new file mode 100644 index 00000000000..60016f59594 --- /dev/null +++ b/src/test/run-pass/use-keyword-2.rs @@ -0,0 +1,30 @@ +// Copyright 2016 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. + +pub struct A; + +mod test { + pub use super :: A; + + pub use self :: A as B; +} + +impl A { + fn f() {} + fn g() { + Self :: f() + } +} + +fn main() { + let a: A = test::A; + let b: A = test::B; + let c: () = A::g(); +} -- cgit 1.4.1-3-g733a5 From 6c44bea64435fd3859439a6ecab7758855a13f07 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 19 Apr 2016 00:42:18 +0300 Subject: syntax: Check paths in visibilities for type parameters syntax: Merge PathParsingMode::NoTypesAllowed and PathParsingMode::ImportPrefix syntax: Rename PathParsingMode and its variants to better express their purpose syntax: Remove obsolete error message about 'self lifetime syntax: Remove ALLOW_MODULE_PATHS workaround syntax/resolve: Adjust some error messages resolve: Compare unhygienic (not renamed) names with keywords::Invalid, invalid identifiers may appear to be valid after renaming --- src/librustc_resolve/build_reduced_graph.rs | 5 +- src/librustc_resolve/lib.rs | 10 +- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/ext/quote.rs | 11 +- src/libsyntax/ext/tt/macro_parser.rs | 4 +- src/libsyntax/feature_gate.rs | 14 ++- src/libsyntax/parse/lexer/mod.rs | 14 +-- src/libsyntax/parse/parser.rs | 121 ++++++++++----------- src/test/compile-fail/import-ty-params.rs | 2 +- .../compile-fail/privacy/restricted/ty-params.rs | 20 ++++ src/test/compile-fail/self_type_keyword.rs | 2 +- src/test/parse-fail/issue-10412.rs | 14 +-- src/test/parse-fail/lifetime-no-keyword.rs | 3 +- src/test/parse-fail/lifetime-obsoleted-self.rs | 15 --- 14 files changed, 121 insertions(+), 116 deletions(-) create mode 100644 src/test/compile-fail/privacy/restricted/ty-params.rs delete mode 100644 src/test/parse-fail/lifetime-obsoleted-self.rs (limited to 'src/test') diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index f92673b781e..ed473da1917 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -112,15 +112,14 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> { !segment.parameters.bindings().is_empty() }); if found_param { - self.session.span_err(path.span, - "type or lifetime parameter is found in import path"); + self.session.span_err(path.span, "type or lifetime parameters in import path"); } // Checking for special identifiers in path // prevent `self` or `super` at beginning of global path if path.global && path.segments.len() > 0 { let first = path.segments[0].identifier.name; - if first == keywords::Super.ident.name || first == keywords::SelfValue.ident.name { + if first == keywords::Super.name() || first == keywords::SelfValue.name() { self.session.add_lint( lint::builtin::SUPER_OR_SELF_IN_GLOBAL_PATH, id, path.span, format!("expected identifier, found keyword `{}`", first) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index bc09cfdb583..293b4de71fa 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -62,7 +62,7 @@ use syntax::ast::{CRATE_NODE_ID, Name, NodeId, CrateNum, IntTy, UintTy}; use syntax::attr::AttrMetaMethods; use syntax::codemap::{self, Span, Pos}; use syntax::errors::DiagnosticBuilder; -use syntax::parse::token::{self, keywords, special_idents}; +use syntax::parse::token::{self, keywords}; use syntax::util::lev_distance::find_best_match_for_name; use rustc::hir::intravisit::{self, FnKind, Visitor}; @@ -1954,7 +1954,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let mut self_type_rib = Rib::new(NormalRibKind); // plain insert (no renaming, types are not currently hygienic....) - self_type_rib.bindings.insert(keywords::SelfType.ident.name, self_def); + self_type_rib.bindings.insert(keywords::SelfType.name(), self_def); self.type_ribs.push(self_type_rib); f(self); if !self.resolved { @@ -2197,7 +2197,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { let is_invalid_self_type_name = path.segments.len() > 0 && maybe_qself.is_none() && path.segments[0].identifier.name == - keywords::SelfType.ident.name; + keywords::SelfType.name(); if is_invalid_self_type_name { resolve_error(self, ty.span, @@ -2641,7 +2641,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { namespace: Namespace, record_used: bool) -> Option { - if identifier.name == special_idents::Invalid.name { + if identifier.unhygienic_name == keywords::Invalid.name() { return Some(LocalDef::from_def(Def::Err)); } @@ -3073,7 +3073,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> { }); if method_scope && - &path_name[..] == keywords::SelfValue.ident.name.as_str() { + &path_name[..] == keywords::SelfValue.name().as_str() { resolve_error(self, expr.span, ResolutionError::SelfNotAvailableInStaticMethod); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index dd6e9a1e4a6..001db0b13ca 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1486,7 +1486,7 @@ mod tests { use ext::mtwt; use fold::Folder; use parse; - use parse::token; + use parse::token::{self, keywords}; use util::parser_testing::{string_to_parser}; use util::parser_testing::{string_to_pat, string_to_crate, strs_to_idents}; use visit; diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 9734b49ba7c..ee9a197ce56 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -13,7 +13,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::base; use ext::build::AstBuilder; -use parse::parser::{Parser, PathParsingMode}; +use parse::parser::{Parser, PathStyle}; use parse::token::*; use parse::token; use ptr::P; @@ -401,7 +401,7 @@ pub fn parse_meta_item_panic(parser: &mut Parser) -> P { panictry!(parser.parse_meta_item()) } -pub fn parse_path_panic(parser: &mut Parser, mode: PathParsingMode) -> ast::Path { +pub fn parse_path_panic(parser: &mut Parser, mode: PathStyle) -> ast::Path { panictry!(parser.parse_path(mode)) } @@ -500,7 +500,7 @@ pub fn expand_quote_path(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box { - let mode = mk_parser_path(cx, sp, "LifetimeAndTypesWithoutColons"); + let mode = mk_parser_path(cx, sp, &["PathStyle", "Type"]); let expanded = expand_parse_call(cx, sp, "parse_path_panic", vec!(mode), tts); base::MacEager::expr(expanded) } @@ -557,8 +557,9 @@ fn mk_token_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { cx.expr_path(cx.path_global(sp, idents)) } -fn mk_parser_path(cx: &ExtCtxt, sp: Span, name: &str) -> P { - let idents = vec!(id_ext("syntax"), id_ext("parse"), id_ext("parser"), id_ext(name)); +fn mk_parser_path(cx: &ExtCtxt, sp: Span, names: &[&str]) -> P { + let mut idents = vec![id_ext("syntax"), id_ext("parse"), id_ext("parser")]; + idents.extend(names.iter().cloned().map(id_ext)); cx.expr_path(cx.path_global(sp, idents)) } diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index 8b33bbd3700..89ecf02ee4c 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -85,7 +85,7 @@ use codemap; use errors::FatalError; use parse::lexer::*; //resolve bug? use parse::ParseSess; -use parse::parser::{LifetimeAndTypesWithoutColons, Parser}; +use parse::parser::{PathStyle, Parser}; use parse::token::{DocComment, MatchNt, SubstNt}; use parse::token::{Token, Nonterminal}; use parse::token; @@ -546,7 +546,7 @@ pub fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal { } }, "path" => { - token::NtPath(Box::new(panictry!(p.parse_path(LifetimeAndTypesWithoutColons)))) + token::NtPath(Box::new(panictry!(p.parse_path(PathStyle::Type)))) }, "meta" => token::NtMeta(panictry!(p.parse_meta_item())), _ => { diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index d8352430eb9..c77671d89f8 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1168,7 +1168,19 @@ impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> { fn visit_vis(&mut self, vis: &'v ast::Visibility) { let span = match *vis { ast::Visibility::Crate(span) => span, - ast::Visibility::Restricted { ref path, .. } => path.span, + ast::Visibility::Restricted { ref path, .. } => { + // Check for type parameters + let found_param = path.segments.iter().any(|segment| { + !segment.parameters.types().is_empty() || + !segment.parameters.lifetimes().is_empty() || + !segment.parameters.bindings().is_empty() + }); + if found_param { + self.context.span_handler.span_err(path.span, "type or lifetime parameters \ + in visibility path"); + } + path.span + } _ => return, }; self.gate_feature("pub_restricted", span, "`pub(restricted)` syntax is experimental"); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index 265a432ae82..2eda13adcb5 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -13,8 +13,7 @@ use codemap::{BytePos, CharPos, CodeMap, Pos, Span}; use codemap; use errors::{FatalError, Handler, DiagnosticBuilder}; use ext::tt::transcribe::tt_next_token; -use parse::token::str_to_ident; -use parse::token; +use parse::token::{self, keywords, str_to_ident}; use str::char_at; use rustc_unicode::property::Pattern_White_Space; @@ -1229,14 +1228,9 @@ impl<'a> StringReader<'a> { }); let keyword_checking_token = &token::Ident(keyword_checking_ident); let last_bpos = self.last_pos; - if keyword_checking_token.is_keyword(token::keywords::SelfValue) { - self.err_span_(start, - last_bpos, - "invalid lifetime name: 'self is no longer a special \ - lifetime"); - } else if keyword_checking_token.is_any_keyword() && - !keyword_checking_token.is_keyword(token::keywords::Static) { - self.err_span_(start, last_bpos, "invalid lifetime name"); + if keyword_checking_token.is_any_keyword() && + !keyword_checking_token.is_keyword(keywords::Static) { + self.err_span_(start, last_bpos, "lifetimes cannot use keyword names"); } return token::Lifetime(ident); diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3eec497c331..a4d2c5b6110 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -pub use self::PathParsingMode::*; - use abi::{self, Abi}; use ast::BareFnTy; use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier}; @@ -51,7 +49,7 @@ use parse::common::SeqSep; use parse::lexer::{Reader, TokenAndSpan}; use parse::obsolete::{ParserObsoleteMethods, ObsoleteSyntax}; use parse::token::{self, intern, MatchNt, SubstNt, SpecialVarNt, InternedString}; -use parse::token::{keywords, special_idents, SpecialMacroVar}; +use parse::token::{keywords, SpecialMacroVar}; use parse::{new_sub_parser_from_file, ParseSess}; use util::parser::{AssocOp, Fixity}; use print::pprust; @@ -69,26 +67,24 @@ bitflags! { const RESTRICTION_STMT_EXPR = 1 << 0, const RESTRICTION_NO_STRUCT_LITERAL = 1 << 1, const NO_NONINLINE_MOD = 1 << 2, - const ALLOW_MODULE_PATHS = 1 << 3, } } type ItemInfo = (Ident, ItemKind, Option >); -/// How to parse a path. There are four different kinds of paths, all of which +/// How to parse a path. There are three different kinds of paths, all of which /// are parsed somewhat differently. #[derive(Copy, Clone, PartialEq)] -pub enum PathParsingMode { - /// A path with no type parameters; e.g. `foo::bar::Baz` - NoTypesAllowed, - /// Same as `NoTypesAllowed`, but may end with `::{` or `::*`, which are left unparsed - ImportPrefix, +pub enum PathStyle { + /// A path with no type parameters, e.g. `foo::bar::Baz`, used in imports or visibilities. + Mod, /// A path with a lifetime and type parameters, with no double colons - /// before the type parameters; e.g. `foo::bar<'a>::Baz` - LifetimeAndTypesWithoutColons, + /// before the type parameters; e.g. `foo::bar<'a>::Baz`, used in types. + /// Paths using this style can be passed into macros expecting `path` nonterminals. + Type, /// A path with a lifetime and type parameters with double colons before - /// the type parameters; e.g. `foo::bar::<'a>::Baz::` - LifetimeAndTypesWithColons, + /// the type parameters; e.g. `foo::bar::<'a>::Baz::`, used in expressions or patterns. + Expr, } /// How to parse a bound, whether to allow bound modifiers such as `?`. @@ -292,7 +288,7 @@ impl TokenType { match *self { TokenType::Token(ref t) => format!("`{}`", Parser::token_to_string(t)), TokenType::Operator => "an operator".to_string(), - TokenType::Keyword(kw) => format!("`{}`", kw.ident.name), + TokenType::Keyword(kw) => format!("`{}`", kw.name()), } } } @@ -562,7 +558,7 @@ impl<'a> Parser<'a> { } pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> { - self.check_used_keywords(); + self.check_strict_keywords(); self.check_reserved_keywords(); match self.token { token::Ident(i) => { @@ -661,8 +657,8 @@ impl<'a> Parser<'a> { } /// Signal an error if the given string is a strict keyword - pub fn check_used_keywords(&mut self) { - if self.token.is_used_keyword() { + pub fn check_strict_keywords(&mut self) { + if self.token.is_strict_keyword() { let token_str = self.this_token_to_string(); let span = self.span; self.span_err(span, @@ -1164,7 +1160,7 @@ impl<'a> Parser<'a> { } pub fn parse_ty_path(&mut self) -> PResult<'a, TyKind> { - Ok(TyKind::Path(None, self.parse_path(LifetimeAndTypesWithoutColons)?)) + Ok(TyKind::Path(None, self.parse_path(PathStyle::Type)?)) } /// parse a TyKind::BareFn type: @@ -1467,11 +1463,11 @@ impl<'a> Parser<'a> { } else if self.eat_lt() { let (qself, path) = - self.parse_qualified_path(LifetimeAndTypesWithoutColons)?; + self.parse_qualified_path(PathStyle::Type)?; TyKind::Path(Some(qself), path) } else if self.is_path_start() { - let path = self.parse_path(LifetimeAndTypesWithoutColons)?; + let path = self.parse_path(PathStyle::Type)?; if self.check(&token::Not) { // MACRO INVOCATION self.bump(); @@ -1556,7 +1552,7 @@ impl<'a> Parser<'a> { } else { debug!("parse_arg_general ident_to_pat"); let sp = self.last_span; - let spanned = Spanned { span: sp, node: special_idents::Invalid }; + let spanned = Spanned { span: sp, node: keywords::Invalid.ident() }; P(Pat { id: ast::DUMMY_NODE_ID, node: PatKind::Ident(BindingMode::ByValue(Mutability::Immutable), @@ -1724,12 +1720,12 @@ impl<'a> Parser<'a> { /// /// `::a` /// `::F::a::` - pub fn parse_qualified_path(&mut self, mode: PathParsingMode) + pub fn parse_qualified_path(&mut self, mode: PathStyle) -> PResult<'a, (QSelf, ast::Path)> { let span = self.last_span; let self_type = self.parse_ty_sum()?; let mut path = if self.eat_keyword(keywords::As) { - self.parse_path(LifetimeAndTypesWithoutColons)? + self.parse_path(PathStyle::Type)? } else { ast::Path { span: span, @@ -1747,14 +1743,14 @@ impl<'a> Parser<'a> { self.expect(&token::ModSep)?; let segments = match mode { - LifetimeAndTypesWithoutColons => { + PathStyle::Type => { self.parse_path_segments_without_colons()? } - LifetimeAndTypesWithColons => { + PathStyle::Expr => { self.parse_path_segments_with_colons()? } - NoTypesAllowed | ImportPrefix => { - self.parse_path_segments_without_types(mode == ImportPrefix)? + PathStyle::Mod => { + self.parse_path_segments_without_types()? } }; path.segments.extend(segments); @@ -1768,7 +1764,7 @@ impl<'a> Parser<'a> { /// mode. The `mode` parameter determines whether lifetimes, types, and/or /// bounds are permitted and whether `::` must precede type parameter /// groups. - pub fn parse_path(&mut self, mode: PathParsingMode) -> PResult<'a, ast::Path> { + pub fn parse_path(&mut self, mode: PathStyle) -> PResult<'a, ast::Path> { // Check for a whole path... let found = match self.token { token::Interpolated(token::NtPath(_)) => Some(self.bump_and_get()), @@ -1785,14 +1781,14 @@ impl<'a> Parser<'a> { // identifier followed by an optional lifetime and a set of types. // A bound set is a set of type parameter bounds. let segments = match mode { - LifetimeAndTypesWithoutColons => { + PathStyle::Type => { self.parse_path_segments_without_colons()? } - LifetimeAndTypesWithColons => { + PathStyle::Expr => { self.parse_path_segments_with_colons()? } - NoTypesAllowed | ImportPrefix => { - self.parse_path_segments_without_types(mode == ImportPrefix)? + PathStyle::Mod => { + self.parse_path_segments_without_types()? } }; @@ -1907,10 +1903,9 @@ impl<'a> Parser<'a> { } } - /// Examples: /// - `a::b::c` - pub fn parse_path_segments_without_types(&mut self, import_prefix: bool) + pub fn parse_path_segments_without_types(&mut self) -> PResult<'a, Vec> { let mut segments = Vec::new(); loop { @@ -1924,7 +1919,7 @@ impl<'a> Parser<'a> { }); // If we do not see a `::` or see `::{`/`::*`, stop. - if !self.check(&token::ModSep) || import_prefix && self.is_import_coupler() { + if !self.check(&token::ModSep) || self.is_import_coupler() { return Ok(segments); } else { self.bump(); @@ -2256,7 +2251,7 @@ impl<'a> Parser<'a> { _ => { if self.eat_lt() { let (qself, path) = - self.parse_qualified_path(LifetimeAndTypesWithColons)?; + self.parse_qualified_path(PathStyle::Expr)?; hi = path.span.hi; return Ok(self.mk_expr(lo, hi, ExprKind::Path(Some(qself), path), attrs)); } @@ -2338,13 +2333,13 @@ impl<'a> Parser<'a> { } hi = self.last_span.hi; } else if self.token.is_keyword(keywords::Let) { - // Catch this syntax error here, instead of in `check_used_keywords`, so + // Catch this syntax error here, instead of in `check_strict_keywords`, so // that we can explicitly mention that let is not to be used as an expression let mut db = self.fatal("expected expression, found statement (`let`)"); db.note("variable declaration using `let` is a statement"); return Err(db); } else if self.is_path_start() { - let pth = self.parse_path(LifetimeAndTypesWithColons)?; + let pth = self.parse_path(PathStyle::Expr)?; // `!`, as an operator, is prefix, so we know this isn't that if self.check(&token::Not) { @@ -2621,7 +2616,7 @@ impl<'a> Parser<'a> { self.span_err(self.span, &format!("unexpected token: `{}`", actual)); let dot_pos = self.last_span.hi; - e = self.parse_dot_suffix(special_idents::Invalid, + e = self.parse_dot_suffix(keywords::Invalid.ident(), mk_sp(dot_pos, dot_pos), e, lo)?; } @@ -2698,9 +2693,8 @@ impl<'a> Parser<'a> { _ => unreachable!() }; // continue by trying to parse the `:ident` after `$name` - if self.token == token::Colon && self.look_ahead(1, |t| t.is_ident() && - !t.is_used_keyword() && - !t.is_reserved_keyword()) { + if self.token == token::Colon && + self.look_ahead(1, |t| t.is_ident() && !t.is_any_keyword()) { self.bump(); sp = mk_sp(sp.lo, self.span.hi); let nt_kind = self.parse_ident()?; @@ -3578,11 +3572,11 @@ impl<'a> Parser<'a> { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - self.parse_qualified_path(LifetimeAndTypesWithColons)?; + self.parse_qualified_path(PathStyle::Expr)?; (Some(qself), path) } else { // Parse an unqualified path - (None, self.parse_path(LifetimeAndTypesWithColons)?) + (None, self.parse_path(PathStyle::Expr)?) }; let hi = self.last_span.hi; Ok(self.mk_expr(lo, hi, ExprKind::Path(qself, path), None)) @@ -3676,11 +3670,11 @@ impl<'a> Parser<'a> { let (qself, path) = if self.eat_lt() { // Parse a qualified path let (qself, path) = - self.parse_qualified_path(LifetimeAndTypesWithColons)?; + self.parse_qualified_path(PathStyle::Expr)?; (Some(qself), path) } else { // Parse an unqualified path - (None, self.parse_path(LifetimeAndTypesWithColons)?) + (None, self.parse_path(PathStyle::Expr)?) }; match self.token { token::DotDotDot => { @@ -3943,7 +3937,7 @@ impl<'a> Parser<'a> { self.bump(); let id = match self.token { - token::OpenDelim(_) => token::special_idents::Invalid, // no special identifier + token::OpenDelim(_) => keywords::Invalid.ident(), // no special identifier _ => self.parse_ident()?, }; @@ -3955,7 +3949,7 @@ impl<'a> Parser<'a> { _ => { // we only expect an ident if we didn't parse one // above. - let ident_str = if id.name == token::special_idents::Invalid.name { + let ident_str = if id.name == keywords::Invalid.name() { "identifier, " } else { "" @@ -3981,7 +3975,7 @@ impl<'a> Parser<'a> { MacStmtStyle::NoBraces }; - if id.name == token::special_idents::Invalid.name { + if id.name == keywords::Invalid.name() { let mac = P(spanned(lo, hi, Mac_ { path: pth, tts: tts, ctxt: EMPTY_CTXT })); let stmt = StmtKind::Mac(mac, style, attrs.into_thin_attrs()); spanned(lo, hi, stmt) @@ -4611,10 +4605,10 @@ impl<'a> Parser<'a> { fn expect_self_ident(&mut self) -> PResult<'a, ast::Ident> { match self.token { - token::Ident(id) if id.name == keywords::SelfValue.ident.name => { + token::Ident(id) if id.name == keywords::SelfValue.name() => { self.bump(); // The hygiene context of `id` needs to be preserved here, - // so we can't just return `SelfValue.ident`. + // so we can't just return `SelfValue.ident()`. Ok(id) }, _ => { @@ -4699,7 +4693,7 @@ impl<'a> Parser<'a> { self.bump(); } // error case, making bogus self ident: - SelfKind::Value(keywords::SelfValue.ident) + SelfKind::Value(keywords::SelfValue.ident()) } token::Ident(..) => { if self.token.is_keyword(keywords::SelfValue) { @@ -4974,7 +4968,7 @@ impl<'a> Parser<'a> { if delim != token::Brace { self.expect(&token::Semi)? } - Ok((token::special_idents::Invalid, vec![], ast::ImplItemKind::Macro(m))) + Ok((keywords::Invalid.ident(), vec![], ast::ImplItemKind::Macro(m))) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; let ident = self.parse_ident()?; @@ -5069,7 +5063,7 @@ impl<'a> Parser<'a> { self.expect(&token::OpenDelim(token::Brace))?; self.expect(&token::CloseDelim(token::Brace))?; - Ok((special_idents::Invalid, + Ok((keywords::Invalid.ident(), ItemKind::DefaultImpl(unsafety, opt_trait.unwrap()), None)) } else { if opt_trait.is_some() { @@ -5085,7 +5079,7 @@ impl<'a> Parser<'a> { impl_items.push(self.parse_impl_item()?); } - Ok((special_idents::Invalid, + Ok((keywords::Invalid.ident(), ItemKind::Impl(unsafety, polarity, generics, opt_trait, ty, impl_items), Some(attrs))) } @@ -5094,7 +5088,7 @@ impl<'a> Parser<'a> { /// Parse a::B fn parse_trait_ref(&mut self) -> PResult<'a, TraitRef> { Ok(ast::TraitRef { - path: self.parse_path(LifetimeAndTypesWithoutColons)?, + path: self.parse_path(PathStyle::Type)?, ref_id: ast::DUMMY_NODE_ID, }) } @@ -5254,8 +5248,7 @@ impl<'a> Parser<'a> { self.expect(&token::CloseDelim(token::Paren))?; Ok(Visibility::Crate(span)) } else { - let path = self.with_res(Restrictions::ALLOW_MODULE_PATHS, - |this| this.parse_path(NoTypesAllowed))?; + let path = self.parse_path(PathStyle::Mod)?; self.expect(&token::CloseDelim(token::Paren))?; Ok(Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID }) } @@ -5263,7 +5256,7 @@ impl<'a> Parser<'a> { /// Parse defaultness: DEFAULT or nothing fn parse_defaultness(&mut self) -> PResult<'a, Defaultness> { - if self.eat_contextual_keyword(special_idents::Default) { + if self.eat_contextual_keyword(keywords::Default.ident()) { Ok(Defaultness::Default) } else { Ok(Defaultness::Final) @@ -5591,7 +5584,7 @@ impl<'a> Parser<'a> { }; Ok(self.mk_item(lo, last_span.hi, - special_idents::Invalid, + keywords::Invalid.ident(), ItemKind::ForeignMod(m), visibility, attrs)) @@ -5730,7 +5723,7 @@ impl<'a> Parser<'a> { let last_span = self.last_span; let item = self.mk_item(lo, last_span.hi, - token::special_idents::Invalid, + keywords::Invalid.ident(), item_, visibility, attrs); @@ -6021,7 +6014,7 @@ impl<'a> Parser<'a> { let id = if self.token.is_ident() { self.parse_ident()? } else { - token::special_idents::Invalid // no special identifier + keywords::Invalid.ident() // no special identifier }; // eat a matched-delimiter token tree: let delim = self.expect_open_delim()?; @@ -6118,7 +6111,7 @@ impl<'a> Parser<'a> { let items = self.parse_path_list_items()?; Ok(P(spanned(lo, self.span.hi, ViewPathList(prefix, items)))) } else { - let prefix = self.parse_path(ImportPrefix)?; + let prefix = self.parse_path(PathStyle::Mod)?; if self.is_import_coupler() { // `foo::bar::{a, b}` or `foo::bar::*` self.bump(); diff --git a/src/test/compile-fail/import-ty-params.rs b/src/test/compile-fail/import-ty-params.rs index 66d4d6d0621..7344f31535f 100644 --- a/src/test/compile-fail/import-ty-params.rs +++ b/src/test/compile-fail/import-ty-params.rs @@ -20,6 +20,6 @@ macro_rules! import { ($p: path) => (use $p;); } -import! { a::b::c::S } //~ERROR type or lifetime parameter is found in import path +import! { a::b::c::S } //~ERROR type or lifetime parameters in import path fn main() {} diff --git a/src/test/compile-fail/privacy/restricted/ty-params.rs b/src/test/compile-fail/privacy/restricted/ty-params.rs new file mode 100644 index 00000000000..04d8e983304 --- /dev/null +++ b/src/test/compile-fail/privacy/restricted/ty-params.rs @@ -0,0 +1,20 @@ +// Copyright 2016 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. + +#![feature(pub_restricted)] + +macro_rules! m { + ($p: path) => (pub($p) struct Z;) +} + +struct S(T); +m!{ S } //~ ERROR type or lifetime parameters in visibility path + +fn main() {} diff --git a/src/test/compile-fail/self_type_keyword.rs b/src/test/compile-fail/self_type_keyword.rs index b28f48bb105..b9c9d7a389b 100644 --- a/src/test/compile-fail/self_type_keyword.rs +++ b/src/test/compile-fail/self_type_keyword.rs @@ -14,7 +14,7 @@ struct Self; //~^ ERROR expected identifier, found keyword `Self` struct Bar<'Self>; -//~^ ERROR invalid lifetime name +//~^ ERROR lifetimes cannot use keyword names pub fn main() { let Self = 5; diff --git a/src/test/parse-fail/issue-10412.rs b/src/test/parse-fail/issue-10412.rs index b75e7b12bbd..fc2598d1e9d 100644 --- a/src/test/parse-fail/issue-10412.rs +++ b/src/test/parse-fail/issue-10412.rs @@ -11,17 +11,17 @@ // compile-flags: -Z parse-only -Z continue-parse-after-error -trait Serializable<'self, T> { //~ ERROR no longer a special lifetime - fn serialize(val : &'self T) -> Vec ; //~ ERROR no longer a special lifetime - fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR no longer a special lifetime +trait Serializable<'self, T> { //~ ERROR lifetimes cannot use keyword names + fn serialize(val : &'self T) -> Vec ; //~ ERROR lifetimes cannot use keyword names + fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names } -impl<'self> Serializable for &'self str { //~ ERROR no longer a special lifetime - //~^ ERROR no longer a special lifetime - fn serialize(val : &'self str) -> Vec { //~ ERROR no longer a special lifetime +impl<'self> Serializable for &'self str { //~ ERROR lifetimes cannot use keyword names + //~^ ERROR lifetimes cannot use keyword names + fn serialize(val : &'self str) -> Vec { //~ ERROR lifetimes cannot use keyword names vec!(1) } - fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR no longer a special lifetime + fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR lifetimes cannot use keyword names "hi" } } diff --git a/src/test/parse-fail/lifetime-no-keyword.rs b/src/test/parse-fail/lifetime-no-keyword.rs index 84b02e6ba09..9ca81d9918e 100644 --- a/src/test/parse-fail/lifetime-no-keyword.rs +++ b/src/test/parse-fail/lifetime-no-keyword.rs @@ -12,6 +12,7 @@ fn foo<'a>(a: &'a isize) { } fn bar(a: &'static isize) { } -fn baz(a: &'let isize) { } //~ ERROR invalid lifetime name +fn baz(a: &'let isize) { } //~ ERROR lifetimes cannot use keyword names +fn zab(a: &'self isize) { } //~ ERROR lifetimes cannot use keyword names fn main() { } diff --git a/src/test/parse-fail/lifetime-obsoleted-self.rs b/src/test/parse-fail/lifetime-obsoleted-self.rs deleted file mode 100644 index e8b76750eb9..00000000000 --- a/src/test/parse-fail/lifetime-obsoleted-self.rs +++ /dev/null @@ -1,15 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// compile-flags: -Z parse-only - -fn baz(a: &'self isize) { } //~ ERROR invalid lifetime name: 'self is no longer a special lifetime - -fn main() { } -- cgit 1.4.1-3-g733a5 From a97f60ee8618fde7bafe49d79a3ea670758e6a0c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Thu, 21 Apr 2016 02:03:29 +0300 Subject: syntax: Make `is_path_start` precise and improve some error messages about unexpected tokens --- src/libsyntax/parse/parser.rs | 92 ++++++++++++++-------- src/libsyntax/parse/token.rs | 5 ++ src/test/compile-fail/fail-simple.rs | 4 +- src/test/compile-fail/issue-10636-2.rs | 2 +- src/test/compile-fail/issue-31804.rs | 2 +- src/test/compile-fail/macro-context.rs | 2 +- src/test/compile-fail/macro-incomplete-parse.rs | 2 +- src/test/compile-fail/reserved-become.rs | 2 +- src/test/compile-fail/token-error-correct.rs | 4 +- src/test/compile-fail/vec-macro-with-comma-only.rs | 2 +- src/test/parse-fail/issue-14303-path.rs | 2 +- src/test/parse-fail/issue-32505.rs | 2 +- src/test/parse-fail/keyword-abstract.rs | 2 +- src/test/parse-fail/keyword-final.rs | 2 +- src/test/parse-fail/keyword-override.rs | 2 +- src/test/parse-fail/keyword-typeof.rs | 2 +- .../keywords-followed-by-double-colon.rs | 2 +- .../parse-fail/match-arrows-block-then-binop.rs | 2 +- src/test/parse-fail/obsolete-proc.rs | 5 +- src/test/parse-fail/removed-syntax-mode.rs | 2 +- src/test/parse-fail/removed-syntax-mut-vec-expr.rs | 4 +- src/test/parse-fail/removed-syntax-mut-vec-ty.rs | 4 +- .../parse-fail/removed-syntax-uniq-mut-expr.rs | 4 +- src/test/parse-fail/removed-syntax-uniq-mut-ty.rs | 4 +- src/test/parse-fail/unsized2.rs | 5 +- 25 files changed, 88 insertions(+), 73 deletions(-) (limited to 'src/test') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index a4d2c5b6110..7842d9dca53 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -394,6 +394,17 @@ impl<'a> Parser<'a> { Parser::token_to_string(&self.token) } + pub fn this_token_descr(&self) -> String { + let s = self.this_token_to_string(); + if self.token.is_strict_keyword() { + format!("keyword `{}`", s) + } else if self.token.is_reserved_keyword() { + format!("reserved keyword `{}`", s) + } else { + format!("`{}`", s) + } + } + pub fn unexpected_last(&self, t: &token::Token) -> PResult<'a, T> { let token_str = Parser::token_to_string(t); let last_span = self.last_span; @@ -1466,7 +1477,7 @@ impl<'a> Parser<'a> { self.parse_qualified_path(PathStyle::Type)?; TyKind::Path(Some(qself), path) - } else if self.is_path_start() { + } else if self.token.is_path_start() { let path = self.parse_path(PathStyle::Type)?; if self.check(&token::Not) { // MACRO INVOCATION @@ -1485,9 +1496,8 @@ impl<'a> Parser<'a> { // TYPE TO BE INFERRED TyKind::Infer } else { - let this_token_str = self.this_token_to_string(); - let msg = format!("expected type, found `{}`", this_token_str); - return Err(self.fatal(&msg[..])); + let msg = format!("expected type, found {}", self.this_token_descr()); + return Err(self.fatal(&msg)); }; let sp = mk_sp(lo, self.last_span.hi); @@ -1604,12 +1614,12 @@ impl<'a> Parser<'a> { } /// Matches token_lit = LIT_INTEGER | ... - pub fn lit_from_token(&self, tok: &token::Token) -> PResult<'a, LitKind> { - match *tok { + pub fn parse_lit_token(&mut self) -> PResult<'a, LitKind> { + let out = match self.token { token::Interpolated(token::NtExpr(ref v)) => { match v.node { - ExprKind::Lit(ref lit) => { Ok(lit.node.clone()) } - _ => { return self.unexpected_last(tok); } + ExprKind::Lit(ref lit) => { lit.node.clone() } + _ => { return self.unexpected_last(&self.token); } } } token::Literal(lit, suf) => { @@ -1624,13 +1634,13 @@ impl<'a> Parser<'a> { (false, parse::integer_lit(&s.as_str(), suf.as_ref().map(|s| s.as_str()), &self.sess.span_diagnostic, - self.last_span)) + self.span)) } token::Float(s) => { (false, parse::float_lit(&s.as_str(), suf.as_ref().map(|s| s.as_str()), &self.sess.span_diagnostic, - self.last_span)) + self.span)) } token::Str_(s) => { @@ -1652,14 +1662,17 @@ impl<'a> Parser<'a> { }; if suffix_illegal { - let sp = self.last_span; + let sp = self.span; self.expect_no_suffix(sp, &format!("{} literal", lit.short_name()), suf) } - Ok(out) + out } - _ => { return self.unexpected_last(tok); } - } + _ => { return self.unexpected_last(&self.token); } + }; + + self.bump(); + Ok(out) } /// Matches lit = true | false | token_lit @@ -1670,8 +1683,7 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(keywords::False) { LitKind::Bool(false) } else { - let token = self.bump_and_get(); - let lit = self.lit_from_token(&token)?; + let lit = self.parse_lit_token()?; lit }; Ok(codemap::Spanned { node: lit, span: mk_sp(lo, self.last_span.hi) }) @@ -2338,7 +2350,7 @@ impl<'a> Parser<'a> { let mut db = self.fatal("expected expression, found statement (`let`)"); db.note("variable declaration using `let` is a statement"); return Err(db); - } else if self.is_path_start() { + } else if self.token.is_path_start() { let pth = self.parse_path(PathStyle::Expr)?; // `!`, as an operator, is prefix, so we know this isn't that @@ -2419,10 +2431,18 @@ impl<'a> Parser<'a> { hi = pth.span.hi; ex = ExprKind::Path(None, pth); } else { - // other literal expression - let lit = self.parse_lit()?; - hi = lit.span.hi; - ex = ExprKind::Lit(P(lit)); + match self.parse_lit() { + Ok(lit) => { + hi = lit.span.hi; + ex = ExprKind::Lit(P(lit)); + } + Err(mut err) => { + err.cancel(); + let msg = format!("expected expression, found {}", + self.this_token_descr()); + return Err(self.fatal(&msg)); + } + } } } } @@ -3567,7 +3587,7 @@ impl<'a> Parser<'a> { } fn parse_pat_range_end(&mut self) -> PResult<'a, P> { - if self.is_path_start() { + if self.token.is_path_start() { let lo = self.span.lo; let (qself, path) = if self.eat_lt() { // Parse a qualified path @@ -3585,12 +3605,6 @@ impl<'a> Parser<'a> { } } - fn is_path_start(&self) -> bool { - (self.token == token::Lt || self.token == token::ModSep - || self.token.is_ident() || self.token.is_path()) - && !self.token.is_keyword(keywords::True) && !self.token.is_keyword(keywords::False) - } - /// Parse a pattern. pub fn parse_pat(&mut self) -> PResult<'a, P> { maybe_whole!(self, NtPat); @@ -3641,7 +3655,7 @@ impl<'a> Parser<'a> { // Parse box pat let subpat = self.parse_pat()?; pat = PatKind::Box(subpat); - } else if self.is_path_start() { + } else if self.token.is_path_start() { // Parse pattern starting with a path if self.token.is_ident() && self.look_ahead(1, |t| *t != token::DotDotDot && *t != token::OpenDelim(token::Brace) && @@ -3731,12 +3745,20 @@ impl<'a> Parser<'a> { } } else { // Try to parse everything else as literal with optional minus - let begin = self.parse_pat_literal_maybe_minus()?; - if self.eat(&token::DotDotDot) { - let end = self.parse_pat_range_end()?; - pat = PatKind::Range(begin, end); - } else { - pat = PatKind::Lit(begin); + match self.parse_pat_literal_maybe_minus() { + Ok(begin) => { + if self.eat(&token::DotDotDot) { + let end = self.parse_pat_range_end()?; + pat = PatKind::Range(begin, end); + } else { + pat = PatKind::Lit(begin); + } + } + Err(mut err) => { + err.cancel(); + let msg = format!("expected pattern, found {}", self.this_token_descr()); + return Err(self.fatal(&msg)); + } } } } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 32078c875be..fcb6c3539db 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -243,6 +243,11 @@ impl Token { self.is_keyword(keywords::Const) } + pub fn is_path_start(&self) -> bool { + self == &ModSep || self == &Lt || self.is_path() || + self.is_path_segment_keyword() || self.is_ident() && !self.is_any_keyword() + } + /// Maps a token to its corresponding binary operator. pub fn to_binop(&self) -> Option { match *self { diff --git a/src/test/compile-fail/fail-simple.rs b/src/test/compile-fail/fail-simple.rs index 97b709592a9..e889d354770 100644 --- a/src/test/compile-fail/fail-simple.rs +++ b/src/test/compile-fail/fail-simple.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. - -// error-pattern:unexpected token fn main() { - panic!(@); + panic!(@); //~ ERROR expected expression, found `@` } diff --git a/src/test/compile-fail/issue-10636-2.rs b/src/test/compile-fail/issue-10636-2.rs index 747252d5924..beaf9e5059f 100644 --- a/src/test/compile-fail/issue-10636-2.rs +++ b/src/test/compile-fail/issue-10636-2.rs @@ -15,4 +15,4 @@ pub fn trace_option(option: Option) { option.map(|some| 42; //~ NOTE: unclosed delimiter //~^ ERROR: expected one of } //~ ERROR: incorrect close delimiter -//~^ ERROR: unexpected token +//~^ ERROR: expected expression, found `)` diff --git a/src/test/compile-fail/issue-31804.rs b/src/test/compile-fail/issue-31804.rs index b6a04bee85d..cea52b11c5d 100644 --- a/src/test/compile-fail/issue-31804.rs +++ b/src/test/compile-fail/issue-31804.rs @@ -13,4 +13,4 @@ fn main() { let -} //~ ERROR unexpected token: `}` +} //~ ERROR expected pattern, found `}` diff --git a/src/test/compile-fail/macro-context.rs b/src/test/compile-fail/macro-context.rs index 8fa5e0a7089..5d07f0747ff 100644 --- a/src/test/compile-fail/macro-context.rs +++ b/src/test/compile-fail/macro-context.rs @@ -12,7 +12,7 @@ // (typeof used because it's surprisingly hard to find an unparsed token after a stmt) macro_rules! m { - () => ( i ; typeof ); //~ ERROR `typeof` is a reserved keyword + () => ( i ; typeof ); //~ ERROR expected expression, found reserved keyword `typeof` //~| ERROR macro expansion ignores token `typeof` //~| ERROR macro expansion ignores token `;` //~| ERROR macro expansion ignores token `;` diff --git a/src/test/compile-fail/macro-incomplete-parse.rs b/src/test/compile-fail/macro-incomplete-parse.rs index 0d5f9079649..8d515622e53 100644 --- a/src/test/compile-fail/macro-incomplete-parse.rs +++ b/src/test/compile-fail/macro-incomplete-parse.rs @@ -19,7 +19,7 @@ macro_rules! ignored_item { } macro_rules! ignored_expr { - () => ( 1, //~ ERROR unexpected token: `,` + () => ( 1, //~ ERROR expected expression, found `,` 2 ) } diff --git a/src/test/compile-fail/reserved-become.rs b/src/test/compile-fail/reserved-become.rs index 82e9ebc10d1..bcda61e363d 100644 --- a/src/test/compile-fail/reserved-become.rs +++ b/src/test/compile-fail/reserved-become.rs @@ -10,5 +10,5 @@ fn main() { let become = 0; - //~^ ERROR `become` is a reserved keyword + //~^ ERROR expected pattern, found reserved keyword `become` } diff --git a/src/test/compile-fail/token-error-correct.rs b/src/test/compile-fail/token-error-correct.rs index 6c54acd7bdb..f5fecf3e174 100644 --- a/src/test/compile-fail/token-error-correct.rs +++ b/src/test/compile-fail/token-error-correct.rs @@ -13,8 +13,10 @@ fn main() { foo(bar(; //~ NOTE: unclosed delimiter //~^ NOTE: unclosed delimiter - //~^^ ERROR: unexpected token: `;` + //~^^ ERROR: expected expression, found `;` //~^^^ ERROR: unresolved name `bar` //~^^^^ ERROR: unresolved name `foo` + //~^^^^^ ERROR: expected one of `)`, `,`, `.`, `<`, `?` } //~ ERROR: incorrect close delimiter: `}` //~^ ERROR: incorrect close delimiter: `}` +//~^^ ERROR: expected expression, found `)` diff --git a/src/test/compile-fail/vec-macro-with-comma-only.rs b/src/test/compile-fail/vec-macro-with-comma-only.rs index 8c8e789cd96..346cf1ec555 100644 --- a/src/test/compile-fail/vec-macro-with-comma-only.rs +++ b/src/test/compile-fail/vec-macro-with-comma-only.rs @@ -9,5 +9,5 @@ // except according to those terms. pub fn main() { - vec!(,); //~ ERROR unexpected token + vec!(,); //~ ERROR expected expression, found `,` } diff --git a/src/test/parse-fail/issue-14303-path.rs b/src/test/parse-fail/issue-14303-path.rs index 7c30b5f2629..431a917c2d9 100644 --- a/src/test/parse-fail/issue-14303-path.rs +++ b/src/test/parse-fail/issue-14303-path.rs @@ -12,4 +12,4 @@ fn bar<'a, T>(x: mymodule::X<'a, T, 'b, 'c>) {} //~^ ERROR lifetime parameters must be declared prior to type parameters -//~^^ ERROR unexpected token +//~^^ ERROR expected pattern, found `'c` diff --git a/src/test/parse-fail/issue-32505.rs b/src/test/parse-fail/issue-32505.rs index e697e98bc06..246941ff259 100644 --- a/src/test/parse-fail/issue-32505.rs +++ b/src/test/parse-fail/issue-32505.rs @@ -11,7 +11,7 @@ // compile-flags: -Z parse-only -Z continue-parse-after-error pub fn test() { - foo(|_|) //~ ERROR unexpected token: `)` + foo(|_|) //~ ERROR expected expression, found `)` } fn main() { } diff --git a/src/test/parse-fail/keyword-abstract.rs b/src/test/parse-fail/keyword-abstract.rs index bd3fbbe79a8..2db5a5c583a 100644 --- a/src/test/parse-fail/keyword-abstract.rs +++ b/src/test/parse-fail/keyword-abstract.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only fn main() { - let abstract = (); //~ ERROR `abstract` is a reserved keyword + let abstract = (); //~ ERROR expected pattern, found reserved keyword `abstract` } diff --git a/src/test/parse-fail/keyword-final.rs b/src/test/parse-fail/keyword-final.rs index 4b06312d099..be29a739443 100644 --- a/src/test/parse-fail/keyword-final.rs +++ b/src/test/parse-fail/keyword-final.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only fn main() { - let final = (); //~ ERROR `final` is a reserved keyword + let final = (); //~ ERROR expected pattern, found reserved keyword `final` } diff --git a/src/test/parse-fail/keyword-override.rs b/src/test/parse-fail/keyword-override.rs index 3f79e437189..60333762b33 100644 --- a/src/test/parse-fail/keyword-override.rs +++ b/src/test/parse-fail/keyword-override.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only fn main() { - let override = (); //~ ERROR `override` is a reserved keyword + let override = (); //~ ERROR expected pattern, found reserved keyword `override` } diff --git a/src/test/parse-fail/keyword-typeof.rs b/src/test/parse-fail/keyword-typeof.rs index 29ec4f5844b..40e26bd375a 100644 --- a/src/test/parse-fail/keyword-typeof.rs +++ b/src/test/parse-fail/keyword-typeof.rs @@ -11,5 +11,5 @@ // compile-flags: -Z parse-only fn main() { - let typeof = (); //~ ERROR `typeof` is a reserved keyword + let typeof = (); //~ ERROR expected pattern, found reserved keyword `typeof` } diff --git a/src/test/parse-fail/keywords-followed-by-double-colon.rs b/src/test/parse-fail/keywords-followed-by-double-colon.rs index 5e27d3e4f38..bb8a1dfdb19 100644 --- a/src/test/parse-fail/keywords-followed-by-double-colon.rs +++ b/src/test/parse-fail/keywords-followed-by-double-colon.rs @@ -12,5 +12,5 @@ fn main() { struct::foo(); //~ ERROR expected identifier - mut::baz(); //~ ERROR expected identifier + mut::baz(); //~ ERROR expected expression, found keyword `mut` } diff --git a/src/test/parse-fail/match-arrows-block-then-binop.rs b/src/test/parse-fail/match-arrows-block-then-binop.rs index 3026e159a44..e8cfb77f059 100644 --- a/src/test/parse-fail/match-arrows-block-then-binop.rs +++ b/src/test/parse-fail/match-arrows-block-then-binop.rs @@ -14,6 +14,6 @@ fn main() { match 0 { 0 => { - } + 5 //~ ERROR unexpected token: `+` + } + 5 //~ ERROR expected pattern, found `+` } } diff --git a/src/test/parse-fail/obsolete-proc.rs b/src/test/parse-fail/obsolete-proc.rs index 1ef8cd2714d..648c46d246c 100644 --- a/src/test/parse-fail/obsolete-proc.rs +++ b/src/test/parse-fail/obsolete-proc.rs @@ -12,9 +12,8 @@ // Test that we generate obsolete syntax errors around usages of `proc`. -fn foo(p: proc()) { } //~ ERROR `proc` is a reserved keyword +fn foo(p: proc()) { } //~ ERROR expected type, found reserved keyword `proc` -fn bar() { proc() 1; } //~ ERROR `proc` is a reserved keyword - //~^ ERROR expected +fn bar() { proc() 1; } //~ ERROR expected expression, found reserved keyword `proc` fn main() { } diff --git a/src/test/parse-fail/removed-syntax-mode.rs b/src/test/parse-fail/removed-syntax-mode.rs index 4dafc36e912..6e99f8b3eea 100644 --- a/src/test/parse-fail/removed-syntax-mode.rs +++ b/src/test/parse-fail/removed-syntax-mode.rs @@ -10,4 +10,4 @@ // compile-flags: -Z parse-only -fn f(+x: isize) {} //~ ERROR unexpected token: `+` +fn f(+x: isize) {} //~ ERROR expected pattern, found `+` diff --git a/src/test/parse-fail/removed-syntax-mut-vec-expr.rs b/src/test/parse-fail/removed-syntax-mut-vec-expr.rs index 301bd0e8b1c..7e5bd27b497 100644 --- a/src/test/parse-fail/removed-syntax-mut-vec-expr.rs +++ b/src/test/parse-fail/removed-syntax-mut-vec-expr.rs @@ -11,7 +11,5 @@ // compile-flags: -Z parse-only fn f() { - let v = [mut 1, 2, 3, 4]; - //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `!`, `,`, `.`, `::`, `;`, `?`, `]`, `{`, or an operator, found `1` + let v = [mut 1, 2, 3, 4]; //~ ERROR expected expression, found keyword `mut` } diff --git a/src/test/parse-fail/removed-syntax-mut-vec-ty.rs b/src/test/parse-fail/removed-syntax-mut-vec-ty.rs index 91918f01bb0..0cdf1981a23 100644 --- a/src/test/parse-fail/removed-syntax-mut-vec-ty.rs +++ b/src/test/parse-fail/removed-syntax-mut-vec-ty.rs @@ -10,6 +10,4 @@ // compile-flags: -Z parse-only -type v = [mut isize]; - //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `]`, found `isize` +type v = [mut isize]; //~ ERROR expected type, found keyword `mut` diff --git a/src/test/parse-fail/removed-syntax-uniq-mut-expr.rs b/src/test/parse-fail/removed-syntax-uniq-mut-expr.rs index 2f637cf0b4e..b16c77ab6b5 100644 --- a/src/test/parse-fail/removed-syntax-uniq-mut-expr.rs +++ b/src/test/parse-fail/removed-syntax-uniq-mut-expr.rs @@ -11,7 +11,5 @@ // compile-flags: -Z parse-only fn f() { - let a_box = box mut 42; - //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `!`, `.`, `::`, `;`, `?`, `{`, or an operator, found `42` + let a_box = box mut 42; //~ ERROR expected expression, found keyword `mut` } diff --git a/src/test/parse-fail/removed-syntax-uniq-mut-ty.rs b/src/test/parse-fail/removed-syntax-uniq-mut-ty.rs index e1637901266..9bd8dc9b11b 100644 --- a/src/test/parse-fail/removed-syntax-uniq-mut-ty.rs +++ b/src/test/parse-fail/removed-syntax-uniq-mut-ty.rs @@ -10,6 +10,4 @@ // compile-flags: -Z parse-only -type mut_box = Box; - //~^ ERROR expected identifier, found keyword `mut` - //~^^ ERROR expected one of `!`, `(`, `+`, `,`, `::`, `<`, or `>`, found `isize` +type mut_box = Box; //~ ERROR expected type, found keyword `mut` diff --git a/src/test/parse-fail/unsized2.rs b/src/test/parse-fail/unsized2.rs index a4a4c0dcfd9..f3af8740be9 100644 --- a/src/test/parse-fail/unsized2.rs +++ b/src/test/parse-fail/unsized2.rs @@ -15,8 +15,5 @@ fn f() {} pub fn main() { - f(); - //~^ ERROR expected identifier, found keyword `type` - //~^^ ERROR: chained comparison - //~^^^ HELP: use `::< + f(); //~ ERROR expected expression, found keyword `type` } -- cgit 1.4.1-3-g733a5 From 4bd44be369c883f1fb2b0645f4de4827066cec57 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 24 Apr 2016 21:35:50 +0300 Subject: Fix keyword parsing tests --- src/etc/generate-keyword-tests.py | 8 +++++--- src/test/compile-fail/keyword-false-as-identifier.rs | 8 ++------ src/test/compile-fail/keyword-true-as-identifier.rs | 8 ++------ src/test/parse-fail/keyword-as-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-box-as-identifier.rs | 15 +++++++++++++++ src/test/parse-fail/keyword-break-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-const-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-continue-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-crate-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-else-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-enum-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-extern-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-fn-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-for-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-if-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-impl-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-in-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-let-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-loop-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-match-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-mod-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-move-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-mut-as-identifier.rs | 6 ++---- src/test/parse-fail/keyword-pub-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-ref-as-identifier.rs | 6 ++---- src/test/parse-fail/keyword-return-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-self-as-identifier.rs | 6 ++---- src/test/parse-fail/keyword-static-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-struct-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-super-as-identifier.rs | 6 ++---- src/test/parse-fail/keyword-trait-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-type-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-unsafe-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-use-as-identifier.rs | 4 ++-- src/test/parse-fail/keyword-where-as-identifier.rs | 17 +++++++++++++++++ src/test/parse-fail/keyword-while-as-identifier.rs | 4 ++-- 36 files changed, 178 insertions(+), 75 deletions(-) create mode 100644 src/test/parse-fail/keyword-box-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-const-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-continue-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-crate-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-in-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-move-as-identifier.rs create mode 100644 src/test/parse-fail/keyword-where-as-identifier.rs (limited to 'src/test') diff --git a/src/etc/generate-keyword-tests.py b/src/etc/generate-keyword-tests.py index 937c231a473..e53d6c718c1 100755 --- a/src/etc/generate-keyword-tests.py +++ b/src/etc/generate-keyword-tests.py @@ -34,15 +34,17 @@ template = """// Copyright %d The Rust Project Developers. See the COPYRIGHT // option. This file may not be copied, modified, or distributed // except according to those terms. +// compile-flags: -Z parse-only + // This file was auto-generated using 'src/etc/generate-keyword-tests.py %s' fn main() { - let %s = "foo"; //~ error: ident + let %s = "foo"; //~ error: expected pattern, found keyword `%s` } """ test_dir = os.path.abspath( - os.path.join(os.path.dirname(__file__), '../test/compile-fail') + os.path.join(os.path.dirname(__file__), '../test/parse-fail') ) for kw in sys.argv[1:]: @@ -53,7 +55,7 @@ for kw in sys.argv[1:]: os.chmod(test_file, stat.S_IWUSR) with open(test_file, 'wt') as f: - f.write(template % (datetime.datetime.now().year, kw, kw)) + f.write(template % (datetime.datetime.now().year, kw, kw, kw)) # mark file read-only os.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) diff --git a/src/test/compile-fail/keyword-false-as-identifier.rs b/src/test/compile-fail/keyword-false-as-identifier.rs index 60caca3da57..e8af94f16b1 100644 --- a/src/test/compile-fail/keyword-false-as-identifier.rs +++ b/src/test/compile-fail/keyword-false-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test -- FIXME #33010 - -// This file was auto-generated using 'src/etc/generate-keyword-tests.py false' - fn main() { - let false = "foo"; //~ error: ident + let false = "foo"; //~ error: mismatched types } diff --git a/src/test/compile-fail/keyword-true-as-identifier.rs b/src/test/compile-fail/keyword-true-as-identifier.rs index 716a0ebf21c..90414fa912d 100644 --- a/src/test/compile-fail/keyword-true-as-identifier.rs +++ b/src/test/compile-fail/keyword-true-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -8,10 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// ignore-test -- FIXME #33010 - -// This file was auto-generated using 'src/etc/generate-keyword-tests.py true' - fn main() { - let true = "foo"; //~ error: ident + let true = "foo"; //~ error: mismatched types } diff --git a/src/test/parse-fail/keyword-as-as-identifier.rs b/src/test/parse-fail/keyword-as-as-identifier.rs index bc05a7c4f25..c6070c456e8 100644 --- a/src/test/parse-fail/keyword-as-as-identifier.rs +++ b/src/test/parse-fail/keyword-as-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py as' fn main() { - let as = "foo"; //~ error: ident + let as = "foo"; //~ error: expected pattern, found keyword `as` } diff --git a/src/test/parse-fail/keyword-box-as-identifier.rs b/src/test/parse-fail/keyword-box-as-identifier.rs new file mode 100644 index 00000000000..b5abe14dbe8 --- /dev/null +++ b/src/test/parse-fail/keyword-box-as-identifier.rs @@ -0,0 +1,15 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +fn main() { + let box = "foo"; //~ error: expected pattern, found `=` +} diff --git a/src/test/parse-fail/keyword-break-as-identifier.rs b/src/test/parse-fail/keyword-break-as-identifier.rs index bd7527f399e..65c775fa1b6 100644 --- a/src/test/parse-fail/keyword-break-as-identifier.rs +++ b/src/test/parse-fail/keyword-break-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py break' fn main() { - let break = "foo"; //~ error: ident + let break = "foo"; //~ error: expected pattern, found keyword `break` } diff --git a/src/test/parse-fail/keyword-const-as-identifier.rs b/src/test/parse-fail/keyword-const-as-identifier.rs new file mode 100644 index 00000000000..6ecf14957e3 --- /dev/null +++ b/src/test/parse-fail/keyword-const-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py const' + +fn main() { + let const = "foo"; //~ error: expected pattern, found keyword `const` +} diff --git a/src/test/parse-fail/keyword-continue-as-identifier.rs b/src/test/parse-fail/keyword-continue-as-identifier.rs new file mode 100644 index 00000000000..87377ac8364 --- /dev/null +++ b/src/test/parse-fail/keyword-continue-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py continue' + +fn main() { + let continue = "foo"; //~ error: expected pattern, found keyword `continue` +} diff --git a/src/test/parse-fail/keyword-crate-as-identifier.rs b/src/test/parse-fail/keyword-crate-as-identifier.rs new file mode 100644 index 00000000000..8a914ca7b17 --- /dev/null +++ b/src/test/parse-fail/keyword-crate-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py crate' + +fn main() { + let crate = "foo"; //~ error: expected pattern, found keyword `crate` +} diff --git a/src/test/parse-fail/keyword-else-as-identifier.rs b/src/test/parse-fail/keyword-else-as-identifier.rs index 24bd18a738f..6878f7fea03 100644 --- a/src/test/parse-fail/keyword-else-as-identifier.rs +++ b/src/test/parse-fail/keyword-else-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py else' fn main() { - let else = "foo"; //~ error: ident + let else = "foo"; //~ error: expected pattern, found keyword `else` } diff --git a/src/test/parse-fail/keyword-enum-as-identifier.rs b/src/test/parse-fail/keyword-enum-as-identifier.rs index e4745270414..042a02d79e0 100644 --- a/src/test/parse-fail/keyword-enum-as-identifier.rs +++ b/src/test/parse-fail/keyword-enum-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py enum' fn main() { - let enum = "foo"; //~ error: ident + let enum = "foo"; //~ error: expected pattern, found keyword `enum` } diff --git a/src/test/parse-fail/keyword-extern-as-identifier.rs b/src/test/parse-fail/keyword-extern-as-identifier.rs index 579cd9f9166..3bbe24ed56c 100644 --- a/src/test/parse-fail/keyword-extern-as-identifier.rs +++ b/src/test/parse-fail/keyword-extern-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py extern' fn main() { - let extern = "foo"; //~ error: ident + let extern = "foo"; //~ error: expected pattern, found keyword `extern` } diff --git a/src/test/parse-fail/keyword-fn-as-identifier.rs b/src/test/parse-fail/keyword-fn-as-identifier.rs index 0ace9ddf1f0..0d454f67d1c 100644 --- a/src/test/parse-fail/keyword-fn-as-identifier.rs +++ b/src/test/parse-fail/keyword-fn-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py fn' fn main() { - let fn = "foo"; //~ error: ident + let fn = "foo"; //~ error: expected pattern, found keyword `fn` } diff --git a/src/test/parse-fail/keyword-for-as-identifier.rs b/src/test/parse-fail/keyword-for-as-identifier.rs index 035c87b80bb..d341669f727 100644 --- a/src/test/parse-fail/keyword-for-as-identifier.rs +++ b/src/test/parse-fail/keyword-for-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py for' fn main() { - let for = "foo"; //~ error: ident + let for = "foo"; //~ error: expected pattern, found keyword `for` } diff --git a/src/test/parse-fail/keyword-if-as-identifier.rs b/src/test/parse-fail/keyword-if-as-identifier.rs index 1aad0a780f9..417e40425e0 100644 --- a/src/test/parse-fail/keyword-if-as-identifier.rs +++ b/src/test/parse-fail/keyword-if-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py if' fn main() { - let if = "foo"; //~ error: ident + let if = "foo"; //~ error: expected pattern, found keyword `if` } diff --git a/src/test/parse-fail/keyword-impl-as-identifier.rs b/src/test/parse-fail/keyword-impl-as-identifier.rs index 585109505d4..fe97c191f68 100644 --- a/src/test/parse-fail/keyword-impl-as-identifier.rs +++ b/src/test/parse-fail/keyword-impl-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py impl' fn main() { - let impl = "foo"; //~ error: ident + let impl = "foo"; //~ error: expected pattern, found keyword `impl` } diff --git a/src/test/parse-fail/keyword-in-as-identifier.rs b/src/test/parse-fail/keyword-in-as-identifier.rs new file mode 100644 index 00000000000..c0f9396b981 --- /dev/null +++ b/src/test/parse-fail/keyword-in-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py in' + +fn main() { + let in = "foo"; //~ error: expected pattern, found keyword `in` +} diff --git a/src/test/parse-fail/keyword-let-as-identifier.rs b/src/test/parse-fail/keyword-let-as-identifier.rs index 07bc7901686..5d6dca78d78 100644 --- a/src/test/parse-fail/keyword-let-as-identifier.rs +++ b/src/test/parse-fail/keyword-let-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py let' fn main() { - let let = "foo"; //~ error: ident + let let = "foo"; //~ error: expected pattern, found keyword `let` } diff --git a/src/test/parse-fail/keyword-loop-as-identifier.rs b/src/test/parse-fail/keyword-loop-as-identifier.rs index 7b2b10a2d6d..7c3d11d67f6 100644 --- a/src/test/parse-fail/keyword-loop-as-identifier.rs +++ b/src/test/parse-fail/keyword-loop-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py loop' fn main() { - let loop = "foo"; //~ error: ident + let loop = "foo"; //~ error: expected pattern, found keyword `loop` } diff --git a/src/test/parse-fail/keyword-match-as-identifier.rs b/src/test/parse-fail/keyword-match-as-identifier.rs index 528873c1794..7c727f44da7 100644 --- a/src/test/parse-fail/keyword-match-as-identifier.rs +++ b/src/test/parse-fail/keyword-match-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py match' fn main() { - let match = "foo"; //~ error: ident + let match = "foo"; //~ error: expected pattern, found keyword `match` } diff --git a/src/test/parse-fail/keyword-mod-as-identifier.rs b/src/test/parse-fail/keyword-mod-as-identifier.rs index b29bcbc76c3..85b4cc2e02c 100644 --- a/src/test/parse-fail/keyword-mod-as-identifier.rs +++ b/src/test/parse-fail/keyword-mod-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py mod' fn main() { - let mod = "foo"; //~ error: ident + let mod = "foo"; //~ error: expected pattern, found keyword `mod` } diff --git a/src/test/parse-fail/keyword-move-as-identifier.rs b/src/test/parse-fail/keyword-move-as-identifier.rs new file mode 100644 index 00000000000..b785ac0058c --- /dev/null +++ b/src/test/parse-fail/keyword-move-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py move' + +fn main() { + let move = "foo"; //~ error: expected pattern, found keyword `move` +} diff --git a/src/test/parse-fail/keyword-mut-as-identifier.rs b/src/test/parse-fail/keyword-mut-as-identifier.rs index b637d07d8b6..0aeca9b34ab 100644 --- a/src/test/parse-fail/keyword-mut-as-identifier.rs +++ b/src/test/parse-fail/keyword-mut-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -// This file was auto-generated using 'src/etc/generate-keyword-tests.py mut' - fn main() { - let mut = "foo"; //~ error: ident + let mut = "foo"; //~ error: expected identifier, found `=` } diff --git a/src/test/parse-fail/keyword-pub-as-identifier.rs b/src/test/parse-fail/keyword-pub-as-identifier.rs index 959bbfbf882..92337286970 100644 --- a/src/test/parse-fail/keyword-pub-as-identifier.rs +++ b/src/test/parse-fail/keyword-pub-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py pub' fn main() { - let pub = "foo"; //~ error: ident + let pub = "foo"; //~ error: expected pattern, found keyword `pub` } diff --git a/src/test/parse-fail/keyword-ref-as-identifier.rs b/src/test/parse-fail/keyword-ref-as-identifier.rs index 3db6d11c2e8..a689c4eeea4 100644 --- a/src/test/parse-fail/keyword-ref-as-identifier.rs +++ b/src/test/parse-fail/keyword-ref-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -// This file was auto-generated using 'src/etc/generate-keyword-tests.py ref' - fn main() { - let ref = "foo"; //~ error: ident + let ref = "foo"; //~ error: expected identifier, found `=` } diff --git a/src/test/parse-fail/keyword-return-as-identifier.rs b/src/test/parse-fail/keyword-return-as-identifier.rs index df8aeba6d71..bcf7f137543 100644 --- a/src/test/parse-fail/keyword-return-as-identifier.rs +++ b/src/test/parse-fail/keyword-return-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py return' fn main() { - let return = "foo"; //~ error: ident + let return = "foo"; //~ error: expected pattern, found keyword `return` } diff --git a/src/test/parse-fail/keyword-self-as-identifier.rs b/src/test/parse-fail/keyword-self-as-identifier.rs index 0e0d07ca6a5..f8b93a1796b 100644 --- a/src/test/parse-fail/keyword-self-as-identifier.rs +++ b/src/test/parse-fail/keyword-self-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -// This file was auto-generated using 'src/etc/generate-keyword-tests.py self' - fn main() { - let self = "foo"; //~ error: ident + let Self = "foo"; //~ error: expected identifier, found keyword `Self` } diff --git a/src/test/parse-fail/keyword-static-as-identifier.rs b/src/test/parse-fail/keyword-static-as-identifier.rs index d5b529af4b8..793262266a3 100644 --- a/src/test/parse-fail/keyword-static-as-identifier.rs +++ b/src/test/parse-fail/keyword-static-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py static' fn main() { - let static = "foo"; //~ error: ident + let static = "foo"; //~ error: expected pattern, found keyword `static` } diff --git a/src/test/parse-fail/keyword-struct-as-identifier.rs b/src/test/parse-fail/keyword-struct-as-identifier.rs index 7d2160dfd29..591bd25db65 100644 --- a/src/test/parse-fail/keyword-struct-as-identifier.rs +++ b/src/test/parse-fail/keyword-struct-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py struct' fn main() { - let struct = "foo"; //~ error: ident + let struct = "foo"; //~ error: expected pattern, found keyword `struct` } diff --git a/src/test/parse-fail/keyword-super-as-identifier.rs b/src/test/parse-fail/keyword-super-as-identifier.rs index 4d866918868..a48683a4f54 100644 --- a/src/test/parse-fail/keyword-super-as-identifier.rs +++ b/src/test/parse-fail/keyword-super-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -10,8 +10,6 @@ // compile-flags: -Z parse-only -// This file was auto-generated using 'src/etc/generate-keyword-tests.py super' - fn main() { - let super = "foo"; //~ error: ident + let super = "foo"; //~ error: expected identifier, found keyword `super` } diff --git a/src/test/parse-fail/keyword-trait-as-identifier.rs b/src/test/parse-fail/keyword-trait-as-identifier.rs index 7a8be0baa27..bdb5d264b03 100644 --- a/src/test/parse-fail/keyword-trait-as-identifier.rs +++ b/src/test/parse-fail/keyword-trait-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py trait' fn main() { - let trait = "foo"; //~ error: ident + let trait = "foo"; //~ error: expected pattern, found keyword `trait` } diff --git a/src/test/parse-fail/keyword-type-as-identifier.rs b/src/test/parse-fail/keyword-type-as-identifier.rs index c76bea89ab4..2ba99d098de 100644 --- a/src/test/parse-fail/keyword-type-as-identifier.rs +++ b/src/test/parse-fail/keyword-type-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py type' fn main() { - let type = "foo"; //~ error: ident + let type = "foo"; //~ error: expected pattern, found keyword `type` } diff --git a/src/test/parse-fail/keyword-unsafe-as-identifier.rs b/src/test/parse-fail/keyword-unsafe-as-identifier.rs index d3c48c6ded0..a72723e566d 100644 --- a/src/test/parse-fail/keyword-unsafe-as-identifier.rs +++ b/src/test/parse-fail/keyword-unsafe-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py unsafe' fn main() { - let unsafe = "foo"; //~ error: ident + let unsafe = "foo"; //~ error: expected pattern, found keyword `unsafe` } diff --git a/src/test/parse-fail/keyword-use-as-identifier.rs b/src/test/parse-fail/keyword-use-as-identifier.rs index d3815c650a3..de74907ff20 100644 --- a/src/test/parse-fail/keyword-use-as-identifier.rs +++ b/src/test/parse-fail/keyword-use-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py use' fn main() { - let use = "foo"; //~ error: ident + let use = "foo"; //~ error: expected pattern, found keyword `use` } diff --git a/src/test/parse-fail/keyword-where-as-identifier.rs b/src/test/parse-fail/keyword-where-as-identifier.rs new file mode 100644 index 00000000000..4b7c8920b13 --- /dev/null +++ b/src/test/parse-fail/keyword-where-as-identifier.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +// compile-flags: -Z parse-only + +// This file was auto-generated using 'src/etc/generate-keyword-tests.py where' + +fn main() { + let where = "foo"; //~ error: expected pattern, found keyword `where` +} diff --git a/src/test/parse-fail/keyword-while-as-identifier.rs b/src/test/parse-fail/keyword-while-as-identifier.rs index 331fdc07cc1..01793caa38a 100644 --- a/src/test/parse-fail/keyword-while-as-identifier.rs +++ b/src/test/parse-fail/keyword-while-as-identifier.rs @@ -1,4 +1,4 @@ -// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -13,5 +13,5 @@ // This file was auto-generated using 'src/etc/generate-keyword-tests.py while' fn main() { - let while = "foo"; //~ error: ident + let while = "foo"; //~ error: expected pattern, found keyword `while` } -- cgit 1.4.1-3-g733a5