Auto merge of #89405 - GuillaumeGomez:fix-clippy-lints, r=cjgillot

Fix clippy lints

I'm currently working on allowing clippy to run on librustdoc after a discussion I had with `@Mark-Simulacrum.` So in the meantime, I fixed a few lints on the compiler crates.
This commit is contained in:
bors 2021-10-02 10:52:09 +00:00
commit b27661eb33
61 changed files with 458 additions and 506 deletions

View file

@ -109,7 +109,7 @@ fn prepare_lto(
.extend(exported_symbols[&cnum].iter().filter_map(symbol_filter));
}
let archive = ArchiveRO::open(&path).expect("wanted an rlib");
let archive = ArchiveRO::open(path).expect("wanted an rlib");
let obj_files = archive
.iter()
.filter_map(|child| child.ok().and_then(|c| c.name().map(|name| (name, c))))
@ -316,14 +316,14 @@ fn fat_lto(
.generic_activity_with_arg("LLVM_fat_lto_link_module", format!("{:?}", name));
info!("linking {:?}", name);
let data = bc_decoded.data();
linker.add(&data).map_err(|()| {
linker.add(data).map_err(|()| {
let msg = format!("failed to load bc of {:?}", name);
write::llvm_err(&diag_handler, &msg)
write::llvm_err(diag_handler, &msg)
})?;
serialized_bitcode.push(bc_decoded);
}
drop(linker);
save_temp_bitcode(&cgcx, &module, "lto.input");
save_temp_bitcode(cgcx, &module, "lto.input");
// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
@ -347,14 +347,14 @@ fn fat_lto(
ptr as *const *const libc::c_char,
symbols_below_threshold.len() as libc::size_t,
);
save_temp_bitcode(&cgcx, &module, "lto.after-restriction");
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
}
if cgcx.no_landing_pads {
unsafe {
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
}
save_temp_bitcode(&cgcx, &module, "lto.after-nounwind");
save_temp_bitcode(cgcx, &module, "lto.after-nounwind");
}
}
@ -498,7 +498,7 @@ fn thin_lto(
symbols_below_threshold.as_ptr(),
symbols_below_threshold.len() as u32,
)
.ok_or_else(|| write::llvm_err(&diag_handler, "failed to prepare thin LTO context"))?;
.ok_or_else(|| write::llvm_err(diag_handler, "failed to prepare thin LTO context"))?;
let data = ThinData(data);
@ -572,7 +572,7 @@ fn thin_lto(
if let Some(path) = key_map_path {
if let Err(err) = curr_key_map.save_to_file(&path) {
let msg = format!("Error while writing ThinLTO key data: {}", err);
return Err(write::llvm_err(&diag_handler, &msg));
return Err(write::llvm_err(diag_handler, &msg));
}
}
@ -744,8 +744,7 @@ pub unsafe fn optimize_thin_module(
// crates but for locally codegened modules we may be able to reuse
// that LLVM Context and Module.
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
let llmod_raw =
parse_module(llcx, &module_name, thin_module.data(), &diag_handler)? as *const _;
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
let module = ModuleCodegen {
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
name: thin_module.name().to_string(),
@ -754,7 +753,7 @@ pub unsafe fn optimize_thin_module(
{
let target = &*module.module_llvm.tm;
let llmod = module.module_llvm.llmod();
save_temp_bitcode(&cgcx, &module, "thin-lto-input");
save_temp_bitcode(cgcx, &module, "thin-lto-input");
// Before we do much else find the "main" `DICompileUnit` that we'll be
// using below. If we find more than one though then rustc has changed
@ -775,7 +774,7 @@ pub unsafe fn optimize_thin_module(
.prof
.generic_activity_with_arg("LLVM_thin_lto_remove_landing_pads", thin_module.name());
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
save_temp_bitcode(&cgcx, &module, "thin-lto-after-nounwind");
save_temp_bitcode(cgcx, &module, "thin-lto-after-nounwind");
}
// Up next comes the per-module local analyses that we do for Thin LTO.
@ -947,7 +946,7 @@ pub fn parse_module<'a>(
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()).ok_or_else(
|| {
let msg = "failed to parse bitcode for LTO module";
write::llvm_err(&diag_handler, msg)
write::llvm_err(diag_handler, msg)
},
)
}

View file

@ -41,7 +41,7 @@ use std::sync::Arc;
pub fn llvm_err(handler: &rustc_errors::Handler, msg: &str) -> FatalError {
match llvm::last_error() {
Some(err) => handler.fatal(&format!("{}: {}", msg, err)),
None => handler.fatal(&msg),
None => handler.fatal(msg),
}
}
@ -96,7 +96,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut ll
None
};
let config = TargetMachineFactoryConfig { split_dwarf_file };
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(()))(config)
target_machine_factory(tcx.sess, tcx.backend_optimization_level(()))(config)
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
}
@ -558,7 +558,7 @@ pub(crate) unsafe fn optimize(
let prepare_for_thin_lto = cgcx.lto == Lto::Thin
|| cgcx.lto == Lto::ThinLocal
|| (cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled());
with_llvm_pmb(llmod, &config, opt_level, prepare_for_thin_lto, &mut |b| {
with_llvm_pmb(llmod, config, opt_level, prepare_for_thin_lto, &mut |b| {
llvm::LLVMRustAddLastExtensionPasses(
b,
extra_passes.as_ptr(),
@ -660,9 +660,9 @@ pub(crate) fn link(
let _timer =
cgcx.prof.generic_activity_with_arg("LLVM_link_module", format!("{:?}", module.name));
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
linker.add(&buffer.data()).map_err(|()| {
linker.add(buffer.data()).map_err(|()| {
let msg = format!("failed to serialize module {:?}", module.name);
llvm_err(&diag_handler, &msg)
llvm_err(diag_handler, &msg)
})?;
}
drop(linker);