Skip to content

Commit 7ff5d39

Browse files
authored
Merge pull request #469 from tempdragon/master
Clippy related fixes
2 parents b5d61f1 + 0a49351 commit 7ff5d39

18 files changed

+160
-158
lines changed

.github/workflows/ci.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ jobs:
4949
# `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests.
5050
run: sudo apt-get install ninja-build ripgrep llvm-14-tools
5151

52-
- name: Install rustfmt
53-
run: rustup component add rustfmt
52+
- name: Install rustfmt & clippy
53+
run: rustup component add rustfmt clippy
5454

5555
- name: Download artifact
5656
run: curl -LO https://github.com/antoyo/gcc/releases/latest/download/${{ matrix.libgccjit_version.gcc }}
@@ -98,6 +98,11 @@ jobs:
9898
- name: Check formatting
9999
run: cargo fmt -- --check
100100

101+
- name: clippy
102+
run: |
103+
cargo clippy --all-targets -- -D warnings
104+
cargo clippy --all-targets --features master -- -D warnings
105+
101106
duplicates:
102107
runs-on: ubuntu-latest
103108
steps:

src/attributes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
9292
let mut function_features = function_features
9393
.iter()
9494
.flat_map(|feat| to_gcc_features(cx.tcx.sess, feat).into_iter())
95-
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match x {
95+
.chain(codegen_fn_attrs.instruction_set.iter().map(|x| match *x {
9696
InstructionSetAttr::ArmA32 => "-thumb-mode", // TODO(antoyo): support removing feature.
9797
InstructionSetAttr::ArmT32 => "thumb-mode",
9898
}))
@@ -118,8 +118,8 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
118118

119119
if feature.starts_with('-') {
120120
Some(format!("no{}", feature))
121-
} else if feature.starts_with('+') {
122-
Some(feature[1..].to_string())
121+
} else if let Some(stripped) = feature.strip_prefix('+') {
122+
Some(stripped.to_string())
123123
} else {
124124
Some(feature.to_string())
125125
}

src/back/lto.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ fn prepare_lto(
128128
}
129129

130130
let archive_data = unsafe {
131-
Mmap::map(File::open(&path).expect("couldn't open rlib"))
132-
.expect("couldn't map rlib")
131+
Mmap::map(File::open(path).expect("couldn't open rlib")).expect("couldn't map rlib")
133132
};
134133
let archive = ArchiveFile::parse(&*archive_data).expect("wanted an rlib");
135134
let obj_files = archive

src/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub(crate) unsafe fn codegen(
104104
// FIXME(antoyo): segfault in dump_reproducer_to_file() might be caused by
105105
// transmuting an rvalue to an lvalue.
106106
// Segfault is actually in gcc::jit::reproducer::get_identifier_as_lvalue
107-
context.dump_reproducer_to_file(&format!("/tmp/reproducers/{}.c", module.name));
107+
context.dump_reproducer_to_file(format!("/tmp/reproducers/{}.c", module.name));
108108
println!("Dumped reproducer {}", module.name);
109109
}
110110
if env::var("CG_GCCJIT_DUMP_TO_FILE").as_deref() == Ok("1") {

src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub fn compile_codegen_unit(
135135

136136
let target_cpu = gcc_util::target_cpu(tcx.sess);
137137
if target_cpu != "generic" {
138-
context.add_command_line_option(&format!("-march={}", target_cpu));
138+
context.add_command_line_option(format!("-march={}", target_cpu));
139139
}
140140

141141
if tcx

src/builder.rs

+17-19
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
225225

226226
let mut on_stack_param_indices = FxHashSet::default();
227227
if let Some(indices) = self.on_stack_params.borrow().get(&gcc_func) {
228-
on_stack_param_indices = indices.clone();
228+
on_stack_param_indices.clone_from(indices);
229229
}
230230

231231
if all_args_match {
@@ -256,8 +256,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
256256
actual_val.dereference(self.location).to_rvalue()
257257
} else {
258258
assert!(
259-
!((actual_ty.is_vector() && !expected_ty.is_vector())
260-
|| (!actual_ty.is_vector() && expected_ty.is_vector())),
259+
(!expected_ty.is_vector() || actual_ty.is_vector())
260+
&& (expected_ty.is_vector() || !actual_ty.is_vector()),
261261
"{:?} ({}) -> {:?} ({}), index: {:?}[{}]",
262262
actual_ty,
263263
actual_ty.is_vector(),
@@ -277,8 +277,8 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
277277
.collect();
278278

279279
// NOTE: to take into account variadic functions.
280-
for i in casted_args.len()..args.len() {
281-
casted_args.push(args[i]);
280+
for arg in args.iter().skip(casted_args.len()) {
281+
casted_args.push(*arg);
282282
}
283283

284284
Cow::Owned(casted_args)
@@ -353,15 +353,15 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
353353
let function_address_names = self.function_address_names.borrow();
354354
let original_function_name = function_address_names.get(&func_ptr);
355355
llvm::adjust_intrinsic_arguments(
356-
&self,
356+
self,
357357
gcc_func,
358358
args.into(),
359359
&func_name,
360360
original_function_name,
361361
)
362362
};
363363
let args_adjusted = args.len() != previous_arg_count;
364-
let args = self.check_ptr_call("call", func_ptr, &*args);
364+
let args = self.check_ptr_call("call", func_ptr, &args);
365365

366366
// gccjit requires to use the result of functions, even when it's not used.
367367
// That's why we assign the result to a local or call add_eval().
@@ -373,7 +373,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
373373
unsafe { RETURN_VALUE_COUNT += 1 };
374374
let return_value = self.cx.context.new_call_through_ptr(self.location, func_ptr, &args);
375375
let return_value = llvm::adjust_intrinsic_return_value(
376-
&self,
376+
self,
377377
return_value,
378378
&func_name,
379379
&args,
@@ -441,7 +441,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
441441
self.block.add_assignment(
442442
self.location,
443443
result,
444-
self.cx.context.new_call(self.location, func, &args),
444+
self.cx.context.new_call(self.location, func, args),
445445
);
446446
result.to_rvalue()
447447
}
@@ -595,7 +595,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
595595
) -> RValue<'gcc> {
596596
let try_block = self.current_func().new_block("try");
597597

598-
let current_block = self.block.clone();
598+
let current_block = self.block;
599599
self.block = try_block;
600600
let call = self.call(typ, fn_attrs, None, func, args, None); // TODO(antoyo): use funclet here?
601601
self.block = current_block;
@@ -1176,7 +1176,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
11761176
// NOTE: due to opaque pointers now being used, we need to cast here.
11771177
let ptr = self.context.new_cast(self.location, ptr, typ.make_pointer());
11781178
// NOTE: array indexing is always considered in bounds in GCC (TODO(antoyo): to be verified).
1179-
let mut indices = indices.into_iter();
1179+
let mut indices = indices.iter();
11801180
let index = indices.next().expect("first index in inbounds_gep");
11811181
let mut result = self.context.new_array_access(self.location, ptr, *index);
11821182
for index in indices {
@@ -1684,7 +1684,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
16841684

16851685
fn zext(&mut self, value: RValue<'gcc>, dest_typ: Type<'gcc>) -> RValue<'gcc> {
16861686
// FIXME(antoyo): this does not zero-extend.
1687-
if value.get_type().is_bool() && dest_typ.is_i8(&self.cx) {
1687+
if value.get_type().is_bool() && dest_typ.is_i8(self.cx) {
16881688
// FIXME(antoyo): hack because base::from_immediate converts i1 to i8.
16891689
// Fix the code in codegen_ssa::base::from_immediate.
16901690
return value;
@@ -2057,7 +2057,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
20572057
self.context.new_rvalue_from_vector(self.location, mask_type, &vector_elements);
20582058
let shifted = self.context.new_rvalue_vector_perm(self.location, res, res, mask);
20592059
shift *= 2;
2060-
res = op(res, shifted, &self.context);
2060+
res = op(res, shifted, self.context);
20612061
}
20622062
self.context
20632063
.new_vector_access(self.location, res, self.context.new_rvalue_zero(self.int_type))
@@ -2073,7 +2073,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
20732073
}
20742074

20752075
pub fn vector_reduce_op(&mut self, src: RValue<'gcc>, op: BinaryOp) -> RValue<'gcc> {
2076-
let loc = self.location.clone();
2076+
let loc = self.location;
20772077
self.vector_reduce(src, |a, b, context| context.new_binary_op(loc, op, a.get_type(), a, b))
20782078
}
20792079

@@ -2090,7 +2090,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
20902090
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
20912091
let element_count = vector_type.get_num_units();
20922092
(0..element_count)
2093-
.into_iter()
20942093
.map(|i| {
20952094
self.context
20962095
.new_vector_access(
@@ -2121,7 +2120,6 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
21212120
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
21222121
let element_count = vector_type.get_num_units();
21232122
(0..element_count)
2124-
.into_iter()
21252123
.map(|i| {
21262124
self.context
21272125
.new_vector_access(
@@ -2141,7 +2139,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
21412139

21422140
// Inspired by Hacker's Delight min implementation.
21432141
pub fn vector_reduce_min(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
2144-
let loc = self.location.clone();
2142+
let loc = self.location;
21452143
self.vector_reduce(src, |a, b, context| {
21462144
let differences_or_zeros = difference_or_zero(loc, a, b, context);
21472145
context.new_binary_op(loc, BinaryOp::Plus, b.get_type(), b, differences_or_zeros)
@@ -2150,7 +2148,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
21502148

21512149
// Inspired by Hacker's Delight max implementation.
21522150
pub fn vector_reduce_max(&mut self, src: RValue<'gcc>) -> RValue<'gcc> {
2153-
let loc = self.location.clone();
2151+
let loc = self.location;
21542152
self.vector_reduce(src, |a, b, context| {
21552153
let differences_or_zeros = difference_or_zero(loc, a, b, context);
21562154
context.new_binary_op(loc, BinaryOp::Minus, a.get_type(), a, differences_or_zeros)
@@ -2345,7 +2343,7 @@ impl<'tcx> HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
23452343

23462344
impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23472345
fn target_spec(&self) -> &Target {
2348-
&self.cx.target_spec()
2346+
self.cx.target_spec()
23492347
}
23502348
}
23512349

src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
2828

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

31-
let func = if let Some(_func) = cx.get_declared_value(&sym) {
31+
let func = if let Some(_func) = cx.get_declared_value(sym) {
3232
// FIXME(antoyo): we never reach this because get_declared_value only returns global variables
3333
// and here we try to get a function.
3434
unreachable!();
@@ -68,7 +68,7 @@ pub fn get_fn<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, instance: Instance<'tcx>)
6868
}*/
6969
} else {
7070
cx.linkage.set(FunctionType::Extern);
71-
let func = cx.declare_fn(&sym, &fn_abi);
71+
let func = cx.declare_fn(sym, fn_abi);
7272

7373
attributes::from_fn_attrs(cx, func, instance);
7474

src/common.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2121

2222
fn global_string(&self, string: &str) -> LValue<'gcc> {
2323
// TODO(antoyo): handle non-null-terminated strings.
24-
let string = self.context.new_string_literal(&*string);
24+
let string = self.context.new_string_literal(string);
2525
let sym = self.generate_local_symbol_name("str");
2626
let global = self.declare_private_global(&sym, self.val_ty(string));
2727
global.global_set_initializer_rvalue(string);
@@ -170,7 +170,8 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
170170
return self
171171
.context
172172
.new_rvalue_from_double(ty, f32::from_bits(data as u32) as f64);
173-
} else if ty == self.double_type {
173+
}
174+
if ty == self.double_type {
174175
return self.context.new_rvalue_from_double(ty, f64::from_bits(data as u64));
175176
}
176177

@@ -293,7 +294,7 @@ impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
293294
} else if self.is_ulonglong(cx) {
294295
cx.longlong_type
295296
} else {
296-
self.clone()
297+
*self
297298
}
298299
}
299300

@@ -319,7 +320,7 @@ impl<'gcc, 'tcx> SignType<'gcc, 'tcx> for Type<'gcc> {
319320
} else if self.is_longlong(cx) {
320321
cx.ulonglong_type
321322
} else {
322-
self.clone()
323+
*self
323324
}
324325
}
325326
}
@@ -432,7 +433,7 @@ impl<'gcc, 'tcx> TypeReflection<'gcc, 'tcx> for Type<'gcc> {
432433
}
433434

434435
fn is_vector(&self) -> bool {
435-
let mut typ = self.clone();
436+
let mut typ = *self;
436437
loop {
437438
if typ.dyncast_vector().is_some() {
438439
return true;

src/consts.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
6666
fn codegen_static(&self, def_id: DefId, is_mutable: bool) {
6767
let attrs = self.tcx.codegen_fn_attrs(def_id);
6868

69-
let value = match codegen_static_initializer(&self, def_id) {
69+
let value = match codegen_static_initializer(self, def_id) {
7070
Ok((value, _)) => value,
7171
// Error has already been reported
7272
Err(_) => return,
@@ -231,13 +231,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
231231
}
232232

233233
let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
234-
let global = self.declare_global(
235-
&sym,
236-
llty,
237-
GlobalKind::Exported,
238-
is_tls,
239-
fn_attrs.link_section,
240-
);
234+
let global =
235+
self.declare_global(sym, llty, GlobalKind::Exported, is_tls, fn_attrs.link_section);
241236

242237
if !self.tcx.is_reachable_non_generic(def_id) {
243238
#[cfg(feature = "master")]
@@ -246,7 +241,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
246241

247242
global
248243
} else {
249-
check_and_apply_linkage(&self, &fn_attrs, ty, sym)
244+
check_and_apply_linkage(self, fn_attrs, ty, sym)
250245
};
251246

252247
if !def_id.is_local() {
@@ -367,11 +362,8 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
367362
let gcc_type = cx.layout_of(ty).gcc_type(cx);
368363
if let Some(linkage) = attrs.import_linkage {
369364
// Declare a symbol `foo` with the desired linkage.
370-
let global1 = cx.declare_global_with_linkage(
371-
&sym,
372-
cx.type_i8(),
373-
base::global_linkage_to_gcc(linkage),
374-
);
365+
let global1 =
366+
cx.declare_global_with_linkage(sym, cx.type_i8(), base::global_linkage_to_gcc(linkage));
375367

376368
// Declare an internal global `extern_with_linkage_foo` which
377369
// is initialized with the address of `foo`. If `foo` is
@@ -380,7 +372,7 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
380372
// `extern_with_linkage_foo` will instead be initialized to
381373
// zero.
382374
let mut real_name = "_rust_extern_with_linkage_".to_string();
383-
real_name.push_str(&sym);
375+
real_name.push_str(sym);
384376
let global2 = cx.define_global(&real_name, gcc_type, is_tls, attrs.link_section);
385377
// TODO(antoyo): set linkage.
386378
let value = cx.const_ptrcast(global1.get_address(None), gcc_type);
@@ -397,6 +389,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
397389
// don't do this then linker errors can be generated where the linker
398390
// complains that one object files has a thread local version of the
399391
// symbol and another one doesn't.
400-
cx.declare_global(&sym, gcc_type, GlobalKind::Imported, is_tls, attrs.link_section)
392+
cx.declare_global(sym, gcc_type, GlobalKind::Imported, is_tls, attrs.link_section)
401393
}
402394
}

src/context.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
384384
}
385385

386386
pub fn sess(&self) -> &'tcx Session {
387-
&self.tcx.sess
387+
self.tcx.sess
388388
}
389389

390390
pub fn bitcast_if_needed(
@@ -431,7 +431,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
431431
let func_name = self.tcx.symbol_name(instance).name;
432432

433433
let func = if self.intrinsics.borrow().contains_key(func_name) {
434-
self.intrinsics.borrow()[func_name].clone()
434+
self.intrinsics.borrow()[func_name]
435435
} else {
436436
get_fn(self, instance)
437437
};
@@ -485,7 +485,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
485485
let symbol_name = tcx.symbol_name(instance).name;
486486
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
487487
self.linkage.set(FunctionType::Extern);
488-
let func = self.declare_fn(symbol_name, &fn_abi);
488+
let func = self.declare_fn(symbol_name, fn_abi);
489489
let func: RValue<'gcc> = unsafe { std::mem::transmute(func) };
490490
func
491491
}
@@ -505,7 +505,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
505505
}
506506

507507
fn sess(&self) -> &Session {
508-
&self.tcx.sess
508+
self.tcx.sess
509509
}
510510

511511
fn check_overflow(&self) -> bool {
@@ -612,7 +612,7 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
612612
// user defined names
613613
let mut name = String::with_capacity(prefix.len() + 6);
614614
name.push_str(prefix);
615-
name.push_str(".");
615+
name.push('.');
616616
base_n::push_str(idx as u128, base_n::ALPHANUMERIC_ONLY, &mut name);
617617
name
618618
}

0 commit comments

Comments
 (0)