Skip to content

Commit e4ec64a

Browse files
authored
Merge pull request rust-lang#459 from tempdragon/master
fix(fmt/style): Clippy-generated Code Correction
2 parents 3937fd1 + aeffc2f commit e4ec64a

File tree

10 files changed

+38
-43
lines changed

10 files changed

+38
-43
lines changed

src/allocator.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(crate) unsafe fn codegen(
6363
tcx,
6464
context,
6565
"__rust_alloc_error_handler",
66-
&alloc_error_handler_name(alloc_error_handler_kind),
66+
alloc_error_handler_name(alloc_error_handler_kind),
6767
&[usize, usize],
6868
None,
6969
);
@@ -93,7 +93,7 @@ fn create_wrapper_function(
9393
let args: Vec<_> = types
9494
.iter()
9595
.enumerate()
96-
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
96+
.map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
9797
.collect();
9898
let func = context.new_function(
9999
None,
@@ -115,7 +115,7 @@ fn create_wrapper_function(
115115
let args: Vec<_> = types
116116
.iter()
117117
.enumerate()
118-
.map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index)))
118+
.map(|(index, typ)| context.new_parameter(None, *typ, format!("param{}", index)))
119119
.collect();
120120
let callee = context.new_function(
121121
None,

src/asm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl AsmOutOperand<'_, '_, '_> {
9696
res.push('&');
9797
}
9898

99-
res.push_str(&self.constraint);
99+
res.push_str(self.constraint);
100100
res
101101
}
102102
}
@@ -304,7 +304,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
304304
tmp_var.set_register_name(reg_name);
305305

306306
outputs.push(AsmOutOperand {
307-
constraint: "r".into(),
307+
constraint: "r",
308308
rust_idx,
309309
late,
310310
readwrite: false,
@@ -343,7 +343,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
343343
tmp_var.set_register_name(reg_name);
344344

345345
outputs.push(AsmOutOperand {
346-
constraint: "r".into(),
346+
constraint: "r",
347347
rust_idx,
348348
late,
349349
readwrite: false,

src/back/lto.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,10 @@ fn prepare_lto(
106106
if !crate_type_allows_lto(*crate_type) {
107107
dcx.emit_err(LtoDisallowed);
108108
return Err(FatalError);
109-
} else if *crate_type == CrateType::Dylib {
110-
if !cgcx.opts.unstable_opts.dylib_lto {
111-
dcx.emit_err(LtoDylib);
112-
return Err(FatalError);
113-
}
109+
}
110+
if *crate_type == CrateType::Dylib && !cgcx.opts.unstable_opts.dylib_lto {
111+
dcx.emit_err(LtoDylib);
112+
return Err(FatalError);
114113
}
115114
}
116115

src/consts.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
7777
// boolean SSA values are i1, but they have to be stored in i8 slots,
7878
// otherwise some LLVM optimization passes don't work as expected
7979
let val_llty = self.val_ty(value);
80-
let value = if val_llty == self.type_i1() {
80+
if val_llty == self.type_i1() {
8181
unimplemented!();
82-
} else {
83-
value
8482
};
8583

8684
let instance = Instance::mono(self.tcx, def_id);
@@ -94,11 +92,9 @@ impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
9492

9593
// As an optimization, all shared statics which do not have interior
9694
// mutability are placed into read-only memory.
97-
if !is_mutable {
98-
if self.type_is_freeze(ty) {
99-
#[cfg(feature = "master")]
100-
global.global_set_readonly();
101-
}
95+
if !is_mutable && self.type_is_freeze(ty) {
96+
#[cfg(feature = "master")]
97+
global.global_set_readonly();
10298
}
10399

104100
if attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {

src/debuginfo.rs

-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
255255
_variable_kind: VariableKind,
256256
_span: Span,
257257
) -> Self::DIVariable {
258-
()
259258
}
260259

261260
fn dbg_scope_fn(

src/intrinsic/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
10651065

10661066
// Return `result_type`'s maximum or minimum value on overflow
10671067
// NOTE: convert the type to unsigned to have an unsigned shift.
1068-
let unsigned_type = result_type.to_unsigned(&self.cx);
1068+
let unsigned_type = result_type.to_unsigned(self.cx);
10691069
let shifted = self.gcc_lshr(
10701070
self.gcc_int_cast(lhs, unsigned_type),
10711071
self.gcc_int(unsigned_type, width as i64 - 1),
@@ -1108,9 +1108,10 @@ fn try_intrinsic<'a, 'b, 'gcc, 'tcx>(
11081108
// we can never unwind.
11091109
let ret_align = bx.tcx.data_layout.i32_align.abi;
11101110
bx.store(bx.const_i32(0), dest, ret_align);
1111-
} else if wants_msvc_seh(bx.sess()) {
1112-
unimplemented!();
11131111
} else {
1112+
if wants_msvc_seh(bx.sess()) {
1113+
unimplemented!();
1114+
}
11141115
#[cfg(feature = "master")]
11151116
codegen_gnu_try(bx, try_func, data, _catch_func, dest);
11161117
#[cfg(not(feature = "master"))]
@@ -1160,7 +1161,7 @@ fn codegen_gnu_try<'gcc>(
11601161
let catch_func = func.get_param(2).to_rvalue();
11611162
let try_func_ty = bx.type_func(&[bx.type_i8p()], bx.type_void());
11621163

1163-
let current_block = bx.block.clone();
1164+
let current_block = bx.block;
11641165

11651166
bx.switch_to_block(then);
11661167
bx.ret(bx.const_i32(0));

src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl CodegenBackend for GccCodegenBackend {
187187
// Get the second TargetInfo with the correct CPU features by setting the arch.
188188
let context = Context::default();
189189
if target_cpu != "generic" {
190-
context.add_command_line_option(&format!("-march={}", target_cpu));
190+
context.add_command_line_option(format!("-march={}", target_cpu));
191191
}
192192

193193
**self.target_info.info.lock().expect("lock") = context.get_target_info();
@@ -224,9 +224,9 @@ impl CodegenBackend for GccCodegenBackend {
224224
providers.global_backend_features = |tcx, ()| gcc_util::global_gcc_features(tcx.sess, true)
225225
}
226226

227-
fn codegen_crate<'tcx>(
227+
fn codegen_crate(
228228
&self,
229-
tcx: TyCtxt<'tcx>,
229+
tcx: TyCtxt<'_>,
230230
metadata: EncodedMetadata,
231231
need_metadata_module: bool,
232232
) -> Box<dyn Any> {
@@ -292,9 +292,9 @@ fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {
292292
}
293293

294294
impl ExtraBackendMethods for GccCodegenBackend {
295-
fn codegen_allocator<'tcx>(
295+
fn codegen_allocator(
296296
&self,
297-
tcx: TyCtxt<'tcx>,
297+
tcx: TyCtxt<'_>,
298298
module_name: &str,
299299
kind: AllocatorKind,
300300
alloc_error_handler_kind: AllocatorKind,
@@ -486,6 +486,6 @@ pub fn target_features(
486486
sha, sse, sse2, sse3, sse4.1, sse4.2, sse4a, ssse3, tbm, vaes, vpclmulqdq, xsave, xsavec, xsaveopt, xsaves
487487
*/
488488
})
489-
.map(|feature| Symbol::intern(feature))
489+
.map(Symbol::intern)
490490
.collect()
491491
}

src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
4747

4848
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
4949
self.linkage.set(base::linkage_to_gcc(linkage));
50-
let decl = self.declare_fn(symbol_name, &fn_abi);
50+
let decl = self.declare_fn(symbol_name, fn_abi);
5151
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
5252

5353
attributes::from_fn_attrs(self, decl, instance);

src/type_.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ impl<'gcc, 'tcx> BaseTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
133133
fn type_struct(&self, fields: &[Type<'gcc>], packed: bool) -> Type<'gcc> {
134134
let types = fields.to_vec();
135135
if let Some(typ) = self.struct_types.borrow().get(fields) {
136-
return typ.clone();
136+
return *typ;
137137
}
138138
let fields: Vec<_> = fields
139139
.iter()
140140
.enumerate()
141141
.map(|(index, field)| {
142-
self.context.new_field(None, *field, &format!("field{}_TODO", index))
142+
self.context.new_field(None, *field, format!("field{}_TODO", index))
143143
})
144144
.collect();
145145
let typ = self.context.new_struct_type(None, "struct", &fields).as_type();
@@ -240,7 +240,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
240240
let fields: Vec<_> = fields
241241
.iter()
242242
.enumerate()
243-
.map(|(index, field)| self.context.new_field(None, *field, &format!("field_{}", index)))
243+
.map(|(index, field)| self.context.new_field(None, *field, format!("field_{}", index)))
244244
.collect();
245245
typ.set_fields(None, &fields);
246246
if packed {
@@ -265,7 +265,7 @@ pub fn struct_fields<'gcc, 'tcx>(
265265
let mut prev_effective_align = layout.align.abi;
266266
let mut result: Vec<_> = Vec::with_capacity(1 + field_count * 2);
267267
for i in layout.fields.index_by_increasing_offset() {
268-
let target_offset = layout.fields.offset(i as usize);
268+
let target_offset = layout.fields.offset(i);
269269
let field = layout.field(cx, i);
270270
let effective_field_align =
271271
layout.align.abi.min(field.align.abi).restrict_for_offset(target_offset);

tests/lang_tests_common.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ pub fn main_inner(profile: Profile) {
7676
exe.push(&tempdir);
7777
exe.push(path.file_stem().expect("file_stem"));
7878
let mut compiler = Command::new("rustc");
79-
compiler.args(&[
79+
compiler.args([
8080
&format!("-Zcodegen-backend={}/target/debug/librustc_codegen_gcc.so", current_dir),
8181
"--sysroot",
8282
&format!("{}/build_sysroot/sysroot/", current_dir),
@@ -91,7 +91,7 @@ pub fn main_inner(profile: Profile) {
9191
// TODO(antoyo): find a way to send this via a cli argument.
9292
let test_target = std::env::var("CG_GCC_TEST_TARGET");
9393
if let Ok(ref target) = test_target {
94-
compiler.args(&["--target", &target]);
94+
compiler.args(["--target", target]);
9595
let linker = format!("{}-gcc", target);
9696
compiler.args(&[format!("-Clinker={}", linker)]);
9797
let mut env_path = std::env::var("PATH").unwrap_or_default();
@@ -102,32 +102,32 @@ pub fn main_inner(profile: Profile) {
102102

103103
if let Some(flags) = option_env!("TEST_FLAGS") {
104104
for flag in flags.split_whitespace() {
105-
compiler.arg(&flag);
105+
compiler.arg(flag);
106106
}
107107
}
108108
match profile {
109109
Profile::Debug => {}
110110
Profile::Release => {
111-
compiler.args(&["-C", "opt-level=3", "-C", "lto=no"]);
111+
compiler.args(["-C", "opt-level=3", "-C", "lto=no"]);
112112
}
113113
}
114114
// Test command 2: run `tempdir/x`.
115115
if test_target.is_ok() {
116116
let vm_parent_dir = std::env::var("CG_GCC_VM_DIR")
117-
.map(|dir| PathBuf::from(dir))
117+
.map(PathBuf::from)
118118
.unwrap_or_else(|_| std::env::current_dir().unwrap());
119119
let vm_dir = "vm";
120120
let exe_filename = exe.file_name().unwrap();
121121
let vm_home_dir = vm_parent_dir.join(vm_dir).join("home");
122122
let vm_exe_path = vm_home_dir.join(exe_filename);
123123
// FIXME(antoyo): panicking here makes the test pass.
124-
let inside_vm_exe_path = PathBuf::from("/home").join(&exe_filename);
124+
let inside_vm_exe_path = PathBuf::from("/home").join(exe_filename);
125125
let mut copy = Command::new("sudo");
126126
copy.arg("cp");
127-
copy.args(&[&exe, &vm_exe_path]);
127+
copy.args([&exe, &vm_exe_path]);
128128

129129
let mut runtime = Command::new("sudo");
130-
runtime.args(&["chroot", vm_dir, "qemu-m68k-static"]);
130+
runtime.args(["chroot", vm_dir, "qemu-m68k-static"]);
131131
runtime.arg(inside_vm_exe_path);
132132
runtime.current_dir(vm_parent_dir);
133133
vec![("Compiler", compiler), ("Copy", copy), ("Run-time", runtime)]

0 commit comments

Comments
 (0)