From 14c6c119042d2cfbaea0e17e47d2c160261e73ab Mon Sep 17 00:00:00 2001 From: Seiichi Uchida Date: Fri, 6 Oct 2017 19:16:16 +0900 Subject: Add a semicolon to span for ast::Local --- src/libsyntax/parse/parser.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 65dabe98a06..978e06c75dd 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3671,12 +3671,17 @@ impl<'a> Parser<'a> { None }; let init = self.parse_initializer()?; + let hi = if self.token == token::Semi { + self.span + } else { + self.prev_span + }; Ok(P(ast::Local { ty, pat, init, id: ast::DUMMY_NODE_ID, - span: lo.to(self.prev_span), + span: lo.to(hi), attrs, })) } -- cgit 1.4.1-3-g733a5 From 3e4d9df02bf8a801fb6f4903697ec523590210a9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 9 Oct 2017 20:02:17 +0300 Subject: Fix a bug in diagnostics for `x as usize < y` Improve diagnostics for `x as usize << y` --- src/libsyntax/parse/parser.rs | 19 ++++++++++++++++--- src/test/ui/issue-22644.rs | 2 ++ src/test/ui/issue-22644.stderr | 13 +++++++++++-- src/test/ui/issue-44406.rs | 19 +++++++++++++++++++ src/test/ui/issue-44406.stderr | 26 ++++++++++++++++++++++++++ 5 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/issue-44406.rs create mode 100644 src/test/ui/issue-44406.stderr (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 978e06c75dd..ff020445715 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2890,17 +2890,30 @@ impl<'a> Parser<'a> { match self.parse_path(PathStyle::Expr) { Ok(path) => { + let (op_noun, op_verb) = match self.token { + token::Lt => ("comparison", "comparing"), + token::BinOp(token::Shl) => ("shift", "shifting"), + _ => { + // We can end up here even without `<` being the next token, for + // example because `parse_ty_no_plus` returns `Err` on keywords, + // but `parse_path` returns `Ok` on them due to error recovery. + // Return original error and parser state. + mem::replace(self, parser_snapshot_after_type); + return Err(type_err); + } + }; + // Successfully parsed the type path leaving a `<` yet to parse. type_err.cancel(); // Report non-fatal diagnostics, keep `x as usize` as an expression // in AST and continue parsing. let msg = format!("`<` is interpreted as a start of generic \ - arguments for `{}`, not a comparison", path); + arguments for `{}`, not a {}", path, op_noun); let mut err = self.sess.span_diagnostic.struct_span_err(self.span, &msg); err.span_label(self.look_ahead_span(1).to(parser_snapshot_after_type.span), "interpreted as generic arguments"); - err.span_label(self.span, "not interpreted as comparison"); + err.span_label(self.span, format!("not interpreted as {}", op_noun)); let expr = mk_expr(self, P(Ty { span: path.span, @@ -2911,7 +2924,7 @@ impl<'a> Parser<'a> { let expr_str = self.sess.codemap().span_to_snippet(expr.span) .unwrap_or(pprust::expr_to_string(&expr)); err.span_suggestion(expr.span, - "try comparing the casted value", + &format!("try {} the casted value", op_verb), format!("({})", expr_str)); err.emit(); diff --git a/src/test/ui/issue-22644.rs b/src/test/ui/issue-22644.rs index b482d0595f7..c8e0cd1763f 100644 --- a/src/test/ui/issue-22644.rs +++ b/src/test/ui/issue-22644.rs @@ -35,5 +35,7 @@ fn main() { < 5); + println!("{}", a as usize << long_name); + println!("{}", a: &mut 4); } diff --git a/src/test/ui/issue-22644.stderr b/src/test/ui/issue-22644.stderr index 54c325b24a3..f4967c4803b 100644 --- a/src/test/ui/issue-22644.stderr +++ b/src/test/ui/issue-22644.stderr @@ -76,9 +76,18 @@ help: try comparing the casted value 33 | ... +error: `<` is interpreted as a start of generic arguments for `usize`, not a shift + --> $DIR/issue-22644.rs:38:31 + | +38 | println!("{}", a as usize << long_name); + | ---------- ^^ --------- interpreted as generic arguments + | | | + | | not interpreted as shift + | help: try shifting the casted value: `(a as usize)` + error: expected type, found `4` - --> $DIR/issue-22644.rs:38:28 + --> $DIR/issue-22644.rs:40:28 | -38 | println!("{}", a: &mut 4); +40 | println!("{}", a: &mut 4); | ^ expecting a type here because of type ascription diff --git a/src/test/ui/issue-44406.rs b/src/test/ui/issue-44406.rs new file mode 100644 index 00000000000..abf572118fc --- /dev/null +++ b/src/test/ui/issue-44406.rs @@ -0,0 +1,19 @@ +// Copyright 2017 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. + +macro_rules! foo { + ($rest: tt) => { + bar(baz: $rest) + } +} + +fn main() { + foo!(true); +} diff --git a/src/test/ui/issue-44406.stderr b/src/test/ui/issue-44406.stderr new file mode 100644 index 00000000000..e07face24ba --- /dev/null +++ b/src/test/ui/issue-44406.stderr @@ -0,0 +1,26 @@ +error: expected identifier, found keyword `true` + --> $DIR/issue-44406.rs:18:10 + | +18 | foo!(true); + | ^^^^ + +error: expected type, found keyword `true` + --> $DIR/issue-44406.rs:18:10 + | +13 | bar(baz: $rest) + | - help: did you mean to use `;` here? +... +18 | foo!(true); + | ^^^^ expecting a type here because of type ascription + +error: expected one of `!`, `&&`, `&`, `(`, `*`, `.`, `;`, `<`, `?`, `[`, `_`, `extern`, `fn`, `for`, `impl`, `unsafe`, `}`, an operator, or lifetime, found `true` + --> $DIR/issue-44406.rs:18:10 + | +13 | bar(baz: $rest) + | - expected one of 19 possible tokens here +... +18 | foo!(true); + | ^^^^ unexpected token + +error: aborting due to 3 previous errors + -- cgit 1.4.1-3-g733a5 From 72cfd209410da7f9dd09357a3361bb5b561dee33 Mon Sep 17 00:00:00 2001 From: Badel2 <2badel2@gmail.com> Date: Tue, 10 Oct 2017 04:11:22 +0200 Subject: Add error for comma after base struct field `let x = { ..default(), } // This comma is an error` --- src/libsyntax/parse/parser.rs | 11 +++++++++++ src/test/ui/struct-field-init-syntax.rs | 27 +++++++++++++++++++++++++++ src/test/ui/struct-field-init-syntax.stderr | 18 ++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/test/ui/struct-field-init-syntax.rs create mode 100644 src/test/ui/struct-field-init-syntax.stderr (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 978e06c75dd..c1f9b4a7a22 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2314,6 +2314,7 @@ impl<'a> Parser<'a> { while self.token != token::CloseDelim(token::Brace) { if self.eat(&token::DotDot) { + let exp_span = self.prev_span; match self.parse_expr() { Ok(e) => { base = Some(e); @@ -2323,6 +2324,16 @@ impl<'a> Parser<'a> { self.recover_stmt(); } } + if self.token == token::Comma { + let mut err = self.sess.span_diagnostic.mut_span_err( + exp_span.to(self.prev_span), + "cannot use a comma after the base struct", + ); + err.span_suggestion_short(self.span, "remove this comma", "".to_owned()); + err.note("the base struct must always be the last field"); + err.emit(); + self.recover_stmt(); + } break; } diff --git a/src/test/ui/struct-field-init-syntax.rs b/src/test/ui/struct-field-init-syntax.rs new file mode 100644 index 00000000000..8ea62fef9fa --- /dev/null +++ b/src/test/ui/struct-field-init-syntax.rs @@ -0,0 +1,27 @@ +// Copyright 2017 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 + +// issue #41834 + +fn main() { + let foo = Foo { + one: 111, + ..Foo::default(), + //~^ ERROR cannot use a comma after struct expansion + }; + + let foo = Foo { + ..Foo::default(), + //~^ ERROR cannot use a comma after struct expansion + one: 111, + }; +} diff --git a/src/test/ui/struct-field-init-syntax.stderr b/src/test/ui/struct-field-init-syntax.stderr new file mode 100644 index 00000000000..0bca3f83eb1 --- /dev/null +++ b/src/test/ui/struct-field-init-syntax.stderr @@ -0,0 +1,18 @@ +error: cannot use a comma after the base struct + --> $DIR/struct-field-init-syntax.rs:18:9 + | +18 | ..Foo::default(), + | ^^^^^^^^^^^^^^^^- help: remove this comma + | + = note: the base struct must always be the last field + +error: cannot use a comma after the base struct + --> $DIR/struct-field-init-syntax.rs:23:9 + | +23 | ..Foo::default(), + | ^^^^^^^^^^^^^^^^- help: remove this comma + | + = note: the base struct must always be the last field + +error: aborting due to 2 previous errors + -- cgit 1.4.1-3-g733a5 From db91b00065181137fa4a298aeee796ff10755d20 Mon Sep 17 00:00:00 2001 From: Jean Lourenço Date: Sun, 8 Oct 2017 15:01:44 -0300 Subject: output compiler message updated output message is shown in another 'help:' block line with +100 columns formatted test adjusted --- src/libsyntax/parse/parser.rs | 1 + src/test/parse-fail/require-parens-for-chained-comparison.rs | 3 ++- src/test/ui/did_you_mean/issue-40396.stderr | 4 ++++ 3 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 65dabe98a06..0e691624231 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2947,6 +2947,7 @@ impl<'a> Parser<'a> { { // Foo>> err.help( "use `::<...>` instead of `<...>` if you meant to specify type arguments"); + err.help("or use `(...)` if you meant to specify fn arguments"); } err.emit(); } diff --git a/src/test/parse-fail/require-parens-for-chained-comparison.rs b/src/test/parse-fail/require-parens-for-chained-comparison.rs index 7e76dbd31f0..1ee6996ce9c 100644 --- a/src/test/parse-fail/require-parens-for-chained-comparison.rs +++ b/src/test/parse-fail/require-parens-for-chained-comparison.rs @@ -21,5 +21,6 @@ fn main() { f(); //~^ ERROR: chained comparison operators require parentheses - //~^^ HELP: use `::<...>` instead of `<...>` + //~| HELP: use `::<...>` instead of `<...>` + //~| HELP: or use `(...)` } diff --git a/src/test/ui/did_you_mean/issue-40396.stderr b/src/test/ui/did_you_mean/issue-40396.stderr index 1a0c74dc01a..11279f5c612 100644 --- a/src/test/ui/did_you_mean/issue-40396.stderr +++ b/src/test/ui/did_you_mean/issue-40396.stderr @@ -5,6 +5,7 @@ error: chained comparison operators require parentheses | ^^^^^^^^ | = help: use `::<...>` instead of `<...>` if you meant to specify type arguments + = help: or use `(...)` if you meant to specify fn arguments error: chained comparison operators require parentheses --> $DIR/issue-40396.rs:16:25 @@ -13,6 +14,7 @@ error: chained comparison operators require parentheses | ^^^^^^^ | = help: use `::<...>` instead of `<...>` if you meant to specify type arguments + = help: or use `(...)` if you meant to specify fn arguments error: chained comparison operators require parentheses --> $DIR/issue-40396.rs:20:37 @@ -21,6 +23,7 @@ error: chained comparison operators require parentheses | ^^^^^^^^ | = help: use `::<...>` instead of `<...>` if you meant to specify type arguments + = help: or use `(...)` if you meant to specify fn arguments error: chained comparison operators require parentheses --> $DIR/issue-40396.rs:20:41 @@ -29,6 +32,7 @@ error: chained comparison operators require parentheses | ^^^^^^ | = help: use `::<...>` instead of `<...>` if you meant to specify type arguments + = help: or use `(...)` if you meant to specify fn arguments error: aborting due to 4 previous errors -- cgit 1.4.1-3-g733a5 From 19901df00282d11e39bdee8d81b773a5826330fb Mon Sep 17 00:00:00 2001 From: kennytm Date: Thu, 12 Oct 2017 14:53:26 +0800 Subject: Fix typo in libsyntax/parse/lexer/unicode_chars.rs ` (U+0060) should be the "grave" accent, not "Greek" accent. --- src/libsyntax/parse/lexer/unicode_chars.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/lexer/unicode_chars.rs b/src/libsyntax/parse/lexer/unicode_chars.rs index 39b5482a066..35afe8dd56d 100644 --- a/src/libsyntax/parse/lexer/unicode_chars.rs +++ b/src/libsyntax/parse/lexer/unicode_chars.rs @@ -144,7 +144,7 @@ const UNICODE_ARRAY: &'static [(char, &'static str, char)] = &[ ('‵', "Reversed Prime", '\''), ('՚', "Armenian Apostrophe", '\''), ('׳', "Hebrew Punctuation Geresh", '\''), - ('`', "Greek Accent", '\''), + ('`', "Grave Accent", '\''), ('`', "Greek Varia", '\''), ('`', "Fullwidth Grave Accent", '\''), ('´', "Acute Accent", '\''), -- cgit 1.4.1-3-g733a5 From e6115af4bd5f07024e0b73139e1dbcd68c96d9f7 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 10 Oct 2017 17:33:19 +0300 Subject: Implement `dyn Trait` syntax --- src/librustc/hir/lowering.rs | 2 +- src/librustc_passes/ast_validation.rs | 2 +- src/librustc_save_analysis/sig.rs | 2 +- src/libsyntax/ast.rs | 9 ++- src/libsyntax/feature_gate.rs | 7 +++ src/libsyntax/fold.rs | 4 +- src/libsyntax/parse/parser.rs | 66 +++++++++++++--------- src/libsyntax/parse/token.rs | 6 ++ src/libsyntax/print/pprust.rs | 5 +- src/libsyntax/visit.rs | 2 +- src/libsyntax_pos/symbol.rs | 9 +-- src/test/compile-fail/dyn-trait-compatibility.rs | 29 ++++++++++ src/test/compile-fail/feature-gate-dyn-trait.rs | 14 +++++ .../compile-fail/trait-bounds-not-on-struct.rs | 3 + src/test/parse-fail/trait-object-bad-parens.rs | 2 + src/test/run-pass/dyn-trait.rs | 24 ++++++++ src/test/ui/issue-44406.stderr | 4 +- 17 files changed, 149 insertions(+), 41 deletions(-) create mode 100644 src/test/compile-fail/dyn-trait-compatibility.rs create mode 100644 src/test/compile-fail/feature-gate-dyn-trait.rs create mode 100644 src/test/run-pass/dyn-trait.rs (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 64a2ba1fa6f..54aecb4b00f 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -705,7 +705,7 @@ impl<'a> LoweringContext<'a> { let expr = self.lower_body(None, |this| this.lower_expr(expr)); hir::TyTypeof(expr) } - TyKind::TraitObject(ref bounds) => { + TyKind::TraitObject(ref bounds, ..) => { let mut lifetime_bound = None; let bounds = bounds.iter().filter_map(|bound| { match *bound { diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index efb5b031809..14e33378969 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -152,7 +152,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { err.emit(); }); } - TyKind::TraitObject(ref bounds) => { + TyKind::TraitObject(ref bounds, ..) => { let mut any_lifetime_bounds = false; for bound in bounds { if let RegionTyParamBound(ref lifetime) = *bound { diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index c7e00245d63..47e5ad6c010 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -288,7 +288,7 @@ impl Sig for ast::Ty { }) } } - ast::TyKind::TraitObject(ref bounds) => { + ast::TyKind::TraitObject(ref bounds, ..) => { // FIXME recurse into bounds let nested = pprust::bounds_to_string(bounds); Ok(text_sig(nested)) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 021f96aff8c..f445def9e03 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1419,7 +1419,7 @@ pub enum TyKind { Path(Option, Path), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. - TraitObject(TyParamBounds), + TraitObject(TyParamBounds, TraitObjectSyntax), /// An `impl Bound1 + Bound2 + Bound3` type /// where `Bound` is a trait or a lifetime. ImplTrait(TyParamBounds), @@ -1438,6 +1438,13 @@ pub enum TyKind { Err, } +/// Syntax used to declare a trait object. +#[derive(Clone, Copy, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum TraitObjectSyntax { + Dyn, + None, +} + /// Inline assembly dialect. /// /// E.g. `"intel"` as in `asm!("mov eax, 2" : "={eax}"(result) : : : "intel")`` diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index a2f29181a20..9060a613bc1 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -398,6 +398,9 @@ declare_features! ( // Default match binding modes (RFC 2005) (active, match_default_bindings, "1.22.0", Some(42640)), + + // Trait object syntax with `dyn` prefix + (active, dyn_trait, "1.22.0", Some(44662)), ); declare_features! ( @@ -1417,6 +1420,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { gate_feature_post!(&self, never_type, ty.span, "The `!` type is experimental"); }, + ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::Dyn) => { + gate_feature_post!(&self, dyn_trait, ty.span, + "`dyn Trait` syntax is unstable"); + } _ => {} } visit::walk_ty(self, ty) diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 03c47b71d02..d7d491db71f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -400,8 +400,8 @@ pub fn noop_fold_ty(t: P, fld: &mut T) -> P { TyKind::Typeof(expr) => { TyKind::Typeof(fld.fold_expr(expr)) } - TyKind::TraitObject(bounds) => { - TyKind::TraitObject(bounds.move_map(|b| fld.fold_ty_param_bound(b))) + TyKind::TraitObject(bounds, syntax) => { + TyKind::TraitObject(bounds.move_map(|b| fld.fold_ty_param_bound(b)), syntax) } TyKind::ImplTrait(bounds) => { TyKind::ImplTrait(bounds.move_map(|b| fld.fold_ty_param_bound(b))) diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 04e6cdcfe58..bd400ef6dd6 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -33,7 +33,7 @@ use ast::{Stmt, StmtKind}; use ast::{VariantData, StructField}; use ast::StrStyle; use ast::SelfKind; -use ast::{TraitItem, TraitRef}; +use ast::{TraitItem, TraitRef, TraitObjectSyntax}; use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; use ast::{Visibility, WhereClause}; @@ -364,6 +364,13 @@ fn is_ident_or_underscore(t: &token::Token) -> bool { t.is_ident() || *t == token::Underscore } +// Returns true if `IDENT t` can start a type - `IDENT::a::b`, `IDENT`, +// `IDENT<::AssocTy>`, `IDENT(u8, u8) -> u8`. +fn can_continue_type_after_ident(t: &token::Token) -> bool { + t == &token::ModSep || t == &token::Lt || + t == &token::BinOp(token::Shl) || t == &token::OpenDelim(token::Paren) +} + /// Information about the path to a module. pub struct ModulePath { pub name: String, @@ -1428,7 +1435,7 @@ impl<'a> Parser<'a> { TyKind::Path(None, ref path) if maybe_bounds => { self.parse_remaining_bounds(Vec::new(), path.clone(), lo, true)? } - TyKind::TraitObject(ref bounds) + TyKind::TraitObject(ref bounds, TraitObjectSyntax::None) if maybe_bounds && bounds.len() == 1 && !trailing_plus => { let path = match bounds[0] { TraitTyParamBound(ref pt, ..) => pt.trait_ref.path.clone(), @@ -1472,27 +1479,6 @@ impl<'a> Parser<'a> { } else if self.eat(&token::Underscore) { // A type to be inferred `_` TyKind::Infer - } else if self.eat_lt() { - // Qualified path - let (qself, path) = self.parse_qpath(PathStyle::Type)?; - TyKind::Path(Some(qself), path) - } else if self.token.is_path_start() { - // Simple path - let path = self.parse_path(PathStyle::Type)?; - if self.eat(&token::Not) { - // Macro invocation in type position - let (_, tts) = self.expect_delimited_token_tree()?; - TyKind::Mac(respan(lo.to(self.span), Mac_ { path: path, tts: tts })) - } else { - // Just a type path or bound list (trait object type) starting with a trait. - // `Type` - // `Trait1 + Trait2 + 'a` - if allow_plus && self.check(&token::BinOp(token::Plus)) { - self.parse_remaining_bounds(Vec::new(), path, lo, true)? - } else { - TyKind::Path(None, path) - } - } } else if self.token_is_bare_fn_keyword() { // Function pointer type self.parse_ty_bare_fn(Vec::new())? @@ -1512,10 +1498,37 @@ impl<'a> Parser<'a> { } else if self.eat_keyword(keywords::Impl) { // FIXME: figure out priority of `+` in `impl Trait1 + Trait2` (#34511). TyKind::ImplTrait(self.parse_ty_param_bounds()?) + } else if self.check_keyword(keywords::Dyn) && + self.look_ahead(1, |t| t.can_begin_bound() && !can_continue_type_after_ident(t)) { + // FIXME: figure out priority of `+` in `dyn Trait1 + Trait2` (#34511). + self.bump(); // `dyn` + TyKind::TraitObject(self.parse_ty_param_bounds()?, TraitObjectSyntax::Dyn) } else if self.check(&token::Question) || - self.check_lifetime() && self.look_ahead(1, |t| t == &token::BinOp(token::Plus)){ + self.check_lifetime() && self.look_ahead(1, |t| t == &token::BinOp(token::Plus)) { // Bound list (trait object type) - TyKind::TraitObject(self.parse_ty_param_bounds_common(allow_plus)?) + TyKind::TraitObject(self.parse_ty_param_bounds_common(allow_plus)?, + TraitObjectSyntax::None) + } else if self.eat_lt() { + // Qualified path + let (qself, path) = self.parse_qpath(PathStyle::Type)?; + TyKind::Path(Some(qself), path) + } else if self.token.is_path_start() { + // Simple path + let path = self.parse_path(PathStyle::Type)?; + if self.eat(&token::Not) { + // Macro invocation in type position + let (_, tts) = self.expect_delimited_token_tree()?; + TyKind::Mac(respan(lo.to(self.span), Mac_ { path: path, tts: tts })) + } else { + // Just a type path or bound list (trait object type) starting with a trait. + // `Type` + // `Trait1 + Trait2 + 'a` + if allow_plus && self.check(&token::BinOp(token::Plus)) { + self.parse_remaining_bounds(Vec::new(), path, lo, true)? + } else { + TyKind::Path(None, path) + } + } } else { let msg = format!("expected type, found {}", self.this_token_descr()); return Err(self.fatal(&msg)); @@ -1538,7 +1551,7 @@ impl<'a> Parser<'a> { self.bump(); // `+` bounds.append(&mut self.parse_ty_param_bounds()?); } - Ok(TyKind::TraitObject(bounds)) + Ok(TyKind::TraitObject(bounds, TraitObjectSyntax::None)) } fn maybe_recover_from_bad_type_plus(&mut self, allow_plus: bool, ty: &Ty) -> PResult<'a, ()> { @@ -4256,6 +4269,7 @@ impl<'a> Parser<'a> { fn parse_ty_param_bounds_common(&mut self, allow_plus: bool) -> PResult<'a, TyParamBounds> { let mut bounds = Vec::new(); loop { + // This needs to be syncronized with `Token::can_begin_bound`. let is_bound_start = self.check_path() || self.check_lifetime() || self.check(&token::Question) || self.check_keyword(keywords::For) || diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 4888654fac9..20db87cfc82 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -258,6 +258,12 @@ impl Token { } } + /// Returns `true` if the token can appear at the start of a generic bound. + pub fn can_begin_bound(&self) -> bool { + self.is_path_start() || self.is_lifetime() || self.is_keyword(keywords::For) || + self == &Question || self == &OpenDelim(Paren) + } + /// Returns `true` if the token is any literal pub fn is_lit(&self) -> bool { match *self { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 959dd4ef30f..02f871c58c7 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1049,8 +1049,9 @@ impl<'a> State<'a> { ast::TyKind::Path(Some(ref qself), ref path) => { self.print_qpath(path, qself, false)? } - ast::TyKind::TraitObject(ref bounds) => { - self.print_bounds("", &bounds[..])?; + ast::TyKind::TraitObject(ref bounds, syntax) => { + let prefix = if syntax == ast::TraitObjectSyntax::Dyn { "dyn " } else { "" }; + self.print_bounds(prefix, &bounds[..])?; } ast::TyKind::ImplTrait(ref bounds) => { self.print_bounds("impl ", &bounds[..])?; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 05077d42a0b..521c6030eba 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -348,7 +348,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { visitor.visit_ty(ty); visitor.visit_expr(expression) } - TyKind::TraitObject(ref bounds) | + TyKind::TraitObject(ref bounds, ..) | TyKind::ImplTrait(ref bounds) => { walk_list!(visitor, visit_ty_param_bound, bounds); } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 4d3db15ef29..872fc031cfb 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -309,10 +309,11 @@ declare_keywords! { (54, Yield, "yield") // Weak keywords, have special meaning only in specific contexts. - (55, Default, "default") - (56, StaticLifetime, "'static") - (57, Union, "union") - (58, Catch, "catch") + (55, Catch, "catch") + (56, Default, "default") + (57, Dyn, "dyn") + (58, StaticLifetime, "'static") + (59, Union, "union") } // If an interner exists in TLS, return it. Otherwise, prepare a fresh one. diff --git a/src/test/compile-fail/dyn-trait-compatibility.rs b/src/test/compile-fail/dyn-trait-compatibility.rs new file mode 100644 index 00000000000..a7cfda504c7 --- /dev/null +++ b/src/test/compile-fail/dyn-trait-compatibility.rs @@ -0,0 +1,29 @@ +// Copyright 2017 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. + +type A0 = dyn; +//~^ ERROR cannot find type `dyn` in this scope +type A1 = dyn::dyn; +//~^ ERROR Use of undeclared type or module `dyn` +type A2 = dyn; +//~^ ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope +type A3 = dyn<::dyn>; +//~^ ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope +//~| ERROR Use of undeclared type or module `dyn` +type A4 = dyn(dyn, dyn) -> dyn; +//~^ ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope +//~| ERROR cannot find type `dyn` in this scope + +fn main() {} diff --git a/src/test/compile-fail/feature-gate-dyn-trait.rs b/src/test/compile-fail/feature-gate-dyn-trait.rs new file mode 100644 index 00000000000..4b3803d019b --- /dev/null +++ b/src/test/compile-fail/feature-gate-dyn-trait.rs @@ -0,0 +1,14 @@ +// 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. + +trait Trait {} +type A = Box; //~ ERROR `dyn Trait` syntax is unstable + +fn main() {} diff --git a/src/test/compile-fail/trait-bounds-not-on-struct.rs b/src/test/compile-fail/trait-bounds-not-on-struct.rs index cabe0fd48ed..6cd43916731 100644 --- a/src/test/compile-fail/trait-bounds-not-on-struct.rs +++ b/src/test/compile-fail/trait-bounds-not-on-struct.rs @@ -8,9 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(dyn_trait)] struct Foo; fn foo(_x: Box) { } //~ ERROR expected trait, found struct `Foo` +type A = Box>; //~ ERROR expected trait, found struct `Vec` + fn main() { } diff --git a/src/test/parse-fail/trait-object-bad-parens.rs b/src/test/parse-fail/trait-object-bad-parens.rs index a44c0c3f32f..3e8c140eb19 100644 --- a/src/test/parse-fail/trait-object-bad-parens.rs +++ b/src/test/parse-fail/trait-object-bad-parens.rs @@ -17,4 +17,6 @@ fn main() { //~^ ERROR expected a path on the left-hand side of `+`, not `( Copy + Copy)` let _: Box<(Copy +) + Copy>; //~^ ERROR expected a path on the left-hand side of `+`, not `( Copy)` + let _: Box<(dyn Copy) + Copy>; + //~^ ERROR expected a path on the left-hand side of `+`, not `(dyn Copy)` } diff --git a/src/test/run-pass/dyn-trait.rs b/src/test/run-pass/dyn-trait.rs new file mode 100644 index 00000000000..91930852a57 --- /dev/null +++ b/src/test/run-pass/dyn-trait.rs @@ -0,0 +1,24 @@ +// Copyright 2017 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(dyn_trait)] + +use std::fmt::Display; + +static BYTE: u8 = 33; + +fn main() { + let x: &(dyn 'static + Display) = &BYTE; + let y: Box = Box::new(BYTE); + let xstr = format!("{}", x); + let ystr = format!("{}", y); + assert_eq!(xstr, "33"); + assert_eq!(ystr, "33"); +} diff --git a/src/test/ui/issue-44406.stderr b/src/test/ui/issue-44406.stderr index e07face24ba..9beae91540a 100644 --- a/src/test/ui/issue-44406.stderr +++ b/src/test/ui/issue-44406.stderr @@ -13,11 +13,11 @@ error: expected type, found keyword `true` 18 | foo!(true); | ^^^^ expecting a type here because of type ascription -error: expected one of `!`, `&&`, `&`, `(`, `*`, `.`, `;`, `<`, `?`, `[`, `_`, `extern`, `fn`, `for`, `impl`, `unsafe`, `}`, an operator, or lifetime, found `true` +error: expected one of `!`, `&&`, `&`, `(`, `*`, `.`, `;`, `<`, `?`, `[`, `_`, `dyn`, `extern`, `fn`, `for`, `impl`, `unsafe`, `}`, an operator, or lifetime, found `true` --> $DIR/issue-44406.rs:18:10 | 13 | bar(baz: $rest) - | - expected one of 19 possible tokens here + | - expected one of 20 possible tokens here ... 18 | foo!(true); | ^^^^ unexpected token -- cgit 1.4.1-3-g733a5 From 696612c02f7e64b8ca5f62c4614d0cb5b20ff9b7 Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 15 Oct 2017 19:02:45 -0700 Subject: don't issue "expected statement after outer attr." after inner attr. While an inner attribute here is in fact erroneous, that error ("inner attribute is not permitted in this context") successfully gets set earlier; this further admonition is nonsensical. Resolves #45296. --- src/libsyntax/parse/parser.rs | 4 ++-- src/test/ui/issue-45296.rs | 15 +++++++++++++++ src/test/ui/issue-45296.stderr | 11 +++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/issue-45296.rs create mode 100644 src/test/ui/issue-45296.stderr (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index bd400ef6dd6..8fd2bad4e44 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4088,11 +4088,11 @@ impl<'a> Parser<'a> { node: StmtKind::Item(i), }, None => { - let unused_attrs = |attrs: &[_], s: &mut Self| { + let unused_attrs = |attrs: &[Attribute], s: &mut Self| { if !attrs.is_empty() { if s.prev_token_kind == PrevTokenKind::DocComment { s.span_fatal_err(s.prev_span, Error::UselessDocComment).emit(); - } else { + } else if attrs.iter().any(|a| a.style == AttrStyle::Outer) { s.span_err(s.span, "expected statement after outer attribute"); } } diff --git a/src/test/ui/issue-45296.rs b/src/test/ui/issue-45296.rs new file mode 100644 index 00000000000..7a2b4e56d69 --- /dev/null +++ b/src/test/ui/issue-45296.rs @@ -0,0 +1,15 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let unused = (); + + #![allow(unused_variables)] +} diff --git a/src/test/ui/issue-45296.stderr b/src/test/ui/issue-45296.stderr new file mode 100644 index 00000000000..7bfcac974c5 --- /dev/null +++ b/src/test/ui/issue-45296.stderr @@ -0,0 +1,11 @@ +error: an inner attribute is not permitted in this context + --> $DIR/issue-45296.rs:14:7 + | +14 | #![allow(unused_variables)] + | ^ + | + = note: inner attributes and doc comments, like `#![no_std]` or `//! My crate`, annotate the item enclosing them, and are usually found at the beginning of source files. Outer attributes and doc comments, like `#[test]` and + `/// My function`, annotate the item following them. + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From f61394f0bd9c7d5951d2f70207177ff5a6b038fa Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 21 Sep 2017 22:18:47 -0400 Subject: Lifting Generics from MethodSig to TraitItem and ImplItem since we want to support generics in each variant of TraitItem and ImplItem --- src/librustc/hir/lowering.rs | 10 +++++----- src/librustc_resolve/lib.rs | 7 ++++--- src/librustc_save_analysis/dump_visitor.rs | 9 ++++++--- src/librustc_save_analysis/sig.rs | 6 ++++-- src/libsyntax/ast.rs | 3 ++- src/libsyntax/ext/placeholders.rs | 5 +++-- src/libsyntax/fold.rs | 3 ++- src/libsyntax/parse/parser.rs | 32 +++++++++++++++--------------- src/libsyntax/print/pprust.rs | 7 ++++--- src/libsyntax/visit.rs | 6 +++--- src/libsyntax_ext/deriving/generic/mod.rs | 3 ++- 11 files changed, 51 insertions(+), 40 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 54aecb4b00f..f3363bde6e7 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -1548,7 +1548,7 @@ impl<'a> LoweringContext<'a> { } TraitItemKind::Method(ref sig, None) => { let names = this.lower_fn_args_to_names(&sig.decl); - hir::TraitItemKind::Method(this.lower_method_sig(sig), + hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), hir::TraitMethod::Required(names)) } TraitItemKind::Method(ref sig, Some(ref body)) => { @@ -1556,7 +1556,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::TraitItemKind::Method(this.lower_method_sig(sig), + hir::TraitItemKind::Method(this.lower_method_sig(&i.generics, sig), hir::TraitMethod::Provided(body_id)) } TraitItemKind::Type(ref bounds, ref default) => { @@ -1615,7 +1615,7 @@ impl<'a> LoweringContext<'a> { let body = this.lower_block(body, false); this.expr_block(body, ThinVec::new()) }); - hir::ImplItemKind::Method(this.lower_method_sig(sig), body_id) + hir::ImplItemKind::Method(this.lower_method_sig(&i.generics, sig), body_id) } ImplItemKind::Type(ref ty) => hir::ImplItemKind::Type(this.lower_ty(ty)), ImplItemKind::Macro(..) => panic!("Shouldn't exist any more"), @@ -1727,9 +1727,9 @@ impl<'a> LoweringContext<'a> { }) } - fn lower_method_sig(&mut self, sig: &MethodSig) -> hir::MethodSig { + fn lower_method_sig(&mut self, generics: &Generics, sig: &MethodSig) -> hir::MethodSig { hir::MethodSig { - generics: self.lower_generics(&sig.generics), + generics: self.lower_generics(generics), abi: sig.abi, unsafety: self.lower_unsafety(sig.unsafety), constness: self.lower_constness(sig.constness), diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 4aab43cbec7..8d546a66ef5 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -723,7 +723,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { ItemRibKind } FnKind::Method(_, sig, _, _) => { - self.visit_generics(&sig.generics); MethodRibKind(!sig.decl.has_self()) } FnKind::Closure(_) => ClosureRibKind(node_id), @@ -1864,6 +1863,7 @@ impl<'a> Resolver<'a> { for trait_item in trait_items { this.check_proc_macro_attrs(&trait_item.attrs); + this.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { @@ -1880,7 +1880,7 @@ impl<'a> Resolver<'a> { } TraitItemKind::Method(ref sig, _) => { let type_parameters = - HasTypeParameters(&sig.generics, + HasTypeParameters(&trait_item.generics, MethodRibKind(!sig.decl.has_self())); this.with_type_parameter_rib(type_parameters, |this| { visit::walk_trait_item(this, trait_item) @@ -2075,6 +2075,7 @@ impl<'a> Resolver<'a> { this.with_current_self_type(self_type, |this| { for impl_item in impl_items { this.check_proc_macro_attrs(&impl_item.attrs); + this.visit_generics(&impl_item.generics); this.resolve_visibility(&impl_item.vis); match impl_item.node { ImplItemKind::Const(..) => { @@ -2097,7 +2098,7 @@ impl<'a> Resolver<'a> { // We also need a new scope for the method- // specific type parameters. let type_parameters = - HasTypeParameters(&sig.generics, + HasTypeParameters(&impl_item.generics, MethodRibKind(!sig.decl.has_self())); this.with_type_parameter_rib(type_parameters, |this| { visit::walk_impl_item(this, impl_item); diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 3e730cf8365..c57d5305d80 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -354,23 +354,24 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { body: Option<&'l ast::Block>, id: ast::NodeId, name: ast::Ident, + generics: &'l ast::Generics, vis: ast::Visibility, span: Span) { debug!("process_method: {}:{}", id, name); if let Some(mut method_data) = self.save_ctxt.get_method_data(id, name.name, span) { - let sig_str = ::make_signature(&sig.decl, &sig.generics); + let sig_str = ::make_signature(&sig.decl, &generics); if body.is_some() { self.nest_tables(id, |v| { v.process_formals(&sig.decl.inputs, &method_data.qualname) }); } - self.process_generic_params(&sig.generics, span, &method_data.qualname, id); + self.process_generic_params(&generics, span, &method_data.qualname, id); method_data.value = sig_str; - method_data.sig = sig::method_signature(id, name, sig, &self.save_ctxt); + method_data.sig = sig::method_signature(id, name, generics, sig, &self.save_ctxt); self.dumper.dump_def(vis == ast::Visibility::Public, method_data); } @@ -1007,6 +1008,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { body.as_ref().map(|x| &**x), trait_item.id, trait_item.ident, + &trait_item.generics, ast::Visibility::Public, trait_item.span); } @@ -1066,6 +1068,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> { Some(body), impl_item.id, impl_item.ident, + &impl_item.generics, impl_item.vis.clone(), impl_item.span); } diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 47e5ad6c010..88f574d513b 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -77,13 +77,14 @@ pub fn variant_signature(variant: &ast::Variant, scx: &SaveContext) -> Option Option { if !scx.config.signatures { return None; } - make_method_signature(id, ident, m, scx).ok() + make_method_signature(id, ident, generics, m, scx).ok() } pub fn assoc_const_signature(id: NodeId, @@ -895,6 +896,7 @@ fn make_assoc_const_signature(id: NodeId, fn make_method_signature(id: NodeId, ident: ast::Ident, + generics: &ast::Generics, m: &ast::MethodSig, scx: &SaveContext) -> Result { @@ -915,7 +917,7 @@ fn make_method_signature(id: NodeId, let mut sig = name_and_generics(text, 0, - &m.generics, + generics, id, ident, scx)?; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f445def9e03..b985ac78056 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1178,7 +1178,6 @@ pub struct MethodSig { pub constness: Spanned, pub abi: Abi, pub decl: P, - pub generics: Generics, } /// Represents an item declaration within a trait declaration, @@ -1190,6 +1189,7 @@ pub struct TraitItem { pub id: NodeId, pub ident: Ident, pub attrs: Vec, + pub generics: Generics, pub node: TraitItemKind, pub span: Span, /// See `Item::tokens` for what this is @@ -1211,6 +1211,7 @@ pub struct ImplItem { pub vis: Visibility, pub defaultness: Defaultness, pub attrs: Vec, + pub generics: Generics, pub node: ImplItemKind, pub span: Span, /// See `Item::tokens` for what this is diff --git a/src/libsyntax/ext/placeholders.rs b/src/libsyntax/ext/placeholders.rs index 4fc2b92d3cd..2f5b386346b 100644 --- a/src/libsyntax/ext/placeholders.rs +++ b/src/libsyntax/ext/placeholders.rs @@ -32,6 +32,7 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion { let ident = keywords::Invalid.ident(); let attrs = Vec::new(); + let generics = ast::Generics::default(); let vis = ast::Visibility::Inherited; let span = DUMMY_SP; let expr_placeholder = || P(ast::Expr { @@ -49,12 +50,12 @@ pub fn placeholder(kind: ExpansionKind, id: ast::NodeId) -> Expansion { tokens: None, }))), ExpansionKind::TraitItems => Expansion::TraitItems(SmallVector::one(ast::TraitItem { - id, span, ident, attrs, + id, span, ident, attrs, generics, node: ast::TraitItemKind::Macro(mac_placeholder()), tokens: None, })), ExpansionKind::ImplItems => Expansion::ImplItems(SmallVector::one(ast::ImplItem { - id, span, ident, vis, attrs, + id, span, ident, vis, attrs, generics, node: ast::ImplItemKind::Macro(mac_placeholder()), defaultness: ast::Defaultness::Final, tokens: None, diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index d7d491db71f..518386a2ad2 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -943,6 +943,7 @@ pub fn noop_fold_trait_item(i: TraitItem, folder: &mut T) id: folder.new_id(i.id), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), + generics: folder.fold_generics(i.generics), node: match i.node { TraitItemKind::Const(ty, default) => { TraitItemKind::Const(folder.fold_ty(ty), @@ -972,6 +973,7 @@ pub fn noop_fold_impl_item(i: ImplItem, folder: &mut T) vis: folder.fold_vis(i.vis), ident: folder.fold_ident(i.ident), attrs: fold_attrs(i.attrs, folder), + generics: folder.fold_generics(i.generics), defaultness: i.defaultness, node: match i.node { ast::ImplItemKind::Const(ty, expr) => { @@ -1074,7 +1076,6 @@ pub fn noop_fold_foreign_item(ni: ForeignItem, folder: &mut T) -> For pub fn noop_fold_method_sig(sig: MethodSig, folder: &mut T) -> MethodSig { MethodSig { - generics: folder.fold_generics(sig.generics), abi: sig.abi, unsafety: sig.unsafety, constness: sig.constness, diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8fd2bad4e44..b0ed4c4e0ee 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1287,10 +1287,10 @@ impl<'a> Parser<'a> { mut attrs: Vec) -> PResult<'a, TraitItem> { let lo = self.span; - let (name, node) = if self.eat_keyword(keywords::Type) { + let (name, node, generics) = if self.eat_keyword(keywords::Type) { let TyParam {ident, bounds, default, ..} = self.parse_ty_param(vec![])?; self.expect(&token::Semi)?; - (ident, TraitItemKind::Type(bounds, default)) + (ident, TraitItemKind::Type(bounds, default), ast::Generics::default()) } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let ident = self.parse_ident()?; @@ -1305,7 +1305,7 @@ impl<'a> Parser<'a> { self.expect(&token::Semi)?; None }; - (ident, TraitItemKind::Const(ty, default)) + (ident, TraitItemKind::Const(ty, default), ast::Generics::default()) } else if self.token.is_path_start() { // trait item macro. // code copied from parse_macro_use_or_failure... abstraction! @@ -1328,7 +1328,7 @@ impl<'a> Parser<'a> { } let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts }); - (keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac)) + (keywords::Invalid.ident(), ast::TraitItemKind::Macro(mac), ast::Generics::default()) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; @@ -1341,13 +1341,12 @@ impl<'a> Parser<'a> { // definition... p.parse_arg_general(false) })?; - generics.where_clause = self.parse_where_clause()?; + let sig = ast::MethodSig { unsafety, constness, decl: d, - generics, abi, }; @@ -1370,13 +1369,14 @@ impl<'a> Parser<'a> { return Err(self.fatal(&format!("expected `;` or `{{`, found `{}`", token_str))); } }; - (ident, ast::TraitItemKind::Method(sig, body)) + (ident, ast::TraitItemKind::Method(sig, body), generics) }; Ok(TraitItem { id: ast::DUMMY_NODE_ID, ident: name, attrs, + generics, node, span: lo.to(self.prev_span), tokens: None, @@ -4901,12 +4901,12 @@ impl<'a> Parser<'a> { let lo = self.span; let vis = self.parse_visibility(false)?; let defaultness = self.parse_defaultness()?; - let (name, node) = if self.eat_keyword(keywords::Type) { + let (name, node, generics) = if self.eat_keyword(keywords::Type) { let name = self.parse_ident()?; self.expect(&token::Eq)?; let typ = self.parse_ty()?; self.expect(&token::Semi)?; - (name, ast::ImplItemKind::Type(typ)) + (name, ast::ImplItemKind::Type(typ), ast::Generics::default()) } else if self.is_const_item() { self.expect_keyword(keywords::Const)?; let name = self.parse_ident()?; @@ -4915,11 +4915,11 @@ impl<'a> Parser<'a> { self.expect(&token::Eq)?; let expr = self.parse_expr()?; self.expect(&token::Semi)?; - (name, ast::ImplItemKind::Const(typ, expr)) + (name, ast::ImplItemKind::Const(typ, expr), ast::Generics::default()) } else { - let (name, inner_attrs, node) = self.parse_impl_method(&vis, at_end)?; + let (name, inner_attrs, generics, node) = self.parse_impl_method(&vis, at_end)?; attrs.extend(inner_attrs); - (name, node) + (name, node, generics) }; Ok(ImplItem { @@ -4929,6 +4929,7 @@ impl<'a> Parser<'a> { vis, defaultness, attrs, + generics, node, tokens: None, }) @@ -4986,7 +4987,7 @@ impl<'a> Parser<'a> { /// Parse a method or a macro invocation in a trait impl. fn parse_impl_method(&mut self, vis: &Visibility, at_end: &mut bool) - -> PResult<'a, (Ident, Vec, ast::ImplItemKind)> { + -> PResult<'a, (Ident, Vec, ast::Generics, ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // Method macro. @@ -5013,7 +5014,7 @@ impl<'a> Parser<'a> { } let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts }); - Ok((keywords::Invalid.ident(), vec![], ast::ImplItemKind::Macro(mac))) + Ok((keywords::Invalid.ident(), vec![], ast::Generics::default(), ast::ImplItemKind::Macro(mac))) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; let ident = self.parse_ident()?; @@ -5022,8 +5023,7 @@ impl<'a> Parser<'a> { generics.where_clause = self.parse_where_clause()?; *at_end = true; let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; - Ok((ident, inner_attrs, ast::ImplItemKind::Method(ast::MethodSig { - generics, + Ok((ident, inner_attrs, generics, ast::ImplItemKind::Method(ast::MethodSig { abi, unsafety, constness, diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 02f871c58c7..b9a7fa04a06 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1525,6 +1525,7 @@ impl<'a> State<'a> { pub fn print_method_sig(&mut self, ident: ast::Ident, + generics: &ast::Generics, m: &ast::MethodSig, vis: &ast::Visibility) -> io::Result<()> { @@ -1533,7 +1534,7 @@ impl<'a> State<'a> { m.constness.node, m.abi, Some(ident), - &m.generics, + &generics, vis) } @@ -1553,7 +1554,7 @@ impl<'a> State<'a> { if body.is_some() { self.head("")?; } - self.print_method_sig(ti.ident, sig, &ast::Visibility::Inherited)?; + self.print_method_sig(ti.ident, &ti.generics, sig, &ast::Visibility::Inherited)?; if let Some(ref body) = *body { self.nbsp()?; self.print_block_with_attrs(body, &ti.attrs)?; @@ -1592,7 +1593,7 @@ impl<'a> State<'a> { } ast::ImplItemKind::Method(ref sig, ref body) => { self.head("")?; - self.print_method_sig(ii.ident, sig, &ii.vis)?; + self.print_method_sig(ii.ident, &ii.generics, sig, &ii.vis)?; self.nbsp()?; self.print_block_with_attrs(body, &ii.attrs)?; } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 521c6030eba..e74296c06a9 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -543,8 +543,7 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl walk_fn_decl(visitor, declaration); visitor.visit_block(body); } - FnKind::Method(_, sig, _, body) => { - visitor.visit_generics(&sig.generics); + FnKind::Method(_, _, _, body) => { walk_fn_decl(visitor, declaration); visitor.visit_block(body); } @@ -558,13 +557,13 @@ pub fn walk_fn<'a, V>(visitor: &mut V, kind: FnKind<'a>, declaration: &'a FnDecl pub fn walk_trait_item<'a, V: Visitor<'a>>(visitor: &mut V, trait_item: &'a TraitItem) { visitor.visit_ident(trait_item.span, trait_item.ident); walk_list!(visitor, visit_attribute, &trait_item.attrs); + visitor.visit_generics(&trait_item.generics); match trait_item.node { TraitItemKind::Const(ref ty, ref default) => { visitor.visit_ty(ty); walk_list!(visitor, visit_expr, default); } TraitItemKind::Method(ref sig, None) => { - visitor.visit_generics(&sig.generics); walk_fn_decl(visitor, &sig.decl); } TraitItemKind::Method(ref sig, Some(ref body)) => { @@ -585,6 +584,7 @@ pub fn walk_impl_item<'a, V: Visitor<'a>>(visitor: &mut V, impl_item: &'a ImplIt visitor.visit_vis(&impl_item.vis); visitor.visit_ident(impl_item.span, impl_item.ident); walk_list!(visitor, visit_attribute, &impl_item.attrs); + visitor.visit_generics(&impl_item.generics); match impl_item.node { ImplItemKind::Const(ref ty, ref expr) => { visitor.visit_ty(ty); diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 5c1ca19d635..18897047538 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -506,6 +506,7 @@ impl<'a> TraitDef<'a> { vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, attrs: Vec::new(), + generics: Generics::default(), node: ast::ImplItemKind::Type(type_def.to_ty(cx, self.span, type_ident, generics)), tokens: None, } @@ -921,12 +922,12 @@ impl<'a> MethodDef<'a> { ast::ImplItem { id: ast::DUMMY_NODE_ID, attrs: self.attributes.clone(), + generics: fn_generics, span: trait_.span, vis: ast::Visibility::Inherited, defaultness: ast::Defaultness::Final, ident: method_ident, node: ast::ImplItemKind::Method(ast::MethodSig { - generics: fn_generics, abi, unsafety, constness: -- cgit 1.4.1-3-g733a5 From e03447dae36022a0155718a8b089fed1204ac39a Mon Sep 17 00:00:00 2001 From: Sunjay Varma Date: Thu, 21 Sep 2017 22:22:33 -0400 Subject: Fixed tidy errors --- src/libsyntax/parse/parser.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index b0ed4c4e0ee..07fa2a4d1a7 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -4987,7 +4987,8 @@ impl<'a> Parser<'a> { /// Parse a method or a macro invocation in a trait impl. fn parse_impl_method(&mut self, vis: &Visibility, at_end: &mut bool) - -> PResult<'a, (Ident, Vec, ast::Generics, ast::ImplItemKind)> { + -> PResult<'a, (Ident, Vec, ast::Generics, + ast::ImplItemKind)> { // code copied from parse_macro_use_or_failure... abstraction! if self.token.is_path_start() { // Method macro. @@ -5014,7 +5015,8 @@ impl<'a> Parser<'a> { } let mac = respan(lo.to(self.prev_span), Mac_ { path: pth, tts: tts }); - Ok((keywords::Invalid.ident(), vec![], ast::Generics::default(), ast::ImplItemKind::Macro(mac))) + Ok((keywords::Invalid.ident(), vec![], ast::Generics::default(), + ast::ImplItemKind::Macro(mac))) } else { let (constness, unsafety, abi) = self.parse_fn_front_matter()?; let ident = self.parse_ident()?; -- cgit 1.4.1-3-g733a5 From 214b0f229395d4460cbcccf17d07cf687ff83b0a Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Thu, 19 Oct 2017 14:43:47 -0700 Subject: `crate` shorthand visibility modifier With regrets, this breaks rustfmt and rls. This is in the matter of #45388. --- .../language-features/crate-visibility-modifier.md | 20 ++++++++++++++++++++ src/librustc/hir/lowering.rs | 2 +- src/libsyntax/ast.rs | 11 ++++++++++- src/libsyntax/feature_gate.rs | 11 +++++++++++ src/libsyntax/parse/parser.rs | 8 ++++++-- src/libsyntax/print/pprust.rs | 5 ++++- .../feature-gate-crate_visibility_modifier.rs | 18 ++++++++++++++++++ .../privacy/restricted/auxiliary/pub_restricted.rs | 7 ++++++- .../privacy/restricted/private-in-public.rs | 3 +++ src/test/compile-fail/privacy/restricted/test.rs | 2 ++ src/test/parse-fail/issue-20711-2.rs | 2 +- src/test/parse-fail/issue-20711.rs | 2 +- src/test/parse-fail/removed-syntax-static-fn.rs | 2 +- src/test/run-pass/macro-pub-matcher.rs | 14 +++++++++++++- src/tools/toolstate.toml | 4 ++-- 15 files changed, 99 insertions(+), 12 deletions(-) create mode 100644 src/doc/unstable-book/src/language-features/crate-visibility-modifier.md create mode 100644 src/test/compile-fail/feature-gate-crate_visibility_modifier.rs (limited to 'src/libsyntax/parse') diff --git a/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md b/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md new file mode 100644 index 00000000000..11b3ee8edf0 --- /dev/null +++ b/src/doc/unstable-book/src/language-features/crate-visibility-modifier.md @@ -0,0 +1,20 @@ +# `crate_visibility_modifier` + +The tracking issue for this feature is: [#45388] + +[#45388]: https://github.com/rust-lang/rust/issues/45388 + +----- + +The `crate_visibility_modifier` feature allows the `crate` keyword to be used +as a visibility modifier synonymous to `pub(crate)`, indicating that a type +(function, _&c._) is to be visible to the entire enclosing crate, but not to +other crates. + +```rust +#![feature(crate_visibility_modifier)] + +crate struct Foo { + bar: usize, +} +``` diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 848da9637a2..012cc1e4ac1 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -2666,7 +2666,7 @@ impl<'a> LoweringContext<'a> { -> hir::Visibility { match *v { Visibility::Public => hir::Public, - Visibility::Crate(_) => hir::Visibility::Crate, + Visibility::Crate(..) => hir::Visibility::Crate, Visibility::Restricted { ref path, id } => { hir::Visibility::Restricted { path: P(self.lower_path(id, path, ParamMode::Explicit, true)), diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index f445def9e03..1e9ac66d237 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1787,10 +1787,19 @@ impl PolyTraitRef { } } +#[derive(Copy, Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] +pub enum CrateSugar { + /// Source is `pub(crate)` + PubCrate, + + /// Source is (just) `crate` + JustCrate, +} + #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)] pub enum Visibility { Public, - Crate(Span), + Crate(Span, CrateSugar), Restricted { path: P, id: NodeId }, Inherited, } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 9060a613bc1..da1a0107f2f 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -401,6 +401,9 @@ declare_features! ( // Trait object syntax with `dyn` prefix (active, dyn_trait, "1.22.0", Some(44662)), + + // `crate` as visibility modifier, synonymous to `pub(crate)` + (active, crate_visibility_modifier, "1.23.0", Some(45388)), ); declare_features! ( @@ -1582,6 +1585,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { visit::walk_impl_item(self, ii); } + fn visit_vis(&mut self, vis: &'a ast::Visibility) { + if let ast::Visibility::Crate(span, ast::CrateSugar::JustCrate) = *vis { + gate_feature_post!(&self, crate_visibility_modifier, span, + "`crate` visibility modifier is experimental"); + } + visit::walk_vis(self, vis); + } + fn visit_generics(&mut self, g: &'a ast::Generics) { for t in &g.ty_params { if !t.attrs.is_empty() { diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 8fd2bad4e44..c9e9a8edcb8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -36,7 +36,7 @@ use ast::SelfKind; use ast::{TraitItem, TraitRef, TraitObjectSyntax}; use ast::{Ty, TyKind, TypeBinding, TyParam, TyParamBounds}; use ast::{ViewPath, ViewPathGlob, ViewPathList, ViewPathSimple}; -use ast::{Visibility, WhereClause}; +use ast::{Visibility, WhereClause, CrateSugar}; use ast::{BinOpKind, UnOp}; use ast::{RangeEnd, RangeSyntax}; use {ast, attr}; @@ -5325,6 +5325,10 @@ impl<'a> Parser<'a> { pub fn parse_visibility(&mut self, can_take_tuple: bool) -> PResult<'a, Visibility> { maybe_whole!(self, NtVis, |x| x); + if self.eat_keyword(keywords::Crate) { + return Ok(Visibility::Crate(self.prev_span, CrateSugar::JustCrate)); + } + if !self.eat_keyword(keywords::Pub) { return Ok(Visibility::Inherited) } @@ -5338,7 +5342,7 @@ impl<'a> Parser<'a> { // `pub(crate)` self.bump(); // `(` self.bump(); // `crate` - let vis = Visibility::Crate(self.prev_span); + let vis = Visibility::Crate(self.prev_span, CrateSugar::PubCrate); self.expect(&token::CloseDelim(token::Paren))?; // `)` return Ok(vis) } else if self.look_ahead(1, |t| t.is_keyword(keywords::In)) { diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 02f871c58c7..4082cc03f12 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1440,7 +1440,10 @@ impl<'a> State<'a> { pub fn print_visibility(&mut self, vis: &ast::Visibility) -> io::Result<()> { match *vis { ast::Visibility::Public => self.word_nbsp("pub"), - ast::Visibility::Crate(_) => self.word_nbsp("pub(crate)"), + ast::Visibility::Crate(_, sugar) => match sugar { + ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"), + ast::CrateSugar::JustCrate => self.word_nbsp("crate") + } ast::Visibility::Restricted { ref path, .. } => { let path = to_string(|s| s.print_path(path, false, 0, true)); if path == "self" || path == "super" { diff --git a/src/test/compile-fail/feature-gate-crate_visibility_modifier.rs b/src/test/compile-fail/feature-gate-crate_visibility_modifier.rs new file mode 100644 index 00000000000..a2937d6de31 --- /dev/null +++ b/src/test/compile-fail/feature-gate-crate_visibility_modifier.rs @@ -0,0 +1,18 @@ +// Copyright 2017 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. + +crate struct Bender { //~ ERROR `crate` visibility modifier is experimental + earth: bool, + fire: bool, + air: bool, + water: bool, +} + +fn main() {} diff --git a/src/test/compile-fail/privacy/restricted/auxiliary/pub_restricted.rs b/src/test/compile-fail/privacy/restricted/auxiliary/pub_restricted.rs index 82d14ddb502..c4ab96c8456 100644 --- a/src/test/compile-fail/privacy/restricted/auxiliary/pub_restricted.rs +++ b/src/test/compile-fail/privacy/restricted/auxiliary/pub_restricted.rs @@ -8,14 +8,19 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(crate_visibility_modifier)] + pub(crate) struct Crate; + #[derive(Default)] pub struct Universe { pub x: i32, - pub(crate) y: i32 + pub(crate) y: i32, + crate z: i32, } impl Universe { pub fn f(&self) {} pub(crate) fn g(&self) {} + crate fn h(&self) {} } diff --git a/src/test/compile-fail/privacy/restricted/private-in-public.rs b/src/test/compile-fail/privacy/restricted/private-in-public.rs index 0fdfbaa84bb..4d3f5377797 100644 --- a/src/test/compile-fail/privacy/restricted/private-in-public.rs +++ b/src/test/compile-fail/privacy/restricted/private-in-public.rs @@ -8,12 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![feature(crate_visibility_modifier)] + mod foo { struct Priv; mod bar { use foo::Priv; pub(super) fn f(_: Priv) {} pub(crate) fn g(_: Priv) {} //~ ERROR E0446 + crate fn h(_: Priv) {} //~ ERROR E0446 } } diff --git a/src/test/compile-fail/privacy/restricted/test.rs b/src/test/compile-fail/privacy/restricted/test.rs index 2e065ac051b..7f076ebf287 100644 --- a/src/test/compile-fail/privacy/restricted/test.rs +++ b/src/test/compile-fail/privacy/restricted/test.rs @@ -50,8 +50,10 @@ fn main() { let u = Universe::default(); let _ = u.x; let _ = u.y; //~ ERROR private + let _ = u.z; //~ ERROR private u.f(); u.g(); //~ ERROR private + u.h(); //~ ERROR private } mod pathological { diff --git a/src/test/parse-fail/issue-20711-2.rs b/src/test/parse-fail/issue-20711-2.rs index a489864e3f7..3a330d8bee2 100644 --- a/src/test/parse-fail/issue-20711-2.rs +++ b/src/test/parse-fail/issue-20711-2.rs @@ -16,6 +16,6 @@ impl Foo { fn foo() {} #[stable(feature = "rust1", since = "1.0.0")] -} //~ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe` +} //~ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe` fn main() {} diff --git a/src/test/parse-fail/issue-20711.rs b/src/test/parse-fail/issue-20711.rs index d9789d55a6f..cd79fa8be7c 100644 --- a/src/test/parse-fail/issue-20711.rs +++ b/src/test/parse-fail/issue-20711.rs @@ -14,6 +14,6 @@ struct Foo; impl Foo { #[stable(feature = "rust1", since = "1.0.0")] -} //~ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe` +} //~ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe` fn main() {} diff --git a/src/test/parse-fail/removed-syntax-static-fn.rs b/src/test/parse-fail/removed-syntax-static-fn.rs index b4c25a75c90..3b783aa79e2 100644 --- a/src/test/parse-fail/removed-syntax-static-fn.rs +++ b/src/test/parse-fail/removed-syntax-static-fn.rs @@ -15,4 +15,4 @@ struct S; impl S { static fn f() {} } -//~^^ ERROR expected one of `const`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}` +//~^^ ERROR expected one of `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe` diff --git a/src/test/run-pass/macro-pub-matcher.rs b/src/test/run-pass/macro-pub-matcher.rs index d79f4b65b69..32145277252 100644 --- a/src/test/run-pass/macro-pub-matcher.rs +++ b/src/test/run-pass/macro-pub-matcher.rs @@ -9,7 +9,7 @@ // except according to those terms. #![allow(dead_code, unused_imports)] -#![feature(macro_vis_matcher)] +#![feature(macro_vis_matcher, crate_visibility_modifier)] /** Ensure that `:vis` matches can be captured in existing positions, and passed @@ -64,6 +64,18 @@ mod with_pub_restricted { vis_passthru! { pub(crate) use A as I; } } +mod with_crate { + vis_passthru! { crate const A: i32 = 0; } + vis_passthru! { crate enum B {} } + vis_passthru! { crate extern "C" fn c() {} } + vis_passthru! { crate mod d {} } + vis_passthru! { crate static E: i32 = 0; } + vis_passthru! { crate struct F; } + vis_passthru! { crate trait G {} } + vis_passthru! { crate type H = i32; } + vis_passthru! { crate use A as I; } +} + mod garden { mod with_pub_restricted_path { vis_passthru! { pub(in garden) const A: i32 = 0; } diff --git a/src/tools/toolstate.toml b/src/tools/toolstate.toml index e62597c5216..da4d26d78da 100644 --- a/src/tools/toolstate.toml +++ b/src/tools/toolstate.toml @@ -29,7 +29,7 @@ miri = "Broken" clippy = "Compiling" # ping @nrc -rls = "Testing" +rls = "Broken" # ping @nrc -rustfmt = "Testing" +rustfmt = "Broken" -- cgit 1.4.1-3-g733a5