Remove feature: crate visibility modifier

This commit is contained in:
Jacob Pratt 2022-05-21 13:53:26 -04:00
parent 6970246886
commit 8cece636b2
No known key found for this signature in database
GPG Key ID: B80E19E4662B5AA4
17 changed files with 19 additions and 116 deletions

View File

@ -2566,15 +2566,6 @@ impl PolyTraitRef {
}
}
#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum CrateSugar {
/// Source is `pub(crate)`.
PubCrate,
/// Source is (just) `crate`.
JustCrate,
}
#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Visibility {
pub kind: VisibilityKind,
@ -2585,7 +2576,7 @@ pub struct Visibility {
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum VisibilityKind {
Public,
Crate(CrateSugar),
Crate,
Restricted { path: P<Path>, id: NodeId },
Inherited,
}

View File

@ -1469,7 +1469,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
match &mut visibility.kind {
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
VisibilityKind::Public | VisibilityKind::Crate | VisibilityKind::Inherited => {}
VisibilityKind::Restricted { path, id } => {
vis.visit_path(path);
vis.visit_id(id);

View File

@ -697,18 +697,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
visit::walk_assoc_item(self, i, ctxt)
}
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.kind {
gate_feature_post!(
&self,
crate_visibility_modifier,
vis.span,
"`crate` visibility modifier is experimental"
);
}
visit::walk_vis(self, vis)
}
}
pub fn check_crate(krate: &ast::Crate, sess: &Session) {
@ -770,7 +758,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
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");
gate_all!(decl_macro, "`macro` is experimental");
gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");

View File

@ -403,10 +403,7 @@ impl<'a> State<'a> {
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
match vis.kind {
ast::VisibilityKind::Public => self.word_nbsp("pub"),
ast::VisibilityKind::Crate(sugar) => match sugar {
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
},
ast::VisibilityKind::Crate => self.word_nbsp("pub(crate)"),
ast::VisibilityKind::Restricted { ref path, .. } => {
let path = Self::to_string(|s| s.print_path(path, false, 0));
if path == "self" || path == "super" {

View File

@ -351,8 +351,6 @@ declare_features! (
(active, const_trait_impl, "1.42.0", Some(67792), None),
/// Allows the `?` operator in const contexts.
(active, const_try, "1.56.0", Some(74935), None),
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
(active, crate_visibility_modifier, "1.23.0", Some(53120), None),
/// Allows non-builtin attributes in inner attribute position.
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.

View File

@ -72,6 +72,8 @@ declare_features! (
/// Allows `T: ?const Trait` syntax in bounds.
(removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None,
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")),
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
(removed, crate_visibility_modifier, "1.63.0", Some(53120), None, Some("removed in favor of `pub(crate)`")),
/// Allows using custom attributes (RFC 572).
(removed, custom_attribute, "1.0.0", Some(29642), None,
Some("removed in favor of `#![register_tool]` and `#![register_attr]`")),

View File

@ -1372,17 +1372,11 @@ impl UnreachablePub {
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
let mut err = lint.build(&format!("unreachable `pub` {}", what));
let replacement = if cx.tcx.features().crate_visibility_modifier {
"crate"
} else {
"pub(crate)"
}
.to_owned();
err.span_suggestion(
vis_span,
"consider restricting its visibility",
replacement,
"pub(crate)".to_owned(),
applicability,
);
if exportable {

View File

@ -302,8 +302,7 @@ impl<'a> Parser<'a> {
/// When parsing a statement, would the start of a path be an item?
pub(super) fn is_path_start_item(&mut self) -> bool {
self.is_crate_vis() // no: `crate::b`, yes: `crate $item`
|| self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
|| self.check_auto_or_unsafe_trait_item() // no: `auto::b`, yes: `auto trait X { .. }`
|| self.is_async_fn() // no(2015): `async::b`, yes: `async fn`
|| matches!(self.is_macro_rules_item(), IsMacroRulesItem::Yes{..}) // no: `macro_rules::b`, yes: `macro_rules! mac`

View File

@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::AttrId;
use rustc_ast::DUMMY_NODE_ID;
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern};
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, Extern};
use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacArgsEq, MacDelimiter, Mutability, StrLit};
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
use rustc_ast_pretty::pprust;
@ -1245,12 +1245,8 @@ impl<'a> Parser<'a> {
res
}
fn is_crate_vis(&self) -> bool {
self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
}
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `pub(self)` for `pub(in self)`
/// and `pub(super)` for `pub(in super)`.
/// If the following element can't be a tuple (i.e., it's a function definition), then
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
/// so emit a proper diagnostic.
@ -1258,17 +1254,6 @@ impl<'a> Parser<'a> {
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
maybe_whole!(self, NtVis, |x| x.into_inner());
self.expected_tokens.push(TokenType::Keyword(kw::Crate));
if self.is_crate_vis() {
self.bump(); // `crate`
self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_token.span);
return Ok(Visibility {
span: self.prev_token.span,
kind: VisibilityKind::Crate(CrateSugar::JustCrate),
tokens: None,
});
}
if !self.eat_keyword(kw::Pub) {
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
// keyword to grab a span from for inherited visibility; an empty span at the
@ -1293,10 +1278,9 @@ impl<'a> Parser<'a> {
self.bump(); // `(`
self.bump(); // `crate`
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
let vis = VisibilityKind::Crate(CrateSugar::PubCrate);
return Ok(Visibility {
span: lo.to(self.prev_token.span),
kind: vis,
kind: VisibilityKind::Crate,
tokens: None,
});
} else if self.is_keyword_ahead(1, &[kw::In]) {

View File

@ -249,9 +249,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let parent_scope = &self.parent_scope;
match vis.kind {
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
ast::VisibilityKind::Crate(..) => {
Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))
}
ast::VisibilityKind::Crate => Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id())),
ast::VisibilityKind::Inherited => {
Ok(match self.parent_scope.module.kind {
// Any inherited visibility resolved directly inside an enum or trait

View File

@ -1,20 +0,0 @@
# `crate_visibility_modifier`
The tracking issue for this feature is: [#53120]
[#53120]: https://github.com/rust-lang/rust/issues/53120
-----
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,
}
```

View File

@ -1,8 +0,0 @@
crate struct Bender { //~ ERROR `crate` visibility modifier is experimental
earth: bool,
fire: bool,
air: bool,
water: bool,
}
fn main() {}

View File

@ -1,12 +0,0 @@
error[E0658]: `crate` visibility modifier is experimental
--> $DIR/feature-gate-crate_visibility_modifier.rs:1:1
|
LL | crate struct Bender {
| ^^^^^
|
= note: see issue #53120 <https://github.com/rust-lang/rust/issues/53120> for more information
= help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable
error: aborting due to previous error
For more information about this error, try `rustc --explain E0658`.

View File

@ -861,10 +861,8 @@ fn test_vis() {
// VisibilityKind::Public
assert_eq!(stringify_vis!(pub), "pub ");
// VisibilityKind::Crate
assert_eq!(stringify_vis!(crate), "crate ");
// VisibilityKind::Restricted
assert_eq!(stringify_vis!(pub(crate)), "pub(crate) ");
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");

View File

@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
use VisibilityKind::*;
match (&l.kind, &r.kind) {
(Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
(Public, Public) | (Inherited, Inherited) | (Crate, Crate) => true,
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
_ => false,
}

View File

@ -1361,7 +1361,7 @@ pub(crate) fn format_struct_struct(
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
match vis.kind {
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
ast::VisibilityKind::Crate | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
_ => default_span.lo(),
}
}

View File

@ -1,7 +1,7 @@
use std::borrow::Cow;
use rustc_ast::ast::{
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
VisibilityKind,
};
use rustc_ast::ptr;
@ -46,12 +46,8 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
(VisibilityKind::Public, VisibilityKind::Public)
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
| (
VisibilityKind::Crate(CrateSugar::PubCrate),
VisibilityKind::Crate(CrateSugar::PubCrate),
)
| (
VisibilityKind::Crate(CrateSugar::JustCrate),
VisibilityKind::Crate(CrateSugar::JustCrate),
VisibilityKind::Crate,
VisibilityKind::Crate,
) => true,
_ => false,
}
@ -65,8 +61,7 @@ pub(crate) fn format_visibility(
match vis.kind {
VisibilityKind::Public => Cow::from("pub "),
VisibilityKind::Inherited => Cow::from(""),
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
VisibilityKind::Crate => Cow::from("pub(crate) "),
VisibilityKind::Restricted { ref path, .. } => {
let Path { ref segments, .. } = **path;
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));