Skip to content

Commit eb0f6a8

Browse files
committed
[WIP] Migrate all tests to the 2024 edition
1 parent a28b986 commit eb0f6a8

File tree

5 files changed

+75
-67
lines changed

5 files changed

+75
-67
lines changed

.vscode/settings.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
"crates": [
1616
{
1717
"root_module": "./example/mini_core.rs",
18-
"edition": "2018",
18+
"edition": "2024",
1919
"deps": [],
2020
"cfg": [],
2121
},
2222
{
2323
"root_module": "./example/mini_core_hello_world.rs",
24-
"edition": "2018",
24+
"edition": "2024",
2525
"deps": [{ "crate": 0, "name": "mini_core" }],
2626
"cfg": [],
2727
},
2828
{
2929
"root_module": "./example/mod_bench.rs",
30-
"edition": "2018",
30+
"edition": "2024",
3131
"deps": [],
3232
"cfg": [],
3333
},
@@ -38,7 +38,7 @@
3838
"crates": [
3939
{
4040
"root_module": "./example/std_example.rs",
41-
"edition": "2015",
41+
"edition": "2024",
4242
"deps": [],
4343
"cfg": [],
4444
},

build_system/tests.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
9090
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
9191
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
9292
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
93-
TestCase::custom("aot.gen_block_iterate", &|runner| {
94-
runner.run_rustc([
95-
"example/gen_block_iterate.rs",
96-
"--edition",
97-
"2024",
98-
"-Zunstable-options",
99-
]);
100-
runner.run_out_command("gen_block_iterate", &[]);
101-
}),
93+
TestCase::build_bin_and_run("aot.gen_block_iterate", "example/gen_block_iterate.rs", &[]),
10294
TestCase::build_bin_and_run("aot.raw-dylib", "example/raw-dylib.rs", &[]),
10395
];
10496

@@ -428,6 +420,7 @@ impl<'a> TestRunner<'a> {
428420
cmd.arg(&self.target_compiler.triple);
429421
cmd.arg("-Cpanic=abort");
430422
cmd.arg("--check-cfg=cfg(jit)");
423+
cmd.arg("--edition=2024");
431424
cmd.args(args);
432425
cmd
433426
}

example/example.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,16 @@ pub fn use_size_of() -> usize {
8181
}
8282

8383
pub unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) {
84-
intrinsics::copy::<u8>(src, dst, 1);
84+
unsafe {
85+
intrinsics::copy::<u8>(src, dst, 1);
86+
}
8587
}
8688

8789
pub unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) {
88-
let copy2 = &intrinsics::copy::<u8>;
89-
copy2(src, dst, 1);
90+
unsafe {
91+
let copy2 = &intrinsics::copy::<u8>;
92+
copy2(src, dst, 1);
93+
}
9094
}
9195

9296
pub const ABC: u8 = 6 * 7;
@@ -130,11 +134,11 @@ pub fn eq_char(a: char, b: char) -> bool {
130134
}
131135

132136
pub unsafe fn transmute(c: char) -> u32 {
133-
intrinsics::transmute(c)
137+
unsafe { intrinsics::transmute(c) }
134138
}
135139

136140
pub unsafe fn deref_str_ptr(s: *const str) -> &'static str {
137-
&*s
141+
unsafe { &*s }
138142
}
139143

140144
pub fn use_array(arr: [u8; 3]) -> u8 {
@@ -150,7 +154,7 @@ pub fn array_as_slice(arr: &[u8; 3]) -> &[u8] {
150154
}
151155

152156
pub unsafe fn use_ctlz_nonzero(a: u16) -> u32 {
153-
intrinsics::ctlz_nonzero(a)
157+
unsafe { intrinsics::ctlz_nonzero(a) }
154158
}
155159

156160
pub fn ptr_as_usize(ptr: *const u8) -> usize {

example/mini_core.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ fn eh_personality() -> ! {
527527
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
528528
// Code here does not matter - this is replaced by the
529529
// real drop glue by the compiler.
530-
drop_in_place(to_drop);
530+
unsafe {
531+
drop_in_place(to_drop);
532+
}
531533
}
532534

533535
#[lang = "unpin"]
@@ -594,7 +596,7 @@ impl<T: ?Sized> Deref for Box<T> {
594596

595597
#[lang = "exchange_malloc"]
596598
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
597-
libc::malloc(size)
599+
unsafe { libc::malloc(size) }
598600
}
599601

600602
#[lang = "drop"]
@@ -616,6 +618,8 @@ pub union MaybeUninit<T> {
616618
}
617619

618620
pub mod intrinsics {
621+
use super::*;
622+
619623
#[rustc_intrinsic]
620624
#[rustc_intrinsic_must_be_overridden]
621625
pub fn abort() -> ! {
@@ -628,7 +632,7 @@ pub mod intrinsics {
628632
}
629633
#[rustc_intrinsic]
630634
#[rustc_intrinsic_must_be_overridden]
631-
pub unsafe fn size_of_val<T: ?::Sized>(_val: *const T) -> usize {
635+
pub unsafe fn size_of_val<T: ?Sized>(_val: *const T) -> usize {
632636
loop {}
633637
}
634638
#[rustc_intrinsic]
@@ -638,7 +642,7 @@ pub mod intrinsics {
638642
}
639643
#[rustc_intrinsic]
640644
#[rustc_intrinsic_must_be_overridden]
641-
pub unsafe fn min_align_of_val<T: ?::Sized>(_val: *const T) -> usize {
645+
pub unsafe fn min_align_of_val<T: ?Sized>(_val: *const T) -> usize {
642646
loop {}
643647
}
644648
#[rustc_intrinsic]
@@ -658,7 +662,7 @@ pub mod intrinsics {
658662
}
659663
#[rustc_intrinsic]
660664
#[rustc_intrinsic_must_be_overridden]
661-
pub fn needs_drop<T: ?::Sized>() -> bool {
665+
pub fn needs_drop<T: ?Sized>() -> bool {
662666
loop {}
663667
}
664668
#[rustc_intrinsic]
@@ -689,13 +693,13 @@ pub mod libc {
689693
// symbols to link against.
690694
#[cfg_attr(unix, link(name = "c"))]
691695
#[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))]
692-
extern "C" {
696+
unsafe extern "C" {
693697
pub fn printf(format: *const i8, ...) -> i32;
694698
}
695699

696700
#[cfg_attr(unix, link(name = "c"))]
697701
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
698-
extern "C" {
702+
unsafe extern "C" {
699703
pub fn puts(s: *const i8) -> i32;
700704
pub fn malloc(size: usize) -> *mut u8;
701705
pub fn free(ptr: *mut u8);
@@ -727,7 +731,7 @@ impl<T> Index<usize> for [T] {
727731
}
728732
}
729733

730-
extern "C" {
734+
unsafe extern "C" {
731735
type VaListImpl;
732736
}
733737

@@ -786,7 +790,7 @@ struct PanicLocation {
786790
column: u32,
787791
}
788792

789-
#[no_mangle]
793+
#[unsafe(no_mangle)]
790794
#[cfg(not(all(windows, target_env = "gnu")))]
791795
pub fn get_tls() -> u8 {
792796
#[thread_local]

example/mini_core_hello_world.rs

Lines changed: 46 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,11 @@ static mut NUM: u8 = 6 * 7;
124124
static NUM_REF: &'static u8 = unsafe { &*&raw const NUM };
125125

126126
unsafe fn zeroed<T>() -> T {
127-
let mut uninit = MaybeUninit { uninit: () };
128-
intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1);
129-
uninit.value.value
127+
unsafe {
128+
let mut uninit = MaybeUninit { uninit: () };
129+
intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1);
130+
uninit.value.value
131+
}
130132
}
131133

132134
fn take_f32(_f: f32) {}
@@ -236,7 +238,7 @@ fn main() {
236238
}
237239

238240
unsafe fn uninitialized<T>() -> T {
239-
MaybeUninit { uninit: () }.value.value
241+
unsafe { MaybeUninit { uninit: () }.value.value }
240242
}
241243

242244
zeroed::<(u8, u8)>();
@@ -269,20 +271,20 @@ fn main() {
269271
let x = &[0u32, 42u32] as &[u32];
270272
match x {
271273
[] => assert_eq!(0u32, 1),
272-
[_, ref y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize),
274+
[_, y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize),
273275
}
274276

275277
assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
276278

277279
#[cfg(not(any(jit, windows)))]
278280
{
279-
extern "C" {
281+
unsafe extern "C" {
280282
#[linkage = "extern_weak"]
281283
static ABC: *const u8;
282284
}
283285

284286
{
285-
extern "C" {
287+
unsafe extern "C" {
286288
#[linkage = "extern_weak"]
287289
static ABC: *const u8;
288290
}
@@ -309,7 +311,7 @@ fn main() {
309311

310312
check_niche_behavior();
311313

312-
extern "C" {
314+
unsafe extern "C" {
313315
type ExternType;
314316
}
315317

@@ -362,7 +364,7 @@ fn stack_val_align() {
362364
}
363365

364366
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
365-
extern "C" {
367+
unsafe extern "C" {
366368
fn global_asm_test();
367369
}
368370

@@ -412,7 +414,7 @@ struct pthread_attr_t {
412414

413415
#[link(name = "pthread")]
414416
#[cfg(unix)]
415-
extern "C" {
417+
unsafe extern "C" {
416418
fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int;
417419

418420
fn pthread_create(
@@ -433,7 +435,7 @@ type HANDLE = *mut c_void;
433435

434436
#[link(name = "msvcrt")]
435437
#[cfg(windows)]
436-
extern "C" {
438+
unsafe extern "C" {
437439
fn WaitForSingleObject(hHandle: LPVOID, dwMilliseconds: DWORD) -> DWORD;
438440

439441
fn CreateThread(
@@ -455,46 +457,51 @@ struct Thread {
455457

456458
impl Thread {
457459
unsafe fn create(f: extern "C" fn(_: *mut c_void) -> *mut c_void) -> Self {
458-
#[cfg(unix)]
459-
{
460-
let mut attr: pthread_attr_t = zeroed();
461-
let mut thread: pthread_t = 0;
460+
unsafe {
461+
#[cfg(unix)]
462+
{
463+
let mut attr: pthread_attr_t = zeroed();
464+
let mut thread: pthread_t = 0;
462465

463-
if pthread_attr_init(&mut attr) != 0 {
464-
assert!(false);
465-
}
466+
if pthread_attr_init(&mut attr) != 0 {
467+
assert!(false);
468+
}
469+
470+
if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 {
471+
assert!(false);
472+
}
466473

467-
if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 {
468-
assert!(false);
474+
Thread { handle: thread }
469475
}
470476

471-
Thread { handle: thread }
472-
}
477+
#[cfg(windows)]
478+
{
479+
let handle =
480+
CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32);
473481

474-
#[cfg(windows)]
475-
{
476-
let handle = CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32);
482+
if (handle as u64) == 0 {
483+
assert!(false);
484+
}
477485

478-
if (handle as u64) == 0 {
479-
assert!(false);
486+
Thread { handle }
480487
}
481-
482-
Thread { handle }
483488
}
484489
}
485490

486491
unsafe fn join(self) {
487-
#[cfg(unix)]
488-
{
489-
let mut res = 0 as *mut c_void;
490-
pthread_join(self.handle, &mut res);
491-
}
492+
unsafe {
493+
#[cfg(unix)]
494+
{
495+
let mut res = 0 as *mut c_void;
496+
pthread_join(self.handle, &mut res);
497+
}
492498

493-
#[cfg(windows)]
494-
{
495-
// The INFINITE macro is used to signal operations that do not timeout.
496-
let infinite = 0xffffffff;
497-
assert!(WaitForSingleObject(self.handle, infinite) == 0);
499+
#[cfg(windows)]
500+
{
501+
// The INFINITE macro is used to signal operations that do not timeout.
502+
let infinite = 0xffffffff;
503+
assert!(WaitForSingleObject(self.handle, infinite) == 0);
504+
}
498505
}
499506
}
500507
}

0 commit comments

Comments
 (0)