diff --git a/src/libsyntax/feature_gate/check.rs b/src/libsyntax/feature_gate/check.rs index 43a3f45bb06a9..58610d8db7e8d 100644 --- a/src/libsyntax/feature_gate/check.rs +++ b/src/libsyntax/feature_gate/check.rs @@ -652,14 +652,6 @@ 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::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.node { - gate_feature_post!(&self, crate_visibility_modifier, vis.span, - "`crate` visibility modifier is experimental"); - } - visit::walk_vis(self, vis) - } } pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute], @@ -847,6 +839,7 @@ pub fn check_crate(krate: &ast::Crate, gate_all!(const_extern_fn, "`const extern fn` definitions are unstable"); gate_all!(trait_alias, "trait aliases are experimental"); gate_all!(associated_type_bounds, "associated type bounds are unstable"); + gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental"); visit::walk_crate(&mut visitor, krate); } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 2ce0046ca276c..f25224d1e36f5 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1122,6 +1122,7 @@ impl<'a> Parser<'a> { self.expected_tokens.push(TokenType::Keyword(kw::Crate)); if self.is_crate_vis() { self.bump(); // `crate` + self.sess.gated_spans.crate_visibility_modifier.borrow_mut().push(self.prev_span); return Ok(respan(self.prev_span, VisibilityKind::Crate(CrateSugar::JustCrate))); } diff --git a/src/libsyntax/sess.rs b/src/libsyntax/sess.rs index 13f89c3720bb5..58a2f89aca969 100644 --- a/src/libsyntax/sess.rs +++ b/src/libsyntax/sess.rs @@ -34,6 +34,8 @@ crate struct GatedSpans { pub trait_alias: Lock>, /// Spans collected for gating `associated_type_bounds`, e.g. `Iterator`. pub associated_type_bounds: Lock>, + /// Spans collected for gating `crate_visibility_modifier`, e.g. `crate fn`. + pub crate_visibility_modifier: Lock>, } /// Info about a parsing session. diff --git a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs index 0e3f6b168be6b..7517fb280ea78 100644 --- a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs +++ b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs @@ -5,4 +5,7 @@ crate struct Bender { //~ ERROR `crate` visibility modifier is experimental water: bool, } +macro_rules! accept_vis { ($v:vis) => {} } +accept_vis!(crate); //~ ERROR `crate` visibility modifier is experimental + fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr index 1e061eced3660..b317872cea817 100644 --- a/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr +++ b/src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr @@ -7,6 +7,15 @@ LL | crate struct Bender { = note: for more information, see https://github.com/rust-lang/rust/issues/53120 = help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable -error: aborting due to previous error +error[E0658]: `crate` visibility modifier is experimental + --> $DIR/feature-gate-crate_visibility_modifier.rs:9:13 + | +LL | accept_vis!(crate); + | ^^^^^ + | + = note: for more information, see https://github.com/rust-lang/rust/issues/53120 + = help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable + +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0658`.