Skip to content

Commit 425ebda

Browse files
committed
type-path-fn: Add location info on start of Fn token
1 parent ef06769 commit 425ebda

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

gcc/rust/ast/rust-path.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -541,11 +541,13 @@ struct TypePathFunction
541541
// FIXME: think of better way to mark as invalid than taking up storage
542542
bool is_invalid;
543543

544-
// TODO: should this have location info?
544+
Location locus;
545545

546546
protected:
547547
// Constructor only used to create invalid type path functions.
548-
TypePathFunction (bool is_invalid) : is_invalid (is_invalid) {}
548+
TypePathFunction (bool is_invalid, Location locus)
549+
: is_invalid (is_invalid), locus (locus)
550+
{}
549551

550552
public:
551553
// Returns whether the return type of the function has been specified.
@@ -558,13 +560,16 @@ struct TypePathFunction
558560
bool is_error () const { return is_invalid; }
559561

560562
// Creates an error state function.
561-
static TypePathFunction create_error () { return TypePathFunction (true); }
563+
static TypePathFunction create_error ()
564+
{
565+
return TypePathFunction (true, Location ());
566+
}
562567

563568
// Constructor
564-
TypePathFunction (std::vector<std::unique_ptr<Type> > inputs,
569+
TypePathFunction (std::vector<std::unique_ptr<Type> > inputs, Location locus,
565570
std::unique_ptr<Type> type = nullptr)
566571
: inputs (std::move (inputs)), return_type (std::move (type)),
567-
is_invalid (false)
572+
is_invalid (false), locus (locus)
568573
{}
569574

570575
// Copy constructor with clone

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6436,7 +6436,8 @@ Parser<ManagedTokenSource>::parse_type_path_segment ()
64366436
}
64376437
case LEFT_PAREN: {
64386438
// parse type path function
6439-
AST::TypePathFunction type_path_function = parse_type_path_function ();
6439+
AST::TypePathFunction type_path_function
6440+
= parse_type_path_function (locus);
64406441

64416442
if (type_path_function.is_error ())
64426443
{
@@ -6462,7 +6463,7 @@ Parser<ManagedTokenSource>::parse_type_path_segment ()
64626463
// Parses a function call representation inside a type path.
64636464
template <typename ManagedTokenSource>
64646465
AST::TypePathFunction
6465-
Parser<ManagedTokenSource>::parse_type_path_function ()
6466+
Parser<ManagedTokenSource>::parse_type_path_function (Location id_location)
64666467
{
64676468
if (!skip_token (LEFT_PAREN))
64686469
{
@@ -6508,7 +6509,8 @@ Parser<ManagedTokenSource>::parse_type_path_function ()
65086509
std::unique_ptr<AST::Type> return_type = parse_function_return_type ();
65096510

65106511
inputs.shrink_to_fit ();
6511-
return AST::TypePathFunction (std::move (inputs), std::move (return_type));
6512+
return AST::TypePathFunction (std::move (inputs), id_location,
6513+
std::move (return_type));
65126514
}
65136515

65146516
// Parses a path inside an expression that allows generic arguments.

gcc/rust/parse/rust-parse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ template <typename ManagedTokenSource> class Parser
139139
AST::PathIdentSegment parse_path_ident_segment ();
140140
AST::GenericArgs parse_path_generic_args ();
141141
AST::GenericArgsBinding parse_generic_args_binding ();
142-
AST::TypePathFunction parse_type_path_function ();
142+
AST::TypePathFunction parse_type_path_function (Location locus);
143143
AST::PathExprSegment parse_path_expr_segment ();
144144
AST::QualifiedPathInExpression
145145
// When given a pratt_parsed_loc, use it as the location of the

0 commit comments

Comments
 (0)