https://gcc.gnu.org/g:b9ff9b0aeaf6ffeab9816acf743737174c032e07
commit r17-5691-gb9ff9b0aeaf6ffeab9816acf743737174c032e07 Author: Pierre-Emmanuel Patry <[email protected]> Date: Wed Jul 15 16:25:42 2026 +0200 gccrs: Add extern crate core library test 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]> Diff: --- gcc/testsuite/rust/minicore/extern_lang_items.rs | 11 ++++ .../rust/minicore/extern_lang_items_core/lib.rs | 25 ++++++++ gcc/testsuite/rust/minicore/minicore.exp | 74 ++++++++++++++++++++++ 3 files changed, 110 insertions(+) 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 000000000000..cce9718ef8be --- /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 000000000000..b708fcc6d61c --- /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 000000000000..141f438a87d6 --- /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
