Skip to content

Commit 0a2d9e8

Browse files
committed
Fix remaining clippy warnings in rustc_codegen_nvvm
- Fix uninlined format args warnings - Fix let-and-return warnings - Fix remaining collapsible-if warnings
1 parent 057c70a commit 0a2d9e8

File tree

7 files changed

+43
-48
lines changed

7 files changed

+43
-48
lines changed

crates/rustc_codegen_nvvm/src/debug_info/metadata.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
800800

801801
// leave the clang LLVM in there just in case, although it shouldnt be needed because
802802
// gpu stuff is different
803-
let producer = format!("clang LLVM ({})", rustc_producer);
803+
let producer = format!("clang LLVM ({rustc_producer})");
804804

805805
let name_in_debuginfo = name_in_debuginfo.to_string_lossy();
806806
let work_dir = tcx
@@ -845,7 +845,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
845845
0,
846846
);
847847

848-
let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
848+
llvm::LLVMRustDIBuilderCreateCompileUnit(
849849
debug_context.builder,
850850
dwarf_const::DW_LANG_Rust,
851851
compile_unit_file,
@@ -862,9 +862,7 @@ pub(crate) fn build_compile_unit_di_node<'ll, 'tcx>(
862862
kind,
863863
0,
864864
tcx.sess.opts.unstable_opts.split_dwarf_inlining,
865-
);
866-
867-
unit_metadata
865+
)
868866
}
869867
}
870868

@@ -1200,31 +1198,31 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
12001198
cx: &CodegenCx<'ll, 'tcx>,
12011199
ty: Ty<'tcx>,
12021200
) -> SmallVec<&'ll DIType> {
1203-
if let ty::Adt(def, args) = *ty.kind() {
1204-
if args.types().next().is_some() {
1205-
let generics = cx.tcx.generics_of(def.did());
1206-
let names = get_parameter_names(cx, generics);
1207-
let template_params: SmallVec<_> = iter::zip(args, names)
1208-
.filter_map(|(kind, name)| {
1209-
kind.as_type().map(|ty| {
1210-
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1211-
let actual_type_di_node = type_di_node(cx, actual_type);
1212-
let name = name.as_str();
1213-
unsafe {
1214-
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
1215-
DIB(cx),
1216-
None,
1217-
name.as_c_char_ptr(),
1218-
name.len(),
1219-
actual_type_di_node,
1220-
)
1221-
}
1222-
})
1201+
if let ty::Adt(def, args) = *ty.kind()
1202+
&& args.types().next().is_some()
1203+
{
1204+
let generics = cx.tcx.generics_of(def.did());
1205+
let names = get_parameter_names(cx, generics);
1206+
let template_params: SmallVec<_> = iter::zip(args, names)
1207+
.filter_map(|(kind, name)| {
1208+
kind.as_type().map(|ty| {
1209+
let actual_type = cx.tcx.normalize_erasing_regions(cx.typing_env(), ty);
1210+
let actual_type_di_node = type_di_node(cx, actual_type);
1211+
let name = name.as_str();
1212+
unsafe {
1213+
llvm::LLVMRustDIBuilderCreateTemplateTypeParameter(
1214+
DIB(cx),
1215+
None,
1216+
name.as_c_char_ptr(),
1217+
name.len(),
1218+
actual_type_di_node,
1219+
)
1220+
}
12231221
})
1224-
.collect();
1222+
})
1223+
.collect();
12251224

1226-
return template_params;
1227-
}
1225+
return template_params;
12281226
}
12291227

12301228
return smallvec![];

crates/rustc_codegen_nvvm/src/intrinsic.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -409,30 +409,30 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
409409
match name {
410410
sym::ctlz | sym::cttz => {
411411
let y = self.const_bool(false);
412-
let llvm_name = format!("llvm.{}.i{}", name, width);
412+
let llvm_name = format!("llvm.{name}.i{width}");
413413
self.call_intrinsic(&llvm_name, &[args[0].immediate(), y])
414414
}
415415
sym::ctlz_nonzero | sym::cttz_nonzero => {
416416
let y = self.const_bool(true);
417-
let llvm_name = format!("llvm.{}.i{}", &name_str[..4], width);
417+
let llvm_name = format!("llvm.{}.i{width}", &name_str[..4]);
418418
self.call_intrinsic(&llvm_name, &[args[0].immediate(), y])
419419
}
420420
sym::ctpop => self.call_intrinsic(
421-
&format!("llvm.ctpop.i{}", width),
421+
&format!("llvm.ctpop.i{width}"),
422422
&[args[0].immediate()],
423423
),
424424
sym::bswap => {
425425
if width == 8 {
426426
args[0].immediate() // byte swap a u8/i8 is just a no-op
427427
} else {
428428
self.call_intrinsic(
429-
&format!("llvm.bswap.i{}", width),
429+
&format!("llvm.bswap.i{width}"),
430430
&[args[0].immediate()],
431431
)
432432
}
433433
}
434434
sym::bitreverse => self.call_intrinsic(
435-
&format!("llvm.bitreverse.i{}", width),
435+
&format!("llvm.bitreverse.i{width}"),
436436
&[args[0].immediate()],
437437
),
438438
sym::rotate_left | sym::rotate_right => {

crates/rustc_codegen_nvvm/src/link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ fn read_metadata(rlib: &Path) -> Result<OwnedSlice, String> {
7777

7878
match read_meta() {
7979
Ok(Some(m)) => Ok(m),
80-
Ok(None) => Err(format!("No .metadata file in rlib: {:?}", rlib)),
81-
Err(io) => Err(format!("Failed to read rlib at {:?}: {}", rlib, io)),
80+
Ok(None) => Err(format!("No .metadata file in rlib: {rlib:?}")),
81+
Err(io) => Err(format!("Failed to read rlib at {rlib:?}: {io}")),
8282
}
8383
}
8484

@@ -153,7 +153,7 @@ pub fn link(
153153
codegen_results,
154154
);
155155
}
156-
other => sess.dcx().fatal(format!("Invalid crate type: {:?}", other)),
156+
other => sess.dcx().fatal(format!("Invalid crate type: {other:?}")),
157157
}
158158
}
159159
}
@@ -311,7 +311,7 @@ fn codegen_into_ptx_file(
311311
fn create_archive(sess: &Session, files: &[&Path], metadata: &[u8], out_filename: &Path) {
312312
if let Err(err) = try_create_archive(files, metadata, out_filename) {
313313
sess.dcx()
314-
.fatal(format!("Failed to create archive: {}", err));
314+
.fatal(format!("Failed to create archive: {err}"));
315315
}
316316
}
317317

crates/rustc_codegen_nvvm/src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'_, 'tcx> {
4040
.unwrap_or_else(|| {
4141
self.sess().dcx().span_fatal(
4242
self.tcx.def_span(def_id),
43-
format!("symbol `{}` is already defined", symbol_name),
43+
format!("symbol `{symbol_name}` is already defined"),
4444
)
4545
});
4646

crates/rustc_codegen_nvvm/src/nvvm.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ pub fn codegen_bitcode_modules(
118118
let log = prog.compiler_log().unwrap().unwrap_or_default();
119119
let footer = "If you plan to submit a bug report please re-run the codegen with `RUSTFLAGS=\"--emit=llvm-ir\" and include the .ll file corresponding to the .o file mentioned in the log";
120120
panic!(
121-
"Malformed NVVM IR program rejected by libnvvm, dumping verifier log:\n\n{}\n\n{}",
122-
log, footer
121+
"Malformed NVVM IR program rejected by libnvvm, dumping verifier log:\n\n{log}\n\n{footer}"
123122
);
124123
}
125124

@@ -128,8 +127,7 @@ pub fn codegen_bitcode_modules(
128127
Err(error) => {
129128
// this should never happen, if it does, something went really bad or its a bug on libnvvm's end
130129
panic!(
131-
"libnvvm returned an error that was not previously caught by the verifier: {:?}",
132-
error
130+
"libnvvm returned an error that was not previously caught by the verifier: {error:?}"
133131
);
134132
}
135133
};

crates/rustc_codegen_nvvm/src/override_fns.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn should_override<'tcx>(func: Instance<'tcx>, cx: &CodegenCx<'_, 'tcx>) -> bool
5050
return false;
5151
}
5252

53-
let libdevice_name = format!("__nv_{}", name);
53+
let libdevice_name = format!("__nv_{name}");
5454
let ld_fn = if let Some((args, ret)) = cx.intrinsics_map.borrow().get(libdevice_name.as_str()) {
5555
cx.type_func(args, ret)
5656
} else {

crates/rustc_codegen_nvvm/src/ty.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,7 @@ impl<'ll, 'tcx> BaseTypeCodegenMethods for CodegenCx<'ll, 'tcx> {
219219
}
220220

221221
fn element_type(&self, ty: &'ll Type) -> &'ll Type {
222-
let out = unsafe { llvm::LLVMGetElementType(ty) };
223-
out
222+
unsafe { llvm::LLVMGetElementType(ty) }
224223
}
225224

226225
fn vector_length(&self, ty: &'ll Type) -> usize {
@@ -542,10 +541,10 @@ fn uncached_llvm_type<'a, 'tcx>(
542541
let mut name = with_no_trimmed_paths!(layout.ty.to_string());
543542
if let (&ty::Adt(def, _), &Variants::Single { index }) =
544543
(layout.ty.kind(), &layout.variants)
544+
&& def.is_enum()
545+
&& !def.variants().is_empty()
545546
{
546-
if def.is_enum() && !def.variants().is_empty() {
547-
write!(&mut name, "::{}", def.variant(index).name).unwrap();
548-
}
547+
write!(&mut name, "::{}", def.variant(index).name).unwrap();
549548
}
550549
if let (&ty::Coroutine(_, _), &Variants::Single { index }) =
551550
(layout.ty.kind(), &layout.variants)

0 commit comments

Comments
 (0)