From: Pierre-Emmanuel Patry <[email protected]>
We usually test components independently, this means we did not test for
lang item declaration within external crate. This commit introduces a new
test directory to test external crate boundary.
gcc/testsuite/ChangeLog:
* rust/minicore/extern_lang_items.rs: New test.
* rust/minicore/extern_lang_items_core/lib.rs: New test.
* rust/minicore/minicore.exp: New test.
Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/0e6eb492b508e7b0eb29f04af628d19b2201dedf
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4758
.../rust/minicore/extern_lang_items.rs | 11 +++
.../minicore/extern_lang_items_core/lib.rs | 25 +++++++
gcc/testsuite/rust/minicore/minicore.exp | 74 +++++++++++++++++++
3 files changed, 110 insertions(+)
create mode 100644 gcc/testsuite/rust/minicore/extern_lang_items.rs
create mode 100644 gcc/testsuite/rust/minicore/extern_lang_items_core/lib.rs
create mode 100644 gcc/testsuite/rust/minicore/minicore.exp
diff --git a/gcc/testsuite/rust/minicore/extern_lang_items.rs
b/gcc/testsuite/rust/minicore/extern_lang_items.rs
new file mode 100644
index 000000000..cce9718ef
--- /dev/null
+++ b/gcc/testsuite/rust/minicore/extern_lang_items.rs
@@ -0,0 +1,11 @@
+#![no_std]
+
+#[derive(Clone)]
+struct MyStruct {
+ inner: i32,
+}
+
+fn main() -> i32 {
+ let a: MyStruct = MyStruct { inner: 8 };
+ a.inner
+}
diff --git a/gcc/testsuite/rust/minicore/extern_lang_items_core/lib.rs
b/gcc/testsuite/rust/minicore/extern_lang_items_core/lib.rs
new file mode 100644
index 000000000..b708fcc6d
--- /dev/null
+++ b/gcc/testsuite/rust/minicore/extern_lang_items_core/lib.rs
@@ -0,0 +1,25 @@
+#![feature(no_core)]
+#![no_core]
+#![feature(lang_items)]
+#![feature(arbitrary_self_types)]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+#[lang = "copy"]
+pub trait Copy {}
+
+mod clone {
+ #[lang = "clone"]
+ trait Clone {
+ pub fn clone(&self) -> Self;
+ }
+
+ impl Clone for i32 {
+ fn clone(&self) -> Self {
+ *self
+ }
+ }
+}
+
+impl Copy for i32 {}
diff --git a/gcc/testsuite/rust/minicore/minicore.exp
b/gcc/testsuite/rust/minicore/minicore.exp
new file mode 100644
index 000000000..141f438a8
--- /dev/null
+++ b/gcc/testsuite/rust/minicore/minicore.exp
@@ -0,0 +1,74 @@
+# Copyright (C) 2026 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with GCC; see the file COPYING3. If not see
+# <http://www.gnu.org/licenses/>.
+
+load_lib rust-dg.exp
+
+# Initialize `dg'.
+dg-init
+
+# Main loop.
+set saved-dg-do-what-default ${dg-do-what-default}
+
+set dg-do-what-default "assemble"
+
+proc rs-compile-with-core { src1 } {
+ global srcdir tmpdir
+
+ verbose "rs-execute: $src1" 1
+ set compile_type "run"
+ set compile_xfail(0) ""
+
+ set dir [file dirname $src1]
+ # Get test name without .rs extension
+ set base [file rootname $src1]
+ set base [string range $base [string length $dir] end]
+ regsub "/" $base "" base
+
+ set done 0
+ set src_list [glob -nocomplain -types f -- "${dir}/${base}_core/lib.rs"]
+ if { [llength ${src_list}] > 1 } {
+ warning "rs-compile-with-core: more than one file matched
${dir}/${base}_${i}.*"
+ }
+
+ # compile core
+ gcc-dg-runtest [lindex ${src_list} 0] "" "-frust-crate=core"
+ # compile test
+ gcc-dg-runtest $src1 "" ""
+}
+
+foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.rs]] {
+ # If we're only testing specific files and this isn't one of them, skip it.
+ if ![runtest_file_p $runtests $src] then {
+ continue
+ }
+
+ # To prevent 'runtest_file_p' being tested again (for example, via
+ # 'gcc-dg-runtest'), with undesirable consequences due to its side effects,
+ # interpose a dummy:
+ rename runtest_file_p saved_runtest_file_p
+ proc runtest_file_p { runtests testcase } {
+ return 1
+ }
+ rs-compile-with-core $src
+ rename runtest_file_p {}
+ rename saved_runtest_file_p runtest_file_p
+
+}
+
+set dg-do-what-default ${saved-dg-do-what-default}
+
+# All done.
+dg-finish
base-commit: 20f362f26936b75da3065b22559bdd35472d05cd
--
2.55.0