Skip to content

Commit eaa91b8

Browse files
committed
Bunch of clippy fixes
1 parent bbedad2 commit eaa91b8

File tree

17 files changed

+70
-79
lines changed

17 files changed

+70
-79
lines changed

src/abi/mod.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub(crate) fn get_function_sig<'tcx>(
8585
clif_sig_from_fn_abi(
8686
tcx,
8787
default_call_conv,
88-
&FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
88+
FullyMonomorphizedLayoutCx(tcx).fn_abi_of_instance(inst, ty::List::empty()),
8989
)
9090
}
9191

@@ -114,7 +114,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
114114
/// Instance must be monomorphized
115115
pub(crate) fn get_function_ref(&mut self, inst: Instance<'tcx>) -> FuncRef {
116116
let func_id = import_function(self.tcx, self.module, inst);
117-
let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func);
117+
let func_ref = self.module.declare_func_in_func(func_id, self.bcx.func);
118118

119119
if self.clif_comments.enabled() {
120120
self.add_comment(func_ref, format!("{:?}", inst));
@@ -185,7 +185,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
185185
) -> &[Value] {
186186
let sig = Signature { params, returns, call_conv: self.target_config.default_call_conv };
187187
let func_id = self.module.declare_function(name, Linkage::Import, &sig).unwrap();
188-
let func_ref = self.module.declare_func_in_func(func_id, &mut self.bcx.func);
188+
let func_ref = self.module.declare_func_in_func(func_id, self.bcx.func);
189189
let call_inst = self.bcx.ins().call(func_ref, args);
190190
if self.clif_comments.enabled() {
191191
self.add_comment(func_ref, format!("{:?}", name));
@@ -419,7 +419,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
419419
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
420420
crate::intrinsics::codegen_llvm_intrinsic_call(
421421
fx,
422-
&fx.tcx.symbol_name(instance).name,
422+
fx.tcx.symbol_name(instance).name,
423423
args,
424424
ret_place,
425425
target,
@@ -534,7 +534,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
534534
}
535535

536536
let (ptr, method) = crate::vtable::get_ptr_and_method_ref(fx, args[0].value, idx);
537-
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
537+
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi);
538538
let sig = fx.bcx.import_signature(sig);
539539

540540
(CallTarget::Indirect(sig, method), Some(ptr.get_addr(fx)))
@@ -554,7 +554,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
554554
}
555555

556556
let func = func.load_scalar(fx);
557-
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
557+
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi);
558558
let sig = fx.bcx.import_signature(sig);
559559

560560
(CallTarget::Indirect(sig, func), None)
@@ -564,7 +564,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
564564
self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| {
565565
let mut call_args = return_ptr
566566
.into_iter()
567-
.chain(first_arg_override.into_iter())
567+
.chain(first_arg_override)
568568
.chain(
569569
args.into_iter()
570570
.enumerate()
@@ -577,7 +577,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
577577

578578
// FIXME: Find a cleaner way to support varargs.
579579
if fn_abi.c_variadic {
580-
adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args);
580+
adjust_call_for_c_variadic(fx, fn_abi, source_info, func_ref, &mut call_args);
581581
}
582582

583583
if fx.clif_comments.enabled() {
@@ -739,7 +739,7 @@ pub(crate) fn codegen_drop<'tcx>(
739739
let fn_abi = FullyMonomorphizedLayoutCx(fx.tcx)
740740
.fn_abi_of_instance(virtual_drop, ty::List::empty());
741741

742-
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, &fn_abi);
742+
let sig = clif_sig_from_fn_abi(fx.tcx, fx.target_config.default_call_conv, fn_abi);
743743
let sig = fx.bcx.import_signature(sig);
744744
codegen_call_with_unwind_action(
745745
fx,
@@ -767,9 +767,12 @@ pub(crate) fn codegen_drop<'tcx>(
767767
if drop_instance.def.requires_caller_location(fx.tcx) {
768768
// Pass the caller location for `#[track_caller]`.
769769
let caller_location = fx.get_caller_location(source_info);
770-
call_args.extend(
771-
adjust_arg_for_abi(fx, caller_location, &fn_abi.args[1], false).into_iter(),
772-
);
770+
call_args.extend(adjust_arg_for_abi(
771+
fx,
772+
caller_location,
773+
&fn_abi.args[1],
774+
false,
775+
));
773776
}
774777

775778
let func_ref = fx.get_function_ref(drop_instance);
@@ -816,9 +819,9 @@ pub(crate) fn codegen_call_with_unwind_action(
816819
match unwind {
817820
UnwindAction::Continue | UnwindAction::Unreachable => {
818821
let call_inst = match func_ref {
819-
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
822+
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, call_args),
820823
CallTarget::Indirect(sig, func_ptr) => {
821-
fx.bcx.ins().call_indirect(sig, func_ptr, &call_args)
824+
fx.bcx.ins().call_indirect(sig, func_ptr, call_args)
822825
}
823826
};
824827

@@ -866,10 +869,10 @@ pub(crate) fn codegen_call_with_unwind_action(
866869

867870
match func_ref {
868871
CallTarget::Direct(func_ref) => {
869-
fx.bcx.ins().try_call(func_ref, &call_args, exception_table);
872+
fx.bcx.ins().try_call(func_ref, call_args, exception_table);
870873
}
871874
CallTarget::Indirect(_sig, func_ptr) => {
872-
fx.bcx.ins().try_call_indirect(func_ptr, &call_args, exception_table);
875+
fx.bcx.ins().try_call_indirect(func_ptr, call_args, exception_table);
873876
}
874877
}
875878

src/abi/pass_mode.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,7 @@ pub(super) fn to_casted_value<'tcx>(
209209
cast_target_to_abi_params(cast)
210210
.into_iter()
211211
.map(|(offset, param)| {
212-
let val = ptr.offset_i64(fx, offset.bytes() as i64).load(
213-
fx,
214-
param.value_type,
215-
MemFlags::new(),
216-
);
217-
val
212+
ptr.offset_i64(fx, offset.bytes() as i64).load(fx, param.value_type, MemFlags::new())
218213
})
219214
.collect()
220215
}

src/base.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ fn verify_func(tcx: TyCtxt<'_>, writer: &crate::pretty_clif::CommentWriter, func
266266

267267
tcx.prof.generic_activity("verify clif ir").run(|| {
268268
let flags = cranelift_codegen::settings::Flags::new(cranelift_codegen::settings::builder());
269-
match cranelift_codegen::verify_function(&func, &flags) {
269+
match cranelift_codegen::verify_function(func, &flags) {
270270
Ok(_) => {}
271271
Err(err) => {
272272
tcx.dcx().err(format!("{:?}", err));
273273
let pretty_error = cranelift_codegen::print_errors::pretty_verifier_error(
274-
&func,
274+
func,
275275
Some(Box::new(writer)),
276276
err,
277277
);
@@ -554,7 +554,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
554554
template,
555555
operands,
556556
*options,
557-
targets.get(0).copied(),
557+
targets.first().copied(),
558558
);
559559
}
560560
TerminatorKind::UnwindTerminate(reason) => {
@@ -1131,7 +1131,7 @@ fn codegen_panic_inner<'tcx>(
11311131
call_conv: fx.target_config.default_call_conv,
11321132
};
11331133
let func_id = fx.module.declare_function(symbol_name, Linkage::Import, &sig).unwrap();
1134-
let func_ref = fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
1134+
let func_ref = fx.module.declare_func_in_func(func_id, fx.bcx.func);
11351135
if fx.clif_comments.enabled() {
11361136
fx.add_comment(func_ref, format!("{:?}", symbol_name));
11371137
}
@@ -1141,7 +1141,7 @@ fn codegen_panic_inner<'tcx>(
11411141
fx.add_comment(nop_inst, format!("panic {}", symbol_name));
11421142
}
11431143

1144-
codegen_call_with_unwind_action(fx, span, CallTarget::Direct(func_ref), unwind, &args, None);
1144+
codegen_call_with_unwind_action(fx, span, CallTarget::Direct(func_ref), unwind, args, None);
11451145

11461146
fx.bcx.ins().trap(TrapCode::user(1 /* unreachable */).unwrap());
11471147
}

src/codegen_f16_f128.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ pub(crate) fn fcmp(fx: &mut FunctionCx<'_, '_, '_>, cc: FloatCC, lhs: Value, rhs
7575
&[lhs, rhs],
7676
)[0];
7777
let zero = fx.bcx.ins().iconst(CMP_RESULT_TY, 0);
78-
let res = fx.bcx.ins().icmp(int_cc, res, zero);
79-
res
78+
fx.bcx.ins().icmp(int_cc, res, zero)
8079
}
8180
_ => unreachable!("{ty:?}"),
8281
}

src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ pub(crate) fn create_wrapper_function(
257257
.map(|param| func.dfg.append_block_param(block, param.value_type))
258258
.collect::<Vec<Value>>();
259259

260-
let callee_func_ref = module.declare_func_in_func(callee_func_id, &mut bcx.func);
260+
let callee_func_ref = module.declare_func_in_func(callee_func_id, bcx.func);
261261
let call_inst = bcx.ins().call(callee_func_ref, &args);
262262
let results = bcx.inst_results(call_inst).to_vec(); // Clone to prevent borrow error
263263

@@ -374,7 +374,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
374374

375375
pub(crate) fn create_stack_slot(&mut self, size: u32, align: u32) -> Pointer {
376376
assert!(
377-
size % align == 0,
377+
size.is_multiple_of(align),
378378
"size must be a multiple of alignment (size={size}, align={align})"
379379
);
380380

@@ -384,7 +384,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
384384
kind: StackSlotKind::ExplicitSlot,
385385
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
386386
// a way to specify stack slot alignment.
387-
size: (size + abi_align - 1) / abi_align * abi_align,
387+
size: size.div_ceil(abi_align) * abi_align,
388388
align_shift: 4,
389389
});
390390
Pointer::stack_slot(stack_slot)

src/constant.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub(crate) fn codegen_tls_ref<'tcx>(
6565
// For a declaration the stated mutability doesn't matter.
6666
false,
6767
);
68-
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
68+
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
6969
if fx.clif_comments.enabled() {
7070
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
7171
}
@@ -111,7 +111,7 @@ pub(crate) fn codegen_const_value<'tcx>(
111111
ConstValue::Scalar(x) => match x {
112112
Scalar::Int(int) => {
113113
if fx.clif_type(layout.ty).is_some() {
114-
return CValue::const_val(fx, layout, int);
114+
CValue::const_val(fx, layout, int)
115115
} else {
116116
let raw_val = int.size().truncate(int.to_bits(int.size()));
117117
let val = match int.size().bytes() {
@@ -150,7 +150,7 @@ pub(crate) fn codegen_const_value<'tcx>(
150150
alloc.inner().mutability,
151151
);
152152
let local_data_id =
153-
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
153+
fx.module.declare_data_in_func(data_id, fx.bcx.func);
154154
if fx.clif_comments.enabled() {
155155
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
156156
}
@@ -159,8 +159,7 @@ pub(crate) fn codegen_const_value<'tcx>(
159159
}
160160
GlobalAlloc::Function { instance, .. } => {
161161
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
162-
let local_func_id =
163-
fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
162+
let local_func_id = fx.module.declare_func_in_func(func_id, fx.bcx.func);
164163
fx.bcx.ins().func_addr(fx.pointer_type, local_func_id)
165164
}
166165
GlobalAlloc::VTable(ty, dyn_ty) => {
@@ -173,8 +172,7 @@ pub(crate) fn codegen_const_value<'tcx>(
173172
fx.tcx.instantiate_bound_regions_with_erased(principal)
174173
}),
175174
);
176-
let local_data_id =
177-
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
175+
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
178176
fx.bcx.ins().symbol_value(fx.pointer_type, local_data_id)
179177
}
180178
GlobalAlloc::TypeId { .. } => {
@@ -191,8 +189,7 @@ pub(crate) fn codegen_const_value<'tcx>(
191189
// For a declaration the stated mutability doesn't matter.
192190
false,
193191
);
194-
let local_data_id =
195-
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
192+
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
196193
if fx.clif_comments.enabled() {
197194
fx.add_comment(local_data_id, format!("{:?}", def_id));
198195
}
@@ -236,7 +233,7 @@ fn pointer_for_allocation<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, alloc_id: All
236233
let data_id =
237234
data_id_for_alloc_id(&mut fx.constants_cx, fx.module, alloc_id, alloc.inner().mutability);
238235

239-
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
236+
let local_data_id = fx.module.declare_data_in_func(data_id, fx.bcx.func);
240237
if fx.clif_comments.enabled() {
241238
fx.add_comment(local_data_id, format!("{:?}", alloc_id));
242239
}
@@ -354,7 +351,7 @@ fn data_id_for_static(
354351
Linkage::Import
355352
};
356353

357-
let data_id = match module.declare_data(
354+
match module.declare_data(
358355
symbol_name,
359356
linkage,
360357
definition_writable,
@@ -365,9 +362,7 @@ fn data_id_for_static(
365362
"attempt to declare `{symbol_name}` as static, but it was already declared as function"
366363
)),
367364
Err(err) => Err::<_, _>(err).unwrap(),
368-
};
369-
370-
data_id
365+
}
371366
}
372367

373368
fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut ConstantCx) {

src/debuginfo/emit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,12 @@ impl Writer for WriterRelocate {
222222
gimli::DW_EH_PE_absptr => {
223223
self.relocs.push(DebugReloc {
224224
offset: self.len() as u32,
225-
size: size.into(),
225+
size,
226226
name: DebugRelocName::Symbol(symbol),
227227
addend,
228228
kind: object::RelocationKind::Absolute,
229229
});
230-
self.write_udata(0, size.into())
230+
self.write_udata(0, size)
231231
}
232232
_ => Err(gimli::write::Error::UnsupportedPointerEncoding(eh_pe)),
233233
},

src/debuginfo/gcc_except_table.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ impl GccExceptTable {
4141
+ self.call_sites.encoded_size()
4242
+ self.actions.encoded_size()
4343
+ type_info_padding)
44-
% 4
45-
== 0
44+
.is_multiple_of(4)
4645
};
4746

4847
let mut type_info_padding = 0;
@@ -69,9 +68,9 @@ impl GccExceptTable {
6968
// In this case we calculated the expected padding amount and used it to write the
7069
// classInfoOffset field. Assert that the expected value matched the actual value to catch
7170
// any inconsistency.
72-
assert!(w.len() % 4 == 0, "type_info must be aligned to 4 bytes");
71+
assert!(w.len().is_multiple_of(4), "type_info must be aligned to 4 bytes");
7372
} else {
74-
while w.len() % 4 != 0 {
73+
while !w.len().is_multiple_of(4) {
7574
w.write_u8(0)?;
7675
}
7776
}
@@ -82,7 +81,7 @@ impl GccExceptTable {
8281
// exception specs (unused for rust)
8382

8483
// align to 4 bytes
85-
while w.len() % 4 != 0 {
84+
while !w.len().is_multiple_of(4) {
8685
w.write_u8(0)?;
8786
}
8887

src/debuginfo/types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl DebugContext {
5656
// ty::FnDef(..) | ty::FnPtr(..)
5757
// ty::Closure(..)
5858
// ty::Adt(def, ..)
59-
ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, *components),
59+
ty::Tuple(components) => self.tuple_type(tcx, type_dbg, ty, components),
6060
// ty::Param(_)
6161
// FIXME implement remaining types and add unreachable!() to the fallback branch
6262
_ => self.placeholder_for_type(tcx, type_dbg, ty),
@@ -152,7 +152,7 @@ impl DebugContext {
152152
components: &'tcx [Ty<'tcx>],
153153
) -> UnitEntryId {
154154
let components = components
155-
.into_iter()
155+
.iter()
156156
.map(|&ty| (ty, self.debug_type(tcx, type_dbg, ty)))
157157
.collect::<Vec<_>>();
158158

0 commit comments

Comments
 (0)