aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-03-27 16:28:45 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-03-27 18:55:14 +0000
commit380c8295051c6b42adb4f703268c7465aed57c44 (patch)
tree24e8da9f594d5d3ddd33107b24a2f220bf40965e
parent573120551a0bc6813f32ed371df65311724e96dd (diff)
downloadgcc-380c8295051c6b42adb4f703268c7465aed57c44.zip
gcc-380c8295051c6b42adb4f703268c7465aed57c44.tar.gz
gcc-380c8295051c6b42adb4f703268c7465aed57c44.tar.bz2
Init NodeId for NodeMappings on HIR::MethodCallExpr
We resolve methods during type resolution since it depends on the receiver type being used. To ensure the function is marked as used we must then mark the method name as resolved, this is also used in the backend GENERIC compilation to lookup the function definition to be compiled. When this was unset multiple method calls would fail. Fixes #310
-rw-r--r--gcc/rust/hir/rust-ast-lower-expr.h6
-rw-r--r--gcc/testsuite/rust.test/compile/methods3.rs41
2 files changed, 44 insertions, 3 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-expr.h b/gcc/rust/hir/rust-ast-lower-expr.h
index c55213d..b003334 100644
--- a/gcc/rust/hir/rust-ast-lower-expr.h
+++ b/gcc/rust/hir/rust-ast-lower-expr.h
@@ -241,9 +241,9 @@ public:
});
auto crate_num = mappings->get_current_crate ();
- Analysis::NodeMapping mapping (
- crate_num, UNKNOWN_NODEID /* this can map back to the AST*/,
- mappings->get_next_hir_id (crate_num), UNKNOWN_LOCAL_DEFID);
+ Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ UNKNOWN_LOCAL_DEFID);
translated
= new HIR::MethodCallExpr (mapping, std::unique_ptr<HIR::Expr> (receiver),
diff --git a/gcc/testsuite/rust.test/compile/methods3.rs b/gcc/testsuite/rust.test/compile/methods3.rs
new file mode 100644
index 0000000..a71d045
--- /dev/null
+++ b/gcc/testsuite/rust.test/compile/methods3.rs
@@ -0,0 +1,41 @@
+struct Point {
+ x: f64,
+ y: f64,
+}
+
+impl Point {
+ fn origin() -> Point {
+ Point { x: 0.0, y: 0.0 }
+ }
+
+ fn new(x: f64, y: f64) -> Point {
+ Point { x: x, y: y }
+ }
+}
+
+struct Rectangle {
+ p1: Point,
+ p2: Point,
+}
+
+impl Rectangle {
+ fn from(p1: Point, p2: Point) -> Self {
+ Self { p1, p2 }
+ }
+
+ fn sum_x(self) -> f64 {
+ let p1 = self.p1;
+ let p2 = self.p2;
+ p1.x + p2.x
+ }
+}
+
+fn main() {
+ let p1 = Point::origin();
+ let p2 = Point::new(3.0, 4.0);
+ let rect = Rectangle::from(p1, p2);
+
+ let sum = rect.sum_x();
+ // multiple MethodCallExpr were causing issue #310
+ let sum = rect.sum_x();
+}