[COMMITTED 34/43] gccrs: add test cases for fn qualifiers, default keyword

arthur.cohen@embecosm.com arthur.cohen@embecosm.com
Tue Apr 14 23:18:55 GMT 2026


From: Philipp Gesang <phg@phi-gamma.net>

gcc/testsuite/ChangeLog:

	* rust/compile/func-qualifier-order.rs: New test file
	* rust/compile/func-qualifier-default.rs: New test file

Signed-off-by: Philipp Gesang <phg@phi-gamma.net>
---
 .../rust/compile/func-qualifier-default.rs    | 18 +++++++++
 .../rust/compile/func-qualifier-order.rs      | 39 +++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 gcc/testsuite/rust/compile/func-qualifier-default.rs
 create mode 100644 gcc/testsuite/rust/compile/func-qualifier-order.rs

diff --git a/gcc/testsuite/rust/compile/func-qualifier-default.rs b/gcc/testsuite/rust/compile/func-qualifier-default.rs
new file mode 100644
index 00000000000..e2e600c4ba3
--- /dev/null
+++ b/gcc/testsuite/rust/compile/func-qualifier-default.rs
@@ -0,0 +1,18 @@
+#![feature(specialization)]
+#![feature(no_core)]
+#![no_core]
+
+trait Trait {
+    fn unqualified_fn();
+    unsafe fn unsafe_fn();
+}
+
+impl<T> Trait for T {
+    default fn unqualified_fn() {}
+
+    // `default` precedes all other qualifiers
+    unsafe default fn unsafe_fn() {}
+    // { dg-error "expecting .fn. but .identifier. found" "" { target *-*-* } .-1 }
+    // { dg-error "expecting ... but .fn. found" "" { target *-*-* } .-2 }
+    // { dg-error "failed to parse trait impl item in trait impl" "" { target *-*-* } .-3 }
+}
diff --git a/gcc/testsuite/rust/compile/func-qualifier-order.rs b/gcc/testsuite/rust/compile/func-qualifier-order.rs
new file mode 100644
index 00000000000..f26bc27678b
--- /dev/null
+++ b/gcc/testsuite/rust/compile/func-qualifier-order.rs
@@ -0,0 +1,39 @@
+// { dg-additional-options "-frust-edition=2018" }
+#![allow(unused)]
+#![allow(incomplete_features)]
+
+#![feature(no_core)]
+#![no_core]
+
+mod valid {
+    pub fn unqualified_fn() {}
+
+    const fn const_fn() {}
+
+    pub async fn async_fn() {}
+
+    pub unsafe fn unsafe_fn() {}
+
+    async unsafe fn async_unsafe_fn() {}
+
+    unsafe extern "C" fn unsafe_extern_fn() {}
+
+    async unsafe extern "C" fn async_unsafe_extern_fn() {}
+
+    const unsafe extern "C" fn const_unsafe_extern_fn() {}
+
+    /*
+    // `safe` is not implemented yet
+    unsafe extern "C" {
+        safe fn const_safe_extern_fn();
+    }
+    */
+}
+
+mod invalid {
+    // `async` precedes `unsafe`
+    unsafe async fn async_unsafe_fn() {}
+    // { dg-error "unexpected token .async. in some sort of unsafe production" "" { target *-*-* } .-1 }
+    // { dg-error "failed to parse item in module" "" { target *-*-* } .-2 }
+}
+
-- 
2.50.1



More information about the Gcc-rust mailing list