Skip to content

Commit 0bddba9

Browse files
committed
Add a span field to Visibility::Restricted
This span covers the whole visibility expression: e.g. `pub (in path)`.
1 parent 01a70c6 commit 0bddba9

File tree

6 files changed

+17
-8
lines changed

6 files changed

+17
-8
lines changed

src/librustc/hir/lowering.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3365,7 +3365,7 @@ impl<'a> LoweringContext<'a> {
33653365
match *v {
33663366
Visibility::Public => hir::Public,
33673367
Visibility::Crate(..) => hir::Visibility::Crate,
3368-
Visibility::Restricted { ref path, id } => {
3368+
Visibility::Restricted { ref path, id, .. } => {
33693369
hir::Visibility::Restricted {
33703370
path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
33713371
id: if let Some(owner) = explicit_owner {

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3802,7 +3802,7 @@ impl<'a> Resolver<'a> {
38023802
ast::Visibility::Inherited => {
38033803
ty::Visibility::Restricted(self.current_module.normal_ancestor_id)
38043804
}
3805-
ast::Visibility::Restricted { ref path, id } => {
3805+
ast::Visibility::Restricted { ref path, id, .. } => {
38063806
let def = self.smart_resolve_path(id, None, path,
38073807
PathSource::Visibility).base_def();
38083808
if def == Def::Err {

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ pub enum CrateSugar {
19411941
pub enum Visibility {
19421942
Public,
19431943
Crate(Span, CrateSugar),
1944-
Restricted { path: P<Path>, id: NodeId },
1944+
Restricted { path: P<Path>, id: NodeId, span: Span },
19451945
Inherited,
19461946
}
19471947

src/libsyntax/fold.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,10 @@ pub fn noop_fold_stmt_kind<T: Folder>(node: StmtKind, folder: &mut T) -> SmallVe
13681368

13691369
pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility {
13701370
match vis {
1371-
Visibility::Restricted { path, id } => Visibility::Restricted {
1371+
Visibility::Restricted { path, id, span } => Visibility::Restricted {
13721372
path: path.map(|path| folder.fold_path(path)),
1373-
id: folder.new_id(id)
1373+
id: folder.new_id(id),
1374+
span: folder.new_span(span),
13741375
},
13751376
_ => vis,
13761377
}

src/libsyntax/parse/parser.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5710,8 +5710,12 @@ impl<'a> Parser<'a> {
57105710
self.bump(); // `(`
57115711
self.bump(); // `in`
57125712
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `path`
5713-
let vis = Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
57145713
self.expect(&token::CloseDelim(token::Paren))?; // `)`
5714+
let vis = Visibility::Restricted {
5715+
path: P(path),
5716+
id: ast::DUMMY_NODE_ID,
5717+
span: self.prev_span,
5718+
};
57155719
return Ok(vis)
57165720
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
57175721
self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
@@ -5720,8 +5724,12 @@ impl<'a> Parser<'a> {
57205724
// `pub(self)` or `pub(super)`
57215725
self.bump(); // `(`
57225726
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `super`/`self`
5723-
let vis = Visibility::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
57245727
self.expect(&token::CloseDelim(token::Paren))?; // `)`
5728+
let vis = Visibility::Restricted {
5729+
path: P(path),
5730+
id: ast::DUMMY_NODE_ID,
5731+
span: self.prev_span,
5732+
};
57255733
return Ok(vis)
57265734
} else if !can_take_tuple { // Provide this diagnostic if this is not a tuple struct
57275735
// `pub(something) fn ...` or `struct X { pub(something) y: Z }`

src/libsyntax/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ pub fn walk_arm<'a, V: Visitor<'a>>(visitor: &mut V, arm: &'a Arm) {
811811
}
812812

813813
pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) {
814-
if let Visibility::Restricted { ref path, id } = *vis {
814+
if let Visibility::Restricted { ref path, id, .. } = *vis {
815815
visitor.visit_path(path, id);
816816
}
817817
}

0 commit comments

Comments
 (0)