#[derive(Clone, Encodable, Decodable, Debug)]
pub enum VisibilityKind {
Public,
- Crate,
Restricted { path: P<Path>, id: NodeId },
Inherited,
}
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::Inherited => {}
VisibilityKind::Restricted { path, id } => {
vis.visit_path(path);
vis.visit_id(id);
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
match vis.kind {
ast::VisibilityKind::Public => self.word_nbsp("pub"),
- 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" {
+ if path == "crate" || path == "self" || path == "super" {
self.word_nbsp(format!("pub({})", path))
} else {
self.word_nbsp(format!("pub(in {})", path))
res
}
- /// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `pub(self)` for `pub(in self)`
- /// and `pub(super)` for `pub(in super)`.
+ /// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in 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
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
/// so emit a proper diagnostic.
// `()` 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
// by the following tokens.
- if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep)
- // account for `pub(crate::foo)`
- {
- // Parse `pub(crate)`.
- self.bump(); // `(`
- self.bump(); // `crate`
- self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
- return Ok(Visibility {
- span: lo.to(self.prev_token.span),
- kind: VisibilityKind::Crate,
- tokens: None,
- });
- } else if self.is_keyword_ahead(1, &[kw::In]) {
+ if self.is_keyword_ahead(1, &[kw::In]) {
// Parse `pub(in path)`.
self.bump(); // `(`
self.bump(); // `in`
tokens: None,
});
} 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(); // `(`
- 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))?; // `)`
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
return Ok(Visibility {
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::Inherited => {
Ok(match self.parent_scope.module.kind {
// Any inherited visibility resolved directly inside an enum or trait
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) => true,
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
_ => false,
}
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::Restricted { .. } => vis.span.hi(),
_ => default_span.lo(),
}
}
VisibilityKind::Restricted { path: q, .. },
) => pprust::path_to_string(p) == pprust::path_to_string(q),
(VisibilityKind::Public, VisibilityKind::Public)
- | (VisibilityKind::Inherited, VisibilityKind::Inherited)
- | (
- VisibilityKind::Crate,
- VisibilityKind::Crate,
- ) => true,
+ | (VisibilityKind::Inherited, VisibilityKind::Inherited) => true,
_ => false,
}
}
match vis.kind {
VisibilityKind::Public => Cow::from("pub "),
VisibilityKind::Inherited => Cow::from(""),
- 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));
.next()
.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 in_str = if is_keyword(&path) { "" } else { "in " };