Skip to content

Commit d24852f

Browse files
committed
Migrate all tests to the 2024 edition
1 parent 5782b21 commit d24852f

File tree

5 files changed

+73
-67
lines changed

5 files changed

+73
-67
lines changed

.vscode/settings.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@
2020
"crates": [
2121
{
2222
"root_module": "./example/mini_core.rs",
23-
"edition": "2015",
23+
"edition": "2024",
2424
"deps": [],
2525
"cfg": [],
2626
},
2727
{
2828
"root_module": "./example/mini_core_hello_world.rs",
29-
"edition": "2015",
29+
"edition": "2024",
3030
"deps": [
3131
{
3232
"crate": 0,
@@ -37,7 +37,7 @@
3737
},
3838
{
3939
"root_module": "./example/std_example.rs",
40-
"edition": "2015",
40+
"edition": "2024",
4141
"deps": [],
4242
"cfg": [],
4343
},

build_system/tests.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[
8989
TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]),
9090
TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"),
9191
TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]),
92-
TestCase::custom("aot.gen_block_iterate", &|runner| {
93-
runner.run_rustc([
94-
"example/gen_block_iterate.rs",
95-
"--edition",
96-
"2024",
97-
"-Zunstable-options",
98-
]);
99-
runner.run_out_command("gen_block_iterate", &[]);
100-
}),
92+
TestCase::build_bin_and_run("aot.gen_block_iterate", "example/gen_block_iterate.rs", &[]),
10193
TestCase::build_bin_and_run("aot.raw-dylib", "example/raw-dylib.rs", &[]),
10294
TestCase::custom("test.sysroot", &|runner| {
10395
apply_patches(
@@ -423,6 +415,7 @@ impl<'a> TestRunner<'a> {
423415
cmd.arg("-Cpanic=abort");
424416
}
425417
cmd.arg("--check-cfg=cfg(jit)");
418+
cmd.arg("--edition=2024");
426419
cmd.args(args);
427420
cmd
428421
}

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: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ fn panic_in_cleanup() -> ! {
545545

546546
#[cfg(all(unix, not(target_vendor = "apple")))]
547547
#[link(name = "gcc_s")]
548-
extern "C" {
548+
unsafe extern "C" {
549549
fn _Unwind_Resume(exc: *mut ()) -> !;
550550
}
551551

@@ -554,7 +554,9 @@ extern "C" {
554554
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
555555
// Code here does not matter - this is replaced by the
556556
// real drop glue by the compiler.
557-
drop_in_place(to_drop);
557+
unsafe {
558+
drop_in_place(to_drop);
559+
}
558560
}
559561

560562
#[lang = "unpin"]
@@ -621,7 +623,7 @@ impl<T: ?Sized> Deref for Box<T> {
621623

622624
#[lang = "exchange_malloc"]
623625
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
624-
libc::malloc(size)
626+
unsafe { libc::malloc(size) }
625627
}
626628

627629
#[lang = "drop"]
@@ -648,19 +650,19 @@ pub mod intrinsics {
648650
#[rustc_intrinsic]
649651
pub fn size_of<T>() -> usize;
650652
#[rustc_intrinsic]
651-
pub unsafe fn size_of_val<T: ?::Sized>(val: *const T) -> usize;
653+
pub unsafe fn size_of_val<T: ?crate::Sized>(val: *const T) -> usize;
652654
#[rustc_intrinsic]
653655
pub fn align_of<T>() -> usize;
654656
#[rustc_intrinsic]
655-
pub unsafe fn align_of_val<T: ?::Sized>(val: *const T) -> usize;
657+
pub unsafe fn align_of_val<T: ?crate::Sized>(val: *const T) -> usize;
656658
#[rustc_intrinsic]
657659
pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize);
658660
#[rustc_intrinsic]
659661
pub unsafe fn transmute<T, U>(e: T) -> U;
660662
#[rustc_intrinsic]
661663
pub unsafe fn ctlz_nonzero<T>(x: T) -> u32;
662664
#[rustc_intrinsic]
663-
pub const fn needs_drop<T: ?::Sized>() -> bool;
665+
pub const fn needs_drop<T: ?crate::Sized>() -> bool;
664666
#[rustc_intrinsic]
665667
pub fn bitreverse<T>(x: T) -> T;
666668
#[rustc_intrinsic]
@@ -677,13 +679,13 @@ pub mod libc {
677679
// symbols to link against.
678680
#[cfg_attr(unix, link(name = "c"))]
679681
#[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))]
680-
extern "C" {
682+
unsafe extern "C" {
681683
pub fn printf(format: *const i8, ...) -> i32;
682684
}
683685

684686
#[cfg_attr(unix, link(name = "c"))]
685687
#[cfg_attr(target_env = "msvc", link(name = "msvcrt"))]
686-
extern "C" {
688+
unsafe extern "C" {
687689
pub fn puts(s: *const i8) -> i32;
688690
pub fn malloc(size: usize) -> *mut u8;
689691
pub fn free(ptr: *mut u8);
@@ -715,7 +717,7 @@ impl<T> Index<usize> for [T] {
715717
}
716718
}
717719

718-
extern "C" {
720+
unsafe extern "C" {
719721
type VaListImpl;
720722
}
721723

@@ -774,7 +776,7 @@ struct PanicLocation {
774776
column: u32,
775777
}
776778

777-
#[no_mangle]
779+
#[unsafe(no_mangle)]
778780
#[cfg(not(all(windows, target_env = "gnu")))]
779781
pub fn get_tls() -> u8 {
780782
#[thread_local]

example/mini_core_hello_world.rs

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

117117
unsafe fn zeroed<T>() -> T {
118-
let mut uninit = MaybeUninit { uninit: () };
119-
intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1);
120-
uninit.value.value
118+
unsafe {
119+
let mut uninit = MaybeUninit { uninit: () };
120+
intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1);
121+
uninit.value.value
122+
}
121123
}
122124

123125
fn take_f32(_f: f32) {}
@@ -228,7 +230,7 @@ fn main() {
228230
}
229231

230232
unsafe fn uninitialized<T>() -> T {
231-
MaybeUninit { uninit: () }.value.value
233+
unsafe { MaybeUninit { uninit: () }.value.value }
232234
}
233235

234236
zeroed::<(u8, u8)>();
@@ -261,20 +263,20 @@ fn main() {
261263
let x = &[0u32, 42u32] as &[u32];
262264
match x {
263265
[] => assert_eq!(0u32, 1),
264-
[_, ref y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize),
266+
[_, y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize),
265267
}
266268

267269
assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42);
268270

269271
#[cfg(not(any(jit, target_vendor = "apple", windows)))]
270272
{
271-
extern "C" {
273+
unsafe extern "C" {
272274
#[linkage = "extern_weak"]
273275
static ABC: *const u8;
274276
}
275277

276278
{
277-
extern "C" {
279+
unsafe extern "C" {
278280
#[linkage = "extern_weak"]
279281
static ABC: *const u8;
280282
}
@@ -301,7 +303,7 @@ fn main() {
301303

302304
check_niche_behavior();
303305

304-
extern "C" {
306+
unsafe extern "C" {
305307
type ExternType;
306308
}
307309

@@ -354,7 +356,7 @@ fn stack_val_align() {
354356
}
355357

356358
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
357-
extern "C" {
359+
unsafe extern "C" {
358360
fn global_asm_test();
359361
}
360362

@@ -402,7 +404,7 @@ struct pthread_attr_t {
402404

403405
#[link(name = "pthread")]
404406
#[cfg(unix)]
405-
extern "C" {
407+
unsafe extern "C" {
406408
fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int;
407409

408410
fn pthread_create(
@@ -423,7 +425,7 @@ type HANDLE = *mut c_void;
423425

424426
#[link(name = "msvcrt")]
425427
#[cfg(windows)]
426-
extern "C" {
428+
unsafe extern "C" {
427429
fn WaitForSingleObject(hHandle: LPVOID, dwMilliseconds: DWORD) -> DWORD;
428430

429431
fn CreateThread(
@@ -445,46 +447,51 @@ struct Thread {
445447

446448
impl Thread {
447449
unsafe fn create(f: extern "C" fn(_: *mut c_void) -> *mut c_void) -> Self {
448-
#[cfg(unix)]
449-
{
450-
let mut attr: pthread_attr_t = zeroed();
451-
let mut thread: pthread_t = 0;
450+
unsafe {
451+
#[cfg(unix)]
452+
{
453+
let mut attr: pthread_attr_t = zeroed();
454+
let mut thread: pthread_t = 0;
452455

453-
if pthread_attr_init(&mut attr) != 0 {
454-
assert!(false);
455-
}
456+
if pthread_attr_init(&mut attr) != 0 {
457+
assert!(false);
458+
}
459+
460+
if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 {
461+
assert!(false);
462+
}
456463

457-
if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 {
458-
assert!(false);
464+
Thread { handle: thread }
459465
}
460466

461-
Thread { handle: thread }
462-
}
467+
#[cfg(windows)]
468+
{
469+
let handle =
470+
CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32);
463471

464-
#[cfg(windows)]
465-
{
466-
let handle = CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32);
472+
if (handle as u64) == 0 {
473+
assert!(false);
474+
}
467475

468-
if (handle as u64) == 0 {
469-
assert!(false);
476+
Thread { handle }
470477
}
471-
472-
Thread { handle }
473478
}
474479
}
475480

476481
unsafe fn join(self) {
477-
#[cfg(unix)]
478-
{
479-
let mut res = 0 as *mut c_void;
480-
pthread_join(self.handle, &mut res);
481-
}
482+
unsafe {
483+
#[cfg(unix)]
484+
{
485+
let mut res = 0 as *mut c_void;
486+
pthread_join(self.handle, &mut res);
487+
}
482488

483-
#[cfg(windows)]
484-
{
485-
// The INFINITE macro is used to signal operations that do not timeout.
486-
let infinite = 0xffffffff;
487-
assert!(WaitForSingleObject(self.handle, infinite) == 0);
489+
#[cfg(windows)]
490+
{
491+
// The INFINITE macro is used to signal operations that do not timeout.
492+
let infinite = 0xffffffff;
493+
assert!(WaitForSingleObject(self.handle, infinite) == 0);
494+
}
488495
}
489496
}
490497
}

0 commit comments

Comments
 (0)