public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] gccrs: Add another test case for passing associated type-bounds
@ 2023-02-07 17:54 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-07 17:54 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:bf724a30cc281528d993bd17d7c2d2c7c54d420a

commit bf724a30cc281528d993bd17d7c2d2c7c54d420a
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Thu Jan 12 16:22:17 2023 +0000

    gccrs: Add another test case for passing associated type-bounds
    
    This demonstrates that this also works for custom algebraic data types too.
    
    gcc/testsuite/ChangeLog:
    
            * rust/execute/torture/issue-1720-2.rs: New test.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/testsuite/rust/execute/torture/issue-1720-2.rs | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/gcc/testsuite/rust/execute/torture/issue-1720-2.rs b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs
new file mode 100644
index 00000000000..35833dbb813
--- /dev/null
+++ b/gcc/testsuite/rust/execute/torture/issue-1720-2.rs
@@ -0,0 +1,30 @@
+mod core {
+    mod ops {
+        #[lang = "add"]
+        pub trait Add<Rhs = Self> {
+            type Output;
+
+            fn add(self, rhs: Rhs) -> Self::Output;
+        }
+    }
+}
+
+struct Foo(i32);
+
+impl core::ops::Add for Foo {
+    type Output = i32;
+
+    fn add(self, rhs: Foo) -> Self::Output {
+        self.0 + rhs.0
+    }
+}
+
+pub fn bar<T: core::ops::Add<Output = i32>>(a: T) -> i32 {
+    a + a
+}
+
+pub fn main() -> i32 {
+    let a = Foo(1);
+
+    bar(a) - 2
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-07 17:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-07 17:54 [gcc/devel/rust/master] gccrs: Add another test case for passing associated type-bounds Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).