Skip to content

Commit 057c70a

Browse files
committed
Fix clippy warnings in rustc_codegen_nvvm (part 1)
- Fix collapsible-if warnings using && syntax - Fix uninlined format args warnings - Fix unnecessary-mut-passed warning
1 parent 643f618 commit 057c70a

File tree

5 files changed

+43
-48
lines changed

5 files changed

+43
-48
lines changed

crates/rustc_codegen_nvvm/src/abi.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ pub(crate) fn readjust_fn_abi<'tcx>(
4343
arg.mode = PassMode::Ignore;
4444
}
4545

46-
if let TyKind::Ref(_, ty, _) = arg.layout.ty.kind() {
47-
if matches!(ty.kind(), TyKind::Slice(_)) {
48-
let mut ptr_attrs = ArgAttributes::new();
49-
if let PassMode::Indirect { attrs, .. } = arg.mode {
50-
ptr_attrs.regular = attrs.regular;
51-
}
52-
arg.mode = PassMode::Pair(ptr_attrs, ArgAttributes::new());
46+
if let TyKind::Ref(_, ty, _) = arg.layout.ty.kind()
47+
&& matches!(ty.kind(), TyKind::Slice(_))
48+
{
49+
let mut ptr_attrs = ArgAttributes::new();
50+
if let PassMode::Indirect { attrs, .. } = arg.mode {
51+
ptr_attrs.regular = attrs.regular;
5352
}
53+
arg.mode = PassMode::Pair(ptr_attrs, ArgAttributes::new());
5454
}
5555

5656
if arg.layout.ty.is_array() && !matches!(arg.mode, PassMode::Direct { .. }) {
@@ -491,11 +491,12 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
491491
// If the value is a boolean, the range is 0..2 and that ultimately
492492
// become 0..0 when the type becomes i1, which would be rejected
493493
// by the LLVM verifier.
494-
if let Primitive::Int(..) = scalar.primitive() {
495-
if !scalar.is_bool() && !scalar.is_always_valid(bx) {
496-
trace!("apply_attrs_callsite -> range_metadata");
497-
bx.range_metadata(callsite, scalar.valid_range(bx));
498-
}
494+
if let Primitive::Int(..) = scalar.primitive()
495+
&& !scalar.is_bool()
496+
&& !scalar.is_always_valid(bx)
497+
{
498+
trace!("apply_attrs_callsite -> range_metadata");
499+
bx.range_metadata(callsite, scalar.valid_range(bx));
499500
}
500501
}
501502
for arg in self.args.iter() {
@@ -549,11 +550,11 @@ impl<'tcx> AbiBuilderMethods for Builder<'_, '_, 'tcx> {
549550
// destructure so rustc doesnt complain in the call to transmute_llval
550551
let Self { cx, llbuilder } = self;
551552
let map = cx.remapped_integer_args.borrow();
552-
if let Some((_, key)) = map.get(&llfnty) {
553-
if let Some((_, new_ty)) = key.iter().find(|t| t.0 == index) {
554-
trace!("Casting irregular param {:?} to {:?}", val, new_ty);
555-
return transmute_llval(llbuilder, cx, val, new_ty);
556-
}
553+
if let Some((_, key)) = map.get(&llfnty)
554+
&& let Some((_, new_ty)) = key.iter().find(|t| t.0 == index)
555+
{
556+
trace!("Casting irregular param {:?} to {:?}", val, new_ty);
557+
return transmute_llval(llbuilder, cx, val, new_ty);
557558
}
558559
val
559560
};

crates/rustc_codegen_nvvm/src/back.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::{LlvmMod, NvvmCodegenBackend, builder::Builder, context::CodegenCx, l
2929

3030
pub fn llvm_err(handle: DiagCtxtHandle, msg: &str) -> FatalError {
3131
match llvm::last_error() {
32-
Some(err) => handle.fatal(format!("{}: {}", msg, err)),
32+
Some(err) => handle.fatal(format!("{msg}: {err}")),
3333
None => handle.fatal(msg.to_string()),
3434
}
3535
}
@@ -121,7 +121,7 @@ pub fn target_machine_factory(
121121
false,
122122
)
123123
};
124-
tm.ok_or_else(|| format!("Could not create LLVM TargetMachine for triple: {}", triple))
124+
tm.ok_or_else(|| format!("Could not create LLVM TargetMachine for triple: {triple}"))
125125
})
126126
}
127127

@@ -146,7 +146,7 @@ pub extern "C" fn demangle_callback(
146146
Err(_) => return 0,
147147
};
148148

149-
if write!(cursor, "{:#}", demangled).is_err() {
149+
if write!(cursor, "{demangled:#}").is_err() {
150150
// Possible only if provided buffer is not big enough
151151
return 0;
152152
}
@@ -199,7 +199,7 @@ pub(crate) unsafe fn codegen(
199199
};
200200

201201
result.into_result().map_err(|()| {
202-
let msg = format!("failed to write NVVM IR to {}", out);
202+
let msg = format!("failed to write NVVM IR to {out}");
203203
llvm_err(dcx, &msg)
204204
})?;
205205
}
@@ -288,7 +288,7 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol) -> (ModuleCodegen
288288
// a main function for gpu kernels really makes no sense but
289289
// codegen it anyways.
290290
// sanitize attrs are not allowed in nvvm so do nothing further.
291-
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&mut cx, cgu);
291+
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cgu);
292292

293293
// Run replace-all-uses-with for statics that need it
294294
for &(old_g, new_g) in cx.statics_to_rauw.borrow().iter() {
@@ -390,7 +390,7 @@ pub(crate) unsafe fn optimize(
390390

391391
for pass in &config.passes {
392392
if !addpass(pass) {
393-
diag_handler.warn(format!("unknown pass `{}`, ignoring", pass));
393+
diag_handler.warn(format!("unknown pass `{pass}`, ignoring"));
394394
}
395395
}
396396

crates/rustc_codegen_nvvm/src/builder.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,10 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
522522
bx.nonnull_metadata(load);
523523
}
524524

525-
if let Some(pointee) = layout.pointee_info_at(bx, offset) {
526-
if pointee.safe.is_some() {
527-
bx.align_metadata(load, pointee.align);
528-
}
525+
if let Some(pointee) = layout.pointee_info_at(bx, offset)
526+
&& pointee.safe.is_some()
527+
{
528+
bx.align_metadata(load, pointee.align);
529529
}
530530
}
531531
abi::Primitive::Float(_) => {}
@@ -539,14 +539,12 @@ impl<'ll, 'tcx, 'a> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
539539
let mut const_llval = None;
540540
let llty = place.layout.llvm_type(self);
541541
unsafe {
542-
if let Some(global) = llvm::LLVMIsAGlobalVariable(place.val.llval) {
543-
if llvm::LLVMIsGlobalConstant(global) == llvm::True {
544-
if let Some(init) = llvm::LLVMGetInitializer(global) {
545-
if self.val_ty(init) == llty {
546-
const_llval = Some(init);
547-
}
548-
}
549-
}
542+
if let Some(global) = llvm::LLVMIsAGlobalVariable(place.val.llval)
543+
&& llvm::LLVMIsGlobalConstant(global) == llvm::True
544+
&& let Some(init) = llvm::LLVMGetInitializer(global)
545+
&& self.val_ty(init) == llty
546+
{
547+
const_llval = Some(init);
550548
}
551549
}
552550

@@ -1212,9 +1210,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
12121210
) -> Cow<'b, [&'ll Value]> {
12131211
assert!(
12141212
self.cx.type_kind(fn_ty) == TypeKind::Function,
1215-
"builder::{} not passed a function, but {:?}",
1216-
typ,
1217-
fn_ty
1213+
"builder::{typ} not passed a function, but {fn_ty:?}"
12181214
);
12191215

12201216
let param_tys = self.cx.func_params_types(fn_ty);

crates/rustc_codegen_nvvm/src/consts.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
186186
_ => cx
187187
.sess()
188188
.dcx()
189-
.fatal(format!("Unsupported linkage kind: {:?}", linkage)),
189+
.fatal(format!("Unsupported linkage kind: {linkage:?}")),
190190
}
191191

192192
// If this is a static with a linkage specified, then we need to handle
@@ -276,8 +276,7 @@ impl<'ll> CodegenCx<'ll, '_> {
276276
assert!(
277277
!defined_in_current_codegen_unit,
278278
"consts::get_static() should always hit the cache for \
279-
statics defined in the same CGU, but did not for `{:?}`",
280-
def_id
279+
statics defined in the same CGU, but did not for `{def_id:?}`"
281280
);
282281

283282
let ty = instance.ty(self.tcx, self.typing_env());
@@ -286,10 +285,10 @@ impl<'ll> CodegenCx<'ll, '_> {
286285

287286
let g = if def_id.is_local() && !self.tcx.is_foreign_item(def_id) {
288287
let llty = self.layout_of(ty).llvm_type(self);
289-
if let Some(g) = self.get_declared_value(sym) {
290-
if self.val_ty(g) != self.type_ptr_to(llty) {
291-
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
292-
}
288+
if let Some(g) = self.get_declared_value(sym)
289+
&& self.val_ty(g) != self.type_ptr_to(llty)
290+
{
291+
span_bug!(self.tcx.def_span(def_id), "Conflicting types for static");
293292
}
294293

295294
let addrspace = self.static_addrspace(instance);

crates/rustc_codegen_nvvm/src/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
184184

185185
// im lazy i know
186186
pub(crate) fn unsupported(&self, thing: &str) -> ! {
187-
self.fatal(format!("{} is unsupported", thing))
187+
self.fatal(format!("{thing} is unsupported"))
188188
}
189189

190190
pub(crate) fn create_used_variable_impl(&self, name: &'static CStr, values: &[&'ll Value]) {
@@ -282,8 +282,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
282282
let layout = self.layout_of(ty);
283283
if layout.size.bytes() > CONSTANT_MEMORY_SIZE_LIMIT_BYTES {
284284
self.tcx.sess.dcx().warn(format!(
285-
"static `{}` exceeds the constant memory limit; placing in global memory (performance may be reduced)",
286-
instance
285+
"static `{instance}` exceeds the constant memory limit; placing in global memory (performance may be reduced)"
287286
));
288287
// Place instance in global memory if it is too big for constant memory.
289288
AddressSpace(1)

0 commit comments

Comments
 (0)