Skip to content

Commit b73f1c7

Browse files
authoredMay 23, 2022
Rollup merge of rust-lang#97254 - jhpratt:remove-crate-vis, r=cjgillot
Remove feature: `crate` visibility modifier FCP completed in rust-lang#53120.
2 parents e5cf3cb + 7b987e3 commit b73f1c7

File tree

17 files changed

+19
-136
lines changed

17 files changed

+19
-136
lines changed
 

‎compiler/rustc_ast/src/ast.rs

-10
Original file line numberDiff line numberDiff line change
@@ -2552,15 +2552,6 @@ impl PolyTraitRef {
25522552
}
25532553
}
25542554

2555-
#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)]
2556-
pub enum CrateSugar {
2557-
/// Source is `pub(crate)`.
2558-
PubCrate,
2559-
2560-
/// Source is (just) `crate`.
2561-
JustCrate,
2562-
}
2563-
25642555
#[derive(Clone, Encodable, Decodable, Debug)]
25652556
pub struct Visibility {
25662557
pub kind: VisibilityKind,
@@ -2571,7 +2562,6 @@ pub struct Visibility {
25712562
#[derive(Clone, Encodable, Decodable, Debug)]
25722563
pub enum VisibilityKind {
25732564
Public,
2574-
Crate(CrateSugar),
25752565
Restricted { path: P<Path>, id: NodeId },
25762566
Inherited,
25772567
}

‎compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
14691469

14701470
pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
14711471
match &mut visibility.kind {
1472-
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
1472+
VisibilityKind::Public | VisibilityKind::Inherited => {}
14731473
VisibilityKind::Restricted { path, id } => {
14741474
vis.visit_path(path);
14751475
vis.visit_id(id);

‎compiler/rustc_ast_passes/src/feature_gate.rs

-13
Original file line numberDiff line numberDiff line change
@@ -697,18 +697,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
697697
}
698698
visit::walk_assoc_item(self, i, ctxt)
699699
}
700-
701-
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
702-
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.kind {
703-
gate_feature_post!(
704-
&self,
705-
crate_visibility_modifier,
706-
vis.span,
707-
"`crate` visibility modifier is experimental"
708-
);
709-
}
710-
visit::walk_vis(self, vis)
711-
}
712700
}
713701

714702
pub fn check_crate(krate: &ast::Crate, sess: &Session) {
@@ -770,7 +758,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
770758

771759
gate_all!(trait_alias, "trait aliases are experimental");
772760
gate_all!(associated_type_bounds, "associated type bounds are unstable");
773-
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
774761
gate_all!(decl_macro, "`macro` is experimental");
775762
gate_all!(box_patterns, "box pattern syntax is experimental");
776763
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");

‎compiler/rustc_ast_pretty/src/pprust/state/item.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,9 @@ impl<'a> State<'a> {
403403
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
404404
match vis.kind {
405405
ast::VisibilityKind::Public => self.word_nbsp("pub"),
406-
ast::VisibilityKind::Crate(sugar) => match sugar {
407-
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
408-
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
409-
},
410406
ast::VisibilityKind::Restricted { ref path, .. } => {
411407
let path = Self::to_string(|s| s.print_path(path, false, 0));
412-
if path == "self" || path == "super" {
408+
if path == "crate" || path == "self" || path == "super" {
413409
self.word_nbsp(format!("pub({})", path))
414410
} else {
415411
self.word_nbsp(format!("pub(in {})", path))

‎compiler/rustc_feature/src/active.rs

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

‎compiler/rustc_feature/src/removed.rs

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

‎compiler/rustc_lint/src/builtin.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1372,17 +1372,11 @@ impl UnreachablePub {
13721372
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
13731373
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
13741374
let mut err = lint.build(&format!("unreachable `pub` {}", what));
1375-
let replacement = if cx.tcx.features().crate_visibility_modifier {
1376-
"crate"
1377-
} else {
1378-
"pub(crate)"
1379-
}
1380-
.to_owned();
13811375

13821376
err.span_suggestion(
13831377
vis_span,
13841378
"consider restricting its visibility",
1385-
replacement,
1379+
"pub(crate)".to_owned(),
13861380
applicability,
13871381
);
13881382
if exportable {

‎compiler/rustc_parse/src/parser/item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ impl<'a> Parser<'a> {
302302

303303
/// When parsing a statement, would the start of a path be an item?
304304
pub(super) fn is_path_start_item(&mut self) -> bool {
305-
self.is_crate_vis() // no: `crate::b`, yes: `crate $item`
306-
|| self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
305+
self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
307306
|| self.check_auto_or_unsafe_trait_item() // no: `auto::b`, yes: `auto trait X { .. }`
308307
|| self.is_async_fn() // no(2015): `async::b`, yes: `async fn`
309308
|| matches!(self.is_macro_rules_item(), IsMacroRulesItem::Yes{..}) // no: `macro_rules::b`, yes: `macro_rules! mac`

‎compiler/rustc_parse/src/parser/mod.rs

+7-35
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
2525
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2626
use rustc_ast::AttrId;
2727
use rustc_ast::DUMMY_NODE_ID;
28-
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern};
28+
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, Extern};
2929
use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacArgsEq, MacDelimiter, Mutability, StrLit};
3030
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
3131
use rustc_ast_pretty::pprust;
@@ -1245,30 +1245,15 @@ impl<'a> Parser<'a> {
12451245
res
12461246
}
12471247

1248-
fn is_crate_vis(&self) -> bool {
1249-
self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
1250-
}
1251-
1252-
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
1253-
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
1248+
/// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in crate)`, `pub(self)`
1249+
/// for `pub(in self)` and `pub(super)` for `pub(in super)`.
12541250
/// If the following element can't be a tuple (i.e., it's a function definition), then
12551251
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
12561252
/// so emit a proper diagnostic.
12571253
// Public for rustfmt usage.
12581254
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
12591255
maybe_whole!(self, NtVis, |x| x.into_inner());
12601256

1261-
self.expected_tokens.push(TokenType::Keyword(kw::Crate));
1262-
if self.is_crate_vis() {
1263-
self.bump(); // `crate`
1264-
self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_token.span);
1265-
return Ok(Visibility {
1266-
span: self.prev_token.span,
1267-
kind: VisibilityKind::Crate(CrateSugar::JustCrate),
1268-
tokens: None,
1269-
});
1270-
}
1271-
12721257
if !self.eat_keyword(kw::Pub) {
12731258
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
12741259
// keyword to grab a span from for inherited visibility; an empty span at the
@@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
12861271
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
12871272
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
12881273
// by the following tokens.
1289-
if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep)
1290-
// account for `pub(crate::foo)`
1291-
{
1292-
// Parse `pub(crate)`.
1293-
self.bump(); // `(`
1294-
self.bump(); // `crate`
1295-
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
1296-
let vis = VisibilityKind::Crate(CrateSugar::PubCrate);
1297-
return Ok(Visibility {
1298-
span: lo.to(self.prev_token.span),
1299-
kind: vis,
1300-
tokens: None,
1301-
});
1302-
} else if self.is_keyword_ahead(1, &[kw::In]) {
1274+
if self.is_keyword_ahead(1, &[kw::In]) {
13031275
// Parse `pub(in path)`.
13041276
self.bump(); // `(`
13051277
self.bump(); // `in`
@@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
13121284
tokens: None,
13131285
});
13141286
} else if self.look_ahead(2, |t| t == &token::CloseDelim(Delimiter::Parenthesis))
1315-
&& self.is_keyword_ahead(1, &[kw::Super, kw::SelfLower])
1287+
&& self.is_keyword_ahead(1, &[kw::Crate, kw::Super, kw::SelfLower])
13161288
{
1317-
// Parse `pub(self)` or `pub(super)`.
1289+
// Parse `pub(crate)`, `pub(self)`, or `pub(super)`.
13181290
self.bump(); // `(`
1319-
let path = self.parse_path(PathStyle::Mod)?; // `super`/`self`
1291+
let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self`
13201292
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
13211293
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
13221294
return Ok(Visibility {

‎compiler/rustc_resolve/src/build_reduced_graph.rs

-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
249249
let parent_scope = &self.parent_scope;
250250
match vis.kind {
251251
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
252-
ast::VisibilityKind::Crate(..) => {
253-
Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))
254-
}
255252
ast::VisibilityKind::Inherited => {
256253
Ok(match self.parent_scope.module.kind {
257254
// Any inherited visibility resolved directly inside an enum or trait

‎src/doc/unstable-book/src/language-features/crate-visibility-modifier.md

-20
This file was deleted.

‎src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs

-8
This file was deleted.

‎src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr

-12
This file was deleted.

‎src/test/ui/macros/stringify.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,8 @@ fn test_vis() {
861861
// VisibilityKind::Public
862862
assert_eq!(stringify_vis!(pub), "pub ");
863863

864-
// VisibilityKind::Crate
865-
assert_eq!(stringify_vis!(crate), "crate ");
866-
867864
// VisibilityKind::Restricted
865+
assert_eq!(stringify_vis!(pub(crate)), "pub(crate) ");
868866
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
869867
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
870868
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");

‎src/tools/clippy/clippy_utils/src/ast_utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
545545
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
546546
use VisibilityKind::*;
547547
match (&l.kind, &r.kind) {
548-
(Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
548+
(Public, Public) | (Inherited, Inherited) => true,
549549
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
550550
_ => false,
551551
}

‎src/tools/rustfmt/src/items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ pub(crate) fn format_struct_struct(
13611361

13621362
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
13631363
match vis.kind {
1364-
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
1364+
ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
13651365
_ => default_span.lo(),
13661366
}
13671367
}

‎src/tools/rustfmt/src/utils.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::borrow::Cow;
22

33
use rustc_ast::ast::{
4-
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
4+
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
55
VisibilityKind,
66
};
77
use rustc_ast::ptr;
@@ -44,15 +44,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
4444
VisibilityKind::Restricted { path: q, .. },
4545
) => pprust::path_to_string(p) == pprust::path_to_string(q),
4646
(VisibilityKind::Public, VisibilityKind::Public)
47-
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
48-
| (
49-
VisibilityKind::Crate(CrateSugar::PubCrate),
50-
VisibilityKind::Crate(CrateSugar::PubCrate),
51-
)
52-
| (
53-
VisibilityKind::Crate(CrateSugar::JustCrate),
54-
VisibilityKind::Crate(CrateSugar::JustCrate),
55-
) => true,
47+
| (VisibilityKind::Inherited, VisibilityKind::Inherited) => true,
5648
_ => false,
5749
}
5850
}
@@ -65,8 +57,6 @@ pub(crate) fn format_visibility(
6557
match vis.kind {
6658
VisibilityKind::Public => Cow::from("pub "),
6759
VisibilityKind::Inherited => Cow::from(""),
68-
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
69-
VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
7060
VisibilityKind::Restricted { ref path, .. } => {
7161
let Path { ref segments, .. } = **path;
7262
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
@@ -75,7 +65,7 @@ pub(crate) fn format_visibility(
7565
.next()
7666
.expect("Non-global path in pub(restricted)?");
7767
}
78-
let is_keyword = |s: &str| s == "self" || s == "super";
68+
let is_keyword = |s: &str| s == "crate" || s == "self" || s == "super";
7969
let path = segments_iter.collect::<Vec<_>>().join("::");
8070
let in_str = if is_keyword(&path) { "" } else { "in " };
8171

0 commit comments

Comments
 (0)
Please sign in to comment.