Rollup merge of #97254 - jhpratt:remove-crate-vis, r=cjgillot
Remove feature: `crate` visibility modifier FCP completed in #53120.
This commit is contained in:
commit
b73f1c77a7
17 changed files with 19 additions and 136 deletions
|
@ -2552,15 +2552,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)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub struct Visibility {
|
pub struct Visibility {
|
||||||
pub kind: VisibilityKind,
|
pub kind: VisibilityKind,
|
||||||
|
@ -2571,7 +2562,6 @@ pub struct Visibility {
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub enum VisibilityKind {
|
pub enum VisibilityKind {
|
||||||
Public,
|
Public,
|
||||||
Crate(CrateSugar),
|
|
||||||
Restricted { path: P<Path>, id: NodeId },
|
Restricted { path: P<Path>, id: NodeId },
|
||||||
Inherited,
|
Inherited,
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
|
||||||
match &mut visibility.kind {
|
match &mut visibility.kind {
|
||||||
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
|
VisibilityKind::Public | VisibilityKind::Inherited => {}
|
||||||
VisibilityKind::Restricted { path, id } => {
|
VisibilityKind::Restricted { path, id } => {
|
||||||
vis.visit_path(path);
|
vis.visit_path(path);
|
||||||
vis.visit_id(id);
|
vis.visit_id(id);
|
||||||
|
|
|
@ -697,18 +697,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
|
||||||
}
|
}
|
||||||
visit::walk_assoc_item(self, i, ctxt)
|
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) {
|
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!(trait_alias, "trait aliases are experimental");
|
||||||
gate_all!(associated_type_bounds, "associated type bounds are unstable");
|
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!(decl_macro, "`macro` is experimental");
|
||||||
gate_all!(box_patterns, "box pattern syntax is experimental");
|
gate_all!(box_patterns, "box pattern syntax is experimental");
|
||||||
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
|
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
|
||||||
|
|
|
@ -403,13 +403,9 @@ impl<'a> State<'a> {
|
||||||
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
|
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
|
||||||
match vis.kind {
|
match vis.kind {
|
||||||
ast::VisibilityKind::Public => self.word_nbsp("pub"),
|
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::Restricted { ref path, .. } => {
|
ast::VisibilityKind::Restricted { ref path, .. } => {
|
||||||
let path = Self::to_string(|s| s.print_path(path, false, 0));
|
let path = Self::to_string(|s| s.print_path(path, false, 0));
|
||||||
if path == "self" || path == "super" {
|
if path == "crate" || path == "self" || path == "super" {
|
||||||
self.word_nbsp(format!("pub({})", path))
|
self.word_nbsp(format!("pub({})", path))
|
||||||
} else {
|
} else {
|
||||||
self.word_nbsp(format!("pub(in {})", path))
|
self.word_nbsp(format!("pub(in {})", path))
|
||||||
|
|
|
@ -351,8 +351,6 @@ declare_features! (
|
||||||
(active, const_trait_impl, "1.42.0", Some(67792), None),
|
(active, const_trait_impl, "1.42.0", Some(67792), None),
|
||||||
/// Allows the `?` operator in const contexts.
|
/// Allows the `?` operator in const contexts.
|
||||||
(active, const_try, "1.56.0", Some(74935), None),
|
(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.
|
/// Allows non-builtin attributes in inner attribute position.
|
||||||
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
|
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
|
||||||
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
|
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
|
||||||
|
|
|
@ -72,6 +72,8 @@ declare_features! (
|
||||||
/// Allows `T: ?const Trait` syntax in bounds.
|
/// Allows `T: ?const Trait` syntax in bounds.
|
||||||
(removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None,
|
(removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None,
|
||||||
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")),
|
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).
|
/// Allows using custom attributes (RFC 572).
|
||||||
(removed, custom_attribute, "1.0.0", Some(29642), None,
|
(removed, custom_attribute, "1.0.0", Some(29642), None,
|
||||||
Some("removed in favor of `#![register_tool]` and `#![register_attr]`")),
|
Some("removed in favor of `#![register_tool]` and `#![register_attr]`")),
|
||||||
|
|
|
@ -1372,17 +1372,11 @@ impl UnreachablePub {
|
||||||
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
|
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
|
||||||
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
|
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
|
||||||
let mut err = lint.build(&format!("unreachable `pub` {}", what));
|
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(
|
err.span_suggestion(
|
||||||
vis_span,
|
vis_span,
|
||||||
"consider restricting its visibility",
|
"consider restricting its visibility",
|
||||||
replacement,
|
"pub(crate)".to_owned(),
|
||||||
applicability,
|
applicability,
|
||||||
);
|
);
|
||||||
if exportable {
|
if exportable {
|
||||||
|
|
|
@ -302,8 +302,7 @@ impl<'a> Parser<'a> {
|
||||||
|
|
||||||
/// When parsing a statement, would the start of a path be an item?
|
/// When parsing a statement, would the start of a path be an item?
|
||||||
pub(super) fn is_path_start_item(&mut self) -> bool {
|
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.check_auto_or_unsafe_trait_item() // no: `auto::b`, yes: `auto trait X { .. }`
|
||||||
|| self.is_async_fn() // no(2015): `async::b`, yes: `async fn`
|
|| 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`
|
|| matches!(self.is_macro_rules_item(), IsMacroRulesItem::Yes{..}) // no: `macro_rules::b`, yes: `macro_rules! mac`
|
||||||
|
|
|
@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
|
||||||
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
use rustc_ast::tokenstream::{TokenStream, TokenTree};
|
||||||
use rustc_ast::AttrId;
|
use rustc_ast::AttrId;
|
||||||
use rustc_ast::DUMMY_NODE_ID;
|
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::{Async, Expr, ExprKind, MacArgs, MacArgsEq, MacDelimiter, Mutability, StrLit};
|
||||||
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
|
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
|
||||||
use rustc_ast_pretty::pprust;
|
use rustc_ast_pretty::pprust;
|
||||||
|
@ -1245,12 +1245,8 @@ impl<'a> Parser<'a> {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_crate_vis(&self) -> bool {
|
/// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in crate)`, `pub(self)`
|
||||||
self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
|
/// for `pub(in self)` and `pub(super)` for `pub(in super)`.
|
||||||
}
|
|
||||||
|
|
||||||
/// 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)`.
|
|
||||||
/// If the following element can't be a tuple (i.e., it's a function definition), then
|
/// 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,
|
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
|
||||||
/// so emit a proper diagnostic.
|
/// so emit a proper diagnostic.
|
||||||
|
@ -1258,17 +1254,6 @@ impl<'a> Parser<'a> {
|
||||||
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
|
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
|
||||||
maybe_whole!(self, NtVis, |x| x.into_inner());
|
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) {
|
if !self.eat_keyword(kw::Pub) {
|
||||||
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
|
// 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
|
// keyword to grab a span from for inherited visibility; an empty span at the
|
||||||
|
@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
|
||||||
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
|
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
|
||||||
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
|
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
|
||||||
// by the following tokens.
|
// by the following tokens.
|
||||||
if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep)
|
if self.is_keyword_ahead(1, &[kw::In]) {
|
||||||
// account for `pub(crate::foo)`
|
|
||||||
{
|
|
||||||
// Parse `pub(crate)`.
|
|
||||||
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,
|
|
||||||
tokens: None,
|
|
||||||
});
|
|
||||||
} else if self.is_keyword_ahead(1, &[kw::In]) {
|
|
||||||
// Parse `pub(in path)`.
|
// Parse `pub(in path)`.
|
||||||
self.bump(); // `(`
|
self.bump(); // `(`
|
||||||
self.bump(); // `in`
|
self.bump(); // `in`
|
||||||
|
@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
|
||||||
tokens: None,
|
tokens: None,
|
||||||
});
|
});
|
||||||
} else if self.look_ahead(2, |t| t == &token::CloseDelim(Delimiter::Parenthesis))
|
} else if self.look_ahead(2, |t| t == &token::CloseDelim(Delimiter::Parenthesis))
|
||||||
&& self.is_keyword_ahead(1, &[kw::Super, kw::SelfLower])
|
&& self.is_keyword_ahead(1, &[kw::Crate, kw::Super, kw::SelfLower])
|
||||||
{
|
{
|
||||||
// Parse `pub(self)` or `pub(super)`.
|
// Parse `pub(crate)`, `pub(self)`, or `pub(super)`.
|
||||||
self.bump(); // `(`
|
self.bump(); // `(`
|
||||||
let path = self.parse_path(PathStyle::Mod)?; // `super`/`self`
|
let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self`
|
||||||
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
|
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
|
||||||
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
|
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
|
||||||
return Ok(Visibility {
|
return Ok(Visibility {
|
||||||
|
|
|
@ -249,9 +249,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
|
||||||
let parent_scope = &self.parent_scope;
|
let parent_scope = &self.parent_scope;
|
||||||
match vis.kind {
|
match vis.kind {
|
||||||
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
|
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
|
||||||
ast::VisibilityKind::Crate(..) => {
|
|
||||||
Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))
|
|
||||||
}
|
|
||||||
ast::VisibilityKind::Inherited => {
|
ast::VisibilityKind::Inherited => {
|
||||||
Ok(match self.parent_scope.module.kind {
|
Ok(match self.parent_scope.module.kind {
|
||||||
// Any inherited visibility resolved directly inside an enum or trait
|
// Any inherited visibility resolved directly inside an enum or trait
|
||||||
|
|
|
@ -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,
|
|
||||||
}
|
|
||||||
```
|
|
|
@ -1,8 +0,0 @@
|
||||||
crate struct Bender { //~ ERROR `crate` visibility modifier is experimental
|
|
||||||
earth: bool,
|
|
||||||
fire: bool,
|
|
||||||
air: bool,
|
|
||||||
water: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {}
|
|
|
@ -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`.
|
|
|
@ -861,10 +861,8 @@ fn test_vis() {
|
||||||
// VisibilityKind::Public
|
// VisibilityKind::Public
|
||||||
assert_eq!(stringify_vis!(pub), "pub ");
|
assert_eq!(stringify_vis!(pub), "pub ");
|
||||||
|
|
||||||
// VisibilityKind::Crate
|
|
||||||
assert_eq!(stringify_vis!(crate), "crate ");
|
|
||||||
|
|
||||||
// VisibilityKind::Restricted
|
// VisibilityKind::Restricted
|
||||||
|
assert_eq!(stringify_vis!(pub(crate)), "pub(crate) ");
|
||||||
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
|
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
|
||||||
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
|
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
|
||||||
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");
|
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");
|
||||||
|
|
|
@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
|
||||||
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
|
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
|
||||||
use VisibilityKind::*;
|
use VisibilityKind::*;
|
||||||
match (&l.kind, &r.kind) {
|
match (&l.kind, &r.kind) {
|
||||||
(Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
|
(Public, Public) | (Inherited, Inherited) => true,
|
||||||
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
|
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -1361,7 +1361,7 @@ pub(crate) fn format_struct_struct(
|
||||||
|
|
||||||
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
|
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
|
||||||
match vis.kind {
|
match vis.kind {
|
||||||
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
|
ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
|
||||||
_ => default_span.lo(),
|
_ => default_span.lo(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
|
||||||
use rustc_ast::ast::{
|
use rustc_ast::ast::{
|
||||||
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||||
VisibilityKind,
|
VisibilityKind,
|
||||||
};
|
};
|
||||||
use rustc_ast::ptr;
|
use rustc_ast::ptr;
|
||||||
|
@ -44,15 +44,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
|
||||||
VisibilityKind::Restricted { path: q, .. },
|
VisibilityKind::Restricted { path: q, .. },
|
||||||
) => pprust::path_to_string(p) == pprust::path_to_string(q),
|
) => pprust::path_to_string(p) == pprust::path_to_string(q),
|
||||||
(VisibilityKind::Public, VisibilityKind::Public)
|
(VisibilityKind::Public, VisibilityKind::Public)
|
||||||
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
|
| (VisibilityKind::Inherited, VisibilityKind::Inherited) => true,
|
||||||
| (
|
|
||||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
|
||||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
|
||||||
)
|
|
||||||
| (
|
|
||||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
|
||||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
|
||||||
) => true,
|
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -65,8 +57,6 @@ pub(crate) fn format_visibility(
|
||||||
match vis.kind {
|
match vis.kind {
|
||||||
VisibilityKind::Public => Cow::from("pub "),
|
VisibilityKind::Public => Cow::from("pub "),
|
||||||
VisibilityKind::Inherited => Cow::from(""),
|
VisibilityKind::Inherited => Cow::from(""),
|
||||||
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
|
|
||||||
VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
|
|
||||||
VisibilityKind::Restricted { ref path, .. } => {
|
VisibilityKind::Restricted { ref path, .. } => {
|
||||||
let Path { ref segments, .. } = **path;
|
let Path { ref segments, .. } = **path;
|
||||||
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
|
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
|
||||||
|
@ -75,7 +65,7 @@ pub(crate) fn format_visibility(
|
||||||
.next()
|
.next()
|
||||||
.expect("Non-global path in pub(restricted)?");
|
.expect("Non-global path in pub(restricted)?");
|
||||||
}
|
}
|
||||||
let is_keyword = |s: &str| s == "self" || s == "super";
|
let is_keyword = |s: &str| s == "crate" || s == "self" || s == "super";
|
||||||
let path = segments_iter.collect::<Vec<_>>().join("::");
|
let path = segments_iter.collect::<Vec<_>>().join("::");
|
||||||
let in_str = if is_keyword(&path) { "" } else { "in " };
|
let in_str = if is_keyword(&path) { "" } else { "in " };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue