diff --git a/.vscode/settings.json b/.vscode/settings.json index 68bd93aea890..2a3ec5e1c905 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,13 +20,13 @@ "crates": [ { "root_module": "./example/mini_core.rs", - "edition": "2015", + "edition": "2024", "deps": [], "cfg": [], }, { "root_module": "./example/mini_core_hello_world.rs", - "edition": "2015", + "edition": "2024", "deps": [ { "crate": 0, @@ -37,7 +37,7 @@ }, { "root_module": "./example/std_example.rs", - "edition": "2015", + "edition": "2024", "deps": [], "cfg": [], }, diff --git a/build_system/tests.rs b/build_system/tests.rs index 8cd84a79f9f7..3c22450a15f6 100644 --- a/build_system/tests.rs +++ b/build_system/tests.rs @@ -89,15 +89,7 @@ const BASE_SYSROOT_SUITE: &[TestCase] = &[ TestCase::build_bin_and_run("aot.issue-72793", "example/issue-72793.rs", &[]), TestCase::build_bin("aot.issue-59326", "example/issue-59326.rs"), TestCase::build_bin_and_run("aot.neon", "example/neon.rs", &[]), - TestCase::custom("aot.gen_block_iterate", &|runner| { - runner.run_rustc([ - "example/gen_block_iterate.rs", - "--edition", - "2024", - "-Zunstable-options", - ]); - runner.run_out_command("gen_block_iterate", &[]); - }), + TestCase::build_bin_and_run("aot.gen_block_iterate", "example/gen_block_iterate.rs", &[]), TestCase::build_bin_and_run("aot.raw-dylib", "example/raw-dylib.rs", &[]), TestCase::custom("test.sysroot", &|runner| { apply_patches( @@ -423,6 +415,7 @@ impl<'a> TestRunner<'a> { cmd.arg("-Cpanic=abort"); } cmd.arg("--check-cfg=cfg(jit)"); + cmd.arg("--edition=2024"); cmd.args(args); cmd } diff --git a/example/example.rs b/example/example.rs index aeb38331edb0..e86bb8f59339 100644 --- a/example/example.rs +++ b/example/example.rs @@ -81,12 +81,16 @@ pub fn use_size_of() -> usize { } pub unsafe fn use_copy_intrinsic(src: *const u8, dst: *mut u8) { - intrinsics::copy::(src, dst, 1); + unsafe { + intrinsics::copy::(src, dst, 1); + } } pub unsafe fn use_copy_intrinsic_ref(src: *const u8, dst: *mut u8) { - let copy2 = &intrinsics::copy::; - copy2(src, dst, 1); + unsafe { + let copy2 = &intrinsics::copy::; + copy2(src, dst, 1); + } } pub const ABC: u8 = 6 * 7; @@ -130,11 +134,11 @@ pub fn eq_char(a: char, b: char) -> bool { } pub unsafe fn transmute(c: char) -> u32 { - intrinsics::transmute(c) + unsafe { intrinsics::transmute(c) } } pub unsafe fn deref_str_ptr(s: *const str) -> &'static str { - &*s + unsafe { &*s } } pub fn use_array(arr: [u8; 3]) -> u8 { @@ -150,7 +154,7 @@ pub fn array_as_slice(arr: &[u8; 3]) -> &[u8] { } pub unsafe fn use_ctlz_nonzero(a: u16) -> u32 { - intrinsics::ctlz_nonzero(a) + unsafe { intrinsics::ctlz_nonzero(a) } } pub fn ptr_as_usize(ptr: *const u8) -> usize { diff --git a/example/mini_core.rs b/example/mini_core.rs index 2f53bbf8b793..3f846d393ba6 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -545,7 +545,7 @@ fn panic_in_cleanup() -> ! { #[cfg(all(unix, not(target_vendor = "apple")))] #[link(name = "gcc_s")] -extern "C" { +unsafe extern "C" { fn _Unwind_Resume(exc: *mut ()) -> !; } @@ -554,7 +554,9 @@ extern "C" { pub unsafe fn drop_in_place(to_drop: *mut T) { // Code here does not matter - this is replaced by the // real drop glue by the compiler. - drop_in_place(to_drop); + unsafe { + drop_in_place(to_drop); + } } #[lang = "unpin"] @@ -621,7 +623,7 @@ impl Deref for Box { #[lang = "exchange_malloc"] unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size) + unsafe { libc::malloc(size) } } #[lang = "drop"] @@ -648,11 +650,11 @@ pub mod intrinsics { #[rustc_intrinsic] pub fn size_of() -> usize; #[rustc_intrinsic] - pub unsafe fn size_of_val(val: *const T) -> usize; + pub unsafe fn size_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub fn align_of() -> usize; #[rustc_intrinsic] - pub unsafe fn align_of_val(val: *const T) -> usize; + pub unsafe fn align_of_val(val: *const T) -> usize; #[rustc_intrinsic] pub unsafe fn copy(src: *const T, dst: *mut T, count: usize); #[rustc_intrinsic] @@ -660,7 +662,7 @@ pub mod intrinsics { #[rustc_intrinsic] pub unsafe fn ctlz_nonzero(x: T) -> u32; #[rustc_intrinsic] - pub const fn needs_drop() -> bool; + pub const fn needs_drop() -> bool; #[rustc_intrinsic] pub fn bitreverse(x: T) -> T; #[rustc_intrinsic] @@ -677,13 +679,13 @@ pub mod libc { // symbols to link against. #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "legacy_stdio_definitions"))] - extern "C" { + unsafe extern "C" { pub fn printf(format: *const i8, ...) -> i32; } #[cfg_attr(unix, link(name = "c"))] #[cfg_attr(target_env = "msvc", link(name = "msvcrt"))] - extern "C" { + unsafe extern "C" { pub fn puts(s: *const i8) -> i32; pub fn malloc(size: usize) -> *mut u8; pub fn free(ptr: *mut u8); @@ -715,7 +717,7 @@ impl Index for [T] { } } -extern "C" { +unsafe extern "C" { type VaListImpl; } @@ -774,7 +776,7 @@ struct PanicLocation { column: u32, } -#[no_mangle] +#[unsafe(no_mangle)] #[cfg(not(all(windows, target_env = "gnu")))] pub fn get_tls() -> u8 { #[thread_local] diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 66ecc9ec034a..3a5bcc55584f 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -115,9 +115,11 @@ static mut NUM: u8 = 6 * 7; static NUM_REF: &'static u8 = unsafe { &*&raw const NUM }; unsafe fn zeroed() -> T { - let mut uninit = MaybeUninit { uninit: () }; - intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1); - uninit.value.value + unsafe { + let mut uninit = MaybeUninit { uninit: () }; + intrinsics::write_bytes(&mut uninit.value.value as *mut T, 0, 1); + uninit.value.value + } } fn take_f32(_f: f32) {} @@ -228,7 +230,7 @@ fn main() { } unsafe fn uninitialized() -> T { - MaybeUninit { uninit: () }.value.value + unsafe { MaybeUninit { uninit: () }.value.value } } zeroed::<(u8, u8)>(); @@ -261,20 +263,20 @@ fn main() { let x = &[0u32, 42u32] as &[u32]; match x { [] => assert_eq!(0u32, 1), - [_, ref y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize), + [_, y @ ..] => assert_eq!(&x[1] as *const u32 as usize, &y[0] as *const u32 as usize), } assert_eq!(((|()| 42u8) as fn(()) -> u8)(()), 42); #[cfg(not(any(jit, target_vendor = "apple", windows)))] { - extern "C" { + unsafe extern "C" { #[linkage = "extern_weak"] static ABC: *const u8; } { - extern "C" { + unsafe extern "C" { #[linkage = "extern_weak"] static ABC: *const u8; } @@ -301,7 +303,7 @@ fn main() { check_niche_behavior(); - extern "C" { + unsafe extern "C" { type ExternType; } @@ -354,7 +356,7 @@ fn stack_val_align() { } #[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))] -extern "C" { +unsafe extern "C" { fn global_asm_test(); } @@ -402,7 +404,7 @@ struct pthread_attr_t { #[link(name = "pthread")] #[cfg(unix)] -extern "C" { +unsafe extern "C" { fn pthread_attr_init(attr: *mut pthread_attr_t) -> c_int; fn pthread_create( @@ -423,7 +425,7 @@ type HANDLE = *mut c_void; #[link(name = "msvcrt")] #[cfg(windows)] -extern "C" { +unsafe extern "C" { fn WaitForSingleObject(hHandle: LPVOID, dwMilliseconds: DWORD) -> DWORD; fn CreateThread( @@ -445,46 +447,51 @@ struct Thread { impl Thread { unsafe fn create(f: extern "C" fn(_: *mut c_void) -> *mut c_void) -> Self { - #[cfg(unix)] - { - let mut attr: pthread_attr_t = zeroed(); - let mut thread: pthread_t = 0; + unsafe { + #[cfg(unix)] + { + let mut attr: pthread_attr_t = zeroed(); + let mut thread: pthread_t = 0; - if pthread_attr_init(&mut attr) != 0 { - assert!(false); + if pthread_attr_init(&mut attr) != 0 { + assert!(false); + } + + if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 { + assert!(false); + } + + Thread { handle: thread } } - if pthread_create(&mut thread, &attr, f, 0 as *mut c_void) != 0 { - assert!(false); + #[cfg(windows)] + { + let handle = + CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32); + + if (handle as u64) == 0 { + assert!(false); + } + + Thread { handle } } - - Thread { handle: thread } - } - - #[cfg(windows)] - { - let handle = CreateThread(0 as *mut c_void, 0, f, 0 as *mut c_void, 0, 0 as *mut u32); - - if (handle as u64) == 0 { - assert!(false); - } - - Thread { handle } } } unsafe fn join(self) { - #[cfg(unix)] - { - let mut res = 0 as *mut c_void; - pthread_join(self.handle, &mut res); - } + unsafe { + #[cfg(unix)] + { + let mut res = 0 as *mut c_void; + pthread_join(self.handle, &mut res); + } - #[cfg(windows)] - { - // The INFINITE macro is used to signal operations that do not timeout. - let infinite = 0xffffffff; - assert!(WaitForSingleObject(self.handle, infinite) == 0); + #[cfg(windows)] + { + // The INFINITE macro is used to signal operations that do not timeout. + let infinite = 0xffffffff; + assert!(WaitForSingleObject(self.handle, infinite) == 0); + } } } }