Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4cc6b4f

Browse files
committed
Fix many clippy warnings
1 parent 5103a25 commit 4cc6b4f

23 files changed

+88
-109
lines changed

src/abi/comments.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use crate::abi::pass_mode::*;
1111
use crate::prelude::*;
1212

1313
pub(super) fn add_args_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
14-
fx.add_global_comment(format!(
15-
"kind loc.idx param pass mode ty"
16-
));
14+
fx.add_global_comment(
15+
"kind loc.idx param pass mode ty".to_string(),
16+
);
1717
}
1818

1919
pub(super) fn add_arg_comment<'tcx>(
@@ -56,9 +56,9 @@ pub(super) fn add_arg_comment<'tcx>(
5656

5757
pub(super) fn add_locals_header_comment(fx: &mut FunctionCx<'_, '_, impl Module>) {
5858
fx.add_global_comment(String::new());
59-
fx.add_global_comment(format!(
60-
"kind local ty size align (abi,pref)"
61-
));
59+
fx.add_global_comment(
60+
"kind local ty size align (abi,pref)".to_string(),
61+
);
6262
}
6363

6464
pub(super) fn add_local_place_comments<'tcx>(

src/abi/mod.rs

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'tcx, M: Module> FunctionCx<'_, 'tcx, M> {
300300
return_ty: Ty<'tcx>,
301301
) -> CValue<'tcx> {
302302
let (input_tys, args): (Vec<_>, Vec<_>) = args
303-
.into_iter()
303+
.iter()
304304
.map(|arg| {
305305
(
306306
self.clif_type(arg.layout().ty).unwrap(),
@@ -421,34 +421,31 @@ pub(crate) fn codegen_fn_prelude<'tcx>(
421421

422422
// While this is normally an optimization to prevent an unnecessary copy when an argument is
423423
// not mutated by the current function, this is necessary to support unsized arguments.
424-
match arg_kind {
425-
ArgKind::Normal(Some(val)) => {
426-
if let Some((addr, meta)) = val.try_to_ptr() {
427-
let local_decl = &fx.mir.local_decls[local];
428-
// v this ! is important
429-
let internally_mutable = !val.layout().ty.is_freeze(
430-
fx.tcx.at(local_decl.source_info.span),
431-
ParamEnv::reveal_all(),
432-
);
433-
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
434-
// We wont mutate this argument, so it is fine to borrow the backing storage
435-
// of this argument, to prevent a copy.
436-
437-
let place = if let Some(meta) = meta {
438-
CPlace::for_ptr_with_extra(addr, meta, val.layout())
439-
} else {
440-
CPlace::for_ptr(addr, val.layout())
441-
};
442-
443-
#[cfg(debug_assertions)]
444-
self::comments::add_local_place_comments(fx, place, local);
445-
446-
assert_eq!(fx.local_map.push(place), local);
447-
continue;
448-
}
424+
if let ArgKind::Normal(Some(val)) = arg_kind {
425+
if let Some((addr, meta)) = val.try_to_ptr() {
426+
let local_decl = &fx.mir.local_decls[local];
427+
// v this ! is important
428+
let internally_mutable = !val.layout().ty.is_freeze(
429+
fx.tcx.at(local_decl.source_info.span),
430+
ParamEnv::reveal_all(),
431+
);
432+
if local_decl.mutability == mir::Mutability::Not && !internally_mutable {
433+
// We wont mutate this argument, so it is fine to borrow the backing storage
434+
// of this argument, to prevent a copy.
435+
436+
let place = if let Some(meta) = meta {
437+
CPlace::for_ptr_with_extra(addr, meta, val.layout())
438+
} else {
439+
CPlace::for_ptr(addr, val.layout())
440+
};
441+
442+
#[cfg(debug_assertions)]
443+
self::comments::add_local_place_comments(fx, place, local);
444+
445+
assert_eq!(fx.local_map.push(place), local);
446+
continue;
449447
}
450448
}
451-
_ => {}
452449
}
453450

454451
let place = make_local_place(fx, local, layout, is_ssa);
@@ -568,7 +565,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
568565
}
569566
args
570567
} else {
571-
args.into_iter()
568+
args.iter()
572569
.map(|arg| trans_operand(fx, arg))
573570
.collect::<Vec<_>>()
574571
};

src/allocator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ fn codegen_inner(
123123
.unwrap();
124124

125125
let mut ctx = Context::new();
126-
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig.clone());
126+
ctx.func = Function::with_name_signature(ExternalName::user(0, 0), sig);
127127
{
128128
let mut func_ctx = FunctionBuilderContext::new();
129129
let mut bcx = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
130130

131131
let block = bcx.create_block();
132132
bcx.switch_to_block(block);
133133
let args = (&[usize_ty, usize_ty])
134-
.into_iter()
134+
.iter()
135135
.map(|&ty| bcx.append_block_param(block, ty))
136136
.collect::<Vec<Value>>();
137137

src/archive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
132132
}
133133

134134
// ok, don't skip this
135-
return false;
135+
false
136136
})
137137
}
138138

src/atomic_shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::prelude::*;
77

88
#[cfg(all(feature = "jit", unix))]
99
#[no_mangle]
10-
pub static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
10+
static mut __cg_clif_global_atomic_mutex: libc::pthread_mutex_t =
1111
libc::PTHREAD_MUTEX_INITIALIZER;
1212

1313
pub(crate) fn init_global_lock(

src/backend.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl WriteDebugInfo for ObjectProduct {
7373
// FIXME use SHT_X86_64_UNWIND for .eh_frame
7474
let section_id = self.object.add_section(
7575
segment,
76-
name.clone(),
76+
name,
7777
if id == SectionId::EhFrame {
7878
SectionKind::ReadOnlyData
7979
} else {
@@ -201,6 +201,5 @@ pub(crate) fn make_module(sess: &Session, name: String) -> ObjectModule {
201201
if std::env::var("CG_CLIF_FUNCTION_SECTIONS").is_ok() {
202202
builder.per_function_section(true);
203203
}
204-
let module = ObjectModule::new(builder);
205-
module
204+
ObjectModule::new(builder)
206205
}

src/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ fn trans_stmt<'tcx>(
753753
}
754754
Rvalue::Aggregate(kind, operands) => match **kind {
755755
AggregateKind::Array(_ty) => {
756-
for (i, operand) in operands.into_iter().enumerate() {
756+
for (i, operand) in operands.iter().enumerate() {
757757
let operand = trans_operand(fx, operand);
758758
let index = fx.bcx.ins().iconst(fx.pointer_type, i as i64);
759759
let to = lval.place_index(fx, index);
@@ -938,7 +938,7 @@ pub(crate) fn trans_place<'tcx>(
938938
let ptr = cplace.to_ptr();
939939
cplace = CPlace::for_ptr(
940940
ptr.offset_i64(fx, elem_layout.size.bytes() as i64 * (from as i64)),
941-
fx.layout_of(fx.tcx.mk_array(elem_ty, u64::from(to) - u64::from(from))),
941+
fx.layout_of(fx.tcx.mk_array(elem_ty, to - from)),
942942
);
943943
}
944944
ty::Slice(elem_ty) => {

src/cast.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,10 @@ pub(crate) fn clif_int_or_float_cast(
181181
fx.bcx.ins().select(has_overflow, max_val, val)
182182
};
183183
fx.bcx.ins().ireduce(to_ty, val)
184+
} else if to_signed {
185+
fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
184186
} else {
185-
if to_signed {
186-
fx.bcx.ins().fcvt_to_sint_sat(to_ty, from)
187-
} else {
188-
fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
189-
}
187+
fx.bcx.ins().fcvt_to_uint_sat(to_ty, from)
190188
}
191189
} else if from_ty.is_float() && to_ty.is_float() {
192190
// float -> float

src/codegen_i128.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ pub(crate) fn maybe_codegen<'tcx>(
2121
match bin_op {
2222
BinOp::BitAnd | BinOp::BitOr | BinOp::BitXor => {
2323
assert!(!checked);
24-
return None;
24+
None
2525
}
26-
BinOp::Add | BinOp::Sub if !checked => return None,
26+
BinOp::Add | BinOp::Sub if !checked => None,
2727
BinOp::Add => {
2828
let out_ty = fx.tcx.mk_tup([lhs.layout().ty, fx.tcx.types.bool].iter());
2929
return Some(if is_signed {
@@ -57,7 +57,7 @@ pub(crate) fn maybe_codegen<'tcx>(
5757
};
5858
fx.easy_call("__multi3", &[lhs, rhs], val_ty)
5959
};
60-
return Some(res);
60+
Some(res)
6161
}
6262
BinOp::Div => {
6363
assert!(!checked);
@@ -77,7 +77,7 @@ pub(crate) fn maybe_codegen<'tcx>(
7777
}
7878
BinOp::Lt | BinOp::Le | BinOp::Eq | BinOp::Ge | BinOp::Gt | BinOp::Ne => {
7979
assert!(!checked);
80-
return None;
80+
None
8181
}
8282
BinOp::Shl | BinOp::Shr => {
8383
let is_overflow = if checked {

src/constant.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) fn trans_const_value<'tcx>(
188188
match x {
189189
Scalar::Raw { data, size } => {
190190
assert_eq!(u64::from(size), layout.size.bytes());
191-
return CValue::const_val(fx, layout, data);
191+
CValue::const_val(fx, layout, data)
192192
}
193193
Scalar::Ptr(ptr) => {
194194
let alloc_kind = fx.tcx.get_global_alloc(ptr.alloc_id);
@@ -232,7 +232,7 @@ pub(crate) fn trans_const_value<'tcx>(
232232
} else {
233233
base_addr
234234
};
235-
return CValue::by_val(val, layout);
235+
CValue::by_val(val, layout)
236236
}
237237
}
238238
}
@@ -293,14 +293,12 @@ fn data_id_for_static(
293293
let rlinkage = tcx.codegen_fn_attrs(def_id).linkage;
294294
let linkage = if definition {
295295
crate::linkage::get_static_linkage(tcx, def_id)
296+
} else if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
297+
|| rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
298+
{
299+
Linkage::Preemptible
296300
} else {
297-
if rlinkage == Some(rustc_middle::mir::mono::Linkage::ExternalWeak)
298-
|| rlinkage == Some(rustc_middle::mir::mono::Linkage::WeakAny)
299-
{
300-
Linkage::Preemptible
301-
} else {
302-
Linkage::Import
303-
}
301+
Linkage::Import
304302
};
305303

306304
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);

0 commit comments

Comments
 (0)