From 33c2f80835bf51a38152639b8567011c8de0cd20 Mon Sep 17 00:00:00 2001 From: Sylvester Hesp Date: Thu, 5 Jan 2023 12:56:00 +0100 Subject: [PATCH] Clippy fixes --- .../src/compile_result.rs | 2 +- crates/rustc_codegen_spirv/build.rs | 2 +- crates/rustc_codegen_spirv/src/abi.rs | 7 +- crates/rustc_codegen_spirv/src/attr.rs | 12 +- .../src/builder/builder_methods.rs | 84 +++++-------- .../src/builder/intrinsics.rs | 10 +- crates/rustc_codegen_spirv/src/builder/mod.rs | 3 +- .../src/builder/spirv_asm.rs | 119 ++++++++---------- .../rustc_codegen_spirv/src/builder_spirv.rs | 3 +- .../src/codegen_cx/constant.rs | 8 +- .../src/codegen_cx/declare.rs | 9 +- .../src/codegen_cx/entry.rs | 12 +- .../rustc_codegen_spirv/src/codegen_cx/mod.rs | 2 +- .../src/codegen_cx/type_.rs | 11 +- crates/rustc_codegen_spirv/src/link.rs | 28 ++--- .../src/linker/import_export_link.rs | 10 +- .../rustc_codegen_spirv/src/linker/inline.rs | 3 +- crates/rustc_codegen_spirv/src/linker/mod.rs | 2 +- .../src/linker/specializer.rs | 46 +++---- crates/rustc_codegen_spirv/src/spirv_type.rs | 20 +-- .../rustc_codegen_spirv/src/target_feature.rs | 2 +- crates/spirv-builder/src/depfile.rs | 2 +- crates/spirv-builder/src/lib.rs | 8 +- crates/spirv-builder/src/watch.rs | 4 +- crates/spirv-std/macros/src/lib.rs | 16 +-- examples/multibuilder/src/main.rs | 2 +- examples/runners/ash/build.rs | 2 +- examples/runners/wgpu/build.rs | 2 +- examples/runners/wgpu/src/compute.rs | 4 +- examples/runners/wgpu/src/graphics.rs | 2 +- examples/shaders/compute-shader/src/main.rs | 6 +- tests/src/main.rs | 6 +- 32 files changed, 197 insertions(+), 252 deletions(-) diff --git a/crates/rustc_codegen_spirv-types/src/compile_result.rs b/crates/rustc_codegen_spirv-types/src/compile_result.rs index ba56cdaec0..7a19591532 100644 --- a/crates/rustc_codegen_spirv-types/src/compile_result.rs +++ b/crates/rustc_codegen_spirv-types/src/compile_result.rs @@ -74,7 +74,7 @@ impl<'a> Trie<'a> { let full_child_name = if full_name.is_empty() { (*child_name).to_string() } else { - format!("{}::{}", full_name, child_name) + format!("{full_name}::{child_name}") }; if child.present { assert!(child.children.is_empty()); diff --git a/crates/rustc_codegen_spirv/build.rs b/crates/rustc_codegen_spirv/build.rs index ecd32240df..d0f126b65b 100644 --- a/crates/rustc_codegen_spirv/build.rs +++ b/crates/rustc_codegen_spirv/build.rs @@ -78,7 +78,7 @@ fn main() -> ExitCode { match check_toolchain_version() { Ok(_) => ExitCode::SUCCESS, Err(e) => { - eprint!("{}", e); + eprint!("{e}"); ExitCode::FAILURE } } diff --git a/crates/rustc_codegen_spirv/src/abi.rs b/crates/rustc_codegen_spirv/src/abi.rs index 6b6bb8c898..f612b21c3b 100644 --- a/crates/rustc_codegen_spirv/src/abi.rs +++ b/crates/rustc_codegen_spirv/src/abi.rs @@ -270,7 +270,7 @@ impl fmt::Display for PointeeTy<'_> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { PointeeTy::Ty(ty) => write!(f, "{}", ty.ty), - PointeeTy::Fn(ty) => write!(f, "{}", ty), + PointeeTy::Fn(ty) => write!(f, "{ty}"), } } } @@ -577,8 +577,7 @@ fn dig_scalar_pointee<'tcx>( Some(old_pointee) if old_pointee != new_pointee => { cx.tcx.sess.fatal(format!( "dig_scalar_pointee: unsupported Pointer with different \ - pointee types ({:?} vs {:?}) at offset {:?} in {:#?}", - old_pointee, new_pointee, offset, layout + pointee types ({old_pointee:?} vs {new_pointee:?}) at offset {offset:?} in {layout:#?}" )); } _ => pointee = Some(new_pointee), @@ -860,7 +859,7 @@ fn trans_intrinsic_type<'tcx>( None => Err(cx .tcx .sess - .err(format!("Invalid value for Image const generic: {}", value))), + .err(format!("Invalid value for Image const generic: {value}"))), } } diff --git a/crates/rustc_codegen_spirv/src/attr.rs b/crates/rustc_codegen_spirv/src/attr.rs index 8191a2a084..6c72f5dab4 100644 --- a/crates/rustc_codegen_spirv/src/attr.rs +++ b/crates/rustc_codegen_spirv/src/attr.rs @@ -158,7 +158,7 @@ impl AggregatedSpirvAttributes { }) => { cx.tcx .sess - .delay_span_bug(span, format!("multiple {} attributes", category)); + .delay_span_bug(span, format!("multiple {category} attributes")); } } } @@ -333,7 +333,7 @@ impl CheckSpirvAttrVisitor<'_> { if let Err(msg) = valid { self.tcx.sess.span_err( span, - format!("`{:?}` storage class {}", storage_class, msg), + format!("`{storage_class:?}` storage class {msg}"), ); } } @@ -355,8 +355,7 @@ impl CheckSpirvAttrVisitor<'_> { self.tcx.sess.span_err( span, format!( - "attribute is only valid on a {}, not on a {}", - expected_target, target + "attribute is only valid on a {expected_target}, not on a {target}" ), ); } @@ -371,11 +370,10 @@ impl CheckSpirvAttrVisitor<'_> { .struct_span_err( span, &format!( - "only one {} attribute is allowed on a {}", - category, target + "only one {category} attribute is allowed on a {target}" ), ) - .span_note(prev_span, &format!("previous {} attribute", category)) + .span_note(prev_span, &format!("previous {category} attribute")) .emit(); } }, diff --git a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs index 663d90ec18..be6f13d694 100644 --- a/crates/rustc_codegen_spirv/src/builder/builder_methods.rs +++ b/crates/rustc_codegen_spirv/src/builder/builder_methods.rs @@ -193,8 +193,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .constant_u64(self.span(), memset_fill_u64(fill_byte)) .def(self), _ => self.fatal(&format!( - "memset on integer width {} not implemented yet", - width + "memset on integer width {width} not implemented yet" )), }, SpirvType::Float(width) => match width { @@ -205,8 +204,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .constant_f64(self.span(), f64::from_bits(memset_fill_u64(fill_byte))) .def(self), _ => self.fatal(&format!( - "memset on float width {} not implemented yet", - width + "memset on float width {width} not implemented yet" )), }, SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"), @@ -253,16 +251,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { 32 => memset_dynamic_scalar(self, fill_var, 4, false), 64 => memset_dynamic_scalar(self, fill_var, 8, false), _ => self.fatal(&format!( - "memset on integer width {} not implemented yet", - width + "memset on integer width {width} not implemented yet" )), }, SpirvType::Float(width) => match width { 32 => memset_dynamic_scalar(self, fill_var, 4, true), 64 => memset_dynamic_scalar(self, fill_var, 8, true), _ => self.fatal(&format!( - "memset on float width {} not implemented yet", - width + "memset on float width {width} not implemented yet" )), }, SpirvType::Adt { .. } => self.fatal("memset on structs not implemented yet"), @@ -367,7 +363,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if !self.builder.has_capability(Capability::VariablePointers) { self.zombie( def, - &format!("{} without OpCapability VariablePointers", inst), + &format!("{inst} without OpCapability VariablePointers"), ); } } @@ -725,8 +721,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { fn construct_8(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand { if v > u8::MAX as u128 { self_.fatal(&format!( - "Switches to values above u8::MAX not supported: {:?}", - v + "Switches to values above u8::MAX not supported: {v:?}" )) } else if signed { // this cast chain can probably be collapsed, but, whatever, be safe @@ -738,8 +733,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { fn construct_16(self_: &Builder<'_, '_>, signed: bool, v: u128) -> Operand { if v > u16::MAX as u128 { self_.fatal(&format!( - "Switches to values above u16::MAX not supported: {:?}", - v + "Switches to values above u16::MAX not supported: {v:?}" )) } else if signed { Operand::LiteralInt32(v as u16 as i16 as i32 as u32) @@ -750,8 +744,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { fn construct_32(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand { if v > u32::MAX as u128 { self_.fatal(&format!( - "Switches to values above u32::MAX not supported: {:?}", - v + "Switches to values above u32::MAX not supported: {v:?}" )) } else { Operand::LiteralInt32(v as u32) @@ -760,8 +753,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { fn construct_64(self_: &Builder<'_, '_>, _signed: bool, v: u128) -> Operand { if v > u64::MAX as u128 { self_.fatal(&format!( - "Switches to values above u64::MAX not supported: {:?}", - v + "Switches to values above u64::MAX not supported: {v:?}" )) } else { Operand::LiteralInt64(v as u64) @@ -776,8 +768,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { 32 => construct_32, 64 => construct_64, other => self.fatal(&format!( - "switch selector cannot have width {} (only 8, 16, 32, and 64 bits allowed)", - other + "switch selector cannot have width {other} (only 8, 16, 32, and 64 bits allowed)" )), }; (signed, construct_case) @@ -1025,8 +1016,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { pointee } ty => self.fatal(&format!( - "load called on variable that wasn't a pointer: {:?}", - ty + "load called on variable that wasn't a pointer: {ty:?}" )), }; self.emit() @@ -1055,8 +1045,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { pointee } ty => self.fatal(&format!( - "atomic_load called on variable that wasn't a pointer: {:?}", - ty + "atomic_load called on variable that wasn't a pointer: {ty:?}" )), }; // TODO: Default to device scope @@ -1135,7 +1124,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let start = dest.project_index(self, zero).llval; let elem_layout = dest.layout.field(self.cx(), 0); - let elem_ty = elem_layout.spirv_type(self.span(), &self); + let elem_ty = elem_layout.spirv_type(self.span(), self); let align = dest.align.restrict_for_offset(elem_layout.size); for i in 0..count { @@ -1159,8 +1148,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let ptr_elem_ty = match self.lookup_type(ptr.ty) { SpirvType::Pointer { pointee } => pointee, ty => self.fatal(&format!( - "store called on variable that wasn't a pointer: {:?}", - ty + "store called on variable that wasn't a pointer: {ty:?}" )), }; @@ -1192,8 +1180,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { ) -> Self::Value { if flags != MemFlags::empty() { self.err(&format!( - "store_with_flags is not supported yet: {:?}", - flags + "store_with_flags is not supported yet: {flags:?}" )); } self.store(val, ptr, align) @@ -1209,8 +1196,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let ptr_elem_ty = match self.lookup_type(ptr.ty) { SpirvType::Pointer { pointee } => pointee, ty => self.fatal(&format!( - "atomic_store called on variable that wasn't a pointer: {:?}", - ty + "atomic_store called on variable that wasn't a pointer: {ty:?}" )), }; assert_ty_eq!(self, ptr_elem_ty, val.ty); @@ -1248,8 +1234,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { pointee } other => self.fatal(&format!( - "struct_gep not on pointer type: {:?}, index {}", - other, idx + "struct_gep not on pointer type: {other:?}, index {idx}" )), }; let pointee_kind = self.lookup_type(pointee); @@ -1264,8 +1249,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { inner_type } other => self.fatal(&format!( - "struct_gep not on struct, array, or vector type: {:?}, index {}", - other, idx + "struct_gep not on struct, array, or vector type: {other:?}, index {idx}" )), }; let result_type = SpirvType::Pointer { @@ -1410,8 +1394,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { match self.lookup_type(val.ty) { SpirvType::Pointer { .. } => (), other => self.fatal(&format!( - "ptrtoint called on non-pointer source type: {:?}", - other + "ptrtoint called on non-pointer source type: {other:?}" )), } if val.ty == dest_ty { @@ -1431,8 +1414,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { match self.lookup_type(dest_ty) { SpirvType::Pointer { .. } => (), other => self.fatal(&format!( - "inttoptr called on non-pointer dest type: {:?}", - other + "inttoptr called on non-pointer dest type: {other:?}" )), } if val.ty == dest_ty { @@ -1540,8 +1522,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { .with_type(dest_ty) } (val_ty, dest_ty_spv) => self.fatal(&format!( - "TODO: intcast not implemented yet: val={:?} val.ty={:?} dest_ty={:?} is_signed={}", - val, val_ty, dest_ty_spv, is_signed + "TODO: intcast not implemented yet: val={val:?} val.ty={val_ty:?} dest_ty={dest_ty_spv:?} is_signed={is_signed}" )), } } @@ -1566,16 +1547,14 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { _ => match self.lookup_type(val.ty) { SpirvType::Pointer { pointee } => (val, pointee), other => self.fatal(&format!( - "pointercast called on non-pointer source type: {:?}", - other + "pointercast called on non-pointer source type: {other:?}" )), }, }; let dest_pointee = match self.lookup_type(dest_ty) { SpirvType::Pointer { pointee } => pointee, other => self.fatal(&format!( - "pointercast called on non-pointer dest type: {:?}", - other + "pointercast called on non-pointer dest type: {other:?}" )), }; if val.ty == dest_ty { @@ -1869,8 +1848,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { ) { if flags != MemFlags::empty() { self.err(&format!( - "memcpy with mem flags is not supported yet: {:?}", - flags + "memcpy with mem flags is not supported yet: {flags:?}" )); } let const_size = self.builder.lookup_const_u64(size); @@ -1928,8 +1906,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { ) { if flags != MemFlags::empty() { self.err(&format!( - "memset with mem flags is not supported yet: {:?}", - flags + "memset with mem flags is not supported yet: {flags:?}" )); } let elem_ty = match self.lookup_type(ptr.ty) { @@ -1979,8 +1956,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let result_type = match self.lookup_type(vec.ty) { SpirvType::Vector { element, .. } => element, other => self.fatal(&format!( - "extract_element not implemented on type {:?}", - other + "extract_element not implemented on type {other:?}" )), }; match self.builder.lookup_const_u64(idx) { @@ -2046,7 +2022,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { SpirvType::Adt { field_types, .. } => { assert_ty_eq!(self, field_types[idx as usize], elt.ty); } - other => self.fatal(&format!("insert_value not implemented on type {:?}", other)), + other => self.fatal(&format!("insert_value not implemented on type {other:?}")), }; self.emit() .composite_insert( @@ -2111,8 +2087,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let dst_pointee_ty = match self.lookup_type(dst.ty) { SpirvType::Pointer { pointee } => pointee, ty => self.fatal(&format!( - "atomic_cmpxchg called on variable that wasn't a pointer: {:?}", - ty + "atomic_cmpxchg called on variable that wasn't a pointer: {ty:?}" )), }; assert_ty_eq!(self, dst_pointee_ty, cmp.ty); @@ -2148,8 +2123,7 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> { let dst_pointee_ty = match self.lookup_type(dst.ty) { SpirvType::Pointer { pointee } => pointee, ty => self.fatal(&format!( - "atomic_rmw called on variable that wasn't a pointer: {:?}", - ty + "atomic_rmw called on variable that wasn't a pointer: {ty:?}" )), }; assert_ty_eq!(self, dst_pointee_ty, src.ty); diff --git a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs index 81f800e458..9e283bc7fe 100644 --- a/crates/rustc_codegen_spirv/src/builder/intrinsics.rs +++ b/crates/rustc_codegen_spirv/src/builder/intrinsics.rs @@ -123,8 +123,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> { } TyKind::Float(_) => self.fadd(args[0].immediate(), args[1].immediate()), other => self.fatal(&format!( - "Unimplemented saturating_add intrinsic type: {:#?}", - other + "Unimplemented saturating_add intrinsic type: {other:#?}" )), }; // TODO: Implement this @@ -139,8 +138,7 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> { } TyKind::Float(_) => self.fsub(args[0].immediate(), args[1].immediate()), other => self.fatal(&format!( - "Unimplemented saturating_sub intrinsic type: {:#?}", - other + "Unimplemented saturating_sub intrinsic type: {other:#?}" )), }; // TODO: Implement this @@ -316,11 +314,11 @@ impl<'a, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'tcx> { let res3 = self.or(res3, res4); self.or(res1, res3) } - other => self.fatal(&format!("bswap not implemented for int width {}", other)), + other => self.fatal(&format!("bswap not implemented for int width {other}")), } } - _ => self.fatal(&format!("TODO: Unknown intrinsic '{}'", name)), + _ => self.fatal(&format!("TODO: Unknown intrinsic '{name}'")), }; if !fn_abi.ret.is_ignore() { diff --git a/crates/rustc_codegen_spirv/src/builder/mod.rs b/crates/rustc_codegen_spirv/src/builder/mod.rs index 92769e9d28..16bc8ef489 100644 --- a/crates/rustc_codegen_spirv/src/builder/mod.rs +++ b/crates/rustc_codegen_spirv/src/builder/mod.rs @@ -137,8 +137,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pointee } other_type => self.fatal(&format!( - "GEP first deref not implemented for type {:?}", - other_type + "GEP first deref not implemented for type {other_type:?}" )), }; for index in indices.iter().cloned().skip(1) { diff --git a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs index fa17ba9703..a8795ab9cd 100644 --- a/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs +++ b/crates/rustc_codegen_spirv/src/builder/spirv_asm.rs @@ -65,8 +65,7 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> { let unsupported_options = options & !SUPPORTED_OPTIONS; if !unsupported_options.is_empty() { self.err(&format!( - "asm flags not supported: {:?}", - unsupported_options + "asm flags not supported: {unsupported_options:?}" )); } // vec of lines, and each line is vec of tokens @@ -105,7 +104,7 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> { if let Some(modifier) = modifier { self.tcx.sess.span_err( span, - format!("asm modifiers are not supported: {}", modifier), + format!("asm modifiers are not supported: {modifier}"), ); } let line = tokens.last_mut().unwrap(); @@ -167,14 +166,13 @@ impl<'a, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'tcx> { (false, AsmBlock::Open) => (), (false, AsmBlock::End(terminator)) => { self.err(&format!( - "trailing terminator {:?} requires `options(noreturn)`", - terminator + "trailing terminator {terminator:?} requires `options(noreturn)`" )); } } for (id, num) in id_map { if !defined_ids.contains(&num) { - self.err(&format!("%{} is used but not defined", id)); + self.err(&format!("%{id} is used but not defined")); } } } @@ -237,7 +235,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { Some('\'') => '\'', Some('"') => '"', Some(escape) => { - self.err(&format!("invalid escape '\\{}'", escape)); + self.err(&format!("invalid escape '\\{escape}'")); return None; } }; @@ -312,12 +310,10 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { if storage_class != StorageClass::Generic { self.struct_err("TypePointer in asm! requires `Generic` storage class") .note(&format!( - "`{:?}` storage class was specified", - storage_class + "`{storage_class:?}` storage class was specified" )) .help(&format!( - "the storage class will be inferred automatically (e.g. to `{:?}`)", - storage_class + "the storage class will be inferred automatically (e.g. to `{storage_class:?}`)" )) .emit(); } @@ -378,8 +374,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { AsmBlock::End(terminator) => { if op != Op::Label { self.err(&format!( - "expected OpLabel after terminator {:?}", - terminator + "expected OpLabel after terminator {terminator:?}" )); } @@ -461,7 +456,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { let inst_class = if let Some(inst) = inst_class { inst } else { - self.err(&format!("unknown spirv instruction {}", inst_name)); + self.err(&format!("unknown spirv instruction {inst_name}")); return; }; let result_id = match out_register { @@ -792,7 +787,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { _ => { self.tcx .sess - .span_err(span, format!("invalid register: {}", reg)); + .span_err(span, format!("invalid register: {reg}")); } } } @@ -809,7 +804,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { Some(OutRegister::Regular({ let num = *id_map.entry(id).or_insert_with(|| self.emit().id()); if !defined_ids.insert(num) { - self.err(&format!("%{} is defined more than once", id)); + self.err(&format!("%{id} is defined more than once")); } num })) @@ -1071,7 +1066,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { (OperandKind::LiteralInteger, Some(word)) => match word.parse() { Ok(v) => inst.operands.push(dr::Operand::LiteralInt32(v)), - Err(e) => self.err(&format!("invalid integer: {}", e)), + Err(e) => self.err(&format!("invalid integer: {e}")), }, (OperandKind::LiteralString, _) => { if let Token::String(value) = token { @@ -1126,7 +1121,7 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { } (OperandKind::LiteralExtInstInteger, Some(word)) => match word.parse() { Ok(v) => inst.operands.push(dr::Operand::LiteralExtInstInteger(v)), - Err(e) => self.err(&format!("invalid integer: {}", e)), + Err(e) => self.err(&format!("invalid integer: {e}")), }, (OperandKind::LiteralSpecConstantOpInteger, Some(word)) => { match self.instruction_table.table.get(word) { @@ -1147,25 +1142,24 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { Some(Token::Word(word)) => match word.parse() { Ok(v) => inst.operands.push(dr::Operand::LiteralInt32(v)), Err(e) => { - self.err(&format!("invalid integer: {}", e)); + self.err(&format!("invalid integer: {e}")); } }, Some(Token::String(_)) => { self.err(&format!( - "expected a literal, not a string for a {:?}", - kind + "expected a literal, not a string for a {kind:?}" )); } Some(Token::Placeholder(_, span)) => { self.tcx.sess.span_err( span, - format!("expected a literal, not a dynamic value for a {:?}", kind), + format!("expected a literal, not a dynamic value for a {kind:?}"), ); } Some(Token::Typeof(_, span, _)) => { self.tcx.sess.span_err( span, - format!("expected a literal, not a type for a {:?}", kind), + format!("expected a literal, not a type for a {kind:?}"), ); } None => { @@ -1191,163 +1185,162 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { (OperandKind::ImageOperands, Some(word)) => { match parse_bitflags_operand(IMAGE_OPERANDS, word) { Some(x) => inst.operands.push(dr::Operand::ImageOperands(x)), - None => self.err(&format!("Unknown ImageOperands {}", word)), + None => self.err(&format!("Unknown ImageOperands {word}")), } } (OperandKind::FPFastMathMode, Some(word)) => { match parse_bitflags_operand(FP_FAST_MATH_MODE, word) { Some(x) => inst.operands.push(dr::Operand::FPFastMathMode(x)), - None => self.err(&format!("Unknown FPFastMathMode {}", word)), + None => self.err(&format!("Unknown FPFastMathMode {word}")), } } (OperandKind::SelectionControl, Some(word)) => { match parse_bitflags_operand(SELECTION_CONTROL, word) { Some(x) => inst.operands.push(dr::Operand::SelectionControl(x)), - None => self.err(&format!("Unknown SelectionControl {}", word)), + None => self.err(&format!("Unknown SelectionControl {word}")), } } (OperandKind::LoopControl, Some(word)) => { match parse_bitflags_operand(LOOP_CONTROL, word) { Some(x) => inst.operands.push(dr::Operand::LoopControl(x)), - None => self.err(&format!("Unknown LoopControl {}", word)), + None => self.err(&format!("Unknown LoopControl {word}")), } } (OperandKind::FunctionControl, Some(word)) => { match parse_bitflags_operand(FUNCTION_CONTROL, word) { Some(x) => inst.operands.push(dr::Operand::FunctionControl(x)), - None => self.err(&format!("Unknown FunctionControl {}", word)), + None => self.err(&format!("Unknown FunctionControl {word}")), } } (OperandKind::MemorySemantics, Some(word)) => { match parse_bitflags_operand(MEMORY_SEMANTICS, word) { Some(x) => inst.operands.push(dr::Operand::MemorySemantics(x)), - None => self.err(&format!("Unknown MemorySemantics {}", word)), + None => self.err(&format!("Unknown MemorySemantics {word}")), } } (OperandKind::MemoryAccess, Some(word)) => { match parse_bitflags_operand(MEMORY_ACCESS, word) { Some(x) => inst.operands.push(dr::Operand::MemoryAccess(x)), - None => self.err(&format!("Unknown MemoryAccess {}", word)), + None => self.err(&format!("Unknown MemoryAccess {word}")), } } (OperandKind::KernelProfilingInfo, Some(word)) => { match parse_bitflags_operand(KERNEL_PROFILING_INFO, word) { Some(x) => inst.operands.push(dr::Operand::KernelProfilingInfo(x)), - None => self.err(&format!("Unknown KernelProfilingInfo {}", word)), + None => self.err(&format!("Unknown KernelProfilingInfo {word}")), } } (OperandKind::RayFlags, Some(word)) => match parse_bitflags_operand(RAY_FLAGS, word) { Some(x) => inst.operands.push(dr::Operand::RayFlags(x)), - None => self.err(&format!("Unknown RayFlags {}", word)), + None => self.err(&format!("Unknown RayFlags {word}")), }, (OperandKind::FragmentShadingRate, Some(word)) => { match parse_bitflags_operand(FRAGMENT_SHADING_RATE, word) { Some(x) => inst.operands.push(dr::Operand::FragmentShadingRate(x)), - None => self.err(&format!("Unknown FragmentShadingRate {}", word)), + None => self.err(&format!("Unknown FragmentShadingRate {word}")), } } (OperandKind::SourceLanguage, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::SourceLanguage(x)), - Err(()) => self.err(&format!("Unknown SourceLanguage {}", word)), + Err(()) => self.err(&format!("Unknown SourceLanguage {word}")), }, (OperandKind::ExecutionModel, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::ExecutionModel(x)), - Err(()) => self.err(&format!("unknown ExecutionModel {}", word)), + Err(()) => self.err(&format!("unknown ExecutionModel {word}")), }, (OperandKind::AddressingModel, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::AddressingModel(x)), - Err(()) => self.err(&format!("unknown AddressingModel {}", word)), + Err(()) => self.err(&format!("unknown AddressingModel {word}")), }, (OperandKind::MemoryModel, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::MemoryModel(x)), - Err(()) => self.err(&format!("unknown MemoryModel {}", word)), + Err(()) => self.err(&format!("unknown MemoryModel {word}")), }, (OperandKind::ExecutionMode, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::ExecutionMode(x)), - Err(()) => self.err(&format!("unknown ExecutionMode {}", word)), + Err(()) => self.err(&format!("unknown ExecutionMode {word}")), }, (OperandKind::StorageClass, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::StorageClass(x)), - Err(()) => self.err(&format!("unknown StorageClass {}", word)), + Err(()) => self.err(&format!("unknown StorageClass {word}")), }, (OperandKind::Dim, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::Dim(x)), - Err(()) => self.err(&format!("unknown Dim {}", word)), + Err(()) => self.err(&format!("unknown Dim {word}")), }, (OperandKind::SamplerAddressingMode, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::SamplerAddressingMode(x)), - Err(()) => self.err(&format!("unknown SamplerAddressingMode {}", word)), + Err(()) => self.err(&format!("unknown SamplerAddressingMode {word}")), }, (OperandKind::SamplerFilterMode, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::SamplerFilterMode(x)), - Err(()) => self.err(&format!("unknown SamplerFilterMode {}", word)), + Err(()) => self.err(&format!("unknown SamplerFilterMode {word}")), }, (OperandKind::ImageFormat, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::ImageFormat(x)), - Err(()) => self.err(&format!("unknown ImageFormat {}", word)), + Err(()) => self.err(&format!("unknown ImageFormat {word}")), }, (OperandKind::ImageChannelOrder, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::ImageChannelOrder(x)), - Err(()) => self.err(&format!("unknown ImageChannelOrder {}", word)), + Err(()) => self.err(&format!("unknown ImageChannelOrder {word}")), }, (OperandKind::ImageChannelDataType, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::ImageChannelDataType(x)), - Err(()) => self.err(&format!("unknown ImageChannelDataType {}", word)), + Err(()) => self.err(&format!("unknown ImageChannelDataType {word}")), }, (OperandKind::FPRoundingMode, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::FPRoundingMode(x)), - Err(()) => self.err(&format!("unknown FPRoundingMode {}", word)), + Err(()) => self.err(&format!("unknown FPRoundingMode {word}")), }, (OperandKind::LinkageType, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::LinkageType(x)), - Err(()) => self.err(&format!("unknown LinkageType {}", word)), + Err(()) => self.err(&format!("unknown LinkageType {word}")), }, (OperandKind::AccessQualifier, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::AccessQualifier(x)), - Err(()) => self.err(&format!("unknown AccessQualifier {}", word)), + Err(()) => self.err(&format!("unknown AccessQualifier {word}")), }, (OperandKind::FunctionParameterAttribute, Some(word)) => match word.parse() { Ok(x) => inst .operands .push(dr::Operand::FunctionParameterAttribute(x)), - Err(()) => self.err(&format!("unknown FunctionParameterAttribute {}", word)), + Err(()) => self.err(&format!("unknown FunctionParameterAttribute {word}")), }, (OperandKind::Decoration, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::Decoration(x)), - Err(()) => self.err(&format!("unknown Decoration {}", word)), + Err(()) => self.err(&format!("unknown Decoration {word}")), }, (OperandKind::BuiltIn, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::BuiltIn(x)), - Err(()) => self.err(&format!("unknown BuiltIn {}", word)), + Err(()) => self.err(&format!("unknown BuiltIn {word}")), }, (OperandKind::Scope, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::Scope(x)), - Err(()) => self.err(&format!("unknown Scope {}", word)), + Err(()) => self.err(&format!("unknown Scope {word}")), }, (OperandKind::GroupOperation, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::GroupOperation(x)), - Err(()) => self.err(&format!("unknown GroupOperation {}", word)), + Err(()) => self.err(&format!("unknown GroupOperation {word}")), }, (OperandKind::KernelEnqueueFlags, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::KernelEnqueueFlags(x)), - Err(()) => self.err(&format!("unknown KernelEnqueueFlags {}", word)), + Err(()) => self.err(&format!("unknown KernelEnqueueFlags {word}")), }, (OperandKind::Capability, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::Capability(x)), - Err(()) => self.err(&format!("unknown Capability {}", word)), + Err(()) => self.err(&format!("unknown Capability {word}")), }, (OperandKind::RayQueryIntersection, Some(word)) => match word.parse() { Ok(x) => inst.operands.push(dr::Operand::RayQueryIntersection(x)), - Err(()) => self.err(&format!("unknown RayQueryIntersection {}", word)), + Err(()) => self.err(&format!("unknown RayQueryIntersection {word}")), }, (OperandKind::RayQueryCommittedIntersectionType, Some(word)) => match word.parse() { Ok(x) => inst .operands .push(dr::Operand::RayQueryCommittedIntersectionType(x)), Err(()) => self.err(&format!( - "unknown RayQueryCommittedIntersectionType {}", - word + "unknown RayQueryCommittedIntersectionType {word}" )), }, (OperandKind::RayQueryCandidateIntersectionType, Some(word)) => match word.parse() { @@ -1355,28 +1348,26 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> { .operands .push(dr::Operand::RayQueryCandidateIntersectionType(x)), Err(()) => self.err(&format!( - "unknown RayQueryCandidateIntersectionType {}", - word + "unknown RayQueryCandidateIntersectionType {word}" )), }, (kind, None) => match token { Token::Word(_) => bug!(), Token::String(_) => { self.err(&format!( - "expected a literal, not a string for a {:?}", - kind + "expected a literal, not a string for a {kind:?}" )); } Token::Placeholder(_, span) => { self.tcx.sess.span_err( span, - format!("expected a literal, not a dynamic value for a {:?}", kind), + format!("expected a literal, not a dynamic value for a {kind:?}"), ); } Token::Typeof(_, span, _) => { self.tcx.sess.span_err( span, - format!("expected a literal, not a type for a {:?}", kind), + format!("expected a literal, not a type for a {kind:?}"), ); } }, diff --git a/crates/rustc_codegen_spirv/src/builder_spirv.rs b/crates/rustc_codegen_spirv/src/builder_spirv.rs index a3d6a44512..da2b6cec13 100644 --- a/crates/rustc_codegen_spirv/src/builder_spirv.rs +++ b/crates/rustc_codegen_spirv/src/builder_spirv.rs @@ -665,8 +665,7 @@ impl<'tcx> BuilderSpirv<'tcx> { assert_eq!( inst.operands.len(), 1, - "global already has initializer defined: {}", - global + "global already has initializer defined: {global}" ); inst.operands.push(Operand::IdRef(initializer)); module.types_global_values.push(inst); diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs index 915447bb4a..34267e7655 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/constant.rs @@ -66,7 +66,7 @@ impl<'tcx> CodegenCx<'tcx> { _ => self .tcx .sess - .fatal(format!("Invalid constant value for bool: {}", val)), + .fatal(format!("Invalid constant value for bool: {val}")), }, SpirvType::Integer(128, _) => { let result = self.undef(ty); @@ -233,7 +233,7 @@ impl<'tcx> ConstMethods<'tcx> for CodegenCx<'tcx> { _ => self .tcx .sess - .fatal(format!("Invalid constant value for bool: {}", data)), + .fatal(format!("Invalid constant value for bool: {data}")), }, other => self.tcx.sess.fatal(format!( "scalar_to_backend Primitive::Int not supported on type {}", @@ -426,7 +426,7 @@ impl<'tcx> CodegenCx<'tcx> { other => { self.tcx .sess - .fatal(format!("invalid size for integer: {}", other)); + .fatal(format!("invalid size for integer: {other}")); } }; Primitive::Int(integer, int_signedness) @@ -437,7 +437,7 @@ impl<'tcx> CodegenCx<'tcx> { other => { self.tcx .sess - .fatal(format!("invalid size for float: {}", other)); + .fatal(format!("invalid size for float: {other}")); } }, SpirvType::Pointer { .. } => Primitive::Pointer, diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs index b3cb866ca4..6d9fe747ec 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/declare.rs @@ -142,8 +142,7 @@ impl<'tcx> CodegenCx<'tcx> { } None => { self.tcx.sess.err(format!( - "missing libm intrinsic {}, which is {}", - symbol_name, instance + "missing libm intrinsic {symbol_name}, which is {instance}" )); } } @@ -215,8 +214,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { Linkage::Internal => None, other => { self.tcx.sess.err(format!( - "TODO: Linkage type {:?} not supported yet for static var symbol {}", - other, symbol_name + "TODO: Linkage type {other:?} not supported yet for static var symbol {symbol_name}" )); None } @@ -245,8 +243,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'tcx> { Linkage::Internal => None, other => { self.tcx.sess.err(format!( - "TODO: Linkage type {:?} not supported yet for function symbol {}", - other, symbol_name + "TODO: Linkage type {other:?} not supported yet for function symbol {symbol_name}" )); None } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs index 4e71932db5..93a720492f 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/entry.rs @@ -38,7 +38,7 @@ impl<'tcx> CodegenCx<'tcx> { } else { self.tcx .sess - .span_err(span, format!("Cannot declare {} as an entry point", name)); + .span_err(span, format!("Cannot declare {name} as an entry point")); return; }; let body = self @@ -253,17 +253,16 @@ impl<'tcx> CodegenCx<'tcx> { .struct_span_err(hir_param.span, "storage class mismatch") .span_label( storage_class_attr.span, - format!("{:?} specified in attribute", storage_class), + format!("{storage_class:?} specified in attribute"), ) .span_label( hir_param.ty_span, - format!("{:?} inferred from type", inferred), + format!("{inferred:?} inferred from type"), ) .span_help( storage_class_attr.span, &format!( - "remove storage class attribute to use {:?} as storage class", - inferred + "remove storage class attribute to use {inferred:?} as storage class" ), ) .emit(); @@ -405,8 +404,7 @@ impl<'tcx> CodegenCx<'tcx> { self.tcx.sess.span_fatal( hir_param.ty_span, format!( - "unsized types are not supported for storage class {:?}", - storage_class + "unsized types are not supported for storage class {storage_class:?}" ), ); } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs index e9cb0859e2..7cddc6ec62 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/mod.rs @@ -281,7 +281,7 @@ impl CodegenArgs { pub fn from_session(sess: &Session) -> Self { match CodegenArgs::parse(&sess.opts.cg.llvm_args) { Ok(ok) => ok, - Err(err) => sess.fatal(format!("Unable to parse llvm-args: {}", err)), + Err(err) => sess.fatal(format!("Unable to parse llvm-args: {err}")), } } diff --git a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs index 342ff3a76c..5f8e9be8fe 100644 --- a/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs +++ b/crates/rustc_codegen_spirv/src/codegen_cx/type_.rs @@ -217,7 +217,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { other => self .tcx .sess - .fatal(format!("Invalid float width in type_kind: {}", other)), + .fatal(format!("Invalid float width in type_kind: {other}")), }, SpirvType::Adt { .. } | SpirvType::InterfaceBlock { .. } => { TypeKind::Struct @@ -247,8 +247,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { SpirvType::Pointer { pointee } => pointee, SpirvType::Vector { element, .. } => element, spirv_type => self.tcx.sess.fatal(format!( - "element_type called on invalid type: {:?}", - spirv_type + "element_type called on invalid type: {spirv_type:?}" )), } } @@ -260,7 +259,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { ty => self .tcx .sess - .fatal(format!("vector_length called on non-vector type: {:?}", ty)), + .fatal(format!("vector_length called on non-vector type: {ty:?}")), } } @@ -270,7 +269,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { ty => self .tcx .sess - .fatal(format!("float_width called on non-float type: {:?}", ty)), + .fatal(format!("float_width called on non-float type: {ty:?}")), } } @@ -281,7 +280,7 @@ impl<'tcx> BaseTypeMethods<'tcx> for CodegenCx<'tcx> { ty => self .tcx .sess - .fatal(format!("int_width called on non-integer type: {:?}", ty)), + .fatal(format!("int_width called on non-integer type: {ty:?}")), } } diff --git a/crates/rustc_codegen_spirv/src/link.rs b/crates/rustc_codegen_spirv/src/link.rs index 73815047f1..7e78544305 100644 --- a/crates/rustc_codegen_spirv/src/link.rs +++ b/crates/rustc_codegen_spirv/src/link.rs @@ -82,7 +82,7 @@ pub fn link( ); } other => { - sess.err(format!("CrateType {:?} not supported yet", other)); + sess.err(format!("CrateType {other:?} not supported yet")); } } } @@ -116,8 +116,7 @@ fn link_rlib(sess: &Session, codegen_results: &CodegenResults, out_filename: &Pa } if let Some(name) = lib.name { sess.err(format!( - "Adding native library to rlib not supported yet: {}", - name + "Adding native library to rlib not supported yet: {name}" )); } } @@ -264,12 +263,11 @@ fn post_link_single_module( } else { let reason = match (sess.opts.optimize, sess.opts.debuginfo == DebugInfo::None) { (OptLevel::No, true) => "debuginfo=None".to_string(), - (optlevel, false) => format!("optlevel={:?}", optlevel), - (optlevel, true) => format!("optlevel={:?}, debuginfo=None", optlevel), + (optlevel, false) => format!("optlevel={optlevel:?}"), + (optlevel, true) => format!("optlevel={optlevel:?}, debuginfo=None"), }; sess.warn(format!( - "`spirv-opt` should have ran ({}) but was disabled by `--no-spirv-opt`", - reason + "`spirv-opt` should have ran ({reason}) but was disabled by `--no-spirv-opt`" )); spv_binary } @@ -287,7 +285,7 @@ fn post_link_single_module( { let mut err = sess.struct_err("failed to serialize spirv-binary to disk"); err.note(&format!("module `{}`", out_filename.display())); - err.note(&format!("I/O error: {:#}", e)); + err.note(&format!("I/O error: {e:#}")); err.emit(); } @@ -452,12 +450,10 @@ fn add_upstream_native_libraries( } match lib.kind { NativeLibKind::Dylib { .. } | NativeLibKind::Unspecified => sess.fatal(format!( - "TODO: dylib nativelibkind not supported yet: {}", - name + "TODO: dylib nativelibkind not supported yet: {name}" )), NativeLibKind::Framework { .. } => sess.fatal(format!( - "TODO: framework nativelibkind not supported yet: {}", - name + "TODO: framework nativelibkind not supported yet: {name}" )), NativeLibKind::Static { bundle: Some(false), @@ -465,8 +461,7 @@ fn add_upstream_native_libraries( } => { if data[cnum.as_usize() - 1] == Linkage::Static { sess.fatal(format!( - "TODO: staticnobundle nativelibkind not supported yet: {}", - name + "TODO: staticnobundle nativelibkind not supported yet: {name}" )) } } @@ -475,11 +470,10 @@ fn add_upstream_native_libraries( .. } => {} NativeLibKind::RawDylib => { - sess.fatal(format!("raw_dylib feature not yet implemented: {}", name)) + sess.fatal(format!("raw_dylib feature not yet implemented: {name}")) } NativeLibKind::LinkArg => sess.fatal(format!( - "TODO: linkarg nativelibkind not supported yet: {}", - name + "TODO: linkarg nativelibkind not supported yet: {name}" )), } } diff --git a/crates/rustc_codegen_spirv/src/linker/import_export_link.rs b/crates/rustc_codegen_spirv/src/linker/import_export_link.rs index dd6a1b88c9..cf40f72d2c 100644 --- a/crates/rustc_codegen_spirv/src/linker/import_export_link.rs +++ b/crates/rustc_codegen_spirv/src/linker/import_export_link.rs @@ -56,7 +56,7 @@ fn find_import_export_pairs_and_killed_params( }; let type_id = *type_map.get(&id).expect("Unexpected op"); if exports.insert(name, (id, type_id)).is_some() { - return Err(sess.err(format!("Multiple exports found for {:?}", name))); + return Err(sess.err(format!("Multiple exports found for {name:?}"))); } } let mut any_err = None; @@ -68,7 +68,7 @@ fn find_import_export_pairs_and_killed_params( }; let (export_id, export_type) = match exports.get(name) { None => { - any_err = Some(sess.err(format!("Unresolved symbol {:?}", name))); + any_err = Some(sess.err(format!("Unresolved symbol {name:?}"))); continue; } Some(&x) => x, @@ -165,7 +165,7 @@ fn check_tys_equal( Some(def) => { write!(buf, "({}", def.class.opname).unwrap(); if let Some(result_type) = def.result_type { - write!(buf, " {}", result_type).unwrap(); + write!(buf, " {result_type}").unwrap(); } for op in &def.operands { if let Some(id) = op.id_ref_any() { @@ -175,7 +175,7 @@ fn check_tys_equal( } write!(buf, ")").unwrap(); } - None => write!(buf, "{}", ty).unwrap(), + None => write!(buf, "{ty}").unwrap(), } } fn format_ty_(ty_defs: &FxHashMap, ty: Word) -> String { @@ -184,7 +184,7 @@ fn check_tys_equal( result } Err(sess - .struct_err(&format!("Types mismatch for {:?}", name)) + .struct_err(&format!("Types mismatch for {name:?}")) .note(&format!( "import type: {}", format_ty_(&ty_defs, import_type) diff --git a/crates/rustc_codegen_spirv/src/linker/inline.rs b/crates/rustc_codegen_spirv/src/linker/inline.rs index cbf4b7e1f6..33810d41a3 100644 --- a/crates/rustc_codegen_spirv/src/linker/inline.rs +++ b/crates/rustc_codegen_spirv/src/linker/inline.rs @@ -125,8 +125,7 @@ fn deny_recursion_in_module(sess: &Session, module: &Module) -> super::Result<() let current_name = get_name(&names, module.functions[current].def_id().unwrap()); let next_name = get_name(&names, module.functions[next].def_id().unwrap()); *has_recursion = Some(sess.err(format!( - "module has recursion, which is not allowed: `{}` calls `{}`", - current_name, next_name + "module has recursion, which is not allowed: `{current_name}` calls `{next_name}`" ))); break; } diff --git a/crates/rustc_codegen_spirv/src/linker/mod.rs b/crates/rustc_codegen_spirv/src/linker/mod.rs index 826b16f5dc..2e778fd53e 100644 --- a/crates/rustc_codegen_spirv/src/linker/mod.rs +++ b/crates/rustc_codegen_spirv/src/linker/mod.rs @@ -135,7 +135,7 @@ fn get_names(module: &Module) -> FxHashMap { fn get_name<'a>(names: &FxHashMap, id: Word) -> Cow<'a, str> { names.get(&id).map_or_else( - || Cow::Owned(format!("Unnamed function ID %{}", id)), + || Cow::Owned(format!("Unnamed function ID %{id}")), |&s| Cow::Borrowed(s), ) } diff --git a/crates/rustc_codegen_spirv/src/linker/specializer.rs b/crates/rustc_codegen_spirv/src/linker/specializer.rs index 2d8ac5424a..7653e2f585 100644 --- a/crates/rustc_codegen_spirv/src/linker/specializer.rs +++ b/crates/rustc_codegen_spirv/src/linker/specializer.rs @@ -208,7 +208,7 @@ pub fn specialize( replacements.to_concrete(&[], |instance| expander.alloc_instance_id(instance)) { if debug { - eprintln!(" {} -> {:?}", operand, loc); + eprintln!(" {operand} -> {loc:?}"); } func.index_set(loc, operand.into()); } @@ -259,8 +259,8 @@ impl From for Operand { impl fmt::Display for CopyOperand { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Self::IdRef(id) => write!(f, "%{}", id), - Self::StorageClass(s) => write!(f, "{:?}", s), + Self::IdRef(id) => write!(f, "%{id}"), + Self::StorageClass(s) => write!(f, "{s:?}"), } } } @@ -349,12 +349,12 @@ impl Instance { } = self; let generic_args_iter = f(generic_args); FmtBy(move |f| { - write!(f, "%{}<", generic_id)?; + write!(f, "%{generic_id}<")?; for (i, arg) in generic_args_iter.clone().enumerate() { if i != 0 { write!(f, ", ")?; } - write!(f, "{}", arg)?; + write!(f, "{arg}")?; } write!(f, ">") }) @@ -793,18 +793,18 @@ impl InferOperand { FmtBy(move |f| { let var_with_value = |v| { FmtBy(move |f| { - write!(f, "{}", v)?; + write!(f, "{v}")?; match infer_var_value(v) { Value::Unknown => Ok(()), - Value::Known(o) => write!(f, " = {}", o), - Value::SameAs(v) => write!(f, " = {}", v), + Value::Known(o) => write!(f, " = {o}"), + Value::SameAs(v) => write!(f, " = {v}"), } }) }; match self { Self::Unknown => write!(f, "_"), Self::Var(v) => write!(f, "{}", var_with_value(*v)), - Self::Concrete(o) => write!(f, "{}", o), + Self::Concrete(o) => write!(f, "{o}"), Self::Instance(instance) => write!( f, "{}", @@ -1136,7 +1136,7 @@ impl<'a> Match<'a> { let mut found = found.iter().map(display); write!(f, "{}", found.next().unwrap())?; for x in found { - write!(f, " = {}", x)?; + write!(f, " = {x}")?; } Ok(()) }) @@ -1192,8 +1192,8 @@ impl<'a> Match<'a> { _ => None, }; match maybe_idx { - Some(idx) => write!(f, ".{}", idx)?, - None => write!(f, "[{}]", operand)?, + Some(idx) => write!(f, ".{idx}")?, + None => write!(f, "[{operand}]")?, } } write!(f, " = {}", leaf.display_with_infer_cx(cx)) @@ -1503,13 +1503,13 @@ impl InferError { // FIXME(eddyb) better error reporting than this. match self { Self::Conflict(a, b) => { - eprintln!("inference conflict: {:?} vs {:?}", a, b); + eprintln!("inference conflict: {a:?} vs {b:?}"); } } eprint!(" in "); // FIXME(eddyb) deduplicate this with other instruction printing logic. if let Some(result_id) = inst.result_id { - eprint!("%{} = ", result_id); + eprint!("%{result_id} = "); } eprint!("Op{:?}", inst.class.opcode); for operand in inst @@ -1518,7 +1518,7 @@ impl InferError { .iter() .chain(inst.operands.iter()) { - eprint!(" {}", operand); + eprint!(" {operand}"); } eprintln!(); @@ -1950,9 +1950,9 @@ impl<'a, S: Specialization> InferCx<'a, S> { if inst_loc != InstructionLocation::Module { eprint!(" "); } - eprint!("{}", prefix); + eprint!("{prefix}"); if let Some(result_id) = inst.result_id { - eprint!("%{} = ", result_id); + eprint!("%{result_id} = "); } eprint!("Op{:?}", inst.class.opcode); for operand in result_type.into_iter().chain(inputs.iter(cx)) { @@ -2025,9 +2025,9 @@ impl<'a, S: Specialization> InferCx<'a, S> { if self.specializer.debug { eprintln!(); - eprint!("specializer::instantiate_function(%{}", func_id); + eprint!("specializer::instantiate_function(%{func_id}"); if let Some(name) = self.specializer.debug_names.get(&func_id) { - eprint!(" {}", name); + eprint!(" {name}"); } eprintln!("):"); } @@ -2482,7 +2482,7 @@ impl<'a, S: Specialization> Expander<'a, S> { // FIXME(eddyb) maybe dump (transitive) dependencies? could use a def-use graph. for (&generic_id, generic) in &self.specializer.generics { if let Some(name) = self.specializer.debug_names.get(&generic_id) { - writeln!(w, "; {}", name)?; + writeln!(w, "; {name}")?; } write!( @@ -2525,7 +2525,7 @@ impl<'a, S: Specialization> Expander<'a, S> { } else if needed == 1 { write!(w, "{}", params.start)?; } else { - write!(w, "{}", operand)?; + write!(w, "{operand}")?; } } writeln!(w)?; @@ -2536,8 +2536,8 @@ impl<'a, S: Specialization> Expander<'a, S> { let p = Param(i as u32); match v { Value::Unknown => {} - Value::Known(o) => write!(w, " {} = {},", p, o)?, - Value::SameAs(q) => write!(w, " {} = {},", p, q)?, + Value::Known(o) => write!(w, " {p} = {o},")?, + Value::SameAs(q) => write!(w, " {p} = {q},")?, } } writeln!(w)?; diff --git a/crates/rustc_codegen_spirv/src/spirv_type.rs b/crates/rustc_codegen_spirv/src/spirv_type.rs index 0f82ff4f09..5cce80991a 100644 --- a/crates/rustc_codegen_spirv/src/spirv_type.rs +++ b/crates/rustc_codegen_spirv/src/spirv_type.rs @@ -123,7 +123,7 @@ impl SpirvType<'_> { other => cx.zombie_with_span( result, def_span, - &format!("Integer width {} invalid for spir-v", other), + &format!("Integer width {other} invalid for spir-v"), ), }; result @@ -141,7 +141,7 @@ impl SpirvType<'_> { other => cx.zombie_with_span( result, def_span, - &format!("Float width {} invalid for spir-v", other), + &format!("Float width {other} invalid for spir-v"), ), }; result @@ -304,7 +304,7 @@ impl SpirvType<'_> { ref other => cx .tcx .sess - .fatal(format!("def_with_id invalid for type {:?}", other)), + .fatal(format!("def_with_id invalid for type {other:?}")), }; cx.type_cache_def(result, self.tcx_arena_alloc_slices(cx), def_span); result @@ -648,9 +648,9 @@ impl SpirvTypePrinter<'_, '_> { SpirvType::Bool => f.write_str("bool"), SpirvType::Integer(width, signedness) => { let prefix = if signedness { "i" } else { "u" }; - write!(f, "{}{}", prefix, width) + write!(f, "{prefix}{width}") } - SpirvType::Float(width) => write!(f, "f{}", width), + SpirvType::Float(width) => write!(f, "f{width}"), SpirvType::Adt { def_id: _, align: _, @@ -674,7 +674,7 @@ impl SpirvTypePrinter<'_, '_> { }; if let Some(name) = first_name { - write!(f, " {}", name)?; + write!(f, " {name}")?; } f.write_str(" { ")?; @@ -688,20 +688,20 @@ impl SpirvTypePrinter<'_, '_> { write!(f, "{}: ", field_names[index])?; } ty(self.cx, stack, f, field)?; - write!(f, "{}", suffix)?; + write!(f, "{suffix}")?; } f.write_str(" }") } SpirvType::Vector { element, count } | SpirvType::Matrix { element, count } => { ty(self.cx, stack, f, element)?; - write!(f, "x{}", count) + write!(f, "x{count}") } SpirvType::Array { element, count } => { let len = self.cx.builder.lookup_const_u64(count); let len = len.expect("Array type has invalid count value"); f.write_str("[")?; ty(self.cx, stack, f, element)?; - write!(f, "; {}]", len) + write!(f, "; {len}]") } SpirvType::RuntimeArray { element } => { f.write_str("[")?; @@ -724,7 +724,7 @@ impl SpirvTypePrinter<'_, '_> { ", " }; ty(self.cx, stack, f, arg)?; - write!(f, "{}", suffix)?; + write!(f, "{suffix}")?; } f.write_str(") -> ")?; ty(self.cx, stack, f, return_type) diff --git a/crates/rustc_codegen_spirv/src/target_feature.rs b/crates/rustc_codegen_spirv/src/target_feature.rs index f95ce4b3a2..2dee66b90a 100644 --- a/crates/rustc_codegen_spirv/src/target_feature.rs +++ b/crates/rustc_codegen_spirv/src/target_feature.rs @@ -16,7 +16,7 @@ impl std::str::FromStr for TargetFeature { Ok(Self::Extension(Symbol::intern(input))) } else { Ok(Self::Capability(input.parse().map_err(|_err| { - format!("Invalid Capability: `{}`", input) + format!("Invalid Capability: `{input}`") })?)) } } diff --git a/crates/spirv-builder/src/depfile.rs b/crates/spirv-builder/src/depfile.rs index 3911e61ee0..1d36bec17b 100644 --- a/crates/spirv-builder/src/depfile.rs +++ b/crates/spirv-builder/src/depfile.rs @@ -16,7 +16,7 @@ pub fn read_deps_file( f: impl FnMut(RawString, Vec) -> Result<(), Error>, ) -> Result<(), Error> { let file = File::open(file_name) - .map_err(|e| Error::new(e.kind(), format!("Unable to read {:?}: {}", file_name, e)))?; + .map_err(|e| Error::new(e.kind(), format!("Unable to read {file_name:?}: {e}")))?; read_deps_file_from(file, f) } diff --git a/crates/spirv-builder/src/lib.rs b/crates/spirv-builder/src/lib.rs index a13db5994b..5b87eb6d1f 100644 --- a/crates/spirv-builder/src/lib.rs +++ b/crates/spirv-builder/src/lib.rs @@ -312,7 +312,7 @@ impl SpirvBuilder { match self.print_metadata { MetadataPrintout::Full | MetadataPrintout::DependencyOnly => { leaf_deps(&metadata_file, |artifact| { - println!("cargo:rerun-if-changed={}", artifact); + println!("cargo:rerun-if-changed={artifact}"); }) // Close enough .map_err(SpirvBuilderError::MetadataFileMissing)?; @@ -488,8 +488,8 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result { } let mut target_features = vec![]; - target_features.extend(builder.capabilities.iter().map(|cap| format!("+{:?}", cap))); - target_features.extend(builder.extensions.iter().map(|ext| format!("+ext:{}", ext))); + target_features.extend(builder.capabilities.iter().map(|cap| format!("+{cap:?}"))); + target_features.extend(builder.extensions.iter().map(|ext| format!("+ext:{ext}"))); let target_features = join_checking_for_separators(target_features, ","); if !target_features.is_empty() { rustflags.push(["-Ctarget-feature=", &target_features].concat()); @@ -600,7 +600,7 @@ fn get_sole_artifact(out: &str) -> Option { Some(line) } else { // Pass through invalid lines - println!("{}", line); + println!("{line}"); None } }) diff --git a/crates/spirv-builder/src/watch.rs b/crates/spirv-builder/src/watch.rs index b905da34fa..d38d2410a5 100644 --- a/crates/spirv-builder/src/watch.rs +++ b/crates/spirv-builder/src/watch.rs @@ -38,7 +38,7 @@ impl SpirvBuilder { let _ = tx.try_send(()); } }, - Err(e) => println!("notify error: {:?}", e), + Err(e) => println!("notify error: {e:?}"), }) .expect("Could create watcher"); // This is likely to notice changes in the `target` dir, however, given that `cargo watch` doesn't seem to handle that, @@ -71,7 +71,7 @@ impl SpirvBuilder { let _ = tx.try_send(()); } }, - Err(e) => println!("notify error: {:?}", e), + Err(e) => println!("notify error: {e:?}"), }) .expect("Could create watcher"); leaf_deps(&metadata_file, |it| { diff --git a/crates/spirv-std/macros/src/lib.rs b/crates/spirv-std/macros/src/lib.rs index 61b652670e..07625ab1c4 100644 --- a/crates/spirv-std/macros/src/lib.rs +++ b/crates/spirv-std/macros/src/lib.rs @@ -483,7 +483,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { let mut has_precision = false; - while matches!(ch, '0'..='9') { + while ch.is_ascii_digit() { ch = match chars.next() { Some(ch) => ch, None => { @@ -508,7 +508,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { } }; - while matches!(ch, '0'..='9') { + while ch.is_ascii_digit() { ch = match chars.next() { Some(ch) => ch, None => return parsing_error( @@ -525,7 +525,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { Some('3') => 3, Some('4') => 4, Some(ch) => { - return parsing_error(&format!("Invalid width for vector: {}", ch), span) + return parsing_error(&format!("Invalid width for vector: {ch}"), span) } None => return parsing_error("Missing vector dimensions specifier", span), }; @@ -539,7 +539,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { Some(ty) => ty, _ => { return parsing_error( - &format!("Unrecognised vector type specifier: '{}'", ch), + &format!("Unrecognised vector type specifier: '{ch}'"), span, ) } @@ -551,7 +551,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { Some(ty) => ty, _ => { return parsing_error( - &format!("Unrecognised format specifier: '{}'", ch), + &format!("Unrecognised format specifier: '{ch}'"), span, ) } @@ -583,7 +583,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { { let ident = quote::format_ident!("_{}", i); - let _ = write!(variable_idents, "%{} ", ident); + let _ = write!(variable_idents, "%{ident} "); let assert_fn = match format_argument { FormatType::Scalar { ty } => { @@ -598,7 +598,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { #ident = in(reg) &#assert_fn(#variable), }); - let op_load = format!("%{ident} = OpLoad _ {{{ident}}}", ident = ident); + let op_load = format!("%{ident} = OpLoad _ {{{ident}}}"); op_loads.push(quote::quote! { #op_load, @@ -610,7 +610,7 @@ fn debug_printf_inner(input: DebugPrintfInput) -> TokenStream { .collect::(); let op_loads = op_loads.into_iter().collect::(); - let op_string = format!("%string = OpString {:?}", format_string); + let op_string = format!("%string = OpString {format_string:?}"); let output = quote::quote! { ::core::arch::asm!( diff --git a/examples/multibuilder/src/main.rs b/examples/multibuilder/src/main.rs index 525d28ff7b..e694b72ee3 100644 --- a/examples/multibuilder/src/main.rs +++ b/examples/multibuilder/src/main.rs @@ -9,5 +9,5 @@ fn main() { .multimodule(true) .build() .unwrap(); - println!("{:#?}", result); + println!("{result:#?}"); } diff --git a/examples/runners/ash/build.rs b/examples/runners/ash/build.rs index 7bf0734bed..5aa3309e79 100644 --- a/examples/runners/ash/build.rs +++ b/examples/runners/ash/build.rs @@ -4,5 +4,5 @@ fn main() { // While OUT_DIR is set for both build.rs and compiling the crate, PROFILE is only set in // build.rs. So, export it to crate compilation as well. let profile = env::var("PROFILE").unwrap(); - println!("cargo:rustc-env=PROFILE={}", profile); + println!("cargo:rustc-env=PROFILE={profile}"); } diff --git a/examples/runners/wgpu/build.rs b/examples/runners/wgpu/build.rs index 52983c1048..4c79f896f8 100644 --- a/examples/runners/wgpu/build.rs +++ b/examples/runners/wgpu/build.rs @@ -11,7 +11,7 @@ fn main() -> Result<(), Box> { // While OUT_DIR is set for both build.rs and compiling the crate, PROFILE is only set in // build.rs. So, export it to crate compilation as well. let profile = env::var("PROFILE").unwrap(); - println!("cargo:rustc-env=PROFILE={}", profile); + println!("cargo:rustc-env=PROFILE={profile}"); if target_os != "android" && target_arch != "wasm32" { return Ok(()); } diff --git a/examples/runners/wgpu/src/compute.rs b/examples/runners/wgpu/src/compute.rs index 07681d4e74..7a896a0005 100644 --- a/examples/runners/wgpu/src/compute.rs +++ b/examples/runners/wgpu/src/compute.rs @@ -173,12 +173,12 @@ pub async fn start_internal( let mut max = 0; for (src, out) in src_range.zip(result.iter().copied()) { if out == u32::MAX { - println!("{}: overflowed", src); + println!("{src}: overflowed"); break; } else if out > max { max = out; // Should produce - println!("{}: {}", src, out); + println!("{src}: {out}"); } } println!( diff --git a/examples/runners/wgpu/src/graphics.rs b/examples/runners/wgpu/src/graphics.rs index 1a8ee5c67f..2a090fc2df 100644 --- a/examples/runners/wgpu/src/graphics.rs +++ b/examples/runners/wgpu/src/graphics.rs @@ -158,7 +158,7 @@ async fn run( let output = match surface.get_current_texture() { Ok(surface) => surface, Err(err) => { - eprintln!("get_current_texture error: {:?}", err); + eprintln!("get_current_texture error: {err:?}"); match err { wgpu::SurfaceError::Lost => { surface.configure(&device, &surface_config); diff --git a/examples/shaders/compute-shader/src/main.rs b/examples/shaders/compute-shader/src/main.rs index ddabff5345..104cf9a26f 100644 --- a/examples/shaders/compute-shader/src/main.rs +++ b/examples/shaders/compute-shader/src/main.rs @@ -19,14 +19,14 @@ fn main() { Some(out) if out > max => { max = out; // Should produce - println!("{}: {}", src, out); + println!("{src}: {out}"); } Some(_) => (), None => { - println!("{}: overflowed", src); + println!("{src}: overflowed"); break; } } } - println!("Took: {:?}", took); + println!("Took: {took:?}"); } diff --git a/tests/src/main.rs b/tests/src/main.rs index d0a30ce23e..4bda1ae715 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -50,7 +50,7 @@ impl DepKind { fn target_dir_suffix(self, target: &str) -> String { match self { - Self::SpirvLib => format!("{}/debug/deps", target), + Self::SpirvLib => format!("{target}/debug/deps"), Self::ProcMacro => "debug/deps".into(), } } @@ -136,7 +136,7 @@ impl Runner { // which offer `// only-S` and `// ignore-S` for any stage ID `S`. let stage_id = if spirt { "spirt" } else { "not_spirt" }; - let target = format!("{}{}", TARGET_PREFIX, env); + let target = format!("{TARGET_PREFIX}{env}"); let libs = build_deps(&self.deps_target_dir, &self.codegen_backend_path, &target); let mut flags = test_rustc_flags( &self.codegen_backend_path, @@ -188,7 +188,7 @@ fn build_deps(deps_target_dir: &Path, codegen_backend_path: &Path, target: &str) "compiletests-deps-helper", "-Zbuild-std=core", "-Zbuild-std-features=compiler-builtins-mem", - &*format!("--target={}", target), + &*format!("--target={target}"), ]) .arg("--target-dir") .arg(deps_target_dir)