Skip to content

Commit 2d3f18c

Browse files
Use unsafe extern blocks throughout the compiler
1 parent 0a6714d commit 2d3f18c

File tree

7 files changed

+29
-26
lines changed

7 files changed

+29
-26
lines changed

compiler/rustc_codegen_llvm/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
// tidy-alphabetical-start
88
#![allow(internal_features)]
9+
#![cfg_attr(bootstrap, feature(unsafe_extern_blocks))]
910
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1011
#![doc(rust_logo)]
1112
#![feature(assert_matches)]

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,12 @@ pub enum ArchiveKind {
564564
}
565565

566566
// LLVMRustThinLTOData
567-
extern "C" {
567+
unsafe extern "C" {
568568
pub type ThinLTOData;
569569
}
570570

571571
// LLVMRustThinLTOBuffer
572-
extern "C" {
572+
unsafe extern "C" {
573573
pub type ThinLTOBuffer;
574574
}
575575

@@ -621,7 +621,7 @@ pub enum MemoryEffects {
621621
InaccessibleMemOnly,
622622
}
623623

624-
extern "C" {
624+
unsafe extern "C" {
625625
type Opaque;
626626
}
627627
#[repr(C)]
@@ -631,54 +631,54 @@ struct InvariantOpaque<'a> {
631631
}
632632

633633
// Opaque pointer types
634-
extern "C" {
634+
unsafe extern "C" {
635635
pub type Module;
636636
}
637-
extern "C" {
637+
unsafe extern "C" {
638638
pub type Context;
639639
}
640-
extern "C" {
640+
unsafe extern "C" {
641641
pub type Type;
642642
}
643-
extern "C" {
643+
unsafe extern "C" {
644644
pub type Value;
645645
}
646-
extern "C" {
646+
unsafe extern "C" {
647647
pub type ConstantInt;
648648
}
649-
extern "C" {
649+
unsafe extern "C" {
650650
pub type Attribute;
651651
}
652-
extern "C" {
652+
unsafe extern "C" {
653653
pub type Metadata;
654654
}
655-
extern "C" {
655+
unsafe extern "C" {
656656
pub type BasicBlock;
657657
}
658658
#[repr(C)]
659659
pub struct Builder<'a>(InvariantOpaque<'a>);
660660
#[repr(C)]
661661
pub struct PassManager<'a>(InvariantOpaque<'a>);
662-
extern "C" {
662+
unsafe extern "C" {
663663
pub type Pass;
664664
}
665-
extern "C" {
665+
unsafe extern "C" {
666666
pub type TargetMachine;
667667
}
668-
extern "C" {
668+
unsafe extern "C" {
669669
pub type Archive;
670670
}
671671
#[repr(C)]
672672
pub struct ArchiveIterator<'a>(InvariantOpaque<'a>);
673673
#[repr(C)]
674674
pub struct ArchiveChild<'a>(InvariantOpaque<'a>);
675-
extern "C" {
675+
unsafe extern "C" {
676676
pub type Twine;
677677
}
678-
extern "C" {
678+
unsafe extern "C" {
679679
pub type DiagnosticInfo;
680680
}
681-
extern "C" {
681+
unsafe extern "C" {
682682
pub type SMDiagnostic;
683683
}
684684
#[repr(C)]
@@ -688,7 +688,7 @@ pub struct OperandBundleDef<'a>(InvariantOpaque<'a>);
688688
#[repr(C)]
689689
pub struct Linker<'a>(InvariantOpaque<'a>);
690690

691-
extern "C" {
691+
unsafe extern "C" {
692692
pub type DiagnosticHandler;
693693
}
694694

@@ -823,7 +823,7 @@ bitflags! {
823823
}
824824
}
825825

826-
extern "C" {
826+
unsafe extern "C" {
827827
pub type ModuleBuffer;
828828
}
829829

@@ -834,7 +834,7 @@ pub type SelfProfileAfterPassCallback = unsafe extern "C" fn(*mut c_void);
834834
pub type GetSymbolsCallback = unsafe extern "C" fn(*mut c_void, *const c_char) -> *mut c_void;
835835
pub type GetSymbolsErrorCallback = unsafe extern "C" fn(*const c_char) -> *mut c_void;
836836

837-
extern "C" {
837+
unsafe extern "C" {
838838
// Create and destroy contexts.
839839
pub fn LLVMContextDispose(C: &'static mut Context);
840840
pub fn LLVMGetMDKindIDInContext(C: &Context, Name: *const c_char, SLen: c_uint) -> c_uint;
@@ -1518,7 +1518,7 @@ extern "C" {
15181518
}
15191519

15201520
#[link(name = "llvm-wrapper", kind = "static")]
1521-
extern "C" {
1521+
unsafe extern "C" {
15221522
pub fn LLVMRustInstallErrorHandlers();
15231523
pub fn LLVMRustDisableSystemDialogsOnCrash();
15241524

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// tidy-alphabetical-start
88
#![allow(internal_features)]
99
#![allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
10+
#![cfg_attr(bootstrap, feature(unsafe_extern_blocks))]
1011
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
1112
#![doc(rust_logo)]
1213
#![feature(decl_macro)]

compiler/rustc_driver_impl/src/signal_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{fmt, mem, ptr};
66

77
use rustc_interface::util::{DEFAULT_STACK_SIZE, STACK_SIZE};
88

9-
extern "C" {
9+
unsafe extern "C" {
1010
fn backtrace_symbols_fd(buffer: *const *mut libc::c_void, size: libc::c_int, fd: libc::c_int);
1111
}
1212

compiler/rustc_llvm/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// tidy-alphabetical-start
22
#![allow(internal_features)]
3+
#![cfg_attr(bootstrap, feature(unsafe_attributes, unsafe_extern_blocks))]
34
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
45
#![doc(rust_logo)]
56
#![feature(rustdoc_internals)]
@@ -28,7 +29,7 @@ impl RustString {
2829
}
2930

3031
/// Appending to a Rust string -- used by RawRustStringOstream.
31-
#[no_mangle]
32+
#[unsafe(no_mangle)]
3233
pub unsafe extern "C" fn LLVMRustStringWriteImpl(
3334
sr: &RustString,
3435
ptr: *const c_char,
@@ -46,7 +47,7 @@ pub fn initialize_available_targets() {
4647
($cfg:meta, $($method:ident),*) => { {
4748
#[cfg($cfg)]
4849
fn init() {
49-
extern "C" {
50+
unsafe extern "C" {
5051
$(fn $method();)*
5152
}
5253
unsafe {

compiler/rustc_middle/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#![allow(rustc::diagnostic_outside_of_impl)]
2929
#![allow(rustc::potential_query_instability)]
3030
#![allow(rustc::untranslatable_diagnostic)]
31-
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns))]
31+
#![cfg_attr(bootstrap, feature(min_exhaustive_patterns, unsafe_extern_blocks))]
3232
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
3333
#![doc(rust_logo)]
3434
#![feature(allocator_api)]

compiler/rustc_middle/src/ty/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<T> Default for &List<T> {
5858
}
5959
}
6060

61-
extern "C" {
61+
unsafe extern "C" {
6262
/// A dummy type used to force `List` to be unsized while not requiring
6363
/// references to it be wide pointers.
6464
type OpaqueListContents;

0 commit comments

Comments
 (0)