Skip to content

Commit 7615df7

Browse files
bors[bot]philberty
andauthored
Merge #836
836: BugFix NodeId skew on AST::Patterns r=philberty a=philberty The AST constructors implicitly generate new NodeId's, their associated copy/move constructors ensure that they preserve the NodeId correctly. The AST::Pattern's here incorrectly had a constructor in the abstract base class which was generating the NodeId's but when this is used within AST::MatchArms the fields contain these patterns which can get copied/moved to cause new NodeId's to be generated which then throws off type checking as the NodeId changes during HIR lowering and thus each of the ID's are all off by one during type checking. Co-authored-by: Philip Herron <[email protected]>
2 parents 83a984b + c81eb14 commit 7615df7

File tree

6 files changed

+113
-41
lines changed

6 files changed

+113
-41
lines changed

gcc/rust/ast/rust-ast.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,24 +1037,18 @@ class Pattern
10371037
virtual ~Pattern () {}
10381038

10391039
virtual std::string as_string () const = 0;
1040-
10411040
virtual void accept_vis (ASTVisitor &vis) = 0;
10421041

10431042
// as only one kind of pattern can be stripped, have default of nothing
10441043
virtual void mark_for_strip () {}
10451044
virtual bool is_marked_for_strip () const { return false; }
10461045

10471046
virtual Location get_locus () const = 0;
1048-
1049-
virtual NodeId get_node_id () const { return node_id; }
1047+
virtual NodeId get_pattern_node_id () const = 0;
10501048

10511049
protected:
10521050
// Clone pattern implementation as pure virtual method
10531051
virtual Pattern *clone_pattern_impl () const = 0;
1054-
1055-
Pattern () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {}
1056-
1057-
NodeId node_id;
10581052
};
10591053

10601054
// forward decl for Type

gcc/rust/ast/rust-macro.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,11 @@ class MacroInvocation : public TypeNoBounds,
394394
outer_attrs = std::move (new_attrs);
395395
}
396396

397+
NodeId get_pattern_node_id () const override final
398+
{
399+
return ExprWithoutBlock::get_node_id ();
400+
}
401+
397402
protected:
398403
/* Use covariance to implement clone function as returning this object rather
399404
* than base */

gcc/rust/ast/rust-path.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ class PathInExpression : public PathPattern, public PathExpr
380380
outer_attrs = std::move (new_attrs);
381381
}
382382

383+
NodeId get_pattern_node_id () const override final { return get_node_id (); }
384+
383385
protected:
384386
/* Use covariance to implement clone function as returning this object rather
385387
* than base */
@@ -902,6 +904,8 @@ class QualifiedPathInExpression : public PathPattern, public PathExpr
902904

903905
NodeId get_node_id () const override { return _node_id; }
904906

907+
NodeId get_pattern_node_id () const override final { return get_node_id (); }
908+
905909
protected:
906910
/* Use covariance to implement clone function as returning this object rather
907911
* than base */

0 commit comments

Comments
 (0)