Skip to content

Commit b27661e

Browse files
committed
Auto merge of rust-lang#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.
2 parents a8387ae + 759eba0 commit b27661e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+460
-508
lines changed

compiler/rustc_borrowck/src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -277,26 +277,26 @@ fn do_mir_borrowck<'a, 'tcx>(
277277

278278
let regioncx = Rc::new(regioncx);
279279

280-
let flow_borrows = Borrows::new(tcx, &body, &regioncx, &borrow_set)
281-
.into_engine(tcx, &body)
280+
let flow_borrows = Borrows::new(tcx, body, &regioncx, &borrow_set)
281+
.into_engine(tcx, body)
282282
.pass_name("borrowck")
283283
.iterate_to_fixpoint();
284-
let flow_uninits = MaybeUninitializedPlaces::new(tcx, &body, &mdpe)
285-
.into_engine(tcx, &body)
284+
let flow_uninits = MaybeUninitializedPlaces::new(tcx, body, &mdpe)
285+
.into_engine(tcx, body)
286286
.pass_name("borrowck")
287287
.iterate_to_fixpoint();
288-
let flow_ever_inits = EverInitializedPlaces::new(tcx, &body, &mdpe)
289-
.into_engine(tcx, &body)
288+
let flow_ever_inits = EverInitializedPlaces::new(tcx, body, &mdpe)
289+
.into_engine(tcx, body)
290290
.pass_name("borrowck")
291291
.iterate_to_fixpoint();
292292

293-
let movable_generator = match tcx.hir().get(id) {
293+
let movable_generator = !matches!(
294+
tcx.hir().get(id),
294295
Node::Expr(&hir::Expr {
295296
kind: hir::ExprKind::Closure(.., Some(hir::Movability::Static)),
296297
..
297-
}) => false,
298-
_ => true,
299-
};
298+
})
299+
);
300300

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

376376
rustc_mir_dataflow::visit_results(
377-
&body,
378-
traversal::reverse_postorder(&body).map(|(bb, _)| bb),
377+
body,
378+
traversal::reverse_postorder(body).map(|(bb, _)| bb),
379379
&results,
380380
&mut mbcx,
381381
);

compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ impl<'tcx> FnAbiLlvmExt<'tcx> for FnAbi<'tcx, Ty<'tcx>> {
526526
};
527527
match self.ret.mode {
528528
PassMode::Direct(ref attrs) => {
529-
attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, &bx.cx, callsite);
529+
attrs.apply_attrs_to_callsite(llvm::AttributePlace::ReturnValue, bx.cx, callsite);
530530
}
531531
PassMode::Indirect { ref attrs, extra_attrs: _, on_stack } => {
532532
assert!(!on_stack);

compiler/rustc_codegen_llvm/src/asm.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
105105
let r = r.unwrap();
106106

107107
// Again, based on how many outputs we have
108-
let outputs = ia.outputs.iter().zip(&outputs).filter(|&(ref o, _)| !o.is_indirect);
108+
let outputs = ia.outputs.iter().zip(&outputs).filter(|&(o, _)| !o.is_indirect);
109109
for (i, (_, &place)) in outputs.enumerate() {
110110
let v = if num_outputs == 1 { r } else { self.extract_value(r, i as u64) };
111111
OperandValue::Immediate(v).store(self, place);
@@ -331,7 +331,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> {
331331
let output_type = match &output_types[..] {
332332
[] => self.type_void(),
333333
[ty] => ty,
334-
tys => self.type_struct(&tys, false),
334+
tys => self.type_struct(tys, false),
335335
};
336336
let dialect = match asm_arch {
337337
InlineAsmArch::X86 | InlineAsmArch::X86_64

compiler/rustc_codegen_llvm/src/back/lto.rs

+12-13
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn prepare_lto(
109109
.extend(exported_symbols[&cnum].iter().filter_map(symbol_filter));
110110
}
111111

112-
let archive = ArchiveRO::open(&path).expect("wanted an rlib");
112+
let archive = ArchiveRO::open(path).expect("wanted an rlib");
113113
let obj_files = archive
114114
.iter()
115115
.filter_map(|child| child.ok().and_then(|c| c.name().map(|name| (name, c))))
@@ -316,14 +316,14 @@ fn fat_lto(
316316
.generic_activity_with_arg("LLVM_fat_lto_link_module", format!("{:?}", name));
317317
info!("linking {:?}", name);
318318
let data = bc_decoded.data();
319-
linker.add(&data).map_err(|()| {
319+
linker.add(data).map_err(|()| {
320320
let msg = format!("failed to load bc of {:?}", name);
321-
write::llvm_err(&diag_handler, &msg)
321+
write::llvm_err(diag_handler, &msg)
322322
})?;
323323
serialized_bitcode.push(bc_decoded);
324324
}
325325
drop(linker);
326-
save_temp_bitcode(&cgcx, &module, "lto.input");
326+
save_temp_bitcode(cgcx, &module, "lto.input");
327327

328328
// Fat LTO also suffers from the invalid DWARF issue similar to Thin LTO.
329329
// Here we rewrite all `DICompileUnit` pointers if there is only one `DICompileUnit`.
@@ -347,14 +347,14 @@ fn fat_lto(
347347
ptr as *const *const libc::c_char,
348348
symbols_below_threshold.len() as libc::size_t,
349349
);
350-
save_temp_bitcode(&cgcx, &module, "lto.after-restriction");
350+
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
351351
}
352352

353353
if cgcx.no_landing_pads {
354354
unsafe {
355355
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
356356
}
357-
save_temp_bitcode(&cgcx, &module, "lto.after-nounwind");
357+
save_temp_bitcode(cgcx, &module, "lto.after-nounwind");
358358
}
359359
}
360360

@@ -498,7 +498,7 @@ fn thin_lto(
498498
symbols_below_threshold.as_ptr(),
499499
symbols_below_threshold.len() as u32,
500500
)
501-
.ok_or_else(|| write::llvm_err(&diag_handler, "failed to prepare thin LTO context"))?;
501+
.ok_or_else(|| write::llvm_err(diag_handler, "failed to prepare thin LTO context"))?;
502502

503503
let data = ThinData(data);
504504

@@ -572,7 +572,7 @@ fn thin_lto(
572572
if let Some(path) = key_map_path {
573573
if let Err(err) = curr_key_map.save_to_file(&path) {
574574
let msg = format!("Error while writing ThinLTO key data: {}", err);
575-
return Err(write::llvm_err(&diag_handler, &msg));
575+
return Err(write::llvm_err(diag_handler, &msg));
576576
}
577577
}
578578

@@ -744,8 +744,7 @@ pub unsafe fn optimize_thin_module(
744744
// crates but for locally codegened modules we may be able to reuse
745745
// that LLVM Context and Module.
746746
let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names);
747-
let llmod_raw =
748-
parse_module(llcx, &module_name, thin_module.data(), &diag_handler)? as *const _;
747+
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), &diag_handler)? as *const _;
749748
let module = ModuleCodegen {
750749
module_llvm: ModuleLlvm { llmod_raw, llcx, tm },
751750
name: thin_module.name().to_string(),
@@ -754,7 +753,7 @@ pub unsafe fn optimize_thin_module(
754753
{
755754
let target = &*module.module_llvm.tm;
756755
let llmod = module.module_llvm.llmod();
757-
save_temp_bitcode(&cgcx, &module, "thin-lto-input");
756+
save_temp_bitcode(cgcx, &module, "thin-lto-input");
758757

759758
// Before we do much else find the "main" `DICompileUnit` that we'll be
760759
// using below. If we find more than one though then rustc has changed
@@ -775,7 +774,7 @@ pub unsafe fn optimize_thin_module(
775774
.prof
776775
.generic_activity_with_arg("LLVM_thin_lto_remove_landing_pads", thin_module.name());
777776
llvm::LLVMRustMarkAllFunctionsNounwind(llmod);
778-
save_temp_bitcode(&cgcx, &module, "thin-lto-after-nounwind");
777+
save_temp_bitcode(cgcx, &module, "thin-lto-after-nounwind");
779778
}
780779

781780
// Up next comes the per-module local analyses that we do for Thin LTO.
@@ -947,7 +946,7 @@ pub fn parse_module<'a>(
947946
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()).ok_or_else(
948947
|| {
949948
let msg = "failed to parse bitcode for LTO module";
950-
write::llvm_err(&diag_handler, msg)
949+
write::llvm_err(diag_handler, msg)
951950
},
952951
)
953952
}

compiler/rustc_codegen_llvm/src/back/write.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::sync::Arc;
4141
pub fn llvm_err(handler: &rustc_errors::Handler, msg: &str) -> FatalError {
4242
match llvm::last_error() {
4343
Some(err) => handler.fatal(&format!("{}: {}", msg, err)),
44-
None => handler.fatal(&msg),
44+
None => handler.fatal(msg),
4545
}
4646
}
4747

@@ -96,7 +96,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut ll
9696
None
9797
};
9898
let config = TargetMachineFactoryConfig { split_dwarf_file };
99-
target_machine_factory(&tcx.sess, tcx.backend_optimization_level(()))(config)
99+
target_machine_factory(tcx.sess, tcx.backend_optimization_level(()))(config)
100100
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
101101
}
102102

@@ -558,7 +558,7 @@ pub(crate) unsafe fn optimize(
558558
let prepare_for_thin_lto = cgcx.lto == Lto::Thin
559559
|| cgcx.lto == Lto::ThinLocal
560560
|| (cgcx.lto != Lto::Fat && cgcx.opts.cg.linker_plugin_lto.enabled());
561-
with_llvm_pmb(llmod, &config, opt_level, prepare_for_thin_lto, &mut |b| {
561+
with_llvm_pmb(llmod, config, opt_level, prepare_for_thin_lto, &mut |b| {
562562
llvm::LLVMRustAddLastExtensionPasses(
563563
b,
564564
extra_passes.as_ptr(),
@@ -660,9 +660,9 @@ pub(crate) fn link(
660660
let _timer =
661661
cgcx.prof.generic_activity_with_arg("LLVM_link_module", format!("{:?}", module.name));
662662
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
663-
linker.add(&buffer.data()).map_err(|()| {
663+
linker.add(buffer.data()).map_err(|()| {
664664
let msg = format!("failed to serialize module {:?}", module.name);
665-
llvm_err(&diag_handler, &msg)
665+
llvm_err(diag_handler, &msg)
666666
})?;
667667
}
668668
drop(linker);

compiler/rustc_codegen_llvm/src/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
8686
impl HasTargetSpec for Builder<'_, '_, 'tcx> {
8787
#[inline]
8888
fn target_spec(&self) -> &Target {
89-
&self.cx.target_spec()
89+
self.cx.target_spec()
9090
}
9191
}
9292

compiler/rustc_codegen_llvm/src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value
4444

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

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

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

8585
attributes::from_fn_attrs(cx, llfn, instance);

compiler/rustc_codegen_llvm/src/consts.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn check_and_apply_linkage(
178178
};
179179
unsafe {
180180
// Declare a symbol `foo` with the desired linkage.
181-
let g1 = cx.declare_global(&sym, llty2);
181+
let g1 = cx.declare_global(sym, llty2);
182182
llvm::LLVMRustSetLinkage(g1, base::linkage_to_llvm(linkage));
183183

184184
// Declare an internal global `extern_with_linkage_foo` which
@@ -188,7 +188,7 @@ fn check_and_apply_linkage(
188188
// `extern_with_linkage_foo` will instead be initialized to
189189
// zero.
190190
let mut real_name = "_rust_extern_with_linkage_".to_string();
191-
real_name.push_str(&sym);
191+
real_name.push_str(sym);
192192
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
193193
cx.sess().span_fatal(
194194
cx.tcx.def_span(span_def_id),
@@ -202,7 +202,7 @@ fn check_and_apply_linkage(
202202
} else {
203203
// Generate an external declaration.
204204
// FIXME(nagisa): investigate whether it can be changed into define_global
205-
cx.declare_global(&sym, llty)
205+
cx.declare_global(sym, llty)
206206
}
207207
}
208208

@@ -234,7 +234,7 @@ impl CodegenCx<'ll, 'tcx> {
234234
_ => self.define_private_global(self.val_ty(cv)),
235235
};
236236
llvm::LLVMSetInitializer(gv, cv);
237-
set_global_alignment(&self, gv, align);
237+
set_global_alignment(self, gv, align);
238238
llvm::SetUnnamedAddress(gv, llvm::UnnamedAddr::Global);
239239
gv
240240
}
@@ -279,7 +279,7 @@ impl CodegenCx<'ll, 'tcx> {
279279

280280
g
281281
} else {
282-
check_and_apply_linkage(&self, &fn_attrs, ty, sym, def_id)
282+
check_and_apply_linkage(self, fn_attrs, ty, sym, def_id)
283283
};
284284

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

372-
let (v, alloc) = match codegen_static_initializer(&self, def_id) {
372+
let (v, alloc) = match codegen_static_initializer(self, def_id) {
373373
Ok(v) => v,
374374
// Error has already been reported
375375
Err(_) => return,
@@ -417,7 +417,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
417417
self.statics_to_rauw.borrow_mut().push((g, new_g));
418418
new_g
419419
};
420-
set_global_alignment(&self, g, self.align_of(ty));
420+
set_global_alignment(self, g, self.align_of(ty));
421421
llvm::LLVMSetInitializer(g, v);
422422

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

433-
debuginfo::create_global_var_metadata(&self, def_id, g);
433+
debuginfo::create_global_var_metadata(self, def_id, g);
434434

435435
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
436436
llvm::set_thread_local_mode(g, self.tls_model);
@@ -518,7 +518,7 @@ impl StaticMethods for CodegenCx<'ll, 'tcx> {
518518
);
519519
}
520520
} else {
521-
base::set_link_section(g, &attrs);
521+
base::set_link_section(g, attrs);
522522
}
523523

524524
if attrs.flags.contains(CodegenFnAttrFlags::USED) {

compiler/rustc_codegen_llvm/src/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
363363

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

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

449449
fn sess(&self) -> &Session {
450-
&self.tcx.sess
450+
self.tcx.sess
451451
}
452452

453453
fn check_overflow(&self) -> bool {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
7373
mapgen.write_coverage_mapping(expressions, counter_regions, coverage_mapping_buffer);
7474
});
7575
debug_assert!(
76-
coverage_mapping_buffer.len() > 0,
76+
!coverage_mapping_buffer.is_empty(),
7777
"Every `FunctionCoverage` should have at least one counter"
7878
);
7979

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

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

318317
let mut first_covered_def_id_by_file: FxHashMap<Symbol, DefId> = FxHashMap::default();

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ fn declare_unused_fn(cx: &CodegenCx<'ll, 'tcx>, def_id: &DefId) -> Instance<'tcx
199199
);
200200

201201
let llfn = cx.declare_fn(
202-
&tcx.symbol_name(instance).name,
203-
&cx.fn_abi_of_fn_ptr(
202+
tcx.symbol_name(instance).name,
203+
cx.fn_abi_of_fn_ptr(
204204
ty::Binder::dummy(tcx.mk_fn_sig(
205205
iter::once(tcx.mk_unit()),
206206
tcx.mk_unit(),

compiler/rustc_codegen_llvm/src/debuginfo/create_scope_map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn compute_mir_scopes(
4141
// Instantiate all scopes.
4242
for idx in 0..mir.source_scopes.len() {
4343
let scope = SourceScope::new(idx);
44-
make_mir_scope(cx, instance, &mir, fn_dbg_scope, &has_variables, debug_context, scope);
44+
make_mir_scope(cx, instance, mir, fn_dbg_scope, &has_variables, debug_context, scope);
4545
}
4646
}
4747

@@ -94,7 +94,7 @@ fn make_mir_scope(
9494
callee,
9595
);
9696
let callee_fn_abi = cx.fn_abi_of_instance(callee, ty::List::empty());
97-
cx.dbg_scope_fn(callee, &callee_fn_abi, None)
97+
cx.dbg_scope_fn(callee, callee_fn_abi, None)
9898
}
9999
None => unsafe {
100100
llvm::LLVMRustDIBuilderCreateLexicalBlock(

compiler/rustc_codegen_llvm/src/debuginfo/gdb.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(cx: &CodegenCx<'ll, '_>) -
5959
}
6060

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

6765
!omit_gdb_pretty_printer_section
6866
&& cx.sess().opts.debuginfo != DebugInfo::None

0 commit comments

Comments
 (0)