]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add test case to show issue is fixed
authorPhilip Herron <herron.philip@googlemail.com>
Mon, 3 Feb 2025 20:43:57 +0000 (20:43 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 24 Mar 2025 12:07:02 +0000 (13:07 +0100)
This was fixed as part of: "gccrs: Fix compilation of trait-items which map to impl items"

Fixes Rust-GCC#3402

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3402-1.rs: New test.
* rust/compile/issue-3402-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/rust/compile/issue-3402-1.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/issue-3402-2.rs [new file with mode: 0644]
gcc/testsuite/rust/compile/nr2/exclude

diff --git a/gcc/testsuite/rust/compile/issue-3402-1.rs b/gcc/testsuite/rust/compile/issue-3402-1.rs
new file mode 100644 (file)
index 0000000..ed603ce
--- /dev/null
@@ -0,0 +1,29 @@
+pub struct Foo {
+    a: i32,
+    // { dg-warning "field is never read" "" { target *-*-* } .-1 }
+}
+pub struct Bar(i32);
+
+#[lang = "sized"]
+trait Sized {}
+
+pub mod core {
+    pub mod default {
+        pub trait Default: Sized {
+            fn default() -> Self;
+        }
+
+        impl Default for i32 {
+            fn default() -> Self {
+                0
+            }
+        }
+    }
+}
+
+impl ::core::default::Default for Bar {
+    #[inline]
+    fn default() -> Bar {
+        Bar(core::default::Default::default())
+    }
+}
diff --git a/gcc/testsuite/rust/compile/issue-3402-2.rs b/gcc/testsuite/rust/compile/issue-3402-2.rs
new file mode 100644 (file)
index 0000000..b665af2
--- /dev/null
@@ -0,0 +1,18 @@
+pub struct Bar(i32);
+
+#[lang = "sized"]
+trait Sized {}
+
+pub trait A: Sized {
+    fn foo() -> Self;
+}
+
+impl A for i32 {
+    fn foo() -> Self {
+        0
+    }
+}
+
+pub fn bar() {
+    let _ = Bar(A::foo());
+}
index f8e280e341c61354a4c7cec1c8ea34ad54daff8d..1b34e9fe20ec9bf8a1a69814b7aea4efa97184cf 100644 (file)
@@ -125,4 +125,5 @@ try-trait.rs
 derive-debug1.rs
 issue-3382.rs
 derive-default1.rs
+issue-3402-1.rs
 # please don't delete the trailing newline