Rollup merge of #129635 - compiler-errors:unsafe-blocks, r=spastorino

Use unsafe extern blocks throughout the compiler

Making this change in preparation for edition 2024.

r? spastorino
This commit is contained in:
Matthias Krüger 2024-08-27 18:59:28 +02:00 committed by GitHub
commit 3299e30abc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 29 additions and 26 deletions

View File

@ -6,6 +6,7 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![allow(internal_features)] #![allow(internal_features)]
#![cfg_attr(bootstrap, feature(unsafe_extern_blocks))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)] #![doc(rust_logo)]
#![feature(assert_matches)] #![feature(assert_matches)]

View File

@ -564,12 +564,12 @@ pub enum ArchiveKind {
} }
// LLVMRustThinLTOData // LLVMRustThinLTOData
extern "C" { unsafe extern "C" {
pub type ThinLTOData; pub type ThinLTOData;
} }
// LLVMRustThinLTOBuffer // LLVMRustThinLTOBuffer
extern "C" { unsafe extern "C" {
pub type ThinLTOBuffer; pub type ThinLTOBuffer;
} }
@ -621,7 +621,7 @@ pub enum MemoryEffects {
InaccessibleMemOnly, InaccessibleMemOnly,
} }
extern "C" { unsafe extern "C" {
type Opaque; type Opaque;
} }
#[repr(C)] #[repr(C)]
@ -631,54 +631,54 @@ struct InvariantOpaque<'a> {
} }
// Opaque pointer types // Opaque pointer types
extern "C" { unsafe extern "C" {
pub type Module; pub type Module;
} }
extern "C" { unsafe extern "C" {
pub type Context; pub type Context;
} }
extern "C" { unsafe extern "C" {
pub type Type; pub type Type;
} }
extern "C" { unsafe extern "C" {
pub type Value; pub type Value;
} }
extern "C" { unsafe extern "C" {
pub type ConstantInt; pub type ConstantInt;
} }
extern "C" { unsafe extern "C" {
pub type Attribute; pub type Attribute;
} }
extern "C" { unsafe extern "C" {
pub type Metadata; pub type Metadata;
} }
extern "C" { unsafe extern "C" {
pub type BasicBlock; pub type BasicBlock;
} }
#[repr(C)] #[repr(C)]
pub struct Builder<'a>(InvariantOpaque<'a>); pub struct Builder<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct PassManager<'a>(InvariantOpaque<'a>); pub struct PassManager<'a>(InvariantOpaque<'a>);
extern "C" { unsafe extern "C" {
pub type Pass; pub type Pass;
} }
extern "C" { unsafe extern "C" {
pub type TargetMachine; pub type TargetMachine;
} }
extern "C" { unsafe extern "C" {
pub type Archive; pub type Archive;
} }
#[repr(C)] #[repr(C)]
pub struct ArchiveIterator<'a>(InvariantOpaque<'a>); pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct ArchiveChild<'a>(InvariantOpaque<'a>); pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
extern "C" { unsafe extern "C" {
pub type Twine; pub type Twine;
} }
extern "C" { unsafe extern "C" {
pub type DiagnosticInfo; pub type DiagnosticInfo;
} }
extern "C" { unsafe extern "C" {
pub type SMDiagnostic; pub type SMDiagnostic;
} }
#[repr(C)] #[repr(C)]
@ -688,7 +688,7 @@ pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
#[repr(C)] #[repr(C)]
pub struct Linker<'a>(InvariantOpaque<'a>); pub struct Linker<'a>(InvariantOpaque<'a>);
extern "C" { unsafe extern "C" {
pub type DiagnosticHandler; pub type DiagnosticHandler;
} }
@ -823,7 +823,7 @@ bitflags! {
} }
} }
extern "C" { unsafe extern "C" {
pub type ModuleBuffer; pub type ModuleBuffer;
} }
@ -834,7 +834,7 @@ pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void; pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void; pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
extern "C" { unsafe extern "C" {
// Create and destroy contexts. // Create and destroy contexts.
pub fn LLVMContextDispose(C: &'static mut Context); pub fn LLVMContextDispose(C: &'static mut Context);
pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint; pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
@ -1518,7 +1518,7 @@ extern "C" {
} }
#[link(name = "llvm-wrapper", kind = "static")] #[link(name = "llvm-wrapper", kind = "static")]
extern "C" { unsafe extern "C" {
pub fn LLVMRustInstallErrorHandlers(); pub fn LLVMRustInstallErrorHandlers();
pub fn LLVMRustDisableSystemDialogsOnCrash(); pub fn LLVMRustDisableSystemDialogsOnCrash();

View File

@ -7,6 +7,7 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![allow(internal_features)] #![allow(internal_features)]
#![allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable #![allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
#![cfg_attr(bootstrap, feature(unsafe_extern_blocks))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)] #![doc(rust_logo)]
#![feature(decl_macro)] #![feature(decl_macro)]

View File

@ -6,7 +6,7 @@ use std::{fmt, mem, ptr};
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE}; use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
extern "C" { unsafe extern "C" {
fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int); fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int);
} }

View File

@ -1,5 +1,6 @@
// tidy-alphabetical-start // tidy-alphabetical-start
#![allow(internal_features)] #![allow(internal_features)]
#![cfg_attr(bootstrap, feature(unsafe_attributes, unsafe_extern_blocks))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)] #![doc(rust_logo)]
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
@ -28,7 +29,7 @@ impl RustString {
} }
/// Appending to a Rust string -- used by RawRustStringOstream. /// Appending to a Rust string -- used by RawRustStringOstream.
#[no_mangle] #[unsafe(no_mangle)]
pub unsafe extern "C" fn LLVMRustStringWriteImpl( pub unsafe extern "C" fn LLVMRustStringWriteImpl(
sr: &RustString, sr: &RustString,
ptr: *const c_char, ptr: *const c_char,
@ -46,7 +47,7 @@ pub fn initialize_available_targets() {
($cfg:meta, $($method:ident),*) => { { ($cfg:meta, $($method:ident),*) => { {
#[cfg($cfg)] #[cfg($cfg)]
fn init() { fn init() {
extern "C" { unsafe extern "C" {
$(fn $method();)* $(fn $method();)*
} }
unsafe { unsafe {

View File

@ -28,7 +28,7 @@
#![allow(rustc::diagnostic_outside_of_impl)] #![allow(rustc::diagnostic_outside_of_impl)]
#![allow(rustc::potential_query_instability)] #![allow(rustc::potential_query_instability)]
#![allow(rustc::untranslatable_diagnostic)] #![allow(rustc::untranslatable_diagnostic)]
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))] #![cfg_attr(bootstrap, feature(min_exhaustive_patterns, unsafe_extern_blocks))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)] #![doc(rust_logo)]
#![feature(allocator_api)] #![feature(allocator_api)]

View File

@ -58,7 +58,7 @@ impl<T> Default for &List<T> {
} }
} }
extern "C" { unsafe extern "C" {
/// A dummy type used to force `List` to be unsized while not requiring /// A dummy type used to force `List` to be unsized while not requiring
/// references to it be wide pointers. /// references to it be wide pointers.
type OpaqueListContents; type OpaqueListContents;