Skip to content

Commit a9daecd

Browse files
Merge #778
778: Add location info in AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem r=philberty a=npate012 Location info has been added to AST::TypeBoundWhereClauseItem and HIR::TypeBoundWhereClauseItem. parse_type_bound_where_clause_item () has been modified to fetch location info and store it in AST::TypeBoundWhereClauseItem. Fixes #766 Signed-off-by: Nirmal Patel <[email protected]> Co-authored-by: Nirmal Patel <[email protected]>
2 parents cba61d8 + a66dd96 commit a9daecd

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

gcc/rust/ast/rust-item.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
228228
std::unique_ptr<Type> bound_type;
229229
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
230230
NodeId node_id;
231+
Location locus;
231232

232233
public:
233234
// Returns whether the item has ForLifetimes
@@ -238,11 +239,12 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
238239

239240
TypeBoundWhereClauseItem (
240241
std::vector<LifetimeParam> for_lifetimes, std::unique_ptr<Type> bound_type,
241-
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds)
242+
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
243+
Location locus)
242244
: for_lifetimes (std::move (for_lifetimes)),
243245
bound_type (std::move (bound_type)),
244246
type_param_bounds (std::move (type_param_bounds)),
245-
node_id (Analysis::Mappings::get ()->get_next_node_id ())
247+
node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
246248
{}
247249

248250
// Copy constructor requires clone
@@ -298,6 +300,8 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
298300

299301
NodeId get_node_id () const override final { return node_id; }
300302

303+
Location get_locus () const { return locus; }
304+
301305
protected:
302306
// Clone function implementation as (not pure) virtual method
303307
TypeBoundWhereClauseItem *clone_where_clause_item_impl () const override

gcc/rust/hir/rust-ast-lower-type.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,8 @@ class ASTLowerWhereClauseItem : public ASTLoweringBase
479479
translated
480480
= new HIR::TypeBoundWhereClauseItem (mapping, std::move (for_lifetimes),
481481
std::move (bound_type),
482-
std::move (type_param_bounds));
482+
std::move (type_param_bounds),
483+
item.get_locus ());
483484
}
484485

485486
private:

gcc/rust/hir/tree/rust-hir-item.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
218218
std::unique_ptr<Type> bound_type;
219219
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds;
220220
Analysis::NodeMapping mappings;
221+
Location locus;
221222

222223
public:
223224
// Returns whether the item has ForLifetimes
@@ -229,11 +230,12 @@ class TypeBoundWhereClauseItem : public WhereClauseItem
229230
TypeBoundWhereClauseItem (
230231
Analysis::NodeMapping mappings, std::vector<LifetimeParam> for_lifetimes,
231232
std::unique_ptr<Type> bound_type,
232-
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds)
233+
std::vector<std::unique_ptr<TypeParamBound>> type_param_bounds,
234+
Location locus)
233235
: for_lifetimes (std::move (for_lifetimes)),
234236
bound_type (std::move (bound_type)),
235237
type_param_bounds (std::move (type_param_bounds)),
236-
mappings (std::move (mappings))
238+
mappings (std::move (mappings)), locus (locus)
237239
{}
238240

239241
// Copy constructor requires clone

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -3612,10 +3612,12 @@ Parser<ManagedTokenSource>::parse_type_bound_where_clause_item ()
36123612
std::vector<std::unique_ptr<AST::TypeParamBound>> type_param_bounds
36133613
= parse_type_param_bounds ();
36143614

3615+
Location locus = lexer.peek_token ()->get_locus ();
3616+
36153617
return std::unique_ptr<AST::TypeBoundWhereClauseItem> (
36163618
new AST::TypeBoundWhereClauseItem (std::move (for_lifetimes),
36173619
std::move (type),
3618-
std::move (type_param_bounds)));
3620+
std::move (type_param_bounds), locus));
36193621
}
36203622

36213623
// Parses a for lifetimes clause, including the for keyword and angle brackets.

0 commit comments

Comments
 (0)