Skip to content

Commit

Permalink
Add a span field to Visibility::Restricted
Browse files Browse the repository at this point in the history
This span covers the whole visibility expression: e.g. `pub (in path)`.
  • Loading branch information
topecongiro committed Feb 17, 2018
1 parent 01a70c6 commit 0bddba9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -3365,7 +3365,7 @@ impl<'a> LoweringContext<'a> {
match *v {
Visibility::Public => hir::Public,
Visibility::Crate(..) => hir::Visibility::Crate,
Visibility::Restricted { ref path, id } => {
Visibility::Restricted { ref path, id, .. } => {
hir::Visibility::Restricted {
path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
id: if let Some(owner) = explicit_owner {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/lib.rs
Expand Up @@ -3802,7 +3802,7 @@ impl<'a> Resolver<'a> {
ast::Visibility::Inherited => {
ty::Visibility::Restricted(self.current_module.normal_ancestor_id)
}
ast::Visibility::Restricted { ref path, id } => {
ast::Visibility::Restricted { ref path, id, .. } => {
let def = self.smart_resolve_path(id, None, path,
PathSource::Visibility).base_def();
if def == Def::Err {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ast.rs
Expand Up @@ -1941,7 +1941,7 @@ pub enum CrateSugar {
pub enum Visibility {
Public,
Crate(Span, CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Restricted { path: P<Path>, id: NodeId, span: Span },
Inherited,
}

Expand Down
5 changes: 3 additions & 2 deletions src/libsyntax/fold.rs
Expand Up @@ -1368,9 +1368,10 @@ pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVe

pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility {
match vis {
Visibility::Restricted { path, id } => Visibility::Restricted {
Visibility::Restricted { path, id, span } => Visibility::Restricted {
path: path.map(|path| folder.fold_path(path)),
id: folder.new_id(id)
id: folder.new_id(id),
span: folder.new_span(span),
},
_ => vis,
}
Expand Down
12 changes: 10 additions & 2 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -5710,8 +5710,12 @@ impl<'a> Parser<'a> {
self.bump(); // `(`
self.bump(); // `in`
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `path`
let vis = Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
self.expect(&token::CloseDelim(token::Paren))?; // `)`
let vis = Visibility::Restricted {
path: P(path),
id: ast::DUMMY_NODE_ID,
span: self.prev_span,
};
return Ok(vis)
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
Expand All @@ -5720,8 +5724,12 @@ impl<'a> Parser<'a> {
// `pub(self)` or `pub(super)`
self.bump(); // `(`
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `super`/`self`
let vis = Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
self.expect(&token::CloseDelim(token::Paren))?; // `)`
let vis = Visibility::Restricted {
path: P(path),
id: ast::DUMMY_NODE_ID,
span: self.prev_span,
};
return Ok(vis)
} else if !can_take_tuple { // Provide this diagnostic if this is not a tuple struct
// `pub(something) fn ...` or `struct X { pub(something) y: Z }`
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/visit.rs
Expand Up @@ -811,7 +811,7 @@ pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
}

pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
if let Visibility::Restricted { ref path, id } = *vis {
if let Visibility::Restricted { ref path, id, .. } = *vis {
visitor.visit_path(path, id);
}
}
Expand Down

0 comments on commit 0bddba9

Please sign in to comment.