Skip to content

Commit dcc536f

Browse files
Rollup merge of #52252 - ljedrz:dyn_librustc_codegen_llvm, r=varkor
Deny bare trait objects in in src/librustc_codegen_llvm Enforce `#![deny(bare_trait_objects)]` in `src/librustc_codegen_llvm`.
2 parents 8d9a6a7 + ea47350 commit dcc536f

File tree

8 files changed

+34
-33
lines changed

8 files changed

+34
-33
lines changed

src/librustc_codegen_llvm/back/archive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ enum Addition {
4848
},
4949
Archive {
5050
archive: ArchiveRO,
51-
skip: Box<FnMut(&str) -> bool>,
51+
skip: Box<dyn FnMut(&str) -> bool>,
5252
},
5353
}
5454

src/librustc_codegen_llvm/back/link.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ fn filename_for_metadata(sess: &Session, crate_name: &str, outputs: &OutputFilen
251251

252252
pub(crate) fn each_linked_rlib(sess: &Session,
253253
info: &CrateInfo,
254-
f: &mut FnMut(CrateNum, &Path)) -> Result<(), String> {
254+
f: &mut dyn FnMut(CrateNum, &Path)) -> Result<(), String> {
255255
let crates = info.used_crates_static.iter();
256256
let fmts = sess.dependency_formats.borrow();
257257
let fmts = fmts.get(&config::CrateTypeExecutable)
@@ -984,7 +984,7 @@ fn exec_linker(sess: &Session, cmd: &mut Command, out_filename: &Path, tmpdir: &
984984
}
985985
}
986986

987-
fn link_args(cmd: &mut Linker,
987+
fn link_args(cmd: &mut dyn Linker,
988988
sess: &Session,
989989
crate_type: config::CrateType,
990990
tmpdir: &Path,
@@ -1195,7 +1195,7 @@ fn link_args(cmd: &mut Linker,
11951195
// Also note that the native libraries linked here are only the ones located
11961196
// in the current crate. Upstream crates with native library dependencies
11971197
// may have their native library pulled in above.
1198-
fn add_local_native_libraries(cmd: &mut Linker,
1198+
fn add_local_native_libraries(cmd: &mut dyn Linker,
11991199
sess: &Session,
12001200
codegen_results: &CodegenResults) {
12011201
sess.target_filesearch(PathKind::All).for_each_lib_search_path(|path, k| {
@@ -1226,7 +1226,7 @@ fn add_local_native_libraries(cmd: &mut Linker,
12261226
// Rust crates are not considered at all when creating an rlib output. All
12271227
// dependencies will be linked when producing the final output (instead of
12281228
// the intermediate rlib version)
1229-
fn add_upstream_rust_crates(cmd: &mut Linker,
1229+
fn add_upstream_rust_crates(cmd: &mut dyn Linker,
12301230
sess: &Session,
12311231
codegen_results: &CodegenResults,
12321232
crate_type: config::CrateType,
@@ -1350,7 +1350,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
13501350
// it's packed in a .rlib, it contains stuff that are not objects that will
13511351
// make the linker error. So we must remove those bits from the .rlib before
13521352
// linking it.
1353-
fn link_sanitizer_runtime(cmd: &mut Linker,
1353+
fn link_sanitizer_runtime(cmd: &mut dyn Linker,
13541354
sess: &Session,
13551355
codegen_results: &CodegenResults,
13561356
tmpdir: &Path,
@@ -1419,7 +1419,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
14191419
// (aka we're making an executable), we can just pass the rlib blindly to
14201420
// the linker (fast) because it's fine if it's not actually included as
14211421
// we're at the end of the dependency chain.
1422-
fn add_static_crate(cmd: &mut Linker,
1422+
fn add_static_crate(cmd: &mut dyn Linker,
14231423
sess: &Session,
14241424
codegen_results: &CodegenResults,
14251425
tmpdir: &Path,
@@ -1524,7 +1524,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
15241524
}
15251525

15261526
// Same thing as above, but for dynamic crates instead of static crates.
1527-
fn add_dynamic_crate(cmd: &mut Linker, sess: &Session, cratepath: &Path) {
1527+
fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
15281528
// If we're performing LTO, then it should have been previously required
15291529
// that all upstream rust dependencies were available in an rlib format.
15301530
assert!(!is_full_lto_enabled(sess));
@@ -1559,7 +1559,7 @@ fn add_upstream_rust_crates(cmd: &mut Linker,
15591559
// generic function calls a native function, then the generic function must
15601560
// be instantiated in the target crate, meaning that the native symbol must
15611561
// also be resolved in the target crate.
1562-
fn add_upstream_native_libraries(cmd: &mut Linker,
1562+
fn add_upstream_native_libraries(cmd: &mut dyn Linker,
15631563
sess: &Session,
15641564
codegen_results: &CodegenResults,
15651565
crate_type: config::CrateType) {

src/librustc_codegen_llvm/back/linker.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ impl LinkerInfo {
4444

4545
pub fn to_linker<'a>(&'a self,
4646
cmd: Command,
47-
sess: &'a Session) -> Box<Linker+'a> {
47+
sess: &'a Session) -> Box<dyn Linker+'a> {
4848
match sess.linker_flavor() {
4949
LinkerFlavor::Lld(LldFlavor::Link) |
5050
LinkerFlavor::Msvc => {
5151
Box::new(MsvcLinker {
5252
cmd,
5353
sess,
5454
info: self
55-
}) as Box<Linker>
55+
}) as Box<dyn Linker>
5656
}
5757
LinkerFlavor::Em => {
5858
Box::new(EmLinker {
5959
cmd,
6060
sess,
6161
info: self
62-
}) as Box<Linker>
62+
}) as Box<dyn Linker>
6363
}
6464
LinkerFlavor::Gcc => {
6565
Box::new(GccLinker {
@@ -68,7 +68,7 @@ impl LinkerInfo {
6868
info: self,
6969
hinted_static: false,
7070
is_ld: false,
71-
}) as Box<Linker>
71+
}) as Box<dyn Linker>
7272
}
7373

7474
LinkerFlavor::Lld(LldFlavor::Ld) |
@@ -80,14 +80,14 @@ impl LinkerInfo {
8080
info: self,
8181
hinted_static: false,
8282
is_ld: true,
83-
}) as Box<Linker>
83+
}) as Box<dyn Linker>
8484
}
8585

8686
LinkerFlavor::Lld(LldFlavor::Wasm) => {
8787
Box::new(WasmLd {
8888
cmd,
8989
sess,
90-
}) as Box<Linker>
90+
}) as Box<dyn Linker>
9191
}
9292
}
9393
}

src/librustc_codegen_llvm/back/rpath.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct RPathConfig<'a> {
2222
pub is_like_osx: bool,
2323
pub has_rpath: bool,
2424
pub linker_is_gnu: bool,
25-
pub get_install_prefix_lib_path: &'a mut FnMut() -> PathBuf,
25+
pub get_install_prefix_lib_path: &'a mut dyn FnMut() -> PathBuf,
2626
}
2727

2828
pub fn get_rpath_flags(config: &mut RPathConfig) -> Vec<String> {

src/librustc_codegen_llvm/back/write.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub fn create_target_machine(sess: &Session, find_features: bool) -> TargetMachi
140140
// that `is_pie_binary` is false. When we discover LLVM target features
141141
// `sess.crate_types` is uninitialized so we cannot access it.
142142
pub fn target_machine_factory(sess: &Session, find_features: bool)
143-
-> Arc<Fn() -> Result<TargetMachineRef, String> + Send + Sync>
143+
-> Arc<dyn Fn() -> Result<TargetMachineRef, String> + Send + Sync>
144144
{
145145
let reloc_model = get_reloc_model(sess);
146146

@@ -343,7 +343,7 @@ pub struct CodegenContext {
343343
regular_module_config: Arc<ModuleConfig>,
344344
metadata_module_config: Arc<ModuleConfig>,
345345
allocator_module_config: Arc<ModuleConfig>,
346-
pub tm_factory: Arc<Fn() -> Result<TargetMachineRef, String> + Send + Sync>,
346+
pub tm_factory: Arc<dyn Fn() -> Result<TargetMachineRef, String> + Send + Sync>,
347347
pub msvc_imps_needed: bool,
348348
pub target_pointer_width: String,
349349
debuginfo: config::DebugInfoLevel,
@@ -362,7 +362,7 @@ pub struct CodegenContext {
362362
// compiling incrementally
363363
pub incr_comp_session_dir: Option<PathBuf>,
364364
// Channel back to the main control thread to send messages to
365-
coordinator_send: Sender<Box<Any + Send>>,
365+
coordinator_send: Sender<Box<dyn Any + Send>>,
366366
// A reference to the TimeGraph so we can register timings. None means that
367367
// measuring is disabled.
368368
time_graph: Option<TimeGraph>,
@@ -884,7 +884,7 @@ pub fn start_async_codegen(tcx: TyCtxt,
884884
time_graph: Option<TimeGraph>,
885885
link: LinkMeta,
886886
metadata: EncodedMetadata,
887-
coordinator_receive: Receiver<Box<Any + Send>>,
887+
coordinator_receive: Receiver<Box<dyn Any + Send>>,
888888
total_cgus: usize)
889889
-> OngoingCodegen {
890890
let sess = tcx.sess;
@@ -1412,7 +1412,7 @@ fn start_executing_work(tcx: TyCtxt,
14121412
crate_info: &CrateInfo,
14131413
shared_emitter: SharedEmitter,
14141414
codegen_worker_send: Sender<Message>,
1415-
coordinator_receive: Receiver<Box<Any + Send>>,
1415+
coordinator_receive: Receiver<Box<dyn Any + Send>>,
14161416
total_cgus: usize,
14171417
jobserver: Client,
14181418
time_graph: Option<TimeGraph>,
@@ -1976,7 +1976,7 @@ fn spawn_work(cgcx: CodegenContext, work: WorkItem) {
19761976
// Set up a destructor which will fire off a message that we're done as
19771977
// we exit.
19781978
struct Bomb {
1979-
coordinator_send: Sender<Box<Any + Send>>,
1979+
coordinator_send: Sender<Box<dyn Any + Send>>,
19801980
result: Option<WorkItemResult>,
19811981
worker_id: usize,
19821982
}
@@ -2056,7 +2056,7 @@ pub unsafe fn with_llvm_pmb(llmod: ModuleRef,
20562056
config: &ModuleConfig,
20572057
opt_level: llvm::CodeGenOptLevel,
20582058
prepare_for_thin_lto: bool,
2059-
f: &mut FnMut(llvm::PassManagerBuilderRef)) {
2059+
f: &mut dyn FnMut(llvm::PassManagerBuilderRef)) {
20602060
use std::ptr;
20612061

20622062
// Create the PassManagerBuilder for LLVM. We configure it with
@@ -2243,7 +2243,7 @@ pub struct OngoingCodegen {
22432243
linker_info: LinkerInfo,
22442244
crate_info: CrateInfo,
22452245
time_graph: Option<TimeGraph>,
2246-
coordinator_send: Sender<Box<Any + Send>>,
2246+
coordinator_send: Sender<Box<dyn Any + Send>>,
22472247
codegen_worker_receive: Receiver<Message>,
22482248
shared_emitter_main: SharedEmitterMain,
22492249
future: thread::JoinHandle<Result<CompiledModules, ()>>,

src/librustc_codegen_llvm/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ pub fn iter_globals(llmod: llvm::ModuleRef) -> ValueIter {
717717
}
718718

719719
pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
720-
rx: mpsc::Receiver<Box<Any + Send>>)
720+
rx: mpsc::Receiver<Box<dyn Any + Send>>)
721721
-> OngoingCodegen {
722722

723723
check_for_rustc_errors_attr(tcx);

src/librustc_codegen_llvm/intrinsic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ fn gen_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
916916
name: &str,
917917
inputs: Vec<Ty<'tcx>>,
918918
output: Ty<'tcx>,
919-
codegen: &mut for<'b> FnMut(Builder<'b, 'tcx>))
919+
codegen: &mut dyn for<'b> FnMut(Builder<'b, 'tcx>))
920920
-> ValueRef {
921921
let rust_fn_ty = cx.tcx.mk_fn_ptr(ty::Binder::bind(cx.tcx.mk_fn_sig(
922922
inputs.into_iter(),
@@ -936,7 +936,7 @@ fn gen_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
936936
//
937937
// This function is only generated once and is then cached.
938938
fn get_rust_try_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
939-
codegen: &mut for<'b> FnMut(Builder<'b, 'tcx>))
939+
codegen: &mut dyn for<'b> FnMut(Builder<'b, 'tcx>))
940940
-> ValueRef {
941941
if let Some(llfn) = cx.rust_try_fn.get() {
942942
return llfn;

src/librustc_codegen_llvm/lib.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#![feature(custom_attribute)]
2424
#![feature(fs_read_write)]
2525
#![allow(unused_attributes)]
26+
#![deny(bare_trait_objects)]
2627
#![feature(libc)]
2728
#![feature(quote)]
2829
#![feature(range_contains)]
@@ -125,7 +126,7 @@ impl !Send for LlvmCodegenBackend {} // Llvm is on a per-thread basis
125126
impl !Sync for LlvmCodegenBackend {}
126127

127128
impl LlvmCodegenBackend {
128-
pub fn new() -> Box<CodegenBackend> {
129+
pub fn new() -> Box<dyn CodegenBackend> {
129130
box LlvmCodegenBackend(())
130131
}
131132
}
@@ -178,7 +179,7 @@ impl CodegenBackend for LlvmCodegenBackend {
178179
target_features(sess)
179180
}
180181

181-
fn metadata_loader(&self) -> Box<MetadataLoader + Sync> {
182+
fn metadata_loader(&self) -> Box<dyn MetadataLoader + Sync> {
182183
box metadata::LlvmMetadataLoader
183184
}
184185

@@ -198,14 +199,14 @@ impl CodegenBackend for LlvmCodegenBackend {
198199
fn codegen_crate<'a, 'tcx>(
199200
&self,
200201
tcx: TyCtxt<'a, 'tcx, 'tcx>,
201-
rx: mpsc::Receiver<Box<Any + Send>>
202-
) -> Box<Any> {
202+
rx: mpsc::Receiver<Box<dyn Any + Send>>
203+
) -> Box<dyn Any> {
203204
box base::codegen_crate(tcx, rx)
204205
}
205206

206207
fn join_codegen_and_link(
207208
&self,
208-
ongoing_codegen: Box<Any>,
209+
ongoing_codegen: Box<dyn Any>,
209210
sess: &Session,
210211
dep_graph: &DepGraph,
211212
outputs: &OutputFilenames,
@@ -247,7 +248,7 @@ impl CodegenBackend for LlvmCodegenBackend {
247248

248249
/// This is the entrypoint for a hot plugged rustc_codegen_llvm
249250
#[no_mangle]
250-
pub fn __rustc_codegen_backend() -> Box<CodegenBackend> {
251+
pub fn __rustc_codegen_backend() -> Box<dyn CodegenBackend> {
251252
LlvmCodegenBackend::new()
252253
}
253254

0 commit comments

Comments
 (0)