summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Herron <herron.philip@googlemail.com>2023-04-20 10:26:18 +0100
committerPhilip Herron <philip.herron@embecosm.com>2023-04-27 22:18:08 +0000
commit5dfcde3b497c0eedb697ab8eb10a4b366e43ec1d (patch)
treefd5443c137e14fa0c93da110183e8f8206cb4c86
parentb5a7e8d10b379c487527204fd5e1b92d668aa906 (diff)
downloadgcc-5dfcde3b497c0eedb697ab8eb10a4b366e43ec1d.tar.gz
gccrs: Add missing where clause lowering for Impl functions
Fixes #2106 gcc/rust/ChangeLog: * hir/rust-ast-lower-implitem.h: add missing where clause lowering gcc/testsuite/ChangeLog: * rust/compile/issue-2106.rs: New test. * rust/compile/issue-1524.rs: regression (placeholder generic) Signed-off-by: Philip Herron <herron.philip@googlemail.com>
-rw-r--r--gcc/rust/hir/rust-ast-lower-implitem.h16
-rw-r--r--gcc/testsuite/rust/compile/issue-1524.rs2
-rw-r--r--gcc/testsuite/rust/compile/issue-2106.rs15
3 files changed, 32 insertions, 1 deletions
diff --git a/gcc/rust/hir/rust-ast-lower-implitem.h b/gcc/rust/hir/rust-ast-lower-implitem.h
index 2990e3efe73..e9599f7a064 100644
--- a/gcc/rust/hir/rust-ast-lower-implitem.h
+++ b/gcc/rust/hir/rust-ast-lower-implitem.h
@@ -133,6 +133,14 @@ public:
{
// ignore for now and leave empty
std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ for (auto &item : function.get_where_clause ().get_items ())
+ {
+ HIR::WhereClauseItem *i
+ = ASTLowerWhereClauseItem::translate (*item.get ());
+ where_clause_items.push_back (
+ std::unique_ptr<HIR::WhereClauseItem> (i));
+ }
+
HIR::WhereClause where_clause (std::move (where_clause_items));
HIR::FunctionQualifiers qualifiers
= lower_qualifiers (function.get_qualifiers ());
@@ -209,6 +217,14 @@ public:
{
// ignore for now and leave empty
std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ for (auto &item : method.get_where_clause ().get_items ())
+ {
+ HIR::WhereClauseItem *i
+ = ASTLowerWhereClauseItem::translate (*item.get ());
+ where_clause_items.push_back (
+ std::unique_ptr<HIR::WhereClauseItem> (i));
+ }
+
HIR::WhereClause where_clause (std::move (where_clause_items));
HIR::FunctionQualifiers qualifiers
= lower_qualifiers (method.get_qualifiers ());
diff --git a/gcc/testsuite/rust/compile/issue-1524.rs b/gcc/testsuite/rust/compile/issue-1524.rs
index e46efe4595f..2d7599f1804 100644
--- a/gcc/testsuite/rust/compile/issue-1524.rs
+++ b/gcc/testsuite/rust/compile/issue-1524.rs
@@ -1,4 +1,4 @@
-// { dg-additional-options "-w" }
+// { dg-additional-options "-w -frust-compile-until=nameresolution" }
// https://github.com/Rust-GCC/gccrs/issues/1524
// https://github.com/rust-lang/rust/blob/673d0db5e393e9c64897005b470bfeb6d5aec61b/src/test/ui/methods/method-normalize-bounds-issue-20604.rs
trait Hasher {
diff --git a/gcc/testsuite/rust/compile/issue-2106.rs b/gcc/testsuite/rust/compile/issue-2106.rs
new file mode 100644
index 00000000000..a4f235c14dd
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2106.rs
@@ -0,0 +1,15 @@
+struct Foo(u32);
+// { dg-warning "struct is never constructed" "" { target *-*-* } .-1 }
+
+pub trait Bar {
+ fn bar(self);
+}
+
+impl Foo {
+ pub fn map<F>(f: F)
+ where
+ F: Bar,
+ {
+ f.bar();
+ }
+}