Skip to content

Commit b4fa674

Browse files
committed
parse: Add correct location to all public visibilities
1 parent 9a9bb44 commit b4fa674

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

gcc/rust/ast/rust-item.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,23 +666,25 @@ struct Visibility
666666
return Visibility (PUB, SimplePath::create_empty ());
667667
}
668668

669-
// Creates a public visibility with crate-relative paths or whatever.
670-
static Visibility create_crate ()
669+
// Creates a public visibility with crate-relative paths
670+
static Visibility create_crate (Location crate_tok_location)
671671
{
672-
return Visibility (PUB_CRATE, SimplePath::create_empty ());
672+
return Visibility (PUB_CRATE,
673+
SimplePath::from_str ("crate", crate_tok_location));
673674
}
674675

675-
// Creates a public visibility with self-relative paths or whatever.
676-
static Visibility create_self ()
676+
// Creates a public visibility with self-relative paths
677+
static Visibility create_self (Location self_tok_location)
677678
{
678-
return Visibility (PUB_SELF, SimplePath::create_empty ());
679+
return Visibility (PUB_SELF,
680+
SimplePath::from_str ("self", self_tok_location));
679681
}
680682

681-
// Creates a public visibility with parent module-relative paths or
682-
// whatever.
683-
static Visibility create_super ()
683+
// Creates a public visibility with parent module-relative paths
684+
static Visibility create_super (Location super_tok_location)
684685
{
685-
return Visibility (PUB_SUPER, SimplePath::create_empty ());
686+
return Visibility (PUB_SUPER,
687+
SimplePath::from_str ("super", super_tok_location));
686688
}
687689

688690
// Creates a private visibility

gcc/rust/hir/rust-ast-lower.cc

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,8 @@ translate_visibility (const AST::Visibility &vis)
4343
case AST::Visibility::PRIV:
4444
case AST::Visibility::PUB_SELF:
4545
return Visibility (Visibility::VisType::PRIVATE);
46-
// Desugar pub(crate) into pub(in crate) and so on
47-
// FIXME: How do we get a location for the SimplePath here?
4846
case AST::Visibility::PUB_CRATE:
49-
return Visibility (Visibility::PUBLIC,
50-
AST::SimplePath::from_str ("crate", Location ()));
5147
case AST::Visibility::PUB_SUPER:
52-
return Visibility (Visibility::PUBLIC,
53-
AST::SimplePath::from_str ("super", Location ()));
5448
case AST::Visibility::PUB_IN_PATH:
5549
return Visibility (Visibility::VisType::PUBLIC, vis.get_path ());
5650
break;

gcc/rust/parse/rust-parse-impl.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,6 +2136,7 @@ Parser<ManagedTokenSource>::parse_visibility ()
21362136
lexer.skip_token ();
21372137

21382138
const_TokenPtr t = lexer.peek_token ();
2139+
auto path_loc = t->get_locus ();
21392140

21402141
switch (t->get_id ())
21412142
{
@@ -2144,19 +2145,19 @@ Parser<ManagedTokenSource>::parse_visibility ()
21442145

21452146
skip_token (RIGHT_PAREN);
21462147

2147-
return AST::Visibility::create_crate ();
2148+
return AST::Visibility::create_crate (path_loc);
21482149
case SELF:
21492150
lexer.skip_token ();
21502151

21512152
skip_token (RIGHT_PAREN);
21522153

2153-
return AST::Visibility::create_self ();
2154+
return AST::Visibility::create_self (path_loc);
21542155
case SUPER:
21552156
lexer.skip_token ();
21562157

21572158
skip_token (RIGHT_PAREN);
21582159

2159-
return AST::Visibility::create_super ();
2160+
return AST::Visibility::create_super (path_loc);
21602161
case IN: {
21612162
lexer.skip_token ();
21622163

0 commit comments

Comments
 (0)