aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-08-31 10:46:24 +0000
committerGitHub <noreply@github.com>2021-08-31 10:46:24 +0000
commit82e1061579796adaa39ab34da77b6c8c6ea82539 (patch)
treea6dfb0000ae748c27dafc1a06499951418bc2b8e /gcc
parentde024718701a7578225682465b2625276e55fb76 (diff)
parent46e8bf357ccd9bb0cf45b1f2f104fb1b72798a1a (diff)
downloadgcc-82e1061579796adaa39ab34da77b6c8c6ea82539.zip
gcc-82e1061579796adaa39ab34da77b6c8c6ea82539.tar.gz
gcc-82e1061579796adaa39ab34da77b6c8c6ea82539.tar.bz2
Merge #651
651: Qualified paths have a mandatory initial segment r=philberty a=philberty see https://doc.rust-lang.org/reference/paths.html#qualified-paths The initial segment is mandatory this changes the AST to reflect this it simplifies error handling down the line. Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-path.h14
-rw-r--r--gcc/rust/parse/rust-parse-impl.h7
2 files changed, 13 insertions, 8 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index c042a8f..6ccd3a0 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -939,6 +939,7 @@ protected:
class QualifiedPathInType : public TypeNoBounds
{
QualifiedPathType path_type;
+ std::unique_ptr<TypePathSegment> associated_segment;
std::vector<std::unique_ptr<TypePathSegment> > segments;
Location locus;
@@ -953,9 +954,11 @@ protected:
public:
QualifiedPathInType (
QualifiedPathType qual_path_type,
+ std::unique_ptr<TypePathSegment> associated_segment,
std::vector<std::unique_ptr<TypePathSegment> > path_segments,
- Location locus = Location ())
+ Location locus)
: path_type (std::move (qual_path_type)),
+ associated_segment (std::move (associated_segment)),
segments (std::move (path_segments)), locus (locus)
{}
@@ -995,8 +998,8 @@ public:
static QualifiedPathInType create_error ()
{
return QualifiedPathInType (
- QualifiedPathType::create_error (),
- std::vector<std::unique_ptr<TypePathSegment> > ());
+ QualifiedPathType::create_error (), nullptr,
+ std::vector<std::unique_ptr<TypePathSegment> > (), Location ());
}
std::string as_string () const override;
@@ -1010,6 +1013,11 @@ public:
return path_type;
}
+ std::unique_ptr<TypePathSegment> &get_associated_segment ()
+ {
+ return associated_segment;
+ }
+
// TODO: this seems kinda dodgy
std::vector<std::unique_ptr<TypePathSegment> > &get_segments ()
{
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 8ee9e42..1c0644d 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -6742,10 +6742,6 @@ Parser<ManagedTokenSource>::parse_qualified_path_in_type ()
return AST::QualifiedPathInType::create_error ();
}
- // parse path segments
- std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
- segments.reserve (1);
-
// parse initial required segment
if (!expect_token (SCOPE_RESOLUTION))
{
@@ -6765,9 +6761,9 @@ Parser<ManagedTokenSource>::parse_qualified_path_in_type ()
return AST::QualifiedPathInType::create_error ();
}
- segments.push_back (std::move (initial_segment));
// parse optional segments (as long as scope resolution operator exists)
+ std::vector<std::unique_ptr<AST::TypePathSegment>> segments;
const_TokenPtr t = lexer.peek_token ();
while (t->get_id () == SCOPE_RESOLUTION)
{
@@ -6796,6 +6792,7 @@ Parser<ManagedTokenSource>::parse_qualified_path_in_type ()
segments.shrink_to_fit ();
return AST::QualifiedPathInType (std::move (qual_path_type),
+ std::move (initial_segment),
std::move (segments), locus);
}