Skip to content

Commit 8b2e6da

Browse files
Merge #1174
1174: Remove default location for `SimplePath`s r=CohenArthur a=CohenArthur This removes the default argument for the locus of `SimplePath`s. Addresses #1159 There are a lot of places in the code where it is not possible to insert a "correct" location for these `SimplePath`s: namely, when creating the use statement for the standard library's prelude, or when creating the `SimplePath`s of attributes. I've left a few FIXMEs in these cases because I'm unsure about the proper course of action. Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 parents 0ce3b06 + b3d85dc commit 8b2e6da

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

gcc/rust/ast/rust-ast-full-test.cc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4695,7 +4695,10 @@ MetaNameValueStr::to_attribute () const
46954695
{
46964696
LiteralExpr lit_expr (str, Literal::LitType::STRING,
46974697
PrimitiveCoreType::CORETYPE_UNKNOWN, {}, Location ());
4698-
return Attribute (SimplePath::from_str (ident),
4698+
// FIXME: What location do we put here? Is the literal above supposed to have
4699+
// an empty location as well?
4700+
// Should MetaNameValueStr keep a location?
4701+
return Attribute (SimplePath::from_str (ident, Location ()),
46994702
std::unique_ptr<AttrInputLiteral> (
47004703
new AttrInputLiteral (std::move (lit_expr))));
47014704
}
@@ -4722,7 +4725,8 @@ MetaItemSeq::to_attribute () const
47224725
Attribute
47234726
MetaWord::to_attribute () const
47244727
{
4725-
return Attribute (SimplePath::from_str (ident), nullptr);
4728+
// FIXME: How do we get a location here?
4729+
return Attribute (SimplePath::from_str (ident, Location ()), nullptr);
47264730
}
47274731

47284732
Attribute
@@ -4740,7 +4744,8 @@ MetaListPaths::to_attribute () const
47404744

47414745
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
47424746
new AttrInputMetaItemContainer (std::move (new_seq)));
4743-
return Attribute (SimplePath::from_str (ident),
4747+
// FIXME: How do we get a location here?
4748+
return Attribute (SimplePath::from_str (ident, Location ()),
47444749
std::move (new_seq_container));
47454750
}
47464751

@@ -4755,7 +4760,8 @@ MetaListNameValueStr::to_attribute () const
47554760

47564761
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
47574762
new AttrInputMetaItemContainer (std::move (new_seq)));
4758-
return Attribute (SimplePath::from_str (ident),
4763+
// FIXME: How do we get a location here?
4764+
return Attribute (SimplePath::from_str (ident, Location ()),
47594765
std::move (new_seq_container));
47604766
}
47614767

gcc/rust/ast/rust-ast.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class SimplePathSegment : public PathSegment
330330
// only allow identifiers, "super", "self", "crate", or "$crate"
331331
public:
332332
// TODO: put checks in constructor to enforce this rule?
333-
SimplePathSegment (std::string segment_name, Location locus = Location ())
333+
SimplePathSegment (std::string segment_name, Location locus)
334334
: segment_name (std::move (segment_name)), locus (locus),
335335
node_id (Analysis::Mappings::get ()->get_next_node_id ())
336336
{}
@@ -342,7 +342,7 @@ class SimplePathSegment : public PathSegment
342342
// Creates an error SimplePathSegment
343343
static SimplePathSegment create_error ()
344344
{
345-
return SimplePathSegment (std::string (""));
345+
return SimplePathSegment (std::string (""), Location ());
346346
}
347347

348348
std::string as_string () const override;
@@ -398,10 +398,10 @@ class SimplePath
398398
* ensure that this is a valid identifier in path, so be careful. Also, this
399399
* will have no location data.
400400
* TODO have checks? */
401-
static SimplePath from_str (std::string str)
401+
static SimplePath from_str (std::string str, Location locus)
402402
{
403403
std::vector<AST::SimplePathSegment> single_segments
404-
= {AST::SimplePathSegment (std::move (str))};
404+
= {AST::SimplePathSegment (std::move (str), locus)};
405405
return SimplePath (std::move (single_segments));
406406
}
407407
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,13 @@ translate_visibility (const AST::Visibility &vis)
4444
case AST::Visibility::PUB_SELF:
4545
return Visibility (Visibility::VisType::PRIVATE);
4646
// Desugar pub(crate) into pub(in crate) and so on
47+
// FIXME: How do we get a location for the SimplePath here?
4748
case AST::Visibility::PUB_CRATE:
4849
return Visibility (Visibility::PUBLIC,
49-
AST::SimplePath::from_str ("crate"));
50+
AST::SimplePath::from_str ("crate", Location ()));
5051
case AST::Visibility::PUB_SUPER:
5152
return Visibility (Visibility::PUBLIC,
52-
AST::SimplePath::from_str ("super"));
53+
AST::SimplePath::from_str ("super", Location ()));
5354
case AST::Visibility::PUB_IN_PATH:
5455
return Visibility (Visibility::VisType::PUBLIC, vis.get_path ());
5556
break;

gcc/rust/rust-session-manager.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,8 @@ Session::injection (AST::Crate &crate)
870870
{
871871
// create "macro use" attribute for use on extern crate item to enable
872872
// loading macros from it
873-
AST::Attribute attr (AST::SimplePath::from_str ("macro_use"), nullptr);
873+
AST::Attribute attr (AST::SimplePath::from_str ("macro_use", Location ()),
874+
nullptr);
874875

875876
// create "extern crate" item with the name
876877
std::unique_ptr<AST::ExternCrate> extern_crate (
@@ -885,13 +886,15 @@ Session::injection (AST::Crate &crate)
885886
// create use tree path
886887
// prelude is injected_crate_name
887888
std::vector<AST::SimplePathSegment> segments
888-
= {AST::SimplePathSegment (injected_crate_name),
889-
AST::SimplePathSegment ("prelude"), AST::SimplePathSegment ("v1")};
889+
= {AST::SimplePathSegment (injected_crate_name, Location ()),
890+
AST::SimplePathSegment ("prelude", Location ()),
891+
AST::SimplePathSegment ("v1", Location ())};
890892
// create use tree and decl
891893
std::unique_ptr<AST::UseTreeGlob> use_tree (
892894
new AST::UseTreeGlob (AST::UseTreeGlob::PATH_PREFIXED,
893895
AST::SimplePath (std::move (segments)), Location ()));
894-
AST::Attribute prelude_attr (AST::SimplePath::from_str ("prelude_import"),
896+
AST::Attribute prelude_attr (AST::SimplePath::from_str ("prelude_import",
897+
Location ()),
895898
nullptr);
896899
std::unique_ptr<AST::UseDeclaration> use_decl (
897900
new AST::UseDeclaration (std::move (use_tree),

0 commit comments

Comments
 (0)