Add a span field to Visibility::Restricted
This span covers the whole visibility expression: e.g. `pub (in path)`.
This commit is contained in:
parent
01a70c6589
commit
0bddba9248
6 changed files with 17 additions and 8 deletions
|
@ -3365,7 +3365,7 @@ impl<'a> LoweringContext<'a> {
|
||||||
match *v {
|
match *v {
|
||||||
Visibility::Public => hir::Public,
|
Visibility::Public => hir::Public,
|
||||||
Visibility::Crate(..) => hir::Visibility::Crate,
|
Visibility::Crate(..) => hir::Visibility::Crate,
|
||||||
Visibility::Restricted { ref path, id } => {
|
Visibility::Restricted { ref path, id, .. } => {
|
||||||
hir::Visibility::Restricted {
|
hir::Visibility::Restricted {
|
||||||
path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
|
path: P(self.lower_path(id, path, ParamMode::Explicit, true)),
|
||||||
id: if let Some(owner) = explicit_owner {
|
id: if let Some(owner) = explicit_owner {
|
||||||
|
|
|
@ -3802,7 +3802,7 @@ impl<'a> Resolver<'a> {
|
||||||
ast::Visibility::Inherited => {
|
ast::Visibility::Inherited => {
|
||||||
ty::Visibility::Restricted(self.current_module.normal_ancestor_id)
|
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,
|
let def = self.smart_resolve_path(id, None, path,
|
||||||
PathSource::Visibility).base_def();
|
PathSource::Visibility).base_def();
|
||||||
if def == Def::Err {
|
if def == Def::Err {
|
||||||
|
|
|
@ -1941,7 +1941,7 @@ pub enum CrateSugar {
|
||||||
pub enum Visibility {
|
pub enum Visibility {
|
||||||
Public,
|
Public,
|
||||||
Crate(Span, CrateSugar),
|
Crate(Span, CrateSugar),
|
||||||
Restricted { path: P<Path>, id: NodeId },
|
Restricted { path: P<Path>, id: NodeId, span: Span },
|
||||||
Inherited,
|
Inherited,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
pub fn noop_fold_vis<T: Folder>(vis: Visibility, folder: &mut T) -> Visibility {
|
||||||
match vis {
|
match vis {
|
||||||
Visibility::Restricted { path, id } => Visibility::Restricted {
|
Visibility::Restricted { path, id, span } => Visibility::Restricted {
|
||||||
path: path.map(|path| folder.fold_path(path)),
|
path: path.map(|path| folder.fold_path(path)),
|
||||||
id: folder.new_id(id)
|
id: folder.new_id(id),
|
||||||
|
span: folder.new_span(span),
|
||||||
},
|
},
|
||||||
_ => vis,
|
_ => vis,
|
||||||
}
|
}
|
||||||
|
|
|
@ -5710,8 +5710,12 @@ impl<'a> Parser<'a> {
|
||||||
self.bump(); // `(`
|
self.bump(); // `(`
|
||||||
self.bump(); // `in`
|
self.bump(); // `in`
|
||||||
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `path`
|
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))?; // `)`
|
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)
|
return Ok(vis)
|
||||||
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
|
} else if self.look_ahead(2, |t| t == &token::CloseDelim(token::Paren)) &&
|
||||||
self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
|
self.look_ahead(1, |t| t.is_keyword(keywords::Super) ||
|
||||||
|
@ -5720,8 +5724,12 @@ impl<'a> Parser<'a> {
|
||||||
// `pub(self)` or `pub(super)`
|
// `pub(self)` or `pub(super)`
|
||||||
self.bump(); // `(`
|
self.bump(); // `(`
|
||||||
let path = self.parse_path(PathStyle::Mod)?.default_to_global(); // `super`/`self`
|
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))?; // `)`
|
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)
|
return Ok(vis)
|
||||||
} else if !can_take_tuple { // Provide this diagnostic if this is not a tuple struct
|
} 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 }`
|
// `pub(something) fn ...` or `struct X { pub(something) y: Z }`
|
||||||
|
|
|
@ -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) {
|
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);
|
visitor.visit_path(path, id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue