Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Oct 1, 2021
1 parent b6057bf commit 759eba0
Show file tree
Hide file tree
Showing 61 changed files with 460 additions and 508 deletions.
24 changes: 12 additions & 12 deletions compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,26 +277,26 @@ fn do_mir_borrowck<'a, 'tcx>(

let regioncx = Rc::new(regioncx);

let flow_borrows = Borrows::new(tcx, &body, &regioncx, &borrow_set)
.into_engine(tcx, &body)
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
.into_engine(tcx, body)
.pass_name("borrowck")
.iterate_to_fixpoint();
let flow_uninits = MaybeUninitializedPlaces::new(tcx, &body, &mdpe)
.into_engine(tcx, &body)
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
.into_engine(tcx, body)
.pass_name("borrowck")
.iterate_to_fixpoint();
let flow_ever_inits = EverInitializedPlaces::new(tcx, &body, &mdpe)
.into_engine(tcx, &body)
let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe)
.into_engine(tcx, body)
.pass_name("borrowck")
.iterate_to_fixpoint();

let movable_generator = match tcx.hir().get(id) {
let movable_generator = !matches!(
tcx.hir().get(id),
Node::Expr(&hir::Expr {
kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
..
}) => false,
_ => true,
};
})
);

for (idx, move_data_results) in promoted_errors {
let promoted_body = &promoted[idx];
Expand Down Expand Up @@ -374,8 +374,8 @@ fn do_mir_borrowck<'a, 'tcx>(
mbcx.report_move_errors(move_errors);

rustc_mir_dataflow::visit_results(
&body,
traversal::reverse_postorder(&body).map(|(bb, _)| bb),
body,
traversal::reverse_postorder(body).map(|(bb, _)| bb),
&results,
&mut mbcx,
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
};
match self.ret.mode {
PassMode::Direct(ref attrs) => {
attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, &bx.cx, callsite);
attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, bx.cx, callsite);
}
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
assert!(!on_stack);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let r = r.unwrap();

// Again, based on how many outputs we have
let outputs = ia.outputs.iter().zip(&outputs).filter(|&(ref o, _)| !o.is_indirect);
let outputs = ia.outputs.iter().zip(&outputs).filter(|&(o, _)| !o.is_indirect);
for (i, (_, &place)) in outputs.enumerate() {
let v = if num_outputs == 1 { r } else { self.extract_value(r, i as u64) };
OperandValue::Immediate(v).store(self, place);
Expand Down Expand Up @@ -331,7 +331,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
let output_type = match &output_types[..] {
[] => self.type_void(),
[ty] => ty,
tys => self.type_struct(&tys, false),
tys => self.type_struct(tys, false),
};
let dialect = match asm_arch {
InlineAsmArch::X86 | InlineAsmArch::X86_64
Expand Down
25 changes: 12 additions & 13 deletions compiler/rustc_codegen_llvm/src/back/lto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down Expand Up @@ -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`.
Expand All @@ -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");
}
}

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -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(),
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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)
},
)
}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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())
}

Expand Down Expand Up @@ -556,7 +556,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(),
Expand Down Expand Up @@ -658,9 +658,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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
impl HasTargetSpec for Builder<'_, '_, 'tcx> {
#[inline]
fn target_spec(&self) -> &Target {
&self.cx.target_spec()
self.cx.target_spec()
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value

let fn_abi = cx.fn_abi_of_instance(instance, ty::List::empty());

let llfn = if let Some(llfn) = cx.get_declared_value(&sym) {
let llfn = if let Some(llfn) = cx.get_declared_value(sym) {
// Create a fn pointer with the new signature.
let llptrty = fn_abi.ptr_to_llvm_type(cx);

Expand Down Expand Up @@ -79,7 +79,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
llfn
}
} else {
let llfn = cx.declare_fn(&sym, &fn_abi);
let llfn = cx.declare_fn(sym, fn_abi);
debug!("get_fn: not casting pointer!");

attributes::from_fn_attrs(cx, llfn, instance);
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn check_and_apply_linkage(
};
unsafe {
// Declare a symbol `foo` with the desired linkage.
let g1 = cx.declare_global(&sym, llty2);
let g1 = cx.declare_global(sym, llty2);
llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage));

// Declare an internal global `extern_with_linkage_foo` which
Expand All @@ -188,7 +188,7 @@ fn check_and_apply_linkage(
// `extern_with_linkage_foo` will instead be initialized to
// zero.
let mut real_name = "_rust_extern_with_linkage_".to_string();
real_name.push_str(&sym);
real_name.push_str(sym);
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
cx.sess().span_fatal(
cx.tcx.def_span(span_def_id),
Expand All @@ -202,7 +202,7 @@ fn check_and_apply_linkage(
} else {
// Generate an external declaration.
// FIXME(nagisa): investigate whether it can be changed into define_global
cx.declare_global(&sym, llty)
cx.declare_global(sym, llty)
}
}

Expand Down Expand Up @@ -234,7 +234,7 @@ impl CodegenCx<'ll, 'tcx> {
_ => self.define_private_global(self.val_ty(cv)),
};
llvm::LLVMSetInitializer(gv, cv);
set_global_alignment(&self, gv, align);
set_global_alignment(self, gv, align);
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
gv
}
Expand Down Expand Up @@ -279,7 +279,7 @@ impl CodegenCx<'ll, 'tcx> {

g
} else {
check_and_apply_linkage(&self, &fn_attrs, ty, sym, def_id)
check_and_apply_linkage(self, fn_attrs, ty, sym, def_id)
};

// Thread-local statics in some other crate need to *always* be linked
Expand Down Expand Up @@ -369,7 +369,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
unsafe {
let attrs = self.tcx.codegen_fn_attrs(def_id);

let (v, alloc) = match codegen_static_initializer(&self, def_id) {
let (v, alloc) = match codegen_static_initializer(self, def_id) {
Ok(v) => v,
// Error has already been reported
Err(_) => return,
Expand Down Expand Up @@ -417,7 +417,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
self.statics_to_rauw.borrow_mut().push((g, new_g));
new_g
};
set_global_alignment(&self, g, self.align_of(ty));
set_global_alignment(self, g, self.align_of(ty));
llvm::LLVMSetInitializer(g, v);

if self.should_assume_dso_local(g, true) {
Expand All @@ -430,7 +430,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
llvm::LLVMSetGlobalConstant(g, llvm::True);
}

debuginfo::create_global_var_metadata(&self, def_id, g);
debuginfo::create_global_var_metadata(self, def_id, g);

if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
llvm::set_thread_local_mode(g, self.tls_model);
Expand Down Expand Up @@ -518,7 +518,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
);
}
} else {
base::set_link_section(g, &attrs);
base::set_link_section(g, attrs);
}

if attrs.flags.contains(CodegenFnAttrFlags::USED) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {

fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) {
let section = cstr!("llvm.metadata");
let array = self.const_array(&self.type_ptr_to(self.type_i8()), values);
let array = self.const_array(self.type_ptr_to(self.type_i8()), values);

unsafe {
let g = llvm::LLVMAddGlobal(self.llmod, self.val_ty(array), name.as_ptr());
Expand Down Expand Up @@ -447,7 +447,7 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
}

fn sess(&self) -> &Session {
&self.tcx.sess
self.tcx.sess
}

fn check_overflow(&self) -> bool {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer);
});
debug_assert!(
coverage_mapping_buffer.len() > 0,
!coverage_mapping_buffer.is_empty(),
"Every `FunctionCoverage` should have at least one counter"
);

Expand Down Expand Up @@ -311,8 +311,7 @@ fn add_unused_functions<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
// for each region in it's MIR.

// Convert the `HashSet` of `codegenned_def_ids` to a sortable vector, and sort them.
let mut sorted_codegenned_def_ids: Vec<DefId> =
codegenned_def_ids.iter().map(|def_id| *def_id).collect();
let mut sorted_codegenned_def_ids: Vec<DefId> = codegenned_def_ids.iter().copied().collect();
sorted_codegenned_def_ids.sort_unstable();

let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ fn declare_unused_fn(cx: &CodegenCx<'ll, 'tcx>, def_id: &DefId) -> Instance<'tcx
);

let llfn = cx.declare_fn(
&tcx.symbol_name(instance).name,
&cx.fn_abi_of_fn_ptr(
tcx.symbol_name(instance).name,
cx.fn_abi_of_fn_ptr(
ty::Binder::dummy(tcx.mk_fn_sig(
iter::once(tcx.mk_unit()),
tcx.mk_unit(),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn compute_mir_scopes(
// Instantiate all scopes.
for idx in 0..mir.source_scopes.len() {
let scope = SourceScope::new(idx);
make_mir_scope(cx, instance, &mir, fn_dbg_scope, &has_variables, debug_context, scope);
make_mir_scope(cx, instance, mir, fn_dbg_scope, &has_variables, debug_context, scope);
}
}

Expand Down Expand Up @@ -94,7 +94,7 @@ fn make_mir_scope(
callee,
);
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
cx.dbg_scope_fn(callee, &callee_fn_abi, None)
cx.dbg_scope_fn(callee, callee_fn_abi, None)
}
None => unsafe {
llvm::LLVMRustDIBuilderCreateLexicalBlock(
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) -
}

pub fn needs_gdb_debug_scripts_section(cx: &CodegenCx<'_, '_>) -> bool {
let omit_gdb_pretty_printer_section = cx
.tcx
.sess
.contains_name(&cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section);
let omit_gdb_pretty_printer_section =
cx.tcx.sess.contains_name(cx.tcx.hir().krate_attrs(), sym::omit_gdb_pretty_printer_section);

!omit_gdb_pretty_printer_section
&& cx.sess().opts.debuginfo != DebugInfo::None
Expand Down
Loading

0 comments on commit 759eba0

Please sign in to comment.