diff --git a/cli/src/bin/naga.rs b/cli/src/bin/naga.rs index b983473a1e..ddf65f59c2 100644 --- a/cli/src/bin/naga.rs +++ b/cli/src/bin/naga.rs @@ -99,8 +99,7 @@ impl FromStr for BoundsCheckPolicyArg { "unchecked" => BoundsCheckPolicy::Unchecked, _ => { return Err(format!( - "Invalid value for --index-bounds-check-policy: {}", - s + "Invalid value for --index-bounds-check-policy: {s}" )) } })) @@ -120,7 +119,7 @@ impl FromStr for ShaderModelArg { "50" => ShaderModel::V5_0, "51" => ShaderModel::V5_1, "60" => ShaderModel::V6_0, - _ => return Err(format!("Invalid value for --shader-model: {}", s)), + _ => return Err(format!("Invalid value for --shader-model: {s}")), })) } } @@ -139,7 +138,7 @@ impl FromStr for GlslProfileArg { } else if s.starts_with("es") { Version::new_gles(s[2..].parse().unwrap_or(310)) } else { - return Err(format!("Unknown profile: {}", s)); + return Err(format!("Unknown profile: {s}")); })) } } @@ -163,7 +162,7 @@ trait PrettyResult { } fn print_err(error: &dyn Error) { - eprint!("{}", error); + eprint!("{error}"); let mut e = error.source(); if e.is_some() { @@ -173,7 +172,7 @@ fn print_err(error: &dyn Error) { } while let Some(source) = e { - eprintln!("\t{}", source); + eprintln!("\t{source}"); e = source.source(); } } @@ -366,10 +365,10 @@ fn run() -> Result<(), Box> { use std::io::Write; let mut file = fs::File::create(output_path)?; - writeln!(file, "{:#?}", module)?; + writeln!(file, "{module:#?}")?; if let Some(ref info) = info { writeln!(file)?; - writeln!(file, "{:#?}", info)?; + writeln!(file, "{info:#?}")?; } } "bin" => { @@ -515,7 +514,7 @@ fn run() -> Result<(), Box> { fs::write(output_path, wgsl)?; } other => { - println!("Unknown output extension: {}", other); + println!("Unknown output extension: {other}"); } } } diff --git a/src/back/dot/mod.rs b/src/back/dot/mod.rs index ce88f02e8e..5da9029ab2 100644 --- a/src/back/dot/mod.rs +++ b/src/back/dot/mod.rs @@ -304,15 +304,13 @@ fn write_fun( for (index, label) in sg.nodes.into_iter().enumerate() { writeln!( output, - "\t\t{}_s{} [ shape=square label=\"{}\" ]", - prefix, index, label, + "\t\t{prefix}_s{index} [ shape=square label=\"{label}\" ]", )?; } for (from, to, label) in sg.flow { writeln!( output, - "\t\t{}_s{} -> {}_s{} [ arrowhead=tee label=\"{}\" ]", - prefix, from, prefix, to, label, + "\t\t{prefix}_s{from} -> {prefix}_s{to} [ arrowhead=tee label=\"{label}\" ]", )?; } for (from, to, label, color_id) in sg.jumps { @@ -384,12 +382,12 @@ fn write_function_expressions( } E::AccessIndex { base, index } => { edges.insert("base", base); - (format!("AccessIndex[{}]", index).into(), 1) + (format!("AccessIndex[{index}]").into(), 1) } E::Constant(_) => ("Constant".into(), 2), E::Splat { size, value } => { edges.insert("value", value); - (format!("Splat{:?}", size).into(), 3) + (format!("Splat{size:?}").into(), 3) } E::Swizzle { size, @@ -403,7 +401,7 @@ fn write_function_expressions( payload = Some(Payload::Arguments(components)); ("Compose".into(), 3) } - E::FunctionArgument(index) => (format!("Argument[{}]", index).into(), 1), + E::FunctionArgument(index) => (format!("Argument[{index}]").into(), 1), E::GlobalVariable(h) => { payload = Some(Payload::Global(h)); ("Global".into(), 2) @@ -450,7 +448,7 @@ fn write_function_expressions( edges.insert("depth_ref", expr); } let string = match gather { - Some(component) => Cow::Owned(format!("ImageGather{:?}", component)), + Some(component) => Cow::Owned(format!("ImageGather{component:?}")), _ => Cow::Borrowed("ImageSample"), }; (string, 5) @@ -484,18 +482,18 @@ fn write_function_expressions( } Cow::from("ImageSize") } - _ => Cow::Owned(format!("{:?}", query)), + _ => Cow::Owned(format!("{query:?}")), }; (args, 7) } E::Unary { op, expr } => { edges.insert("expr", expr); - (format!("{:?}", op).into(), 6) + (format!("{op:?}").into(), 6) } E::Binary { op, left, right } => { edges.insert("left", left); edges.insert("right", right); - (format!("{:?}", op).into(), 6) + (format!("{op:?}").into(), 6) } E::Select { condition, @@ -509,11 +507,11 @@ fn write_function_expressions( } E::Derivative { axis, expr } => { edges.insert("", expr); - (format!("d{:?}", axis).into(), 8) + (format!("d{axis:?}").into(), 8) } E::Relational { fun, argument } => { edges.insert("arg", argument); - (format!("{:?}", fun).into(), 6) + (format!("{fun:?}").into(), 6) } E::Math { fun, @@ -532,7 +530,7 @@ fn write_function_expressions( if let Some(expr) = arg3 { edges.insert("arg3", expr); } - (format!("{:?}", fun).into(), 7) + (format!("{fun:?}").into(), 7) } E::As { kind, @@ -541,8 +539,8 @@ fn write_function_expressions( } => { edges.insert("", expr); let string = match convert { - Some(width) => format!("Convert<{:?},{}>", kind, width), - None => format!("Bitcast<{:?}>", kind), + Some(width) => format!("Convert<{kind:?},{width}>"), + None => format!("Bitcast<{kind:?}>"), }; (string.into(), 3) } @@ -644,7 +642,7 @@ pub fn write( for (handle, fun) in module.functions.iter() { let prefix = format!("f{}", handle.index()); - writeln!(output, "\tsubgraph cluster_{} {{", prefix)?; + writeln!(output, "\tsubgraph cluster_{prefix} {{")?; writeln!( output, "\t\tlabel=\"Function{:?}/'{}'\"", @@ -656,8 +654,8 @@ pub fn write( writeln!(output, "\t}}")?; } for (ep_index, ep) in module.entry_points.iter().enumerate() { - let prefix = format!("ep{}", ep_index); - writeln!(output, "\tsubgraph cluster_{} {{", prefix)?; + let prefix = format!("ep{ep_index}"); + writeln!(output, "\tsubgraph cluster_{prefix} {{")?; writeln!(output, "\t\tlabel=\"{:?}/'{}'\"", ep.stage, ep.name)?; let info = mod_info.map(|a| a.get_entry_point(ep_index)); write_fun(&mut output, prefix, &ep.function, info, &options)?; diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 9b4bf0cf23..4208856387 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -198,8 +198,8 @@ impl PartialOrd for Version { impl fmt::Display for Version { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match *self { - Version::Desktop(v) => write!(f, "{} core", v), - Version::Embedded { version: v, .. } => write!(f, "{} es", v), + Version::Desktop(v) => write!(f, "{v} core"), + Version::Embedded { version: v, .. } => write!(f, "{v} es"), } } } @@ -327,7 +327,7 @@ impl fmt::Display for VaryingName<'_> { // fragment to pipeline (ShaderStage::Fragment, true) => "fs2p", }; - write!(f, "_{}_location{}", prefix, location,) + write!(f, "_{prefix}_location{location}",) } crate::Binding::BuiltIn(built_in) => { write!( @@ -563,7 +563,7 @@ impl<'a, W: Write> Writer<'a, W> { Cd::LessEqual => "less", Cd::Unchanged => "unchanged", }; - writeln!(self.out, "layout (depth_{}) out float gl_FragDepth;", depth)?; + writeln!(self.out, "layout (depth_{depth}) out float gl_FragDepth;")?; } writeln!(self.out)?; } else { @@ -576,7 +576,7 @@ impl<'a, W: Write> Writer<'a, W> { if self.entry_point.stage == ShaderStage::Vertex && self.options.version.is_webgl() { if let Some(multiview) = self.multiview.as_ref() { - writeln!(self.out, "layout(num_views = {}) in;", multiview)?; + writeln!(self.out, "layout(num_views = {multiview}) in;")?; writeln!(self.out)?; } } @@ -597,7 +597,7 @@ impl<'a, W: Write> Writer<'a, W> { .is_dynamically_sized(&self.module.types) { let name = &self.names[&NameKey::Type(handle)]; - write!(self.out, "struct {} ", name)?; + write!(self.out, "struct {name} ")?; self.write_struct_body(handle, members)?; writeln!(self.out, ";")?; } @@ -653,7 +653,7 @@ impl<'a, W: Write> Writer<'a, W> { if layout_binding.is_some() || storage_format_access.is_some() { write!(self.out, "layout(")?; if let Some(binding) = layout_binding { - write!(self.out, "binding = {}", binding)?; + write!(self.out, "binding = {binding}")?; } if let Some((format, _)) = storage_format_access { let format_str = glsl_storage_format(format); @@ -661,7 +661,7 @@ impl<'a, W: Write> Writer<'a, W> { Some(_) => ",", None => "", }; - write!(self.out, "{}{}", separator, format_str)?; + write!(self.out, "{separator}{format_str}")?; } write!(self.out, ") ")?; } @@ -683,7 +683,7 @@ impl<'a, W: Write> Writer<'a, W> { // Finally write the name and end the global with a `;` // The leading space is important let global_name = self.get_global_name(handle, global); - writeln!(self.out, " {};", global_name)?; + writeln!(self.out, " {global_name};")?; writeln!(self.out)?; self.reflection_names_globals.insert(handle, global_name); @@ -717,7 +717,7 @@ impl<'a, W: Write> Writer<'a, W> { self.write_type(ty)?; } }; - write!(self.out, " {} = ", name)?; + write!(self.out, " {name} = ")?; self.write_constant(handle)?; writeln!(self.out, ";")?; } @@ -777,11 +777,11 @@ impl<'a, W: Write> Writer<'a, W> { crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Uint(size), - } => write!(self.out, "{}", size)?, + } => write!(self.out, "{size}")?, crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Sint(size), - } => write!(self.out, "{}", size)?, + } => write!(self.out, "{size}")?, _ => unreachable!(), } } @@ -865,7 +865,7 @@ impl<'a, W: Write> Writer<'a, W> { | TypeInner::Image { .. } | TypeInner::Sampler { .. } | TypeInner::BindingArray { .. } => { - return Err(Error::Custom(format!("Unable to write type {:?}", inner))) + return Err(Error::Custom(format!("Unable to write type {inner:?}"))) } } @@ -890,7 +890,7 @@ impl<'a, W: Write> Writer<'a, W> { TypeInner::Struct { .. } => { // Get the struct name let name = &self.names[&NameKey::Type(ty)]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; Ok(()) } // glsl array has the size separated from the base type @@ -972,7 +972,7 @@ impl<'a, W: Write> Writer<'a, W> { crate::AddressSpace::Uniform => "std140, ", _ => "", }; - write!(self.out, "layout({}binding = {}) ", layout, binding)? + write!(self.out, "layout({layout}binding = {binding}) ")? } None => { log::debug!("unassigned binding for {:?}", global.name); @@ -991,7 +991,7 @@ impl<'a, W: Write> Writer<'a, W> { } if let Some(storage_qualifier) = glsl_storage_qualifier(global.space) { - write!(self.out, "{} ", storage_qualifier)?; + write!(self.out, "{storage_qualifier} ")?; } match global.space { @@ -1071,7 +1071,7 @@ impl<'a, W: Write> Writer<'a, W> { self.block_id.generate(), self.entry_point.stage, ); - write!(self.out, "{} ", block_name)?; + write!(self.out, "{block_name} ")?; self.reflection_names_globals.insert(handle, block_name); match self.module.types[global.ty].inner { @@ -1272,7 +1272,7 @@ impl<'a, W: Write> Writer<'a, W> { // Write the I/O locations, if allowed if self.options.version.supports_explicit_locations() || !emit_interpolation_and_auxiliary { - write!(self.out, "layout(location = {}) ", location)?; + write!(self.out, "layout(location = {location}) ")?; } // Write the interpolation qualifier. @@ -1290,7 +1290,7 @@ impl<'a, W: Write> Writer<'a, W> { if let Some(sampling) = sampling { if emit_interpolation_and_auxiliary { if let Some(qualifier) = glsl_sampling(sampling) { - write!(self.out, "{} ", qualifier)?; + write!(self.out, "{qualifier} ")?; } } } @@ -1314,7 +1314,7 @@ impl<'a, W: Write> Writer<'a, W> { output, targetting_webgl: self.options.version.is_webgl(), }; - writeln!(self.out, " {};", vname)?; + writeln!(self.out, " {vname};")?; Ok(()) } @@ -1366,7 +1366,7 @@ impl<'a, W: Write> Writer<'a, W> { back::FunctionType::Function(handle) => &self.names[&NameKey::Function(handle)], back::FunctionType::EntryPoint(_) => "main", }; - write!(self.out, " {}(", function_name)?; + write!(self.out, " {function_name}(")?; // Write the comma separated argument list // @@ -1448,7 +1448,7 @@ impl<'a, W: Write> Writer<'a, W> { write!(self.out, "{}", back::INDENT)?; self.write_type(arg.ty)?; let name = &self.names[&NameKey::EntryPointArgument(ep_index, index as u32)]; - write!(self.out, " {}", name)?; + write!(self.out, " {name}")?; write!(self.out, " = ")?; match self.module.types[arg.ty].inner { crate::TypeInner::Struct { ref members, .. } => { @@ -1464,7 +1464,7 @@ impl<'a, W: Write> Writer<'a, W> { if index != 0 { write!(self.out, ", ")?; } - write!(self.out, "{}", varying_name)?; + write!(self.out, "{varying_name}")?; } writeln!(self.out, ");")?; } @@ -1475,7 +1475,7 @@ impl<'a, W: Write> Writer<'a, W> { output: false, targetting_webgl: self.options.version.is_webgl(), }; - writeln!(self.out, "{};", varying_name)?; + writeln!(self.out, "{varying_name};")?; } } } @@ -1547,8 +1547,7 @@ impl<'a, W: Write> Writer<'a, W> { writeln!( self.out, - "{}if (gl_GlobalInvocationID == uvec3(0u)) {{", - level + "{level}if (gl_GlobalInvocationID == uvec3(0u)) {{" )?; for (handle, var) in vars { @@ -1558,7 +1557,7 @@ impl<'a, W: Write> Writer<'a, W> { writeln!(self.out, ";")?; } - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; self.write_barrier(crate::Barrier::WORK_GROUP, level)?; } @@ -1607,17 +1606,17 @@ impl<'a, W: Write> Writer<'a, W> { ref value, } => match *value { // Signed integers don't need anything special - Sv::Sint(int) => write!(self.out, "{}", int)?, + Sv::Sint(int) => write!(self.out, "{int}")?, // Unsigned integers need a `u` at the end // // While `core` doesn't necessarily need it, it's allowed and since `es` needs it we // always write it as the extra branch wouldn't have any benefit in readability - Sv::Uint(int) => write!(self.out, "{}u", int)?, + Sv::Uint(int) => write!(self.out, "{int}u")?, // Floats are written using `Debug` instead of `Display` because it always appends the // decimal part even it's zero which is needed for a valid glsl float constant - Sv::Float(float) => write!(self.out, "{:?}", float)?, + Sv::Float(float) => write!(self.out, "{float:?}")?, // Booleans are either `true` or `false` so nothing special needs to be done - Sv::Bool(boolean) => write!(self.out, "{}", boolean)?, + Sv::Bool(boolean) => write!(self.out, "{boolean}")?, }, // Composite constant are created using the same syntax as compose // `type(components)` where `components` is a comma separated list of constants @@ -1662,13 +1661,13 @@ impl<'a, W: Write> Writer<'a, W> { // it shouldn't produce large expressions. self.write_expr(arg, ctx)?; // Access the current component on the first vector - write!(self.out, ".{} * ", component)?; + write!(self.out, ".{component} * ")?; // Write the second vector expression, this expression is marked to be // cached so unless it can't be cached (for example, it's a Constant) // it shouldn't produce large expressions. self.write_expr(arg1, ctx)?; // Access the current component on the second vector - write!(self.out, ".{}", component)?; + write!(self.out, ".{component}")?; } write!(self.out, ")")?; @@ -1787,14 +1786,14 @@ impl<'a, W: Write> Writer<'a, W> { } = *ctx.info[image].ty.inner_with(&self.module.types) { if let proc::BoundsCheckPolicy::Restrict = self.policies.image { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_clamped_lod(ctx, handle, image, level_expr)? } } } if let Some(name) = expr_name { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_named_expr(handle, name, ctx)?; } } @@ -1803,13 +1802,13 @@ impl<'a, W: Write> Writer<'a, W> { // We could also just print the statements but this is more readable and maps more // closely to the IR Statement::Block(ref block) => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "{{")?; for sta in block.iter() { // Increase the indentation to help with readability self.write_stmt(sta, ctx, level.next())? } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // Ifs are written as in C: // ``` @@ -1824,7 +1823,7 @@ impl<'a, W: Write> Writer<'a, W> { ref accept, ref reject, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "if (")?; self.write_expr(condition, ctx)?; writeln!(self.out, ") {{")?; @@ -1837,7 +1836,7 @@ impl<'a, W: Write> Writer<'a, W> { // If there are no statements in the reject block we skip writing it // This is only for readability if !reject.is_empty() { - writeln!(self.out, "{}}} else {{", level)?; + writeln!(self.out, "{level}}} else {{")?; for sta in reject { // Increase indentation to help with readability @@ -1845,7 +1844,7 @@ impl<'a, W: Write> Writer<'a, W> { } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // Switch are written as in C: // ``` @@ -1868,7 +1867,7 @@ impl<'a, W: Write> Writer<'a, W> { ref cases, } => { // Start the switch - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "switch(")?; self.write_expr(selector, ctx)?; writeln!(self.out, ") {{")?; @@ -1885,9 +1884,9 @@ impl<'a, W: Write> Writer<'a, W> { for case in cases { match case.value { crate::SwitchValue::Integer(value) => { - write!(self.out, "{}case {}{}:", l2, value, type_postfix)? + write!(self.out, "{l2}case {value}{type_postfix}:")? } - crate::SwitchValue::Default => write!(self.out, "{}default:", l2)?, + crate::SwitchValue::Default => write!(self.out, "{l2}default:")?, } let write_block_braces = !(case.fall_through && case.body.is_empty()); @@ -1906,11 +1905,11 @@ impl<'a, W: Write> Writer<'a, W> { } if write_block_braces { - writeln!(self.out, "{}}}", l2)?; + writeln!(self.out, "{l2}}}")?; } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // Loops in naga IR are based on wgsl loops, glsl can emulate the behaviour by using a // while true loop and appending the continuing block to the body resulting on: @@ -1929,45 +1928,45 @@ impl<'a, W: Write> Writer<'a, W> { } => { if !continuing.is_empty() || break_if.is_some() { let gate_name = self.namer.call("loop_init"); - writeln!(self.out, "{}bool {} = true;", level, gate_name)?; - writeln!(self.out, "{}while(true) {{", level)?; + writeln!(self.out, "{level}bool {gate_name} = true;")?; + writeln!(self.out, "{level}while(true) {{")?; let l2 = level.next(); let l3 = l2.next(); - writeln!(self.out, "{}if (!{}) {{", l2, gate_name)?; + writeln!(self.out, "{l2}if (!{gate_name}) {{")?; for sta in continuing { self.write_stmt(sta, ctx, l3)?; } if let Some(condition) = break_if { - write!(self.out, "{}if (", l3)?; + write!(self.out, "{l3}if (")?; self.write_expr(condition, ctx)?; writeln!(self.out, ") {{")?; writeln!(self.out, "{}break;", l3.next())?; - writeln!(self.out, "{}}}", l3)?; + writeln!(self.out, "{l3}}}")?; } - writeln!(self.out, "{}}}", l2)?; + writeln!(self.out, "{l2}}}")?; writeln!(self.out, "{}{} = false;", level.next(), gate_name)?; } else { - writeln!(self.out, "{}while(true) {{", level)?; + writeln!(self.out, "{level}while(true) {{")?; } for sta in body { self.write_stmt(sta, ctx, level.next())?; } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // Break, continue and return as written as in C // `break;` Statement::Break => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "break;")? } // `continue;` Statement::Continue => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "continue;")? } // `return expr;`, `expr` is optional Statement::Return { value } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; match ctx.ty { back::FunctionType::Function(_) => { write!(self.out, "return")?; @@ -1995,7 +1994,7 @@ impl<'a, W: Write> Writer<'a, W> { )?; self.write_expr(value, ctx)?; writeln!(self.out, ";")?; - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; Some(return_struct) } _ => None, @@ -2024,10 +2023,10 @@ impl<'a, W: Write> Writer<'a, W> { output: true, targetting_webgl: self.options.version.is_webgl(), }; - write!(self.out, "{} = ", varying_name)?; + write!(self.out, "{varying_name} = ")?; if let Some(struct_name) = temp_struct_name { - write!(self.out, "{}", struct_name)?; + write!(self.out, "{struct_name}")?; } else { self.write_expr(value, ctx)?; } @@ -2039,7 +2038,7 @@ impl<'a, W: Write> Writer<'a, W> { &self.names [&NameKey::StructMember(result.ty, index as u32)] )?; - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; } } _ => { @@ -2049,10 +2048,10 @@ impl<'a, W: Write> Writer<'a, W> { output: true, targetting_webgl: self.options.version.is_webgl(), }; - write!(self.out, "{} = ", name)?; + write!(self.out, "{name} = ")?; self.write_expr(value, ctx)?; writeln!(self.out, ";")?; - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; } } } @@ -2069,7 +2068,7 @@ impl<'a, W: Write> Writer<'a, W> { self.out, "gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);", )?; - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; } } writeln!(self.out, "return;")?; @@ -2079,13 +2078,13 @@ impl<'a, W: Write> Writer<'a, W> { // This is one of the places were glsl adds to the syntax of C in this case the discard // keyword which ceases all further processing in a fragment shader, it's called OpKill // in spir-v that's why it's called `Statement::Kill` - Statement::Kill => writeln!(self.out, "{}discard;", level)?, + Statement::Kill => writeln!(self.out, "{level}discard;")?, Statement::Barrier(flags) => { self.write_barrier(flags, level)?; } // Stores in glsl are just variable assignments written as `pointer = value;` Statement::Store { pointer, value } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_expr(pointer, ctx)?; write!(self.out, " = ")?; self.write_expr(value, ctx)?; @@ -2098,7 +2097,7 @@ impl<'a, W: Write> Writer<'a, W> { array_index, value, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_image_store(ctx, image, coordinate, array_index, value)? } // A `Call` is written `name(arguments)` where `arguments` is a comma separated expressions list @@ -2107,12 +2106,12 @@ impl<'a, W: Write> Writer<'a, W> { ref arguments, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; if let Some(expr) = result { let name = format!("{}{}", back::BAKE_PREFIX, expr.index()); let result = self.module.functions[function].result.as_ref().unwrap(); self.write_type(result.ty)?; - write!(self.out, " {} = ", name)?; + write!(self.out, " {name} = ")?; self.named_expressions.insert(expr, name); } write!(self.out, "{}(", &self.names[&NameKey::Function(function)])?; @@ -2136,15 +2135,15 @@ impl<'a, W: Write> Writer<'a, W> { value, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; let res_name = format!("{}{}", back::BAKE_PREFIX, result.index()); let res_ty = ctx.info[result].ty.inner_with(&self.module.types); self.write_value_type(res_ty)?; - write!(self.out, " {} = ", res_name)?; + write!(self.out, " {res_name} = ")?; self.named_expressions.insert(result, res_name); let fun_str = fun.to_glsl(); - write!(self.out, "atomic{}(", fun_str)?; + write!(self.out, "atomic{fun_str}(")?; self.write_expr(pointer, ctx)?; write!(self.out, ", ")?; // handle the special cases @@ -2180,7 +2179,7 @@ impl<'a, W: Write> Writer<'a, W> { use crate::Expression; if let Some(name) = self.named_expressions.get(&expr) { - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; return Ok(()); } @@ -2215,7 +2214,7 @@ impl<'a, W: Write> Writer<'a, W> { } TypeInner::Matrix { .. } | TypeInner::Array { .. } - | TypeInner::ValuePointer { .. } => write!(self.out, "[{}]", index)?, + | TypeInner::ValuePointer { .. } => write!(self.out, "[{index}]")?, TypeInner::Struct { .. } => { // This will never panic in case the type is a `Struct`, this is not true // for other types so we can only check while inside this match arm @@ -2227,7 +2226,7 @@ impl<'a, W: Write> Writer<'a, W> { &self.names[&NameKey::StructMember(ty, index)] )? } - ref other => return Err(Error::Custom(format!("Cannot index {:?}", other))), + ref other => return Err(Error::Custom(format!("Cannot index {other:?}"))), } } // Constants are delegated to `write_constant` @@ -2353,7 +2352,7 @@ impl<'a, W: Write> Writer<'a, W> { None => "", }; - write!(self.out, "{}{}(", fun_name, offset_name)?; + write!(self.out, "{fun_name}{offset_name}(")?; // Write the image that will be used self.write_expr(image, ctx)?; @@ -2413,7 +2412,7 @@ impl<'a, W: Write> Writer<'a, W> { crate::ImageDimension::Cube => 3, _ => 2, }; - write!(self.out, ", vec{}(0.0), vec{}(0.0)", vec_dim, vec_dim)?; + write!(self.out, ", vec{vec_dim}(0.0), vec{vec_dim}(0.0)")?; } else if gather.is_none() { write!(self.out, ", 0.0")?; } @@ -2538,7 +2537,7 @@ impl<'a, W: Write> Writer<'a, W> { ImageClass::Sampled { .. } | ImageClass::Depth { .. } => "textureSize", ImageClass::Storage { .. } => "imageSize", }; - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(image, ctx)?; // All textureSize calls requires an lod argument // except for multisampled samplers @@ -2557,7 +2556,7 @@ impl<'a, W: Write> Writer<'a, W> { } ImageClass::Storage { .. } => "imageSamples", }; - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(image, ctx)?; write!(self.out, ")",)?; } @@ -2586,14 +2585,13 @@ impl<'a, W: Write> Writer<'a, W> { Some(Sk::Bool) => "!", ref other => { return Err(Error::Custom(format!( - "Cannot apply not to type {:?}", - other + "Cannot apply not to type {other:?}" ))) } }, }; - write!(self.out, "{}(", operator)?; + write!(self.out, "{operator}(")?; } } @@ -2667,7 +2665,7 @@ impl<'a, W: Write> Writer<'a, W> { Bo::NotEqual => "notEqual(", _ => unreachable!(), }; - write!(self.out, "{}", op_str)?; + write!(self.out, "{op_str}")?; self.write_expr(left, ctx)?; write!(self.out, ", ")?; self.write_expr(right, ctx)?; @@ -2802,7 +2800,7 @@ impl<'a, W: Write> Writer<'a, W> { Rf::All => "all", Rf::Any => "any", }; - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(argument, ctx)?; @@ -2987,7 +2985,7 @@ impl<'a, W: Write> Writer<'a, W> { } } - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; // Cast to int if the function needs it if arg_might_need_uint_to_int { @@ -3199,7 +3197,7 @@ impl<'a, W: Write> Writer<'a, W> { // constructor notation (NOTE: the inner `ivec` can also be a scalar, this // is important for 1D arrayed images). Some(layer_expr) => { - write!(self.out, "ivec{}(", vector_size)?; + write!(self.out, "ivec{vector_size}(")?; self.write_expr(coordinate, ctx)?; write!(self.out, ", ")?; // If we are replacing sampler1D with sampler2D we also need @@ -3229,7 +3227,7 @@ impl<'a, W: Write> Writer<'a, W> { } else if uvec_size.is_some() { match uvec_size { Some(None) => write!(self.out, "int(")?, - Some(Some(size)) => write!(self.out, "ivec{}(", size)?, + Some(Some(size)) => write!(self.out, "ivec{size}(")?, _ => {} } } @@ -3442,7 +3440,7 @@ impl<'a, W: Write> Writer<'a, W> { } // Begin the call to the function used to load the texel - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(image, ctx)?; write!(self.out, ", ")?; @@ -3463,7 +3461,7 @@ impl<'a, W: Write> Writer<'a, W> { if vector_size == 1 { write!(self.out, ", 0")?; } else { - write!(self.out, ", ivec{}(0)", vector_size)?; + write!(self.out, ", ivec{vector_size}(0)")?; } // Start the `textureSize` call to use as the max value. write!(self.out, ", textureSize(")?; @@ -3487,7 +3485,7 @@ impl<'a, W: Write> Writer<'a, W> { if vector_size == 1 { write!(self.out, " - 1")?; } else { - write!(self.out, " - ivec{}(1)", vector_size)?; + write!(self.out, " - ivec{vector_size}(1)")?; } // Close the `clamp` call @@ -3563,7 +3561,7 @@ impl<'a, W: Write> Writer<'a, W> { proc::TypeResolution::Handle(ty_handle) => match self.module.types[ty_handle].inner { TypeInner::Struct { .. } => { let ty_name = &self.names[&NameKey::Type(ty_handle)]; - write!(self.out, "{}", ty_name)?; + write!(self.out, "{ty_name}")?; } _ => { self.write_type(ty_handle)?; @@ -3577,7 +3575,7 @@ impl<'a, W: Write> Writer<'a, W> { let base_ty_res = &ctx.info[handle].ty; let resolved = base_ty_res.inner_with(&self.module.types); - write!(self.out, " {}", name)?; + write!(self.out, " {name}")?; if let TypeInner::Array { base, size, .. } = *resolved { self.write_array_size(base, size)?; } @@ -3629,7 +3627,7 @@ impl<'a, W: Write> Writer<'a, W> { } TypeInner::Struct { ref members, .. } => { let name = &self.names[&NameKey::Type(ty)]; - write!(self.out, "{}(", name)?; + write!(self.out, "{name}(")?; for (i, member) in members.iter().enumerate() { self.write_zero_init_value(member.ty)?; if i != members.len().saturating_sub(1) { @@ -3660,12 +3658,12 @@ impl<'a, W: Write> Writer<'a, W> { /// OpenGL always requires a call to the `barrier()` function after a `memoryBarrier*()` fn write_barrier(&mut self, flags: crate::Barrier, level: back::Level) -> BackendResult { if flags.contains(crate::Barrier::STORAGE) { - writeln!(self.out, "{}memoryBarrierBuffer();", level)?; + writeln!(self.out, "{level}memoryBarrierBuffer();")?; } if flags.contains(crate::Barrier::WORK_GROUP) { - writeln!(self.out, "{}memoryBarrierShared();", level)?; + writeln!(self.out, "{level}memoryBarrierShared();")?; } - writeln!(self.out, "{}barrier();", level)?; + writeln!(self.out, "{level}barrier();")?; Ok(()) } diff --git a/src/back/hlsl/conv.rs b/src/back/hlsl/conv.rs index 819ddb4d43..1773ed71bc 100644 --- a/src/back/hlsl/conv.rs +++ b/src/back/hlsl/conv.rs @@ -175,10 +175,10 @@ impl crate::BuiltIn { // in `Writer::write_expr`. Self::NumWorkGroups => "SV_GroupID", Self::BaseInstance | Self::BaseVertex | Self::WorkGroupSize => { - return Err(Error::Unimplemented(format!("builtin {:?}", self))) + return Err(Error::Unimplemented(format!("builtin {self:?}"))) } Self::ViewIndex | Self::PointCoord => { - return Err(Error::Custom(format!("Unsupported builtin {:?}", self))) + return Err(Error::Custom(format!("Unsupported builtin {self:?}"))) } }) } diff --git a/src/back/hlsl/help.rs b/src/back/hlsl/help.rs index bea6220e78..bb18bf3ab4 100644 --- a/src/back/hlsl/help.rs +++ b/src/back/hlsl/help.rs @@ -125,20 +125,20 @@ impl<'a, W: Write> super::Writer<'a, W> { }; let dim_str = dim.to_hlsl_str(); let arrayed_str = if arrayed { "Array" } else { "" }; - write!(self.out, "{}Texture{}{}", access_str, dim_str, arrayed_str)?; + write!(self.out, "{access_str}Texture{dim_str}{arrayed_str}")?; match class { crate::ImageClass::Depth { multi } => { let multi_str = if multi { "MS" } else { "" }; - write!(self.out, "{}", multi_str)? + write!(self.out, "{multi_str}")? } crate::ImageClass::Sampled { kind, multi } => { let multi_str = if multi { "MS" } else { "" }; let scalar_kind_str = kind.to_hlsl_str(4)?; - write!(self.out, "{}<{}4>", multi_str, scalar_kind_str)? + write!(self.out, "{multi_str}<{scalar_kind_str}4>")? } crate::ImageClass::Storage { format, .. } => { let storage_format_str = format.to_hlsl_str(); - write!(self.out, "<{}>", storage_format_str)? + write!(self.out, "<{storage_format_str}>")? } } Ok(()) @@ -149,7 +149,7 @@ impl<'a, W: Write> super::Writer<'a, W> { query: WrappedArrayLength, ) -> BackendResult { let access_str = if query.writable { "RW" } else { "" }; - write!(self.out, "NagaBufferLength{}", access_str,)?; + write!(self.out, "NagaBufferLength{access_str}",)?; Ok(()) } @@ -180,22 +180,20 @@ impl<'a, W: Write> super::Writer<'a, W> { let access_str = if wal.writable { "RW" } else { "" }; writeln!( self.out, - "{}ByteAddressBuffer {})", - access_str, ARGUMENT_VARIABLE_NAME + "{access_str}ByteAddressBuffer {ARGUMENT_VARIABLE_NAME})" )?; // Write function body writeln!(self.out, "{{")?; // Write `GetDimensions` function. - writeln!(self.out, "{}uint {};", INDENT, RETURN_VARIABLE_NAME)?; + writeln!(self.out, "{INDENT}uint {RETURN_VARIABLE_NAME};")?; writeln!( self.out, - "{}{}.GetDimensions({});", - INDENT, ARGUMENT_VARIABLE_NAME, RETURN_VARIABLE_NAME + "{INDENT}{ARGUMENT_VARIABLE_NAME}.GetDimensions({RETURN_VARIABLE_NAME});" )?; // Write return value - writeln!(self.out, "{}return {};", INDENT, RETURN_VARIABLE_NAME)?; + writeln!(self.out, "{INDENT}return {RETURN_VARIABLE_NAME};")?; // End of function body writeln!(self.out, "}}")?; @@ -226,11 +224,7 @@ impl<'a, W: Write> super::Writer<'a, W> { ImageQuery::NumSamples => "NumSamples", }; - write!( - self.out, - "Naga{}{}{}{}", - class_str, query_str, dim_str, arrayed_str - )?; + write!(self.out, "Naga{class_str}{query_str}{dim_str}{arrayed_str}")?; Ok(()) } @@ -264,10 +258,10 @@ impl<'a, W: Write> super::Writer<'a, W> { write!(self.out, "(")?; // Texture always first parameter self.write_image_type(wiq.dim, wiq.arrayed, wiq.class)?; - write!(self.out, " {}", ARGUMENT_VARIABLE_NAME)?; + write!(self.out, " {ARGUMENT_VARIABLE_NAME}")?; // Mipmap is a second parameter if exists if let ImageQuery::SizeLevel = wiq.query { - write!(self.out, ", uint {}", MIP_LEVEL_PARAM)?; + write!(self.out, ", uint {MIP_LEVEL_PARAM}")?; } writeln!(self.out, ")")?; @@ -303,15 +297,11 @@ impl<'a, W: Write> super::Writer<'a, W> { }; // Write `GetDimensions` function. - writeln!(self.out, "{}uint4 {};", INDENT, RETURN_VARIABLE_NAME)?; - write!( - self.out, - "{}{}.GetDimensions(", - INDENT, ARGUMENT_VARIABLE_NAME - )?; + writeln!(self.out, "{INDENT}uint4 {RETURN_VARIABLE_NAME};")?; + write!(self.out, "{INDENT}{ARGUMENT_VARIABLE_NAME}.GetDimensions(")?; match wiq.query { ImageQuery::SizeLevel => { - write!(self.out, "{}, ", MIP_LEVEL_PARAM)?; + write!(self.out, "{MIP_LEVEL_PARAM}, ")?; } _ => match wiq.class { crate::ImageClass::Sampled { multi: true, .. } @@ -325,7 +315,7 @@ impl<'a, W: Write> super::Writer<'a, W> { } for component in COMPONENTS[..number_of_params - 1].iter() { - write!(self.out, "{}.{}, ", RETURN_VARIABLE_NAME, component)?; + write!(self.out, "{RETURN_VARIABLE_NAME}.{component}, ")?; } // write last parameter without comma and space for last parameter @@ -341,8 +331,7 @@ impl<'a, W: Write> super::Writer<'a, W> { // Write return value writeln!( self.out, - "{}return {}.{};", - INDENT, RETURN_VARIABLE_NAME, ret_swizzle + "{INDENT}return {RETURN_VARIABLE_NAME}.{ret_swizzle};" )?; // End of function body @@ -364,7 +353,7 @@ impl<'a, W: Write> super::Writer<'a, W> { &module.constants, &self.names, )?; - write!(self.out, "Construct{}", name)?; + write!(self.out, "Construct{name}")?; Ok(()) } @@ -404,7 +393,7 @@ impl<'a, W: Write> super::Writer<'a, W> { write!(self.out, ", ")?; } self.write_type(module, ty)?; - write!(self.out, " {}{}", ARGUMENT_VARIABLE_NAME, i)?; + write!(self.out, " {ARGUMENT_VARIABLE_NAME}{i}")?; if let crate::TypeInner::Array { base, size, .. } = module.types[ty].inner { self.write_array_size(module, base, size)?; } @@ -440,8 +429,7 @@ impl<'a, W: Write> super::Writer<'a, W> { let struct_name = &self.names[&NameKey::Type(constructor.ty)]; writeln!( self.out, - "{}{} {} = ({})0;", - INDENT, struct_name, RETURN_VARIABLE_NAME, struct_name + "{INDENT}{struct_name} {RETURN_VARIABLE_NAME} = ({struct_name})0;" )?; for (i, member) in members.iter().enumerate() { let field_name = &self.names[&NameKey::StructMember(constructor.ty, i as u32)]; @@ -455,14 +443,7 @@ impl<'a, W: Write> super::Writer<'a, W> { for j in 0..columns as u8 { writeln!( self.out, - "{}{}.{}_{} = {}{}[{}];", - INDENT, - RETURN_VARIABLE_NAME, - field_name, - j, - ARGUMENT_VARIABLE_NAME, - i, - j + "{INDENT}{RETURN_VARIABLE_NAME}.{field_name}_{j} = {ARGUMENT_VARIABLE_NAME}{i}[{j}];" )?; } } @@ -484,16 +465,11 @@ impl<'a, W: Write> super::Writer<'a, W> { if let crate::TypeInner::Array { base, size, .. } = *other { self.write_array_size(module, base, size)?; } - writeln!(self.out, "){}{};", ARGUMENT_VARIABLE_NAME, i,)?; + writeln!(self.out, "){ARGUMENT_VARIABLE_NAME}{i};",)?; } else { writeln!( self.out, - "{}{}.{} = {}{};", - INDENT, - RETURN_VARIABLE_NAME, - field_name, - ARGUMENT_VARIABLE_NAME, - i, + "{INDENT}{RETURN_VARIABLE_NAME}.{field_name} = {ARGUMENT_VARIABLE_NAME}{i};", )?; } } @@ -505,9 +481,9 @@ impl<'a, W: Write> super::Writer<'a, W> { size: crate::ArraySize::Constant(size), .. } => { - write!(self.out, "{}", INDENT)?; + write!(self.out, "{INDENT}")?; self.write_type(module, base)?; - write!(self.out, " {}", RETURN_VARIABLE_NAME)?; + write!(self.out, " {RETURN_VARIABLE_NAME}")?; self.write_array_size(module, base, crate::ArraySize::Constant(size))?; write!(self.out, " = {{ ")?; let count = module.constants[size].to_array_length().unwrap(); @@ -515,7 +491,7 @@ impl<'a, W: Write> super::Writer<'a, W> { if i != 0 { write!(self.out, ", ")?; } - write!(self.out, "{}{}", ARGUMENT_VARIABLE_NAME, i)?; + write!(self.out, "{ARGUMENT_VARIABLE_NAME}{i}")?; } writeln!(self.out, " }};",)?; } @@ -523,7 +499,7 @@ impl<'a, W: Write> super::Writer<'a, W> { } // Write return value - writeln!(self.out, "{}return {};", INDENT, RETURN_VARIABLE_NAME)?; + writeln!(self.out, "{INDENT}return {RETURN_VARIABLE_NAME};")?; // End of function body writeln!(self.out, "}}")?; @@ -539,7 +515,7 @@ impl<'a, W: Write> super::Writer<'a, W> { ) -> BackendResult { let name = &self.names[&NameKey::Type(access.ty)]; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; - write!(self.out, "GetMat{}On{}", field_name, name)?; + write!(self.out, "GetMat{field_name}On{name}")?; Ok(()) } @@ -566,17 +542,13 @@ impl<'a, W: Write> super::Writer<'a, W> { // Write function parameters write!(self.out, "(")?; let struct_name = &self.names[&NameKey::Type(access.ty)]; - write!( - self.out, - "{} {}", - struct_name, STRUCT_ARGUMENT_VARIABLE_NAME - )?; + write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}")?; // Write function body writeln!(self.out, ") {{")?; // Write return value - write!(self.out, "{}return ", INDENT)?; + write!(self.out, "{INDENT}return ")?; self.write_value_type(module, ret_ty)?; write!(self.out, "(")?; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; @@ -586,11 +558,7 @@ impl<'a, W: Write> super::Writer<'a, W> { if i != 0 { write!(self.out, ", ")?; } - write!( - self.out, - "{}.{}_{}", - STRUCT_ARGUMENT_VARIABLE_NAME, field_name, i - )?; + write!(self.out, "{STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i}")?; } } _ => unreachable!(), @@ -611,7 +579,7 @@ impl<'a, W: Write> super::Writer<'a, W> { ) -> BackendResult { let name = &self.names[&NameKey::Type(access.ty)]; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; - write!(self.out, "SetMat{}On{}", field_name, name)?; + write!(self.out, "SetMat{field_name}On{name}")?; Ok(()) } @@ -633,17 +601,13 @@ impl<'a, W: Write> super::Writer<'a, W> { // Write function parameters write!(self.out, "(")?; let struct_name = &self.names[&NameKey::Type(access.ty)]; - write!( - self.out, - "{} {}, ", - struct_name, STRUCT_ARGUMENT_VARIABLE_NAME - )?; + write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?; let member = match module.types[access.ty].inner { crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize], _ => unreachable!(), }; self.write_type(module, member.ty)?; - write!(self.out, " {}", MATRIX_ARGUMENT_VARIABLE_NAME)?; + write!(self.out, " {MATRIX_ARGUMENT_VARIABLE_NAME}")?; // Write function body writeln!(self.out, ") {{")?; @@ -654,13 +618,7 @@ impl<'a, W: Write> super::Writer<'a, W> { for i in 0..columns as u8 { writeln!( self.out, - "{}{}.{}_{} = {}[{}];", - INDENT, - STRUCT_ARGUMENT_VARIABLE_NAME, - field_name, - i, - MATRIX_ARGUMENT_VARIABLE_NAME, - i + "{INDENT}{STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i} = {MATRIX_ARGUMENT_VARIABLE_NAME}[{i}];" )?; } } @@ -681,7 +639,7 @@ impl<'a, W: Write> super::Writer<'a, W> { ) -> BackendResult { let name = &self.names[&NameKey::Type(access.ty)]; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; - write!(self.out, "SetMatVec{}On{}", field_name, name)?; + write!(self.out, "SetMatVec{field_name}On{name}")?; Ok(()) } @@ -704,11 +662,7 @@ impl<'a, W: Write> super::Writer<'a, W> { // Write function parameters write!(self.out, "(")?; let struct_name = &self.names[&NameKey::Type(access.ty)]; - write!( - self.out, - "{} {}, ", - struct_name, STRUCT_ARGUMENT_VARIABLE_NAME - )?; + write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?; let member = match module.types[access.ty].inner { crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize], _ => unreachable!(), @@ -724,8 +678,7 @@ impl<'a, W: Write> super::Writer<'a, W> { self.write_value_type(module, &vec_ty)?; write!( self.out, - " {}, uint {}", - VECTOR_ARGUMENT_VARIABLE_NAME, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME + " {VECTOR_ARGUMENT_VARIABLE_NAME}, uint {MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}" )?; // Write function body @@ -733,8 +686,7 @@ impl<'a, W: Write> super::Writer<'a, W> { writeln!( self.out, - "{}switch({}) {{", - INDENT, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME + "{INDENT}switch({MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}) {{" )?; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; @@ -744,20 +696,14 @@ impl<'a, W: Write> super::Writer<'a, W> { for i in 0..columns as u8 { writeln!( self.out, - "{}case {}: {{ {}.{}_{} = {}; break; }}", - INDENT, - i, - STRUCT_ARGUMENT_VARIABLE_NAME, - field_name, - i, - VECTOR_ARGUMENT_VARIABLE_NAME + "{INDENT}case {i}: {{ {STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i} = {VECTOR_ARGUMENT_VARIABLE_NAME}; break; }}" )?; } } _ => unreachable!(), } - writeln!(self.out, "{}}}", INDENT)?; + writeln!(self.out, "{INDENT}}}")?; // End of function body writeln!(self.out, "}}")?; @@ -773,7 +719,7 @@ impl<'a, W: Write> super::Writer<'a, W> { ) -> BackendResult { let name = &self.names[&NameKey::Type(access.ty)]; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; - write!(self.out, "SetMatScalar{}On{}", field_name, name)?; + write!(self.out, "SetMatScalar{field_name}On{name}")?; Ok(()) } @@ -797,11 +743,7 @@ impl<'a, W: Write> super::Writer<'a, W> { // Write function parameters write!(self.out, "(")?; let struct_name = &self.names[&NameKey::Type(access.ty)]; - write!( - self.out, - "{} {}, ", - struct_name, STRUCT_ARGUMENT_VARIABLE_NAME - )?; + write!(self.out, "{struct_name} {STRUCT_ARGUMENT_VARIABLE_NAME}, ")?; let member = match module.types[access.ty].inner { crate::TypeInner::Struct { ref members, .. } => &members[access.index as usize], _ => unreachable!(), @@ -816,10 +758,7 @@ impl<'a, W: Write> super::Writer<'a, W> { self.write_value_type(module, &scalar_ty)?; write!( self.out, - " {}, uint {}, uint {}", - SCALAR_ARGUMENT_VARIABLE_NAME, - MATRIX_INDEX_ARGUMENT_VARIABLE_NAME, - VECTOR_INDEX_ARGUMENT_VARIABLE_NAME + " {SCALAR_ARGUMENT_VARIABLE_NAME}, uint {MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}, uint {VECTOR_INDEX_ARGUMENT_VARIABLE_NAME}" )?; // Write function body @@ -827,8 +766,7 @@ impl<'a, W: Write> super::Writer<'a, W> { writeln!( self.out, - "{}switch({}) {{", - INDENT, MATRIX_INDEX_ARGUMENT_VARIABLE_NAME + "{INDENT}switch({MATRIX_INDEX_ARGUMENT_VARIABLE_NAME}) {{" )?; let field_name = &self.names[&NameKey::StructMember(access.ty, access.index)]; @@ -838,21 +776,14 @@ impl<'a, W: Write> super::Writer<'a, W> { for i in 0..columns as u8 { writeln!( self.out, - "{}case {}: {{ {}.{}_{}[{}] = {}; break; }}", - INDENT, - i, - STRUCT_ARGUMENT_VARIABLE_NAME, - field_name, - i, - VECTOR_INDEX_ARGUMENT_VARIABLE_NAME, - SCALAR_ARGUMENT_VARIABLE_NAME + "{INDENT}case {i}: {{ {STRUCT_ARGUMENT_VARIABLE_NAME}.{field_name}_{i}[{VECTOR_INDEX_ARGUMENT_VARIABLE_NAME}] = {SCALAR_ARGUMENT_VARIABLE_NAME}; break; }}" )?; } } _ => unreachable!(), } - writeln!(self.out, "{}}}", INDENT)?; + writeln!(self.out, "{INDENT}}}")?; // End of function body writeln!(self.out, "}}")?; @@ -1088,7 +1019,7 @@ impl<'a, W: Write> super::Writer<'a, W> { // typedef write!(self.out, "typedef struct {{ ")?; for i in 0..columns as u8 { - write!(self.out, "float2 _{}; ", i)?; + write!(self.out, "float2 _{i}; ")?; } writeln!(self.out, "}} __mat{}x2;", columns as u8)?; @@ -1098,12 +1029,12 @@ impl<'a, W: Write> super::Writer<'a, W> { "float2 __get_col_of_mat{}x2(__mat{}x2 mat, uint idx) {{", columns as u8, columns as u8 )?; - writeln!(self.out, "{}switch(idx) {{", INDENT)?; + writeln!(self.out, "{INDENT}switch(idx) {{")?; for i in 0..columns as u8 { - writeln!(self.out, "{}case {}: {{ return mat._{}; }}", INDENT, i, i)?; + writeln!(self.out, "{INDENT}case {i}: {{ return mat._{i}; }}")?; } - writeln!(self.out, "{}default: {{ return (float2)0; }}", INDENT)?; - writeln!(self.out, "{}}}", INDENT)?; + writeln!(self.out, "{INDENT}default: {{ return (float2)0; }}")?; + writeln!(self.out, "{INDENT}}}")?; writeln!(self.out, "}}")?; // __set_col_of_mat @@ -1112,15 +1043,11 @@ impl<'a, W: Write> super::Writer<'a, W> { "void __set_col_of_mat{}x2(__mat{}x2 mat, uint idx, float2 value) {{", columns as u8, columns as u8 )?; - writeln!(self.out, "{}switch(idx) {{", INDENT)?; + writeln!(self.out, "{INDENT}switch(idx) {{")?; for i in 0..columns as u8 { - writeln!( - self.out, - "{}case {}: {{ mat._{} = value; break; }}", - INDENT, i, i - )?; + writeln!(self.out, "{INDENT}case {i}: {{ mat._{i} = value; break; }}")?; } - writeln!(self.out, "{}}}", INDENT)?; + writeln!(self.out, "{INDENT}}}")?; writeln!(self.out, "}}")?; // __set_el_of_mat @@ -1129,15 +1056,14 @@ impl<'a, W: Write> super::Writer<'a, W> { "void __set_el_of_mat{}x2(__mat{}x2 mat, uint idx, uint vec_idx, float value) {{", columns as u8, columns as u8 )?; - writeln!(self.out, "{}switch(idx) {{", INDENT)?; + writeln!(self.out, "{INDENT}switch(idx) {{")?; for i in 0..columns as u8 { writeln!( self.out, - "{}case {}: {{ mat._{}[vec_idx] = value; break; }}", - INDENT, i, i + "{INDENT}case {i}: {{ mat._{i}[vec_idx] = value; break; }}" )?; } - writeln!(self.out, "{}}}", INDENT)?; + writeln!(self.out, "{INDENT}}}")?; writeln!(self.out, "}}")?; writeln!(self.out)?; diff --git a/src/back/hlsl/storage.rs b/src/back/hlsl/storage.rs index 4397150453..21396c953a 100644 --- a/src/back/hlsl/storage.rs +++ b/src/back/hlsl/storage.rs @@ -53,11 +53,11 @@ impl super::Writer<'_, W> { } match *access { SubAccess::Offset(offset) => { - write!(self.out, "{}", offset)?; + write!(self.out, "{offset}")?; } SubAccess::Index { value, stride } => { self.write_expr(module, value, func_ctx)?; - write!(self.out, "*{}", stride)?; + write!(self.out, "*{stride}")?; } } } @@ -97,7 +97,7 @@ impl super::Writer<'_, W> { let chain = mem::take(&mut self.temp_access_chain); let var_name = &self.names[&NameKey::GlobalVariable(var_handle)]; let cast = kind.to_hlsl_cast(); - write!(self.out, "{}({}.Load(", cast, var_name)?; + write!(self.out, "{cast}({var_name}.Load(")?; self.write_storage_address(module, &chain, func_ctx)?; write!(self.out, "))")?; self.temp_access_chain = chain; @@ -183,14 +183,14 @@ impl super::Writer<'_, W> { depth, index, ty: _, - } => write!(self.out, "{}{}[{}]", STORE_TEMP_NAME, depth, index)?, + } => write!(self.out, "{STORE_TEMP_NAME}{depth}[{index}]")?, StoreValue::TempAccess { depth, base, member_index, } => { let name = &self.names[&NameKey::StructMember(base, member_index)]; - write!(self.out, "{}{}.{}", STORE_TEMP_NAME, depth, name)? + write!(self.out, "{STORE_TEMP_NAME}{depth}.{name}")? } } Ok(()) @@ -233,7 +233,7 @@ impl super::Writer<'_, W> { // working around the borrow checker in `self.write_expr` let chain = mem::take(&mut self.temp_access_chain); let var_name = &self.names[&NameKey::GlobalVariable(var_handle)]; - write!(self.out, "{}{}.Store(", level, var_name)?; + write!(self.out, "{level}{var_name}.Store(")?; self.write_storage_address(module, &chain, func_ctx)?; write!(self.out, ", asuint(")?; self.write_store_value(module, &value, func_ctx)?; @@ -257,7 +257,7 @@ impl super::Writer<'_, W> { width, } => { // first, assign the value to a temporary - writeln!(self.out, "{}{{", level)?; + writeln!(self.out, "{level}{{")?; let depth = level.0 + 1; write!( self.out, @@ -293,7 +293,7 @@ impl super::Writer<'_, W> { self.temp_access_chain.pop(); } // done - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } crate::TypeInner::Array { base, @@ -301,11 +301,11 @@ impl super::Writer<'_, W> { .. } => { // first, assign the value to a temporary - writeln!(self.out, "{}{{", level)?; + writeln!(self.out, "{level}{{")?; write!(self.out, "{}", level.next())?; self.write_value_type(module, &module.types[base].inner)?; let depth = level.next().0; - write!(self.out, " {}{}", STORE_TEMP_NAME, depth)?; + write!(self.out, " {STORE_TEMP_NAME}{depth}")?; self.write_array_size(module, base, crate::ArraySize::Constant(const_handle))?; write!(self.out, " = ")?; self.write_store_value(module, &value, func_ctx)?; @@ -324,11 +324,11 @@ impl super::Writer<'_, W> { self.temp_access_chain.pop(); } // done - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } crate::TypeInner::Struct { ref members, .. } => { // first, assign the value to a temporary - writeln!(self.out, "{}{{", level)?; + writeln!(self.out, "{level}{{")?; let depth = level.next().0; let struct_ty = ty_resolution.handle().unwrap(); let struct_name = &self.names[&NameKey::Type(struct_ty)]; @@ -355,7 +355,7 @@ impl super::Writer<'_, W> { self.temp_access_chain.pop(); } // done - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } _ => unreachable!(), } @@ -386,10 +386,7 @@ impl super::Writer<'_, W> { (base, AccessIndex::Constant(index)) } ref other => { - return Err(Error::Unimplemented(format!( - "Pointer access of {:?}", - other - ))) + return Err(Error::Unimplemented(format!("Pointer access of {other:?}"))) } }; diff --git a/src/back/hlsl/writer.rs b/src/back/hlsl/writer.rs index 664b326a16..1641c2ee02 100644 --- a/src/back/hlsl/writer.rs +++ b/src/back/hlsl/writer.rs @@ -104,7 +104,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { // Write special constants, if needed if let Some(ref bt) = self.options.special_constants_binding { - writeln!(self.out, "struct {} {{", SPECIAL_CBUF_TYPE)?; + writeln!(self.out, "struct {SPECIAL_CBUF_TYPE} {{")?; writeln!(self.out, "{}int {};", back::INDENT, SPECIAL_BASE_VERTEX)?; writeln!(self.out, "{}int {};", back::INDENT, SPECIAL_BASE_INSTANCE)?; writeln!(self.out, "{}uint {};", back::INDENT, SPECIAL_OTHER)?; @@ -320,13 +320,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } => { if let Some(interpolation) = interpolation { if let Some(string) = interpolation.to_hlsl_str() { - write!(self.out, "{} ", string)? + write!(self.out, "{string} ")? } } if let Some(sampling) = sampling { if let Some(string) = sampling.to_hlsl_str() { - write!(self.out, "{} ", string)? + write!(self.out, "{string} ")? } } } @@ -346,13 +346,13 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { match *binding { crate::Binding::BuiltIn(builtin) => { let builtin_str = builtin.to_hlsl_str()?; - write!(self.out, " : {}", builtin_str)?; + write!(self.out, " : {builtin_str}")?; } crate::Binding::Location { location, .. } => { if stage == Some((crate::ShaderStage::Fragment, Io::Output)) { - write!(self.out, " : SV_Target{}", location)?; + write!(self.out, " : SV_Target{location}")?; } else { - write!(self.out, " : {}{}", LOCATION_SEMANTIC, location)?; + write!(self.out, " : {LOCATION_SEMANTIC}{location}")?; } } } @@ -372,7 +372,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { // interfaces to match with regards to order. members.sort_by_key(|m| InterfaceKey::new(m.binding.as_ref())); - write!(self.out, "struct {}", struct_name)?; + write!(self.out, "struct {struct_name}")?; writeln!(self.out, " {{")?; for m in members.iter() { write!(self.out, "{}", back::INDENT)?; @@ -416,7 +416,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { stage: ShaderStage, entry_point_name: &str, ) -> Result { - let struct_name = format!("{:?}Input_{}", stage, entry_point_name); + let struct_name = format!("{stage:?}Input_{entry_point_name}"); let mut fake_members = Vec::new(); for arg in func.arguments.iter() { @@ -459,7 +459,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { stage: ShaderStage, entry_point_name: &str, ) -> Result { - let struct_name = format!("{:?}Output_{}", stage, entry_point_name); + let struct_name = format!("{stage:?}Output_{entry_point_name}"); let mut fake_members = Vec::new(); let empty = []; @@ -526,7 +526,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, "{}", back::INDENT)?; self.write_type(module, arg.ty)?; let arg_name = &self.names[&NameKey::EntryPointArgument(ep_index, arg_index as u32)]; - write!(self.out, " {}", arg_name)?; + write!(self.out, " {arg_name}")?; match module.types[arg.ty].inner { TypeInner::Array { base, size, .. } => { self.write_array_size(module, base, size)?; @@ -602,7 +602,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } else { ("", "t") }; - write!(self.out, "{}ByteAddressBuffer", prefix)?; + write!(self.out, "{prefix}ByteAddressBuffer")?; register } crate::AddressSpace::Handle => { @@ -645,7 +645,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } let name = &self.names[&NameKey::GlobalVariable(handle)]; - write!(self.out, " {}", name)?; + write!(self.out, " {name}")?; // Push constants need to be assigned a binding explicitly by the consumer // since naga has no way to know the binding from the shader alone @@ -669,7 +669,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { // need to write the binding array size if the type was emitted with `write_type` if let TypeInner::BindingArray { base, size, .. } = module.types[global.ty].inner { if let Some(overridden_size) = bt.binding_array_size { - write!(self.out, "[{}]", overridden_size)?; + write!(self.out, "[{overridden_size}]")?; } else { self.write_array_size(module, base, size)?; } @@ -743,24 +743,24 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { crate::ScalarValue::Bool(_) => "bool", }; let name = &self.names[&NameKey::Constant(handle)]; - write!(self.out, "{} {} = ", ty_str, name)?; + write!(self.out, "{ty_str} {name} = ")?; // Second match required to avoid heap allocation by `format!()` match *value { - crate::ScalarValue::Sint(value) => write!(self.out, "{}", value)?, - crate::ScalarValue::Uint(value) => write!(self.out, "{}", value)?, + crate::ScalarValue::Sint(value) => write!(self.out, "{value}")?, + crate::ScalarValue::Uint(value) => write!(self.out, "{value}")?, crate::ScalarValue::Float(value) => { // Floats are written using `Debug` instead of `Display` because it always appends the // decimal part even it's zero - write!(self.out, "{:?}", value)? + write!(self.out, "{value:?}")? } - crate::ScalarValue::Bool(value) => write!(self.out, "{}", value)?, + crate::ScalarValue::Bool(value) => write!(self.out, "{value}")?, }; } crate::ConstantInner::Composite { ty, ref components } => { self.write_type(module, ty)?; let name = &self.names[&NameKey::Constant(handle)]; - write!(self.out, " {} = ", name)?; + write!(self.out, " {name} = ")?; self.write_composite_constant(module, ty, components)?; } } @@ -782,7 +782,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { match size { crate::ArraySize::Constant(const_handle) => { let size = module.constants[const_handle].to_array_length().unwrap(); - write!(self.out, "{}", size)?; + write!(self.out, "{size}")?; } crate::ArraySize::Dynamic => {} } @@ -815,7 +815,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { ) -> BackendResult { // Write struct name let struct_name = &self.names[&NameKey::Type(handle)]; - writeln!(self.out, "struct {} {{", struct_name)?; + writeln!(self.out, "struct {struct_name} {{")?; let mut last_offset = 0; for (index, member) in members.iter().enumerate() { @@ -1011,7 +1011,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } else { "SamplerState" }; - write!(self.out, "{}", sampler)?; + write!(self.out, "{sampler}")?; } // HLSL arrays are written as `type name[size]` // Current code is written arrays only as `[size]` @@ -1019,12 +1019,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { TypeInner::Array { base, size, .. } | TypeInner::BindingArray { base, size } => { self.write_array_size(module, base, size)?; } - _ => { - return Err(Error::Unimplemented(format!( - "write_value_type {:?}", - inner - ))) - } + _ => return Err(Error::Unimplemented(format!("write_value_type {inner:?}"))), } Ok(()) @@ -1075,7 +1070,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } // Write function name - write!(self.out, " {}(", name)?; + write!(self.out, " {name}(")?; let need_workgroup_variables_initialization = self.need_workgroup_variables_initialization(func_ctx, module); @@ -1103,7 +1098,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { &self.names[&NameKey::FunctionArgument(handle, index as u32)]; // Write argument name. Space is important. - write!(self.out, " {}", argument_name)?; + write!(self.out, " {argument_name}")?; if let TypeInner::Array { base, size, .. } = module.types[arg.ty].inner { self.write_array_size(module, base, size)?; } @@ -1123,7 +1118,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let argument_name = &self.names[&NameKey::EntryPointArgument(ep_index, index as u32)]; - write!(self.out, " {}", argument_name)?; + write!(self.out, " {argument_name}")?; if let TypeInner::Array { base, size, .. } = module.types[arg.ty].inner { self.write_array_size(module, base, size)?; } @@ -1242,8 +1237,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { writeln!( self.out, - "{}if (all(__global_invocation_id == uint3(0u, 0u, 0u))) {{", - level + "{level}if (all(__global_invocation_id == uint3(0u, 0u, 0u))) {{" )?; let vars = module.global_variables.iter().filter(|&(handle, var)| { @@ -1257,7 +1251,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { writeln!(self.out, ";")?; } - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; self.write_barrier(crate::Barrier::WORK_GROUP, level) } @@ -1302,20 +1296,20 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }; if let Some(name) = expr_name { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_named_expr(module, handle, name, func_ctx)?; } } } // TODO: copy-paste from glsl-out Statement::Block(ref block) => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "{{")?; for sta in block.iter() { // Increase the indentation to help with readability self.write_stmt(module, sta, func_ctx, level.next())? } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // TODO: copy-paste from glsl-out Statement::If { @@ -1323,7 +1317,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { ref accept, ref reject, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "if (")?; self.write_expr(module, condition, func_ctx)?; writeln!(self.out, ") {{")?; @@ -1337,7 +1331,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { // If there are no statements in the reject block we skip writing it // This is only for readability if !reject.is_empty() { - writeln!(self.out, "{}}} else {{", level)?; + writeln!(self.out, "{level}}} else {{")?; for sta in reject { // Increase indentation to help with readability @@ -1345,12 +1339,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } // TODO: copy-paste from glsl-out - Statement::Kill => writeln!(self.out, "{}discard;", level)?, + Statement::Kill => writeln!(self.out, "{level}discard;")?, Statement::Return { value: None } => { - writeln!(self.out, "{}return;", level)?; + writeln!(self.out, "{level}return;")?; } Statement::Return { value: Some(expr) } => { let base_ty_res = &func_ctx.info[expr].ty; @@ -1364,11 +1358,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let ty = base_ty_res.handle().unwrap(); let struct_name = &self.names[&NameKey::Type(ty)]; let variable_name = self.namer.call(&struct_name.to_lowercase()); - write!( - self.out, - "{}const {} {} = ", - level, struct_name, variable_name, - )?; + write!(self.out, "{level}const {struct_name} {variable_name} = ",)?; self.write_expr(module, expr, func_ctx)?; writeln!(self.out, ";")?; @@ -1392,16 +1382,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, ", ")?; } let member_name = &self.names[&NameKey::StructMember(ty, m.index)]; - write!(self.out, "{}.{}", variable_name, member_name)?; + write!(self.out, "{variable_name}.{member_name}")?; } writeln!(self.out, " }};")?; final_name } None => variable_name, }; - writeln!(self.out, "{}return {};", level, final_name)?; + writeln!(self.out, "{level}return {final_name};")?; } else { - write!(self.out, "{}return ", level)?; + write!(self.out, "{level}return ")?; self.write_expr(module, expr, func_ctx)?; writeln!(self.out, ";")? } @@ -1507,7 +1497,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } } - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; if let Some(MatrixAccess { index, base }) = matrix { let base_ty_res = &func_ctx.info[base].ty; @@ -1530,7 +1520,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, "[")?; match scalar_index { Index::Static(index) => { - write!(self.out, "{}", index)?; + write!(self.out, "{index}")?; } Index::Expression(index) => { self.write_expr(module, index, func_ctx)?; @@ -1571,7 +1561,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, ", ")?; match scalar_index { Index::Static(index) => { - write!(self.out, "{}", index)?; + write!(self.out, "{index}")?; } Index::Expression(index) => { self.write_expr(module, index, func_ctx)?; @@ -1665,7 +1655,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, ", ")?; match scalar_index { Index::Static(index) => { - write!(self.out, "{}", index)?; + write!(self.out, "{index}")?; } Index::Expression(index) => { self.write_expr(module, index, func_ctx)?; @@ -1719,33 +1709,33 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let l2 = level.next(); if !continuing.is_empty() || break_if.is_some() { let gate_name = self.namer.call("loop_init"); - writeln!(self.out, "{}bool {} = true;", level, gate_name)?; - writeln!(self.out, "{}while(true) {{", level)?; - writeln!(self.out, "{}if (!{}) {{", l2, gate_name)?; + writeln!(self.out, "{level}bool {gate_name} = true;")?; + writeln!(self.out, "{level}while(true) {{")?; + writeln!(self.out, "{l2}if (!{gate_name}) {{")?; let l3 = l2.next(); for sta in continuing.iter() { self.write_stmt(module, sta, func_ctx, l3)?; } if let Some(condition) = break_if { - write!(self.out, "{}if (", l3)?; + write!(self.out, "{l3}if (")?; self.write_expr(module, condition, func_ctx)?; writeln!(self.out, ") {{")?; writeln!(self.out, "{}break;", l3.next())?; - writeln!(self.out, "{}}}", l3)?; + writeln!(self.out, "{l3}}}")?; } - writeln!(self.out, "{}}}", l2)?; - writeln!(self.out, "{}{} = false;", l2, gate_name)?; + writeln!(self.out, "{l2}}}")?; + writeln!(self.out, "{l2}{gate_name} = false;")?; } else { - writeln!(self.out, "{}while(true) {{", level)?; + writeln!(self.out, "{level}while(true) {{")?; } for sta in body.iter() { self.write_stmt(module, sta, func_ctx, l2)?; } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } - Statement::Break => writeln!(self.out, "{}break;", level)?, - Statement::Continue => writeln!(self.out, "{}continue;", level)?, + Statement::Break => writeln!(self.out, "{level}break;")?, + Statement::Continue => writeln!(self.out, "{level}continue;")?, Statement::Barrier(barrier) => { self.write_barrier(barrier, level)?; } @@ -1755,7 +1745,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { array_index, value, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.write_expr(module, image, func_ctx)?; write!(self.out, "[")?; @@ -1780,7 +1770,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { ref arguments, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; if let Some(expr) = result { write!(self.out, "const ")?; let name = format!("{}{}", back::BAKE_PREFIX, expr.index()); @@ -1791,11 +1781,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { self.write_value_type(module, value)? } }; - write!(self.out, " {} = ", name)?; + write!(self.out, " {name} = ")?; self.named_expressions.insert(expr, name); } let func_name = &self.names[&NameKey::Function(function)]; - write!(self.out, "{}(", func_name)?; + write!(self.out, "{func_name}(")?; for (index, argument) in arguments.iter().enumerate() { self.write_expr(module, *argument, func_ctx)?; // Only write a comma if isn't the last element @@ -1812,7 +1802,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { value, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; let res_name = format!("{}{}", back::BAKE_PREFIX, result.index()); match func_ctx.info[result].ty { proc::TypeResolution::Handle(handle) => self.write_type(module, handle)?, @@ -1827,11 +1817,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let var_name = &self.names[&NameKey::GlobalVariable(var_handle)]; let fun_str = fun.to_hlsl_suffix(); - write!( - self.out, - " {}; {}.Interlocked{}(", - res_name, var_name, fun_str - )?; + write!(self.out, " {res_name}; {var_name}.Interlocked{fun_str}(")?; self.write_storage_address(module, &chain, func_ctx)?; write!(self.out, ", ")?; // handle the special cases @@ -1846,7 +1832,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { _ => {} } self.write_expr(module, value, func_ctx)?; - writeln!(self.out, ", {});", res_name)?; + writeln!(self.out, ", {res_name});")?; self.temp_access_chain = chain; self.named_expressions.insert(result, res_name); } @@ -1855,7 +1841,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { ref cases, } => { // Start the switch - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "switch(")?; self.write_expr(module, selector, func_ctx)?; writeln!(self.out, ") {{")?; @@ -1873,13 +1859,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { for (i, case) in cases.iter().enumerate() { match case.value { - crate::SwitchValue::Integer(value) => write!( - self.out, - "{}case {}{}:", - indent_level_1, value, type_postfix - )?, + crate::SwitchValue::Integer(value) => { + write!(self.out, "{indent_level_1}case {value}{type_postfix}:")? + } crate::SwitchValue::Default => { - write!(self.out, "{}default:", indent_level_1)? + write!(self.out, "{indent_level_1}default:")? } } @@ -1923,16 +1907,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { .unwrap(); let indent_level_3 = indent_level_2.next(); for case in &cases[i..=end_case_idx] { - writeln!(self.out, "{}{{", indent_level_2)?; + writeln!(self.out, "{indent_level_2}{{")?; for sta in case.body.iter() { self.write_stmt(module, sta, func_ctx, indent_level_3)?; } - writeln!(self.out, "{}}}", indent_level_2)?; + writeln!(self.out, "{indent_level_2}}}")?; } let last_case = &cases[end_case_idx]; if last_case.body.last().map_or(true, |s| !s.is_terminator()) { - writeln!(self.out, "{}break;", indent_level_2)?; + writeln!(self.out, "{indent_level_2}break;")?; } } else { for sta in case.body.iter() { @@ -1941,16 +1925,16 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { if !case.fall_through && case.body.last().map_or(true, |s| !s.is_terminator()) { - writeln!(self.out, "{}break;", indent_level_2)?; + writeln!(self.out, "{indent_level_2}break;")?; } } if write_block_braces { - writeln!(self.out, "{}}}", indent_level_1)?; + writeln!(self.out, "{indent_level_1}}}")?; } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } } @@ -1977,15 +1961,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }; let closing_bracket = match ff_input { Some(crate::BuiltIn::VertexIndex) => { - write!(self.out, "({}.{} + ", SPECIAL_CBUF_VAR, SPECIAL_BASE_VERTEX)?; + write!(self.out, "({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_VERTEX} + ")?; ")" } Some(crate::BuiltIn::InstanceIndex) => { - write!( - self.out, - "({}.{} + ", - SPECIAL_CBUF_VAR, SPECIAL_BASE_INSTANCE, - )?; + write!(self.out, "({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_INSTANCE} + ",)?; ")" } Some(crate::BuiltIn::NumWorkGroups) => { @@ -1994,13 +1974,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { // of workgroups, which we are using here. write!( self.out, - "uint3({}.{}, {}.{}, {}.{})", - SPECIAL_CBUF_VAR, - SPECIAL_BASE_VERTEX, - SPECIAL_CBUF_VAR, - SPECIAL_BASE_INSTANCE, - SPECIAL_CBUF_VAR, - SPECIAL_OTHER, + "uint3({SPECIAL_CBUF_VAR}.{SPECIAL_BASE_VERTEX}, {SPECIAL_CBUF_VAR}.{SPECIAL_BASE_INSTANCE}, {SPECIAL_CBUF_VAR}.{SPECIAL_OTHER})", )?; return Ok(()); } @@ -2008,7 +1982,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }; if let Some(name) = self.named_expressions.get(&expr) { - write!(self.out, "{}{}", name, closing_bracket)?; + write!(self.out, "{name}{closing_bracket}")?; return Ok(()); } @@ -2177,7 +2151,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } TypeInner::Matrix { .. } | TypeInner::Array { .. } - | TypeInner::BindingArray { .. } => write!(writer.out, "[{}]", index)?, + | TypeInner::BindingArray { .. } => write!(writer.out, "[{index}]")?, TypeInner::Struct { .. } => { // This will never panic in case the type is a `Struct`, this is not true // for other types so we can only check while inside this match arm @@ -2190,7 +2164,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { )? } ref other => { - return Err(Error::Custom(format!("Cannot index {:?}", other))) + return Err(Error::Custom(format!("Cannot index {other:?}"))) } } Ok(()) @@ -2205,7 +2179,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }) = get_inner_matrix_of_struct_array_member(module, base, func_ctx, true) { self.write_expr(module, base, func_ctx)?; - write!(self.out, "._{}", index)?; + write!(self.out, "._{index}")?; return Ok(()); } @@ -2257,7 +2231,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } }; let name = &self.names[&key]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } Expression::ImageSample { image, @@ -2289,11 +2263,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }; self.write_expr(module, image, func_ctx)?; - write!( - self.out, - ".{}{}{}{}(", - base_str, cmp_str, component_str, level_str - )?; + write!(self.out, ".{base_str}{cmp_str}{component_str}{level_str}(")?; self.write_expr(module, sampler, func_ctx)?; write!(self.out, ", ")?; self.write_texture_coordinates( @@ -2399,7 +2369,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { crate::AddressSpace::Storage { .. } => {} _ => { let name = &self.names[&NameKey::GlobalVariable(handle)]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } }, Expression::LocalVariable(handle) => { @@ -2470,13 +2440,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Some(Sk::Bool) => "!", ref other => { return Err(Error::Custom(format!( - "Cannot apply not to type {:?}", - other + "Cannot apply not to type {other:?}" ))) } }, }; - write!(self.out, "{}(", op_str)?; + write!(self.out, "{op_str}(")?; self.write_expr(module, expr, func_ctx)?; write!(self.out, ")")?; } @@ -2511,8 +2480,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } _ => { return Err(Error::Unimplemented(format!( - "write_expr expression::as {:?}", - inner + "write_expr expression::as {inner:?}" ))); } }; @@ -2606,7 +2574,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Mf::FindLsb => Function::Regular("firstbitlow"), Mf::FindMsb => Function::Regular("firstbithigh"), Mf::Unpack2x16float => Function::Unpack2x16float, - _ => return Err(Error::Unimplemented(format!("write_expr_math {:?}", fun))), + _ => return Err(Error::Unimplemented(format!("write_expr_math {fun:?}"))), }; match fun { @@ -2637,7 +2605,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, ") >> 16))")?; } Function::Regular(fun_name) => { - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(module, arg, func_ctx)?; if let Some(arg) = arg1 { write!(self.out, ", ")?; @@ -2659,11 +2627,11 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { .inner_with(&module.types) .scalar_kind(); if let Some(ScalarKind::Sint) = *scalar_kind { - write!(self.out, "asint({}(asuint(", fun_name)?; + write!(self.out, "asint({fun_name}(asuint(")?; self.write_expr(module, arg, func_ctx)?; write!(self.out, ")))")?; } else { - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(module, arg, func_ctx)?; write!(self.out, ")")?; } @@ -2718,7 +2686,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { write!(self.out, "((")?; self.write_wrapped_array_length_function_name(wrapped_array_length)?; let var_name = &self.names[&NameKey::GlobalVariable(var_handle)]; - write!(self.out, "({}) - {}) / {})", var_name, offset, stride)? + write!(self.out, "({var_name}) - {offset}) / {stride})")? } Expression::Derivative { axis, expr } => { use crate::DerivativeAxis as Da; @@ -2728,7 +2696,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Da::Y => "ddy", Da::Width => "fwidth", }; - write!(self.out, "{}(", fun_str)?; + write!(self.out, "{fun_str}(")?; self.write_expr(module, expr, func_ctx)?; write!(self.out, ")")? } @@ -2743,7 +2711,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { Rf::IsFinite => "isfinite", Rf::IsNormal => "isnormal", }; - write!(self.out, "{}(", fun_str)?; + write!(self.out, "{fun_str}(")?; self.write_expr(module, argument, func_ctx)?; write!(self.out, ")")? } @@ -2758,7 +2726,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { }; write!(self.out, "(")?; self.write_expr(module, value, func_ctx)?; - write!(self.out, ").{}", number_of_components)? + write!(self.out, ").{number_of_components}")? } Expression::Select { condition, @@ -2778,7 +2746,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { } if !closing_bracket.is_empty() { - write!(self.out, "{}", closing_bracket)?; + write!(self.out, "{closing_bracket}")?; } Ok(()) } @@ -2848,12 +2816,12 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { use crate::ScalarValue as Sv; match value { - Sv::Sint(value) => write!(self.out, "{}", value)?, - Sv::Uint(value) => write!(self.out, "{}u", value)?, + Sv::Sint(value) => write!(self.out, "{value}")?, + Sv::Uint(value) => write!(self.out, "{value}u")?, // Floats are written using `Debug` instead of `Display` because it always appends the // decimal part even it's zero - Sv::Float(value) => write!(self.out, "{:?}", value)?, - Sv::Bool(value) => write!(self.out, "{}", value)?, + Sv::Float(value) => write!(self.out, "{value:?}")?, + Sv::Bool(value) => write!(self.out, "{value}")?, } Ok(()) @@ -2870,7 +2838,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { proc::TypeResolution::Handle(ty_handle) => match module.types[ty_handle].inner { TypeInner::Struct { .. } => { let ty_name = &self.names[&NameKey::Type(ty_handle)]; - write!(self.out, "{}", ty_name)?; + write!(self.out, "{ty_name}")?; } _ => { self.write_type(module, ty_handle)?; @@ -2884,7 +2852,7 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { let base_ty_res = &ctx.info[handle].ty; let resolved = base_ty_res.inner_with(&module.types); - write!(self.out, " {}", name)?; + write!(self.out, " {name}")?; // If rhs is a array type, we should write array size if let TypeInner::Array { base, size, .. } = *resolved { self.write_array_size(module, base, size)?; @@ -2910,10 +2878,10 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> { fn write_barrier(&mut self, barrier: crate::Barrier, level: back::Level) -> BackendResult { if barrier.contains(crate::Barrier::STORAGE) { - writeln!(self.out, "{}DeviceMemoryBarrierWithGroupSync();", level)?; + writeln!(self.out, "{level}DeviceMemoryBarrierWithGroupSync();")?; } if barrier.contains(crate::Barrier::WORK_GROUP) { - writeln!(self.out, "{}GroupMemoryBarrierWithGroupSync();", level)?; + writeln!(self.out, "{level}GroupMemoryBarrierWithGroupSync();")?; } Ok(()) } diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index 679e5ed29b..271557fbf2 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -412,16 +412,16 @@ impl ResolvedBinding { return Err(Error::UnsupportedBuiltIn(built_in)) } }; - write!(out, "{}", name)?; + write!(out, "{name}")?; } - Self::Attribute(index) => write!(out, "attribute({})", index)?, - Self::Color(index) => write!(out, "color({})", index)?, + Self::Attribute(index) => write!(out, "attribute({index})")?, + Self::Color(index) => write!(out, "color({index})")?, Self::User { prefix, index, interpolation, } => { - write!(out, "user({}{})", prefix, index)?; + write!(out, "user({prefix}{index})")?; if let Some(interpolation) = interpolation { write!(out, ", ")?; interpolation.try_fmt(out)?; @@ -429,11 +429,11 @@ impl ResolvedBinding { } Self::Resource(ref target) => { if let Some(id) = target.buffer { - write!(out, "buffer({})", id)?; + write!(out, "buffer({id})")?; } else if let Some(id) = target.texture { - write!(out, "texture({})", id)?; + write!(out, "texture({id})")?; } else if let Some(BindSamplerTarget::Resource(id)) = target.sampler { - write!(out, "sampler({})", id)?; + write!(out, "sampler({id})")?; } else { return Err(Error::UnimplementedBindTarget(target.clone())); } diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 5b505b358a..b72c76783b 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -82,7 +82,7 @@ impl<'a> Display for TypeContext<'a> { let ty = &self.module.types[self.handle]; if ty.needs_alias() && !self.first_time { let name = &self.names[&NameKey::Type(self.handle)]; - return write!(out, "{}", name); + return write!(out, "{name}"); } match ty.inner { @@ -104,7 +104,7 @@ impl<'a> Display for TypeContext<'a> { Some(name) => name, None => return Ok(()), }; - write!(out, "{} {}&", space_name, sub) + write!(out, "{space_name} {sub}&") } crate::TypeInner::ValuePointer { size, @@ -113,7 +113,7 @@ impl<'a> Display for TypeContext<'a> { space, } => { match space.to_msl_name() { - Some(name) => write!(out, "{} ", name)?, + Some(name) => write!(out, "{name} ")?, None => return Ok(()), }; match size { @@ -131,7 +131,7 @@ impl<'a> Display for TypeContext<'a> { }; // Array lengths go at the end of the type definition, // so just print the element type here. - write!(out, "{}", sub) + write!(out, "{sub}") } crate::TypeInner::Struct { .. } => unreachable!(), crate::TypeInner::Image { @@ -188,19 +188,11 @@ impl<'a> Display for TypeContext<'a> { let array_str = if arrayed { "_array" } else { "" }; write!( out, - "{}::{}{}{}{}<{}, {}::access::{}>", - NAMESPACE, - texture_str, - dim_str, - msaa_str, - array_str, - base_name, - NAMESPACE, - access, + "{NAMESPACE}::{texture_str}{dim_str}{msaa_str}{array_str}<{base_name}, {NAMESPACE}::access::{access}>", ) } crate::TypeInner::Sampler { comparison: _ } => { - write!(out, "{}::sampler", NAMESPACE) + write!(out, "{NAMESPACE}::sampler") } crate::TypeInner::BindingArray { base, size } => { let base_tyname = Self { @@ -214,11 +206,7 @@ impl<'a> Display for TypeContext<'a> { .. })) = self.binding { - write!( - out, - "{}::array<{}, {}>", - NAMESPACE, base_tyname, override_size - ) + write!(out, "{NAMESPACE}::array<{base_tyname}, {override_size}>") } else if let crate::ArraySize::Constant(size) = size { let constant_ctx = ConstantContext { handle: size, @@ -226,11 +214,7 @@ impl<'a> Display for TypeContext<'a> { names: self.names, first_time: false, }; - write!( - out, - "{}::array<{}, {}>", - NAMESPACE, base_tyname, constant_ctx - ) + write!(out, "{NAMESPACE}::array<{base_tyname}, {constant_ctx}>") } else { unreachable!("metal requires all arrays be constant sized"); } @@ -321,31 +305,31 @@ impl<'a> Display for ConstantContext<'a> { let con = &self.arena[self.handle]; if con.needs_alias() && !self.first_time { let name = &self.names[&NameKey::Constant(self.handle)]; - return write!(out, "{}", name); + return write!(out, "{name}"); } match con.inner { crate::ConstantInner::Scalar { value, width: _ } => match value { crate::ScalarValue::Sint(value) => { - write!(out, "{}", value) + write!(out, "{value}") } crate::ScalarValue::Uint(value) => { - write!(out, "{}u", value) + write!(out, "{value}u") } crate::ScalarValue::Float(value) => { if value.is_infinite() { let sign = if value.is_sign_negative() { "-" } else { "" }; - write!(out, "{}INFINITY", sign) + write!(out, "{sign}INFINITY") } else if value.is_nan() { write!(out, "NAN") } else { let suffix = if value.fract() == 0.0 { ".0" } else { "" }; - write!(out, "{}{}", value, suffix) + write!(out, "{value}{suffix}") } } crate::ScalarValue::Bool(value) => { - write!(out, "{}", value) + write!(out, "{value}") } }, crate::ConstantInner::Composite { .. } => unreachable!("should be aliased"), @@ -693,7 +677,7 @@ impl Writer { context: &ExpressionContext, ) -> BackendResult { self.put_expression(image, context, false)?; - write!(self.out, ".get_{}(", query)?; + write!(self.out, ".get_{query}(")?; if let Some(level) = level { self.put_level_of_detail(level, context)?; } @@ -731,14 +715,14 @@ impl Writer { } } crate::ImageDimension::D2 => { - write!(self.out, "{}::{}2(", NAMESPACE, coordinate_type)?; + write!(self.out, "{NAMESPACE}::{coordinate_type}2(")?; self.put_image_query(image, "width", level, context)?; write!(self.out, ", ")?; self.put_image_query(image, "height", level, context)?; write!(self.out, ")")?; } crate::ImageDimension::D3 => { - write!(self.out, "{}::{}3(", NAMESPACE, coordinate_type)?; + write!(self.out, "{NAMESPACE}::{coordinate_type}3(")?; self.put_image_query(image, "width", level, context)?; write!(self.out, ", ")?; self.put_image_query(image, "height", level, context)?; @@ -747,7 +731,7 @@ impl Writer { write!(self.out, ")")?; } crate::ImageDimension::Cube => { - write!(self.out, "{}::{}2(", NAMESPACE, coordinate_type)?; + write!(self.out, "{NAMESPACE}::{coordinate_type}2(")?; self.put_image_query(image, "width", level, context)?; write!(self.out, ")")?; } @@ -793,17 +777,17 @@ impl Writer { log::warn!("1D image can't be sampled with level {:?}", level); } crate::SampleLevel::Exact(h) => { - write!(self.out, ", {}::level(", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::level(")?; self.put_expression(h, context, true)?; write!(self.out, ")")?; } crate::SampleLevel::Bias(h) => { - write!(self.out, ", {}::bias(", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::bias(")?; self.put_expression(h, context, true)?; write!(self.out, ")")?; } crate::SampleLevel::Gradient { x, y } => { - write!(self.out, ", {}::gradient2d(", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::gradient2d(")?; self.put_expression(x, context, true)?; write!(self.out, ", ")?; self.put_expression(y, context, true)?; @@ -848,11 +832,11 @@ impl Writer { limit_method: &str, context: &ExpressionContext, ) -> BackendResult { - write!(self.out, "{}::min(uint(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::min(uint(")?; self.put_expression(index, context, true)?; write!(self.out, "), ")?; self.put_expression(image, context, false)?; - write!(self.out, ".{}() - 1)", limit_method)?; + write!(self.out, ".{limit_method}() - 1)")?; Ok(()) } @@ -863,7 +847,7 @@ impl Writer { context: &ExpressionContext, ) -> BackendResult { // Write the coordinate. - write!(self.out, "{}::min(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::min(")?; self.put_cast_to_uint_scalar_or_vector(address.coordinate, context)?; write!(self.out, ", ")?; self.put_image_coordinate_limits(image, address.level, context)?; @@ -926,7 +910,7 @@ impl Writer { // Check array index, if present. if let Some(array_index) = address.array_index { - write!(self.out, "{}uint(", conjunction)?; + write!(self.out, "{conjunction}uint(")?; self.put_expression(array_index, context, true)?; write!(self.out, ") < ")?; self.put_expression(image, context, true)?; @@ -939,9 +923,9 @@ impl Writer { crate::TypeInner::Vector { .. } => true, _ => false, }; - write!(self.out, "{}", conjunction)?; + write!(self.out, "{conjunction}")?; if coord_is_vector { - write!(self.out, "{}::all(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::all(")?; } self.put_cast_to_uint_scalar_or_vector(address.coordinate, context)?; write!(self.out, " < ")?; @@ -1035,7 +1019,7 @@ impl Writer { // support writes to mipmapped textures. debug_assert!(address.level.is_none()); - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.put_expression(image, &context.expression, false)?; write!(self.out, ".write(")?; self.put_expression(value, &context.expression, true)?; @@ -1044,11 +1028,11 @@ impl Writer { writeln!(self.out, ");")?; } proc::BoundsCheckPolicy::ReadZeroSkipWrite => { - write!(self.out, "{}if (", level)?; + write!(self.out, "{level}if (")?; self.put_image_access_bounds_check(image, address, &context.expression)?; writeln!(self.out, ") {{")?; self.put_unchecked_image_store(level.next(), image, address, value, context)?; - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } proc::BoundsCheckPolicy::Unchecked => { self.put_unchecked_image_store(level, image, address, value, context)?; @@ -1066,7 +1050,7 @@ impl Writer { value: Handle, context: &StatementContext, ) -> BackendResult { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.put_expression(image, &context.expression, false)?; write!(self.out, ".write(")?; self.put_expression(value, &context.expression, true)?; @@ -1213,13 +1197,12 @@ impl Writer { write!( self.out, - "{}::atomic_{}{}_explicit({}", - NAMESPACE, key1, key2, ATOMIC_REFERENCE + "{NAMESPACE}::atomic_{key1}{key2}_explicit({ATOMIC_REFERENCE}" )?; self.put_access_chain(pointer, policy, context)?; write!(self.out, ", ")?; self.put_expression(value, context, true)?; - write!(self.out, ", {}::memory_order_relaxed)", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::memory_order_relaxed)")?; // Finish the ternary expression. if checked { @@ -1253,13 +1236,13 @@ impl Writer { // it shouldn't produce large expressions. self.put_expression(arg, context, true)?; // Access the current component on the first vector - write!(self.out, ".{} * ", component)?; + write!(self.out, ".{component} * ")?; // Write the second vector expression, this expression is marked to be // cached so unless it can't be cached (for example, it's a Constant) // it shouldn't produce large expressions. self.put_expression(arg1, context, true)?; // Access the current component on the second vector - write!(self.out, ".{}", component)?; + write!(self.out, ".{component}")?; } write!(self.out, ")")?; @@ -1290,7 +1273,7 @@ impl Writer { .insert(&expr_handle as *const _ as *const ()); if let Some(name) = self.named_expressions.get(&expr_handle) { - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; return Ok(()); } @@ -1331,7 +1314,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, "{}", coco)?; + write!(self.out, "{coco}")?; } crate::Expression::Splat { size, value } => { let scalar_kind = match *context.resolve_type(value) { @@ -1365,11 +1348,11 @@ impl Writer { } }; let name = &self.names[&name_key]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } crate::Expression::GlobalVariable(handle) => { let name = &self.names[&NameKey::GlobalVariable(handle)]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } crate::Expression::LocalVariable(handle) => { let name_key = match context.origin { @@ -1381,7 +1364,7 @@ impl Writer { } }; let name = &self.names[&name_key]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } crate::Expression::Load { pointer } => self.put_load(pointer, context, is_scoped)?, crate::Expression::ImageSample { @@ -1403,7 +1386,7 @@ impl Writer { None => "", }; self.put_expression(image, context, false)?; - write!(self.out, ".{}{}(", main_op, comparison_op)?; + write!(self.out, ".{main_op}{comparison_op}(")?; self.put_expression(sampler, context, true)?; write!(self.out, ", ")?; self.put_expression(coordinate, context, true)?; @@ -1425,7 +1408,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, ", {}", coco)?; + write!(self.out, ", {coco}")?; } match gather { None | Some(crate::SwizzleComponent::X) => {} @@ -1440,10 +1423,10 @@ impl Writer { // Offset always comes before the gather, except // in cube maps where it's not applicable if offset.is_none() && !is_cube_map { - write!(self.out, ", {}::int2(0)", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::int2(0)")?; } let letter = back::COMPONENTS[component as usize]; - write!(self.out, ", {}::component::{}", NAMESPACE, letter)?; + write!(self.out, ", {NAMESPACE}::component::{letter}")?; } } write!(self.out, ")")?; @@ -1500,7 +1483,7 @@ impl Writer { _ => return Err(Error::Validation), }, }; - write!(self.out, "{}(", op_str)?; + write!(self.out, "{op_str}(")?; self.put_expression(expr, context, false)?; write!(self.out, ")")?; } @@ -1525,7 +1508,7 @@ impl Writer { // if right == 0 return ? see https://github.com/gpuweb/gpuweb/issues/2798 if op == crate::BinaryOperator::Modulo && kind == crate::ScalarKind::Float { - write!(self.out, "{}::fmod(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::fmod(")?; self.put_expression(left, context, true)?; write!(self.out, ", ")?; self.put_expression(right, context, true)?; @@ -1548,7 +1531,7 @@ impl Writer { self.put_expression(left, context, false)?; } - write!(self.out, " {} ", op_str)?; + write!(self.out, " {op_str} ")?; // See comment above if op == crate::BinaryOperator::Multiply @@ -1589,7 +1572,7 @@ impl Writer { kind: crate::ScalarKind::Bool, .. } => { - write!(self.out, "{}::select(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::select(")?; self.put_expression(reject, context, true)?; write!(self.out, ", ")?; self.put_expression(accept, context, true)?; @@ -1605,7 +1588,7 @@ impl Writer { crate::DerivativeAxis::Y => "dfdy", crate::DerivativeAxis::Width => "fwidth", }; - write!(self.out, "{}::{}", NAMESPACE, op)?; + write!(self.out, "{NAMESPACE}::{op}")?; self.put_call_parameters(iter::once(expr), context)?; } crate::Expression::Relational { fun, argument } => { @@ -1617,7 +1600,7 @@ impl Writer { crate::RelationalFunction::IsFinite => "isfinite", crate::RelationalFunction::IsNormal => "isnormal", }; - write!(self.out, "{}::{}", NAMESPACE, op)?; + write!(self.out, "{NAMESPACE}::{op}")?; self.put_call_parameters(iter::once(argument), context)?; } crate::Expression::Math { @@ -1685,7 +1668,7 @@ impl Writer { "Correct TypeInner for dot product should be already validated" ), }, - Mf::Outer => return Err(Error::UnsupportedCall(format!("{:?}", fun))), + Mf::Outer => return Err(Error::UnsupportedCall(format!("{fun:?}"))), Mf::Cross => "cross", Mf::Distance => "distance", Mf::Length if scalar_argument => "abs", @@ -1702,7 +1685,7 @@ impl Writer { Mf::SmoothStep => "smoothstep", Mf::Sqrt => "sqrt", Mf::InverseSqrt => "rsqrt", - Mf::Inverse => return Err(Error::UnsupportedCall(format!("{:?}", fun))), + Mf::Inverse => return Err(Error::UnsupportedCall(format!("{fun:?}"))), Mf::Transpose => "transpose", Mf::Determinant => "determinant", // bits @@ -1727,17 +1710,17 @@ impl Writer { }; if fun == Mf::Distance && scalar_argument { - write!(self.out, "{}::abs(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::abs(")?; self.put_expression(arg, context, false)?; write!(self.out, " - ")?; self.put_expression(arg1.unwrap(), context, false)?; write!(self.out, ")")?; } else if fun == Mf::FindLsb { - write!(self.out, "((({}::ctz(", NAMESPACE)?; + write!(self.out, "((({NAMESPACE}::ctz(")?; self.put_expression(arg, context, true)?; write!(self.out, ") + 1) % 33) - 1)")?; } else if fun == Mf::FindMsb { - write!(self.out, "((({}::clz(", NAMESPACE)?; + write!(self.out, "((({NAMESPACE}::clz(")?; self.put_expression(arg, context, true)?; write!(self.out, ") + 1) % 33) - 1)")? } else if fun == Mf::Unpack2x16float { @@ -1757,7 +1740,7 @@ impl Writer { self.put_expression(arg, context, false)?; write!(self.out, ") * 57.295779513082322865)")?; } else { - write!(self.out, "{}::{}", NAMESPACE, fun_name)?; + write!(self.out, "{NAMESPACE}::{fun_name}")?; self.put_call_parameters( iter::once(arg).chain(arg1).chain(arg2).chain(arg3), context, @@ -1788,7 +1771,7 @@ impl Writer { Some(_) => return Err(Error::Validation), None => "as_type", }; - write!(self.out, "{}<", op)?; + write!(self.out, "{op}<")?; match *context.resolve_type(expr) { crate::TypeInner::Vector { size, .. } => { put_numeric_type(&mut self.out, kind, &[size])? @@ -1865,7 +1848,7 @@ impl Writer { index::GuardedIndex::Expression(expr) => { self.put_expression(expr, context, is_scoped)? } - index::GuardedIndex::Known(value) => write!(self.out, "{}", value)?, + index::GuardedIndex::Known(value) => write!(self.out, "{value}")?, } Ok(()) } @@ -1937,7 +1920,7 @@ impl Writer { if check_written { write!(self.out, " && ")?; } else { - write!(self.out, "{}{}", level, prefix)?; + write!(self.out, "{level}{prefix}")?; check_written = true; } @@ -1948,7 +1931,7 @@ impl Writer { self.put_index(index, context, true)?; self.out.write_str(") < ")?; match length { - index::IndexableLength::Known(value) => write!(self.out, "{}", value)?, + index::IndexableLength::Known(value) => write!(self.out, "{value}")?, index::IndexableLength::Dynamic => { let global = context .function @@ -2028,14 +2011,14 @@ impl Writer { let base_ty = base_ty_handle.unwrap(); self.put_access_chain(base, policy, context)?; let name = &self.names[&NameKey::StructMember(base_ty, index)]; - write!(self.out, ".{}", name)?; + write!(self.out, ".{name}")?; } crate::TypeInner::ValuePointer { .. } | crate::TypeInner::Vector { .. } => { self.put_access_chain(base, policy, context)?; // Prior to Metal v2.1 component access for packed vectors wasn't available // however array indexing is if context.get_packed_vec_kind(base).is_some() { - write!(self.out, "[{}]", index)?; + write!(self.out, "[{index}]")?; } else { write!(self.out, ".{}", back::COMPONENTS[index as usize])?; } @@ -2091,7 +2074,7 @@ impl Writer { self.put_access_chain(base, policy, context)?; if accessing_wrapped_array { - write!(self.out, ".{}", WRAPPED_ARRAY_FIELD)?; + write!(self.out, ".{WRAPPED_ARRAY_FIELD}")?; } write!(self.out, "[")?; @@ -2102,7 +2085,7 @@ impl Writer { None }; if let Some(limit) = restriction_needed { - write!(self.out, "{}::min(unsigned(", NAMESPACE)?; + write!(self.out, "{NAMESPACE}::min(unsigned(")?; self.put_index(index, context, true)?; write!(self.out, "), ")?; match limit { @@ -2175,11 +2158,10 @@ impl Writer { if is_atomic { write!( self.out, - "{}::atomic_load_explicit({}", - NAMESPACE, ATOMIC_REFERENCE + "{NAMESPACE}::atomic_load_explicit({ATOMIC_REFERENCE}" )?; self.put_access_chain(pointer, policy, context)?; - write!(self.out, ", {}::memory_order_relaxed)", NAMESPACE)?; + write!(self.out, ", {NAMESPACE}::memory_order_relaxed)")?; } else { // We don't do any dereferencing with `*` here as pointer arguments to functions // are done by `&` references and not `*` pointers. These do not need to be @@ -2204,10 +2186,10 @@ impl Writer { match context.module.types[result_ty].inner { crate::TypeInner::Struct { ref members, .. } => { let tmp = "_tmp"; - write!(self.out, "{}const auto {} = ", level, tmp)?; + write!(self.out, "{level}const auto {tmp} = ")?; self.put_expression(expr_handle, context, true)?; writeln!(self.out, ";")?; - write!(self.out, "{}return {} {{", level, struct_name)?; + write!(self.out, "{level}return {struct_name} {{")?; let mut is_first = true; @@ -2240,25 +2222,21 @@ impl Writer { let size = context.module.constants[const_handle] .to_array_length() .unwrap(); - write!(self.out, "{} {{", comma)?; + write!(self.out, "{comma} {{")?; for j in 0..size { if j != 0 { write!(self.out, ",")?; } - write!( - self.out, - "{}.{}.{}[{}]", - tmp, name, WRAPPED_ARRAY_FIELD, j - )?; + write!(self.out, "{tmp}.{name}.{WRAPPED_ARRAY_FIELD}[{j}]")?; } write!(self.out, "}}")?; } else { - write!(self.out, "{} {}.{}", comma, tmp, name)?; + write!(self.out, "{comma} {tmp}.{name}")?; } } } _ => { - write!(self.out, "{}return {} {{ ", level, struct_name)?; + write!(self.out, "{level}return {struct_name} {{ ")?; self.put_expression(expr_handle, context, true)?; } } @@ -2276,7 +2254,7 @@ impl Writer { write!(self.out, " }}")?; } None => { - write!(self.out, "{}return ", level)?; + write!(self.out, "{level}return ")?; self.put_expression(expr_handle, context, true)?; } } @@ -2353,7 +2331,7 @@ impl Writer { binding: None, first_time: false, }; - write!(self.out, "{}", ty_name)?; + write!(self.out, "{ty_name}")?; } TypeResolution::Value(crate::TypeInner::Scalar { kind, .. }) => { put_numeric_type(&mut self.out, kind, &[])?; @@ -2371,7 +2349,7 @@ impl Writer { } //TODO: figure out the naming scheme that wouldn't collide with user names. - write!(self.out, " {} = ", name)?; + write!(self.out, " {name} = ")?; Ok(()) } @@ -2498,7 +2476,7 @@ impl Writer { }; if let Some(name) = expr_name { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.start_baking_expression(handle, &context.expression, &name)?; self.put_expression(handle, &context.expression, true)?; self.named_expressions.insert(handle, name); @@ -2508,9 +2486,9 @@ impl Writer { } crate::Statement::Block(ref block) => { if !block.is_empty() { - writeln!(self.out, "{}{{", level)?; + writeln!(self.out, "{level}{{")?; self.put_block(level.next(), block, context)?; - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } } crate::Statement::If { @@ -2518,21 +2496,21 @@ impl Writer { ref accept, ref reject, } => { - write!(self.out, "{}if (", level)?; + write!(self.out, "{level}if (")?; self.put_expression(condition, &context.expression, true)?; writeln!(self.out, ") {{")?; self.put_block(level.next(), accept, context)?; if !reject.is_empty() { - writeln!(self.out, "{}}} else {{", level)?; + writeln!(self.out, "{level}}} else {{")?; self.put_block(level.next(), reject, context)?; } - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } crate::Statement::Switch { selector, ref cases, } => { - write!(self.out, "{}switch(", level)?; + write!(self.out, "{level}switch(")?; self.put_expression(selector, &context.expression, true)?; let type_postfix = match *context.expression.resolve_type(selector) { crate::TypeInner::Scalar { @@ -2546,10 +2524,10 @@ impl Writer { for case in cases.iter() { match case.value { crate::SwitchValue::Integer(value) => { - write!(self.out, "{}case {}{}:", lcase, value, type_postfix)?; + write!(self.out, "{lcase}case {value}{type_postfix}:")?; } crate::SwitchValue::Default => { - write!(self.out, "{}default:", lcase)?; + write!(self.out, "{lcase}default:")?; } } @@ -2568,10 +2546,10 @@ impl Writer { } if write_block_braces { - writeln!(self.out, "{}}}", lcase)?; + writeln!(self.out, "{lcase}}}")?; } } - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } crate::Statement::Loop { ref body, @@ -2580,32 +2558,32 @@ impl Writer { } => { if !continuing.is_empty() || break_if.is_some() { let gate_name = self.namer.call("loop_init"); - writeln!(self.out, "{}bool {} = true;", level, gate_name)?; - writeln!(self.out, "{}while(true) {{", level)?; + writeln!(self.out, "{level}bool {gate_name} = true;")?; + writeln!(self.out, "{level}while(true) {{")?; let lif = level.next(); let lcontinuing = lif.next(); - writeln!(self.out, "{}if (!{}) {{", lif, gate_name)?; + writeln!(self.out, "{lif}if (!{gate_name}) {{")?; self.put_block(lcontinuing, continuing, context)?; if let Some(condition) = break_if { - write!(self.out, "{}if (", lcontinuing)?; + write!(self.out, "{lcontinuing}if (")?; self.put_expression(condition, &context.expression, true)?; writeln!(self.out, ") {{")?; writeln!(self.out, "{}break;", lcontinuing.next())?; - writeln!(self.out, "{}}}", lcontinuing)?; + writeln!(self.out, "{lcontinuing}}}")?; } - writeln!(self.out, "{}}}", lif)?; - writeln!(self.out, "{}{} = false;", lif, gate_name)?; + writeln!(self.out, "{lif}}}")?; + writeln!(self.out, "{lif}{gate_name} = false;")?; } else { - writeln!(self.out, "{}while(true) {{", level)?; + writeln!(self.out, "{level}while(true) {{")?; } self.put_block(level.next(), body, context)?; - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } crate::Statement::Break => { - writeln!(self.out, "{}break;", level)?; + writeln!(self.out, "{level}break;")?; } crate::Statement::Continue => { - writeln!(self.out, "{}continue;", level)?; + writeln!(self.out, "{level}continue;")?; } crate::Statement::Return { value: Some(expr_handle), @@ -2618,10 +2596,10 @@ impl Writer { )?; } crate::Statement::Return { value: None } => { - writeln!(self.out, "{}return;", level)?; + writeln!(self.out, "{level}return;")?; } crate::Statement::Kill => { - writeln!(self.out, "{}{}::discard_fragment();", level, NAMESPACE)?; + writeln!(self.out, "{level}{NAMESPACE}::discard_fragment();")?; } crate::Statement::Barrier(flags) => { self.write_barrier(flags, level)?; @@ -2648,14 +2626,14 @@ impl Writer { ref arguments, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; if let Some(expr) = result { let name = format!("{}{}", back::BAKE_PREFIX, expr.index()); self.start_baking_expression(expr, &context.expression, &name)?; self.named_expressions.insert(expr, name); } let fun_name = &self.names[&NameKey::Function(function)]; - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; // first, write down the actual arguments for (i, &handle) in arguments.iter().enumerate() { if i != 0 { @@ -2678,7 +2656,7 @@ impl Writer { } else { separate = true; } - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } supports_array_length |= needs_array_length(var.ty, &context.expression.module.types); @@ -2699,7 +2677,7 @@ impl Writer { value, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; let res_name = format!("{}{}", back::BAKE_PREFIX, result.index()); self.start_baking_expression(result, &context.expression, &res_name)?; self.named_expressions.insert(result, res_name); @@ -2771,7 +2749,7 @@ impl Writer { { writeln!(self.out, ") {{")?; self.put_unchecked_store(pointer, value, policy, level.next(), context)?; - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; } else { self.put_unchecked_store(pointer, value, policy, level, context)?; } @@ -2807,23 +2785,22 @@ impl Writer { let size = context.expression.module.constants[const_handle] .to_array_length() .unwrap(); - write!(self.out, "{}for(int _i=0; _i<{}; ++_i) ", level, size)?; + write!(self.out, "{level}for(int _i=0; _i<{size}; ++_i) ")?; self.put_access_chain(pointer, policy, &context.expression)?; - write!(self.out, ".{}[_i] = ", WRAPPED_ARRAY_FIELD)?; + write!(self.out, ".{WRAPPED_ARRAY_FIELD}[_i] = ")?; self.put_expression(value, &context.expression, true)?; - writeln!(self.out, ".{}[_i];", WRAPPED_ARRAY_FIELD)?; + writeln!(self.out, ".{WRAPPED_ARRAY_FIELD}[_i];")?; } else if is_atomic { write!( self.out, - "{}{}::atomic_store_explicit({}", - level, NAMESPACE, ATOMIC_REFERENCE + "{level}{NAMESPACE}::atomic_store_explicit({ATOMIC_REFERENCE}" )?; self.put_access_chain(pointer, policy, &context.expression)?; write!(self.out, ", ")?; self.put_expression(value, &context.expression, true)?; - writeln!(self.out, ", {}::memory_order_relaxed);", NAMESPACE)?; + writeln!(self.out, ", {NAMESPACE}::memory_order_relaxed);")?; } else { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.put_access_chain(pointer, policy, &context.expression)?; write!(self.out, " = ")?; self.put_expression(value, &context.expression, true)?; @@ -2854,7 +2831,7 @@ impl Writer { writeln!(self.out, "#include ")?; writeln!(self.out)?; // Work around Metal bug where `uint` is not available by default - writeln!(self.out, "using {}::uint;", NAMESPACE)?; + writeln!(self.out, "using {NAMESPACE}::uint;")?; writeln!(self.out)?; if options @@ -2956,7 +2933,7 @@ impl Writer { first_time: false, }; - writeln!(self.out, "struct {} {{", name)?; + writeln!(self.out, "struct {name} {{")?; writeln!( self.out, "{}{} {}[{}];", @@ -2968,14 +2945,14 @@ impl Writer { writeln!(self.out, "}};")?; } crate::ArraySize::Dynamic => { - writeln!(self.out, "typedef {} {}[1];", base_name, name)?; + writeln!(self.out, "typedef {base_name} {name}[1];")?; } } } crate::TypeInner::Struct { ref members, span, .. } => { - writeln!(self.out, "struct {} {{", name)?; + writeln!(self.out, "struct {name} {{")?; let mut last_offset = 0; for (index, member) in members.iter().enumerate() { // quick and dirty way to figure out if we need this... @@ -3041,7 +3018,7 @@ impl Writer { binding: None, first_time: true, }; - writeln!(self.out, "typedef {} {};", ty_name, name)?; + writeln!(self.out, "typedef {ty_name} {name};")?; } } } @@ -3078,7 +3055,7 @@ impl Writer { names: &self.names, first_time: true, }; - writeln!(self.out, " {} = {};", name, coco)?; + writeln!(self.out, " {name} = {coco};")?; } _ => {} } @@ -3101,7 +3078,7 @@ impl Writer { binding: None, first_time: false, }; - write!(self.out, "constant {} {} = {{", ty_name, name,)?; + write!(self.out, "constant {ty_name} {name} = {{",)?; for (i, &sub_handle) in components.iter().enumerate() { // insert padding initialization, if needed if self.struct_member_pads.contains(&(ty, i as u32)) { @@ -3114,7 +3091,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, "{}{}", separator, coco)?; + write!(self.out, "{separator}{coco}")?; } writeln!(self.out, "}};")?; } @@ -3241,13 +3218,13 @@ impl Writer { binding: None, first_time: false, }; - write!(self.out, "{}", ty_name)?; + write!(self.out, "{ty_name}")?; } None => { write!(self.out, "void")?; } } - writeln!(self.out, " {}(", fun_name)?; + writeln!(self.out, " {fun_name}(")?; for (index, arg) in fun.arguments.iter().enumerate() { let name = &self.names[&NameKey::FunctionArgument(fun_handle, index as u32)]; @@ -3286,7 +3263,7 @@ impl Writer { separate(index + 1 != pass_through_globals.len() || supports_array_length); write!(self.out, "{}", back::INDENT)?; tyvar.try_fmt(&mut self.out)?; - writeln!(self.out, "{}", separator)?; + writeln!(self.out, "{separator}")?; } if supports_array_length { @@ -3318,7 +3295,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, " = {}", coco)?; + write!(self.out, " = {coco}")?; } None => { write!(self.out, " = {{}}")?; @@ -3484,11 +3461,11 @@ impl Writer { // Identify the varyings among the argument values, and emit a // struct type named `Input` to hold them. - let stage_in_name = format!("{}Input", fun_name); + let stage_in_name = format!("{fun_name}Input"); let varyings_member_name = self.namer.call("varyings"); let mut has_varyings = false; if !flattened_arguments.is_empty() { - writeln!(self.out, "struct {} {{", stage_in_name)?; + writeln!(self.out, "struct {stage_in_name} {{")?; for &(ref name_key, ty, binding) in flattened_arguments.iter() { let binding = match binding { Some(ref binding @ &crate::Binding::Location { .. }) => binding, @@ -3514,7 +3491,7 @@ impl Writer { // Define a struct type named for the return value, if any, named // `Output`. - let stage_out_name = format!("{}Output", fun_name); + let stage_out_name = format!("{fun_name}Output"); let result_member_name = self.namer.call("member"); let result_type_name = match fun.result { Some(ref result) => { @@ -3537,7 +3514,7 @@ impl Writer { )); } - writeln!(self.out, "struct {} {{", stage_out_name)?; + writeln!(self.out, "struct {stage_out_name} {{")?; let mut has_point_size = false; for (name, ty, binding) in result_members { let ty_name = TypeContext { @@ -3580,7 +3557,7 @@ impl Writer { let resolved = options.resolve_local_binding(binding, out_mode)?; write!(self.out, "{}{} {}", back::INDENT, ty_name, name)?; if let Some(array_len) = array_len { - write!(self.out, " [{}]", array_len)?; + write!(self.out, " [{array_len}]")?; } resolved.try_fmt(&mut self.out)?; writeln!(self.out, ";")?; @@ -3604,7 +3581,7 @@ impl Writer { }; // Write the entry point function's name, and begin its argument list. - writeln!(self.out, "{} {} {}(", em_str, result_type_name, fun_name)?; + writeln!(self.out, "{em_str} {result_type_name} {fun_name}(")?; let mut is_first_argument = true; // If we have produced a struct holding the `EntryPoint`'s @@ -3612,8 +3589,7 @@ impl Writer { if has_varyings { writeln!( self.out, - " {} {} [[stage_in]]", - stage_in_name, varyings_member_name + " {stage_in_name} {varyings_member_name} [[stage_in]]" )?; is_first_argument = false; } @@ -3664,7 +3640,7 @@ impl Writer { } else { ',' }; - write!(self.out, "{} {} {}", separator, ty_name, name)?; + write!(self.out, "{separator} {ty_name} {name}")?; resolved.try_fmt(&mut self.out)?; writeln!(self.out)?; } @@ -3681,8 +3657,7 @@ impl Writer { }; writeln!( self.out, - "{} {}::uint3 __global_invocation_id [[thread_position_in_grid]]", - separator, NAMESPACE + "{separator} {NAMESPACE}::uint3 __global_invocation_id [[thread_position_in_grid]]" )?; } @@ -3729,7 +3704,7 @@ impl Writer { } else { ',' }; - write!(self.out, "{} ", separator)?; + write!(self.out, "{separator} ")?; tyvar.try_fmt(&mut self.out)?; if let Some(resolved) = resolved { resolved.try_fmt(&mut self.out)?; @@ -3741,7 +3716,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, " = {}", coco)?; + write!(self.out, " = {coco}")?; } writeln!(self.out)?; } @@ -3758,8 +3733,7 @@ impl Writer { }; write!( self.out, - "{} constant _mslBufferSizes& _buffer_sizes", - separator, + "{separator} constant _mslBufferSizes& _buffer_sizes", )?; resolved.try_fmt(&mut self.out)?; writeln!(self.out)?; @@ -3803,7 +3777,7 @@ impl Writer { names: &self.names, first_time: false, }; - writeln!(self.out, " = {};", coco)?; + writeln!(self.out, " = {coco};")?; } None => { writeln!(self.out, " = {{}};")?; @@ -3865,9 +3839,9 @@ impl Writer { write!(self.out, ", ")?; } if let Some(crate::Binding::Location { .. }) = member.binding { - write!(self.out, "{}.", varyings_member_name)?; + write!(self.out, "{varyings_member_name}.")?; } - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } writeln!(self.out, " }};")?; } @@ -3907,7 +3881,7 @@ impl Writer { names: &self.names, first_time: false, }; - write!(self.out, " = {}", coco)?; + write!(self.out, " = {coco}")?; } None => { write!(self.out, " = {{}}")?; @@ -3950,22 +3924,19 @@ impl Writer { if flags.is_empty() { writeln!( self.out, - "{}{}::threadgroup_barrier({}::mem_flags::mem_none);", - level, NAMESPACE, NAMESPACE, + "{level}{NAMESPACE}::threadgroup_barrier({NAMESPACE}::mem_flags::mem_none);", )?; } if flags.contains(crate::Barrier::STORAGE) { writeln!( self.out, - "{}{}::threadgroup_barrier({}::mem_flags::mem_device);", - level, NAMESPACE, NAMESPACE, + "{level}{NAMESPACE}::threadgroup_barrier({NAMESPACE}::mem_flags::mem_device);", )?; } if flags.contains(crate::Barrier::WORK_GROUP) { writeln!( self.out, - "{}{}::threadgroup_barrier({}::mem_flags::mem_threadgroup);", - level, NAMESPACE, NAMESPACE, + "{level}{NAMESPACE}::threadgroup_barrier({NAMESPACE}::mem_flags::mem_threadgroup);", )?; } Ok(()) @@ -3998,7 +3969,7 @@ mod workgroup_mem_init { Access::StructMember(handle, index) => { write!(writer, ".{}", &names[&NameKey::StructMember(handle, index)]) } - Access::Array(depth) => write!(writer, ".{}[__i{}]", WRAPPED_ARRAY_FIELD, depth), + Access::Array(depth) => write!(writer, ".{WRAPPED_ARRAY_FIELD}[__i{depth}]"), } } } @@ -4098,7 +4069,7 @@ mod workgroup_mem_init { })?; } - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; self.write_barrier(crate::Barrier::WORK_GROUP, level) } @@ -4111,7 +4082,7 @@ mod workgroup_mem_init { level: back::Level, ) -> BackendResult { if module_info[ty].contains(valid::TypeFlags::CONSTRUCTIBLE) { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; access_stack.write(&mut self.out, &self.names)?; writeln!(self.out, " = {{}};")?; } else { @@ -4119,11 +4090,10 @@ mod workgroup_mem_init { crate::TypeInner::Atomic { .. } => { write!( self.out, - "{}{}::atomic_store_explicit({}", - level, NAMESPACE, ATOMIC_REFERENCE + "{level}{NAMESPACE}::atomic_store_explicit({ATOMIC_REFERENCE}" )?; access_stack.write(&mut self.out, &self.names)?; - writeln!(self.out, ", 0, {}::memory_order_relaxed);", NAMESPACE)?; + writeln!(self.out, ", 0, {NAMESPACE}::memory_order_relaxed);")?; } crate::TypeInner::Array { base, size, .. } => { let count = match size.to_indexable_length(module).expect("Bad array size") @@ -4135,8 +4105,7 @@ mod workgroup_mem_init { access_stack.enter_array(|access_stack, array_depth| { writeln!( self.out, - "{}for (int __i{} = 0; __i{} < {}; __i{}++) {{", - level, array_depth, array_depth, count, array_depth + "{level}for (int __i{array_depth} = 0; __i{array_depth} < {count}; __i{array_depth}++) {{" )?; self.write_workgroup_variable_initialization( module, @@ -4145,7 +4114,7 @@ mod workgroup_mem_init { access_stack, level.next(), )?; - writeln!(self.out, "{}}}", level)?; + writeln!(self.out, "{level}}}")?; BackendResult::Ok(()) })?; } @@ -4236,7 +4205,7 @@ fn test_stack_size() { // check the size (in debug only) // last observed macOS value: 20528 (CI) if !(11000..=25000).contains(&stack_size) { - panic!("`put_expression` stack size {} has changed!", stack_size); + panic!("`put_expression` stack size {stack_size} has changed!"); } } @@ -4252,7 +4221,7 @@ fn test_stack_size() { // check the size (in debug only) // last observed macOS value: 19152 (CI) if !(9500..=20000).contains(&stack_size) { - panic!("`put_block` stack size {} has changed!", stack_size); + panic!("`put_block` stack size {stack_size} has changed!"); } } } diff --git a/src/back/wgsl/writer.rs b/src/back/wgsl/writer.rs index da3f75d7e2..5524ca9c20 100644 --- a/src/back/wgsl/writer.rs +++ b/src/back/wgsl/writer.rs @@ -187,12 +187,12 @@ impl Writer { use crate::ScalarValue as Sv; match value { - Sv::Sint(value) => write!(self.out, "{}", value)?, - Sv::Uint(value) => write!(self.out, "{}u", value)?, + Sv::Sint(value) => write!(self.out, "{value}")?, + Sv::Uint(value) => write!(self.out, "{value}u")?, // Floats are written using `Debug` instead of `Display` because it always appends the // decimal part even it's zero - Sv::Float(value) => write!(self.out, "{:?}", value)?, - Sv::Bool(value) => write!(self.out, "{}", value)?, + Sv::Float(value) => write!(self.out, "{value:?}")?, + Sv::Bool(value) => write!(self.out, "{value}")?, } Ok(()) @@ -211,7 +211,7 @@ impl Writer { ShaderStage::Vertex => "VertexOutput", }; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; return Ok(()); } } @@ -238,7 +238,7 @@ impl Writer { }; // Write function name - write!(self.out, "fn {}(", func_name)?; + write!(self.out, "fn {func_name}(")?; // Write function arguments for (index, arg) in func.arguments.iter().enumerate() { @@ -259,7 +259,7 @@ impl Writer { } }; - write!(self.out, "{}: ", argument_name)?; + write!(self.out, "{argument_name}: ")?; // Write argument type self.write_type(module, arg.ty)?; if index < func.arguments.len() - 1 { @@ -333,10 +333,10 @@ impl Writer { fn write_attributes(&mut self, attributes: &[Attribute]) -> BackendResult { for attribute in attributes { match *attribute { - Attribute::Location(id) => write!(self.out, "@location({}) ", id)?, + Attribute::Location(id) => write!(self.out, "@location({id}) ")?, Attribute::BuiltIn(builtin_attrib) => { if let Some(builtin) = builtin_str(builtin_attrib) { - write!(self.out, "@builtin({}) ", builtin)?; + write!(self.out, "@builtin({builtin}) ")?; } else { log::warn!("Unsupported builtin attribute: {:?}", builtin_attrib); } @@ -347,7 +347,7 @@ impl Writer { ShaderStage::Fragment => "fragment", ShaderStage::Compute => "compute", }; - write!(self.out, "@{} ", stage_str)?; + write!(self.out, "@{stage_str} ")?; } Attribute::WorkGroupSize(size) => { write!( @@ -356,8 +356,8 @@ impl Writer { size[0], size[1], size[2] )?; } - Attribute::Binding(id) => write!(self.out, "@binding({}) ", id)?, - Attribute::Group(id) => write!(self.out, "@group({}) ", id)?, + Attribute::Binding(id) => write!(self.out, "@binding({id}) ")?, + Attribute::Group(id) => write!(self.out, "@group({id}) ")?, Attribute::Invariant => write!(self.out, "@invariant ")?, Attribute::Interpolate(interpolation, sampling) => { if sampling.is_some() && sampling != Some(crate::Sampling::Center) { @@ -419,7 +419,7 @@ impl Writer { } // Write struct member name and type let member_name = &self.names[&NameKey::StructMember(handle, index as u32)]; - write!(self.out, "{}: ", member_name)?; + write!(self.out, "{member_name}: ")?; self.write_type(module, member.ty)?; write!(self.out, ",")?; writeln!(self.out)?; @@ -500,12 +500,11 @@ impl Writer { }; write!( self.out, - "texture_{}{}{}{}", - class_str, multisampled_str, dim_str, arrayed_str + "texture_{class_str}{multisampled_str}{dim_str}{arrayed_str}" )?; if !format_str.is_empty() { - write!(self.out, "<{}{}>", format_str, storage_str)?; + write!(self.out, "<{format_str}{storage_str}>")?; } } TypeInner::Scalar { kind, width } => { @@ -569,12 +568,12 @@ impl Writer { // Naga IR never produces pointers to handles, so it doesn't matter much // how we write such a type. Just write it as the base type alone. if let Some(space) = address { - write!(self.out, "ptr<{}, ", space)?; + write!(self.out, "ptr<{space}, ")?; } self.write_type(module, base)?; if address.is_some() { if let Some(access) = maybe_access { - write!(self.out, ", {}", access)?; + write!(self.out, ", {access}")?; } write!(self.out, ">")?; } @@ -589,13 +588,12 @@ impl Writer { if let Some(space) = address { write!(self.out, "ptr<{}, {}", space, scalar_kind_str(kind, width))?; if let Some(access) = maybe_access { - write!(self.out, ", {}", access)?; + write!(self.out, ", {access}")?; } write!(self.out, ">")?; } else { return Err(Error::Unimplemented(format!( - "ValuePointer to AddressSpace::Handle {:?}", - inner + "ValuePointer to AddressSpace::Handle {inner:?}" ))); } } @@ -615,22 +613,18 @@ impl Writer { scalar_kind_str(kind, width) )?; if let Some(access) = maybe_access { - write!(self.out, ", {}", access)?; + write!(self.out, ", {access}")?; } write!(self.out, ">")?; } else { return Err(Error::Unimplemented(format!( - "ValuePointer to AddressSpace::Handle {:?}", - inner + "ValuePointer to AddressSpace::Handle {inner:?}" ))); } write!(self.out, ">")?; } _ => { - return Err(Error::Unimplemented(format!( - "write_value_type {:?}", - inner - ))); + return Err(Error::Unimplemented(format!("write_value_type {inner:?}"))); } } @@ -660,7 +654,7 @@ impl Writer { // Also, we use sanitized names! It defense backend from generating variable with name from reserved keywords. Some(self.namer.call(name)) } else if info.ref_count == 0 { - write!(self.out, "{}_ = ", level)?; + write!(self.out, "{level}_ = ")?; self.write_expr(module, handle, func_ctx)?; writeln!(self.out, ";")?; continue; @@ -698,7 +692,7 @@ impl Writer { }; if let Some(name) = expr_name { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; self.start_named_expr(module, handle, func_ctx, &name)?; self.write_expr(module, handle, func_ctx)?; self.named_expressions.insert(handle, name); @@ -712,7 +706,7 @@ impl Writer { ref accept, ref reject, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "if ")?; self.write_expr(module, condition, func_ctx)?; writeln!(self.out, " {{")?; @@ -726,7 +720,7 @@ impl Writer { // If there are no statements in the reject block we skip writing it // This is only for readability if !reject.is_empty() { - writeln!(self.out, "{}}} else {{", level)?; + writeln!(self.out, "{level}}} else {{")?; for sta in reject { // Increase indentation to help with readability @@ -734,10 +728,10 @@ impl Writer { } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } Statement::Return { value } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "return")?; if let Some(return_value) = value { // The leading space is important @@ -748,7 +742,7 @@ impl Writer { } // TODO: copy-paste from glsl-out Statement::Kill => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "discard;")? } Statement::Store { pointer, value } => { @@ -760,7 +754,7 @@ impl Writer { return Ok(()); } } - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; let is_atomic = match *func_ctx.info[pointer].ty.inner_with(&module.types) { crate::TypeInner::Pointer { base, .. } => match module.types[base].inner { @@ -792,14 +786,14 @@ impl Writer { ref arguments, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; if let Some(expr) = result { let name = format!("{}{}", back::BAKE_PREFIX, expr.index()); self.start_named_expr(module, expr, func_ctx, &name)?; self.named_expressions.insert(expr, name); } let func_name = &self.names[&NameKey::Function(function)]; - write!(self.out, "{}(", func_name)?; + write!(self.out, "{func_name}(")?; for (index, &argument) in arguments.iter().enumerate() { self.write_expr(module, argument, func_ctx)?; // Only write a comma if isn't the last element @@ -816,13 +810,13 @@ impl Writer { value, result, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; let res_name = format!("{}{}", back::BAKE_PREFIX, result.index()); self.start_named_expr(module, result, func_ctx, &res_name)?; self.named_expressions.insert(result, res_name); let fun_str = fun.to_wgsl(); - write!(self.out, "atomic{}(", fun_str)?; + write!(self.out, "atomic{fun_str}(")?; self.write_expr(module, pointer, func_ctx)?; if let crate::AtomicFunction::Exchange { compare: Some(cmp) } = *fun { write!(self.out, ", ")?; @@ -838,7 +832,7 @@ impl Writer { array_index, value, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "textureStore(")?; self.write_expr(module, image, func_ctx)?; write!(self.out, ", ")?; @@ -853,20 +847,20 @@ impl Writer { } // TODO: copy-paste from glsl-out Statement::Block(ref block) => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "{{")?; for sta in block.iter() { // Increase the indentation to help with readability self.write_stmt(module, sta, func_ctx, level.next())? } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } Statement::Switch { selector, ref cases, } => { // Start the switch - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; write!(self.out, "switch ")?; self.write_expr(module, selector, func_ctx)?; writeln!(self.out, " {{")?; @@ -892,16 +886,16 @@ impl Writer { match case.value { crate::SwitchValue::Integer(value) => { if new_case { - write!(self.out, "{}case ", l2)?; + write!(self.out, "{l2}case ")?; } - write!(self.out, "{}{}", value, type_postfix)?; + write!(self.out, "{value}{type_postfix}")?; } crate::SwitchValue::Default => { if new_case { if case.fall_through { - write!(self.out, "{}case ", l2)?; + write!(self.out, "{l2}case ")?; } else { - write!(self.out, "{}", l2)?; + write!(self.out, "{l2}")?; } } write!(self.out, "default")?; @@ -921,18 +915,18 @@ impl Writer { } if !case.fall_through { - writeln!(self.out, "{}}}", l2)?; + writeln!(self.out, "{l2}}}")?; } } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } Statement::Loop { ref body, ref continuing, break_if, } => { - write!(self.out, "{}", level)?; + write!(self.out, "{level}")?; writeln!(self.out, "loop {{")?; let l2 = level.next(); @@ -945,7 +939,7 @@ impl Writer { // so even if `continuing` is empty we must generate it if a // `break if` exists if !continuing.is_empty() || break_if.is_some() { - writeln!(self.out, "{}continuing {{", l2)?; + writeln!(self.out, "{l2}continuing {{")?; for sta in continuing.iter() { self.write_stmt(module, sta, func_ctx, l2.next())?; } @@ -960,24 +954,24 @@ impl Writer { writeln!(self.out, ";")?; } - writeln!(self.out, "{}}}", l2)?; + writeln!(self.out, "{l2}}}")?; } - writeln!(self.out, "{}}}", level)? + writeln!(self.out, "{level}}}")? } Statement::Break => { - writeln!(self.out, "{}break;", level)?; + writeln!(self.out, "{level}break;")?; } Statement::Continue => { - writeln!(self.out, "{}continue;", level)?; + writeln!(self.out, "{level}continue;")?; } Statement::Barrier(barrier) => { if barrier.contains(crate::Barrier::STORAGE) { - writeln!(self.out, "{}storageBarrier();", level)?; + writeln!(self.out, "{level}storageBarrier();")?; } if barrier.contains(crate::Barrier::WORK_GROUP) { - writeln!(self.out, "{}workgroupBarrier();", level)?; + writeln!(self.out, "{level}workgroupBarrier();")?; } } } @@ -1052,7 +1046,7 @@ impl Writer { name: &str, ) -> BackendResult { // Write variable name - write!(self.out, "let {}", name)?; + write!(self.out, "let {name}")?; if self.flags.contains(WriterFlags::EXPLICIT_TYPES) { write!(self.out, ": ")?; let ty = &func_ctx.info[handle].ty; @@ -1139,7 +1133,7 @@ impl Writer { use crate::Expression; if let Some(name) = self.named_expressions.get(&expr) { - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; return Ok(()); } @@ -1203,7 +1197,7 @@ impl Writer { Expression::FunctionArgument(pos) => { let name_key = func_ctx.argument_key(pos); let name = &self.names[&name_key]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } Expression::Binary { op, left, right } => { write!(self.out, "(")?; @@ -1240,7 +1234,7 @@ impl Writer { TypeInner::Matrix { .. } | TypeInner::Array { .. } | TypeInner::BindingArray { .. } - | TypeInner::ValuePointer { .. } => write!(self.out, "[{}]", index)?, + | TypeInner::ValuePointer { .. } => write!(self.out, "[{index}]")?, TypeInner::Struct { .. } => { // This will never panic in case the type is a `Struct`, this is not true // for other types so we can only check while inside this match arm @@ -1252,7 +1246,7 @@ impl Writer { &self.names[&NameKey::StructMember(ty, index)] )? } - ref other => return Err(Error::Custom(format!("Cannot index {:?}", other))), + ref other => return Err(Error::Custom(format!("Cannot index {other:?}"))), } } Expression::ImageSample { @@ -1278,7 +1272,7 @@ impl Writer { Sl::Gradient { .. } => "Grad", }; - write!(self.out, "textureSample{}{}(", suffix_cmp, suffix_level)?; + write!(self.out, "textureSample{suffix_cmp}{suffix_level}(")?; self.write_expr(module, image, func_ctx)?; write!(self.out, ", ")?; self.write_expr(module, sampler, func_ctx)?; @@ -1341,7 +1335,7 @@ impl Writer { None => "", }; - write!(self.out, "textureGather{}(", suffix_cmp)?; + write!(self.out, "textureGather{suffix_cmp}(")?; match *func_ctx.info[image].ty.inner_with(&module.types) { TypeInner::Image { class: crate::ImageClass::Depth { multi: _ }, @@ -1384,7 +1378,7 @@ impl Writer { Iq::NumSamples => "textureNumSamples", }; - write!(self.out, "{}(", texture_function)?; + write!(self.out, "{texture_function}(")?; self.write_expr(module, image, func_ctx)?; if let Iq::Size { level: Some(level) } = query { write!(self.out, ", ")?; @@ -1415,7 +1409,7 @@ impl Writer { } Expression::GlobalVariable(handle) => { let name = &self.names[&NameKey::GlobalVariable(handle)]; - write!(self.out, "{}", name)?; + write!(self.out, "{name}")?; } Expression::As { expr, @@ -1443,27 +1437,22 @@ impl Writer { let vector_size_str = back::vector_size_str(size); let scalar_kind_str = scalar_kind_str(kind, convert.unwrap_or(width)); if convert.is_some() { - write!(self.out, "vec{}<{}>", vector_size_str, scalar_kind_str)?; + write!(self.out, "vec{vector_size_str}<{scalar_kind_str}>")?; } else { - write!( - self.out, - "bitcast>", - vector_size_str, scalar_kind_str - )?; + write!(self.out, "bitcast>")?; } } TypeInner::Scalar { width, .. } => { let scalar_kind_str = scalar_kind_str(kind, convert.unwrap_or(width)); if convert.is_some() { - write!(self.out, "{}", scalar_kind_str)? + write!(self.out, "{scalar_kind_str}")? } else { - write!(self.out, "bitcast<{}>", scalar_kind_str)? + write!(self.out, "bitcast<{scalar_kind_str}>")? } } _ => { return Err(Error::Unimplemented(format!( - "write_expr expression::as {:?}", - inner + "write_expr expression::as {inner:?}" ))); } }; @@ -1477,15 +1466,14 @@ impl Writer { crate::TypeInner::Scalar { kind, width } => (kind, width), _ => { return Err(Error::Unimplemented(format!( - "write_expr expression::splat {:?}", - inner + "write_expr expression::splat {inner:?}" ))); } }; let scalar = scalar_kind_str(scalar_kind, scalar_width); let size = back::vector_size_str(size); - write!(self.out, "vec{}<{}>(", size, scalar)?; + write!(self.out, "vec{size}<{scalar}>(")?; self.write_expr(module, value, func_ctx)?; write!(self.out, ")")?; } @@ -1615,7 +1603,7 @@ impl Writer { match function { Function::Regular(fun_name) => { - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(module, arg, func_ctx)?; for arg in IntoIterator::into_iter([arg1, arg2, arg3]).flatten() { write!(self.out, ", ")?; @@ -1651,7 +1639,7 @@ impl Writer { } }; - write!(self.out, "{}(", unary)?; + write!(self.out, "{unary}(")?; self.write_expr(module, expr, func_ctx)?; write!(self.out, ")")? @@ -1677,7 +1665,7 @@ impl Writer { Da::Y => "dpdy", Da::Width => "fwidth", }; - write!(self.out, "{}(", op)?; + write!(self.out, "{op}(")?; self.write_expr(module, expr, func_ctx)?; write!(self.out, ")")? } @@ -1689,7 +1677,7 @@ impl Writer { Rf::Any => "any", _ => return Err(Error::UnsupportedRelationalFunction(fun)), }; - write!(self.out, "{}(", fun_name)?; + write!(self.out, "{fun_name}(")?; self.write_expr(module, argument, func_ctx)?; @@ -1724,9 +1712,9 @@ impl Writer { write!(self.out, "var")?; let (address, maybe_access) = address_space_str(global.space); if let Some(space) = address { - write!(self.out, "<{}", space)?; + write!(self.out, "<{space}")?; if let Some(access) = maybe_access { - write!(self.out, ", {}", access)?; + write!(self.out, ", {access}")?; } write!(self.out, ">")?; } @@ -1826,22 +1814,22 @@ impl Writer { } => { let name = &self.names[&NameKey::Constant(handle)]; // First write only constant name - write!(self.out, "const {}: ", name)?; + write!(self.out, "const {name}: ")?; // Next write constant type and value match *value { crate::ScalarValue::Sint(value) => { - write!(self.out, "i32 = {}", value)?; + write!(self.out, "i32 = {value}")?; } crate::ScalarValue::Uint(value) => { - write!(self.out, "u32 = {}u", value)?; + write!(self.out, "u32 = {value}u")?; } crate::ScalarValue::Float(value) => { // Floats are written using `Debug` instead of `Display` because it always appends the // decimal part even it's zero - write!(self.out, "f32 = {:?}", value)?; + write!(self.out, "f32 = {value:?}")?; } crate::ScalarValue::Bool(value) => { - write!(self.out, "bool = {}", value)?; + write!(self.out, "bool = {value}")?; } }; // End with semicolon @@ -1850,7 +1838,7 @@ impl Writer { crate::ConstantInner::Composite { ty, ref components } => { let name = &self.names[&NameKey::Constant(handle)]; // First write only constant name - write!(self.out, "const {}: ", name)?; + write!(self.out, "const {name}: ")?; // Next write constant type self.write_type(module, ty)?; diff --git a/src/front/glsl/constants.rs b/src/front/glsl/constants.rs index 53b3b77a3c..cdf7a8f63d 100644 --- a/src/front/glsl/constants.rs +++ b/src/front/glsl/constants.rs @@ -241,8 +241,7 @@ impl<'a> ConstantSolver<'a> { ), _ => { return Err(ConstantSolvingError::NotImplemented(format!( - "{:?} applied to vector values", - fun + "{fun:?} applied to vector values" ))) } }; @@ -250,7 +249,7 @@ impl<'a> ConstantSolver<'a> { let inner = ConstantInner::Scalar { width, value }; Ok(self.register_constant(inner, span)) } - _ => Err(ConstantSolvingError::NotImplemented(format!("{:?}", fun))), + _ => Err(ConstantSolvingError::NotImplemented(format!("{fun:?}"))), } } Expression::As { diff --git a/src/front/glsl/context.rs b/src/front/glsl/context.rs index 44aea8a301..930cd45598 100644 --- a/src/front/glsl/context.rs +++ b/src/front/glsl/context.rs @@ -591,8 +591,7 @@ impl Context { parser.errors.push(Error { kind: ErrorKind::SemanticError( format!( - "Cannot apply operation to {:?} and {:?}", - left_inner, right_inner + "Cannot apply operation to {left_inner:?} and {right_inner:?}" ) .into(), ), @@ -823,8 +822,7 @@ impl Context { parser.errors.push(Error { kind: ErrorKind::SemanticError( format!( - "Cannot apply operation to {:?} and {:?}", - left_inner, right_inner + "Cannot apply operation to {left_inner:?} and {right_inner:?}" ) .into(), ), @@ -914,8 +912,7 @@ impl Context { parser.errors.push(Error { kind: ErrorKind::SemanticError( format!( - "Cannot apply operation to {:?} and {:?}", - left_inner, right_inner + "Cannot apply operation to {left_inner:?} and {right_inner:?}" ) .into(), ), @@ -1383,7 +1380,7 @@ impl Context { _ => { return Err(Error { kind: ErrorKind::SemanticError( - format!("unknown method '{}'", name).into(), + format!("unknown method '{name}'").into(), ), meta, }); diff --git a/src/front/glsl/error.rs b/src/front/glsl/error.rs index 299bf57aa4..46b3aecd08 100644 --- a/src/front/glsl/error.rs +++ b/src/front/glsl/error.rs @@ -43,7 +43,7 @@ impl From for ExpectedToken { impl std::fmt::Display for ExpectedToken { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self { - ExpectedToken::Token(ref token) => write!(f, "{:?}", token), + ExpectedToken::Token(ref token) => write!(f, "{token:?}"), ExpectedToken::TypeName => write!(f, "a type"), ExpectedToken::Identifier => write!(f, "identifier"), ExpectedToken::IntLiteral => write!(f, "integer literal"), diff --git a/src/front/glsl/functions.rs b/src/front/glsl/functions.rs index 2c0445bdf2..806008e5b5 100644 --- a/src/front/glsl/functions.rs +++ b/src/front/glsl/functions.rs @@ -721,8 +721,7 @@ impl Parser { self.errors.push(Error { kind: ErrorKind::SemanticError( format!( - "'{}': image needs {:?} access but only {:?} was provided", - name, overload_access, call_access + "'{name}': image needs {overload_access:?} access but only {call_access:?} was provided" ) .into(), ), @@ -829,14 +828,14 @@ impl Parser { if ambiguous { self.errors.push(Error { kind: ErrorKind::SemanticError( - format!("Ambiguous best function for '{}'", name).into(), + format!("Ambiguous best function for '{name}'").into(), ), meta, }) } let overload = maybe_overload.ok_or_else(|| Error { - kind: ErrorKind::SemanticError(format!("Unknown function '{}'", name).into()), + kind: ErrorKind::SemanticError(format!("Unknown function '{name}'").into()), meta, })?; diff --git a/src/front/glsl/types.rs b/src/front/glsl/types.rs index 427b0b27ba..29d6e692b9 100644 --- a/src/front/glsl/types.rs +++ b/src/front/glsl/types.rs @@ -256,7 +256,7 @@ impl Parser { ctx.typifier .grow(expr, &ctx.expressions, &resolve_ctx) .map_err(|error| Error { - kind: ErrorKind::SemanticError(format!("Can't resolve type: {:?}", error).into()), + kind: ErrorKind::SemanticError(format!("Can't resolve type: {error:?}").into()), meta, }) } @@ -322,7 +322,7 @@ impl Parser { ctx.typifier .invalidate(expr, &ctx.expressions, &resolve_ctx) .map_err(|error| Error { - kind: ErrorKind::SemanticError(format!("Can't resolve type: {:?}", error).into()), + kind: ErrorKind::SemanticError(format!("Can't resolve type: {error:?}").into()), meta, }) } diff --git a/src/front/glsl/variables.rs b/src/front/glsl/variables.rs index ea8c9e8b50..e3fba754d8 100644 --- a/src/front/glsl/variables.rs +++ b/src/front/glsl/variables.rs @@ -317,8 +317,7 @@ impl Parser { kind: ErrorKind::SemanticError( format!( - "swizzle cannot have duplicate components in left-hand-side expression for \"{:?}\"", - name + "swizzle cannot have duplicate components in left-hand-side expression for \"{name:?}\"" ) .into(), ), @@ -379,7 +378,7 @@ impl Parser { _ => { self.errors.push(Error { kind: ErrorKind::SemanticError( - format!("Bad swizzle size for \"{:?}\"", name).into(), + format!("Bad swizzle size for \"{name:?}\"").into(), ), meta, }); @@ -413,7 +412,7 @@ impl Parser { } else { Err(Error { kind: ErrorKind::SemanticError( - format!("Invalid swizzle for vector \"{}\"", name).into(), + format!("Invalid swizzle for vector \"{name}\"").into(), ), meta, }) @@ -421,7 +420,7 @@ impl Parser { } _ => Err(Error { kind: ErrorKind::SemanticError( - format!("Can't lookup field on this type \"{}\"", name).into(), + format!("Can't lookup field on this type \"{name}\"").into(), ), meta, }), diff --git a/src/front/spv/function.rs b/src/front/spv/function.rs index 956f93cf9c..39987e62d3 100644 --- a/src/front/spv/function.rs +++ b/src/front/spv/function.rs @@ -170,7 +170,7 @@ impl> super::Parser { None => format!("block_ctx.Fun-{}.txt", module.functions.len()), }; let dest = prefix.join(dump_suffix); - let dump = format!("{:#?}", block_ctx); + let dump = format!("{block_ctx:#?}"); if let Err(e) = std::fs::write(&dest, dump) { log::error!("Unable to dump the block context into {:?}: {}", dest, e); } diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index b51f10f231..93a76178b7 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -1378,7 +1378,7 @@ impl> Parser { let result_type_id = self.next()?; let result_id = self.next()?; - let name = format!("phi_{}", result_id); + let name = format!("phi_{result_id}"); let local = ctx.local_arena.append( crate::LocalVariable { name: Some(name), diff --git a/src/front/wgsl/mod.rs b/src/front/wgsl/mod.rs index c4821ba62b..7e28268457 100644 --- a/src/front/wgsl/mod.rs +++ b/src/front/wgsl/mod.rs @@ -218,20 +218,20 @@ impl<'a> Error<'a> { let expected_str = match expected { ExpectedToken::Token(token) => { match token { - Token::Separator(c) => format!("'{}'", c), - Token::Paren(c) => format!("'{}'", c), + Token::Separator(c) => format!("'{c}'"), + Token::Paren(c) => format!("'{c}'"), Token::Attribute => "@".to_string(), Token::Number(_) => "number".to_string(), Token::Word(s) => s.to_string(), - Token::Operation(c) => format!("operation ('{}')", c), - Token::LogicalOperation(c) => format!("logical operation ('{}')", c), - Token::ShiftOperation(c) => format!("bitshift ('{}{}')", c, c), - Token::AssignmentOperation(c) if c=='<' || c=='>' => format!("bitshift ('{}{}=')", c, c), - Token::AssignmentOperation(c) => format!("operation ('{}=')", c), + Token::Operation(c) => format!("operation ('{c}')"), + Token::LogicalOperation(c) => format!("logical operation ('{c}')"), + Token::ShiftOperation(c) => format!("bitshift ('{c}{c}')"), + Token::AssignmentOperation(c) if c=='<' || c=='>' => format!("bitshift ('{c}{c}=')"), + Token::AssignmentOperation(c) => format!("operation ('{c}=')"), Token::IncrementOperation => "increment operation".to_string(), Token::DecrementOperation => "decrement operation".to_string(), Token::Arrow => "->".to_string(), - Token::Unknown(c) => format!("unknown ('{}')", c), + Token::Unknown(c) => format!("unknown ('{c}')"), Token::Trivia => "trivia".to_string(), Token::End => "end".to_string(), } @@ -261,7 +261,7 @@ impl<'a> Error<'a> { "expected {}, found '{}'", expected_str, &source[unexpected_span], ), - labels: vec![(unexpected_span, format!("expected {}", expected_str).into())], + labels: vec![(unexpected_span, format!("expected {expected_str}").into())], notes: vec![], } } @@ -305,7 +305,7 @@ impl<'a> Error<'a> { notes: vec![], }, Error::UnknownIdent(ident_span, ident) => ParseError { - message: format!("no definition in scope for identifier: '{}'", ident), + message: format!("no definition in scope for identifier: '{ident}'"), labels: vec![(ident_span, "unknown identifier".into())], notes: vec![], }, @@ -342,7 +342,7 @@ impl<'a> Error<'a> { ref from_type, ref to_type, } => { - let msg = format!("cannot cast a {} to a {}", from_type, to_type); + let msg = format!("cannot cast a {from_type} to a {to_type}"); ParseError { message: msg.clone(), labels: vec![(span, msg.into())], @@ -376,10 +376,7 @@ impl<'a> Error<'a> { notes: vec![], }, Error::InvalidConstructorComponentType(bad_span, component) => ParseError { - message: format!( - "invalid type for constructor component at index [{}]", - component - ), + message: format!("invalid type for constructor component at index [{component}]"), labels: vec![(bad_span, "invalid component type".into())], notes: vec![], }, @@ -435,13 +432,13 @@ impl<'a> Error<'a> { notes: vec![], }, Error::SizeAttributeTooLow(bad_span, min_size) => ParseError { - message: format!("struct member size must be at least {}", min_size), - labels: vec![(bad_span, format!("must be at least {}", min_size).into())], + message: format!("struct member size must be at least {min_size}"), + labels: vec![(bad_span, format!("must be at least {min_size}").into())], notes: vec![], }, Error::AlignAttributeTooLow(bad_span, min_align) => ParseError { - message: format!("struct member alignment must be at least {}", min_align), - labels: vec![(bad_span, format!("must be at least {}", min_align).into())], + message: format!("struct member alignment must be at least {min_align}"), + labels: vec![(bad_span, format!("must be at least {min_align}").into())], notes: vec![], }, Error::NonPowerOfTwoAlignAttribute(bad_span) => ParseError { @@ -512,7 +509,7 @@ impl<'a> Error<'a> { notes: vec![], }, Error::NotReference(what, span) => ParseError { - message: format!("{} must be a reference", what), + message: format!("{what} must be a reference"), labels: vec![(span, "expression is not a reference".into())], notes: vec![], }, @@ -532,7 +529,7 @@ impl<'a> Error<'a> { }, }, Error::Pointer(what, span) => ParseError { - message: format!("{} must not be a pointer", what), + message: format!("{what} must not be a pointer"), labels: vec![(span, "expression is a pointer".into())], notes: vec![], }, @@ -733,7 +730,7 @@ impl crate::TypeInner { Ti::Pointer { base, .. } => { let base = &types[base]; let name = base.name.as_deref().unwrap_or("unknown"); - format!("ptr<{}>", name) + format!("ptr<{name}>") } Ti::ValuePointer { kind, width, .. } => { format!("ptr<{}>", kind.to_wgsl(width)) @@ -758,9 +755,9 @@ impl crate::TypeInner { } => size.to_string(), _ => "?".to_string(), }); - format!("array<{}, {}>", base, size) + format!("array<{base}, {size}>") } - crate::ArraySize::Dynamic => format!("array<{}>", base), + crate::ArraySize::Dynamic => format!("array<{base}>"), } } Ti::Struct { .. } => { @@ -794,7 +791,7 @@ impl crate::TypeInner { // The lexer has already verified this, so we can safely assume it here. // https://gpuweb.github.io/gpuweb/wgsl/#sampled-texture-type let element_type = kind.to_wgsl(4); - format!("<{}>", element_type) + format!("<{element_type}>") } crate::ImageClass::Depth { multi: _ } => String::new(), crate::ImageClass::Storage { format, access } => { @@ -806,10 +803,7 @@ impl crate::TypeInner { } }; - format!( - "texture{}{}{}{}", - class_suffix, dim_suffix, array_suffix, type_in_brackets - ) + format!("texture{class_suffix}{dim_suffix}{array_suffix}{type_in_brackets}") } Ti::Sampler { .. } => "sampler".to_string(), Ti::BindingArray { base, size, .. } => { @@ -818,9 +812,9 @@ impl crate::TypeInner { match size { crate::ArraySize::Constant(size) => { let size = constants[size].name.as_deref().unwrap_or("unknown"); - format!("binding_array<{}, {}>", base, size) + format!("binding_array<{base}, {size}>") } - crate::ArraySize::Dynamic => format!("binding_array<{}>", base), + crate::ArraySize::Dynamic => format!("binding_array<{base}>"), } } } @@ -1681,7 +1675,7 @@ impl ParseError { .with_notes( self.notes .iter() - .map(|note| format!("note: {}", note)) + .map(|note| format!("note: {note}")) .collect(), ); diagnostic diff --git a/src/front/wgsl/number.rs b/src/front/wgsl/number.rs index 6c3d93c398..cd7b88c7e0 100644 --- a/src/front/wgsl/number.rs +++ b/src/front/wgsl/number.rs @@ -317,7 +317,7 @@ fn parse_hex_float_missing_period( exponent: &str, kind: Option, ) -> Result { - let hexf_input = format!("{}.{}", significand, exponent); + let hexf_input = format!("{significand}.{exponent}"); parse_hex_float(&hexf_input, kind) } @@ -328,7 +328,7 @@ fn parse_hex_int( kind: Option, ) -> Result { let digits_with_sign = if is_negative { - Cow::Owned(format!("-{}", digits)) + Cow::Owned(format!("-{digits}")) } else { Cow::Borrowed(digits) }; diff --git a/src/proc/namer.rs b/src/proc/namer.rs index 3f4af47884..053126b8ac 100644 --- a/src/proc/namer.rs +++ b/src/proc/namer.rs @@ -64,7 +64,7 @@ impl Namer { for prefix in &self.reserved_prefixes { if base.starts_with(prefix) { - return format!("gen_{}", base).into(); + return format!("gen_{base}").into(); } } @@ -210,11 +210,11 @@ impl Namer { crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Sint(v), - } => write!(temp, "const_{}i", v), + } => write!(temp, "const_{v}i"), crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Uint(v), - } => write!(temp, "const_{}u", v), + } => write!(temp, "const_{v}u"), crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Float(v), @@ -237,7 +237,7 @@ impl Namer { crate::ConstantInner::Scalar { width: _, value: crate::ScalarValue::Bool(v), - } => write!(temp, "const_{}", v), + } => write!(temp, "const_{v}"), crate::ConstantInner::Composite { ty, components: _ } => { write!(temp, "const_{}", output[&NameKey::Type(ty)]) } diff --git a/src/proc/typifier.rs b/src/proc/typifier.rs index 47ad05e06c..4c55d101ab 100644 --- a/src/proc/typifier.rs +++ b/src/proc/typifier.rs @@ -601,8 +601,7 @@ impl<'a> ResolveContext<'a> { (&Ti::Vector { .. }, &Ti::Vector { .. }) => res_left.clone(), (tl, tr) => { return Err(ResolveError::IncompatibleOperands(format!( - "{:?} * {:?}", - tl, tr + "{tl:?} * {tr:?}" ))) } } @@ -622,8 +621,7 @@ impl<'a> ResolveContext<'a> { Ti::Vector { size, .. } => Ti::Vector { size, kind, width }, ref other => { return Err(ResolveError::IncompatibleOperands(format!( - "{:?}({:?}, _)", - op, other + "{op:?}({other:?}, _)" ))) } }; @@ -660,8 +658,7 @@ impl<'a> ResolveContext<'a> { }), ref other => { return Err(ResolveError::IncompatibleOperands(format!( - "{:?}({:?})", - fun, other + "{fun:?}({other:?})" ))) } }, @@ -722,18 +719,18 @@ impl<'a> ResolveContext<'a> { } => TypeResolution::Value(Ti::Scalar { kind, width }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?}, _)", fun, other) + format!("{fun:?}({other:?}, _)") )), }, Mf::Outer => { let arg1 = arg1.ok_or_else(|| ResolveError::IncompatibleOperands( - format!("{:?}(_, None)", fun) + format!("{fun:?}(_, None)") ))?; match (res_arg.inner_with(types), past(arg1)?.inner_with(types)) { (&Ti::Vector {kind: _, size: columns,width}, &Ti::Vector{ size: rows, .. }) => TypeResolution::Value(Ti::Matrix { columns, rows, width }), (left, right) => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?}, {:?})", fun, left, right) + format!("{fun:?}({left:?}, {right:?})") )), } }, @@ -743,7 +740,7 @@ impl<'a> ResolveContext<'a> { Ti::Scalar {width,kind} | Ti::Vector {width,kind,size:_} => TypeResolution::Value(Ti::Scalar { kind, width }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?})", fun, other) + format!("{fun:?}({other:?})") )), }, Mf::Normalize | @@ -769,7 +766,7 @@ impl<'a> ResolveContext<'a> { width, }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?})", fun, other) + format!("{fun:?}({other:?})") )), }, Mf::Inverse => match *res_arg.inner_with(types) { @@ -783,7 +780,7 @@ impl<'a> ResolveContext<'a> { width, }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?})", fun, other) + format!("{fun:?}({other:?})") )), }, Mf::Determinant => match *res_arg.inner_with(types) { @@ -792,7 +789,7 @@ impl<'a> ResolveContext<'a> { .. } => TypeResolution::Value(Ti::Scalar { kind: crate::ScalarKind::Float, width }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?})", fun, other) + format!("{fun:?}({other:?})") )), }, // bits @@ -807,7 +804,7 @@ impl<'a> ResolveContext<'a> { Ti::Vector { size, kind: kind @ (crate::ScalarKind::Sint | crate::ScalarKind::Uint), width } => TypeResolution::Value(Ti::Vector { size, kind, width }), ref other => return Err(ResolveError::IncompatibleOperands( - format!("{:?}({:?})", fun, other) + format!("{fun:?}({other:?})") )), }, // data packing @@ -853,8 +850,7 @@ impl<'a> ResolveContext<'a> { }), ref other => { return Err(ResolveError::IncompatibleOperands(format!( - "{:?} as {:?}", - other, kind + "{other:?} as {kind:?}" ))) } }, diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 00c263946e..ad15d614fd 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -90,7 +90,7 @@ struct Parameters { #[allow(unused_variables)] fn check_targets(module: &naga::Module, name: &str, targets: Targets) { let root = env!("CARGO_MANIFEST_DIR"); - let params = match fs::read_to_string(format!("{}/{}/{}.param.ron", root, BASE_DIR_IN, name)) { + let params = match fs::read_to_string(format!("{root}/{BASE_DIR_IN}/{name}.param.ron")) { Ok(string) => ron::de::from_str(&string).expect("Couldn't parse param file"), Err(_) => Parameters::default(), }; @@ -108,7 +108,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { if targets.contains(Targets::IR) { let config = ron::ser::PrettyConfig::default().new_line("\n".to_string()); let string = ron::ser::to_string_pretty(module, config).unwrap(); - fs::write(dest.join(format!("ir/{}.ron", name)), string).unwrap(); + fs::write(dest.join(format!("ir/{name}.ron")), string).unwrap(); } } @@ -121,7 +121,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { if targets.contains(Targets::ANALYSIS) { let config = ron::ser::PrettyConfig::default().new_line("\n".to_string()); let string = ron::ser::to_string_pretty(&info, config).unwrap(); - fs::write(dest.join(format!("analysis/{}.info.ron", name)), string).unwrap(); + fs::write(dest.join(format!("analysis/{name}.info.ron")), string).unwrap(); } } @@ -177,7 +177,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) { { if targets.contains(Targets::DOT) { let string = naga::back::dot::write(module, Some(&info), Default::default()).unwrap(); - fs::write(dest.join(format!("dot/{}.dot", name)), string).unwrap(); + fs::write(dest.join(format!("dot/{name}.dot")), string).unwrap(); } } #[cfg(all(feature = "deserialize", feature = "hlsl-out"))] @@ -248,7 +248,7 @@ fn write_output_spv( let dis = rspirv::dr::load_words(spv) .expect("Produced invalid SPIR-V") .disassemble(); - fs::write(destination.join(format!("spv/{}.spvasm", file_name)), dis).unwrap(); + fs::write(destination.join(format!("spv/{file_name}.spvasm")), dis).unwrap(); } } @@ -269,7 +269,7 @@ fn write_output_msl( let mut options = options.clone(); options.bounds_check_policies = bounds_check_policies; let (string, tr_info) = msl::write_string(module, info, &options, pipeline_options) - .unwrap_or_else(|err| panic!("Metal write failed: {}", err)); + .unwrap_or_else(|err| panic!("Metal write failed: {err}")); for (ep, result) in module.entry_points.iter().zip(tr_info.entry_point_names) { if let Err(error) = result { @@ -277,7 +277,7 @@ fn write_output_msl( } } - fs::write(destination.join(format!("msl/{}.msl", file_name)), string).unwrap(); + fs::write(destination.join(format!("msl/{file_name}.msl")), string).unwrap(); } #[cfg(feature = "glsl-out")] @@ -316,7 +316,7 @@ fn write_output_glsl( writer.write().expect("GLSL write failed"); fs::write( - destination.join(format!("glsl/{}.{}.{:?}.glsl", file_name, ep_name, stage)), + destination.join(format!("glsl/{file_name}.{ep_name}.{stage:?}.glsl")), buffer, ) .unwrap(); @@ -339,7 +339,7 @@ fn write_output_hlsl( let mut writer = hlsl::Writer::new(&mut buffer, options); let reflection_info = writer.write(module, info).expect("HLSL write failed"); - fs::write(destination.join(format!("hlsl/{}.hlsl", file_name)), buffer).unwrap(); + fs::write(destination.join(format!("hlsl/{file_name}.hlsl")), buffer).unwrap(); // We need a config file for validation script // This file contains an info about profiles (shader stages) contains inside generated shader @@ -387,15 +387,10 @@ fn write_output_hlsl( } } - writeln!( - config_str, - "{})\n{})\n{})", - vertex_str, fragment_str, compute_str - ) - .unwrap(); + writeln!(config_str, "{vertex_str})\n{fragment_str})\n{compute_str})").unwrap(); fs::write( - destination.join(format!("hlsl/{}.hlsl.config", file_name)), + destination.join(format!("hlsl/{file_name}.hlsl.config")), config_str, ) .unwrap(); @@ -418,7 +413,7 @@ fn write_output_wgsl( let string = wgsl::write_string(module, info, flags).expect("WGSL write failed"); - fs::write(destination.join(format!("wgsl/{}.wgsl", file_name)), string).unwrap(); + fs::write(destination.join(format!("wgsl/{file_name}.wgsl")), string).unwrap(); } #[cfg(feature = "wgsl-in")] @@ -564,9 +559,9 @@ fn convert_wgsl() { ]; for &(name, targets) in inputs.iter() { - println!("Processing '{}'", name); + println!("Processing '{name}'"); // WGSL shaders lives in root dir as a privileged. - let file = fs::read_to_string(format!("{}/{}/{}.wgsl", root, BASE_DIR_IN, name)) + let file = fs::read_to_string(format!("{root}/{BASE_DIR_IN}/{name}.wgsl")) .expect("Couldn't find wgsl file"); match naga::front::wgsl::parse_str(&file) { Ok(module) => check_targets(&module, name, targets), @@ -581,8 +576,7 @@ fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { let root = env!("CARGO_MANIFEST_DIR"); let module = naga::front::spv::parse_u8_slice( - &fs::read(format!("{}/{}/spv/{}.spv", root, BASE_DIR_IN, name)) - .expect("Couldn't find spv file"), + &fs::read(format!("{root}/{BASE_DIR_IN}/spv/{name}.spv")).expect("Couldn't find spv file"), &naga::front::spv::Options { adjust_coordinate_space, strict_capabilities: false, @@ -627,7 +621,7 @@ fn convert_spv_all() { #[test] fn convert_glsl_variations_check() { let root = env!("CARGO_MANIFEST_DIR"); - let file = fs::read_to_string(format!("{}/{}/variations.glsl", root, BASE_DIR_IN)) + let file = fs::read_to_string(format!("{root}/{BASE_DIR_IN}/variations.glsl")) .expect("Couldn't find glsl file"); let mut parser = naga::front::glsl::Parser::default(); let module = parser @@ -650,7 +644,7 @@ fn convert_glsl_folder() { let root = env!("CARGO_MANIFEST_DIR"); - for entry in std::fs::read_dir(format!("{}/{}/glsl", root, BASE_DIR_IN)).unwrap() { + for entry in std::fs::read_dir(format!("{root}/{BASE_DIR_IN}/glsl")).unwrap() { let entry = entry.unwrap(); let file_name = entry.file_name().into_string().unwrap(); @@ -658,7 +652,7 @@ fn convert_glsl_folder() { // No needed to validate ron files continue; } - println!("Processing {}", file_name); + println!("Processing {file_name}"); let mut parser = naga::front::glsl::Parser::default(); let module = parser @@ -668,7 +662,7 @@ fn convert_glsl_folder() { "vert" => naga::ShaderStage::Vertex, "frag" => naga::ShaderStage::Fragment, "comp" => naga::ShaderStage::Compute, - ext => panic!("Unknown extension for glsl file {}", ext), + ext => panic!("Unknown extension for glsl file {ext}"), }, defines: Default::default(), }, diff --git a/tests/spirv-capabilities.rs b/tests/spirv-capabilities.rs index 409768910b..0700bce09f 100644 --- a/tests/spirv-capabilities.rs +++ b/tests/spirv-capabilities.rs @@ -40,10 +40,7 @@ fn require_and_forbid(required: &[Ca], forbidden: &[Ca], source: &str) { .cloned() .collect(); if !missing_caps.is_empty() { - panic!( - "shader code should have requested these caps: {:?}\n\n{}", - missing_caps, source - ); + panic!("shader code should have requested these caps: {missing_caps:?}\n\n{source}"); } let forbidden_caps: Vec<_> = forbidden @@ -52,10 +49,7 @@ fn require_and_forbid(required: &[Ca], forbidden: &[Ca], source: &str) { .cloned() .collect(); if !forbidden_caps.is_empty() { - panic!( - "shader code should not have requested these caps: {:?}\n\n{}", - forbidden_caps, source - ); + panic!("shader code should not have requested these caps: {forbidden_caps:?}\n\n{source}"); } } diff --git a/tests/wgsl-errors.rs b/tests/wgsl-errors.rs index 917628b279..039d4751b5 100644 --- a/tests/wgsl-errors.rs +++ b/tests/wgsl-errors.rs @@ -10,9 +10,9 @@ fn check(input: &str, snapshot: &str) { if output != snapshot { for diff in diff::lines(&output, snapshot) { match diff { - diff::Result::Left(l) => println!("-{}", l), - diff::Result::Both(l, _) => println!(" {}", l), - diff::Result::Right(r) => println!("+{}", r), + diff::Result::Left(l) => println!("-{l}"), + diff::Result::Both(l, _) => println!(" {l}"), + diff::Result::Right(r) => println!("+{r}"), } } panic!("Error snapshot failed"); @@ -1419,16 +1419,12 @@ fn wrong_access_mode() { #[test] fn io_shareable_types() { for numeric in "i32 u32 f32".split_whitespace() { - let types = format!( - "{} vec2<{}> vec3<{}> vec4<{}>", - numeric, numeric, numeric, numeric - ); + let types = format!("{numeric} vec2<{numeric}> vec3<{numeric}> vec4<{numeric}>"); for ty in types.split_whitespace() { check_one_validation! { &format!("@vertex - fn f(@location(0) arg: {}) -> @builtin(position) vec4 - {{ return vec4(0.0); }}", - ty), + fn f(@location(0) arg: {ty}) -> @builtin(position) vec4 + {{ return vec4(0.0); }}"), Ok(_module) } } @@ -1443,9 +1439,8 @@ fn io_shareable_types() { { check_one_validation! { &format!("@vertex - fn f(@location(0) arg: {}) -> @builtin(position) vec4 - {{ return vec4(0.0); }}", - ty), + fn f(@location(0) arg: {ty}) -> @builtin(position) vec4 + {{ return vec4(0.0); }}"), Err( naga::valid::ValidationError::EntryPoint { stage: naga::ShaderStage::Vertex, @@ -1474,9 +1469,8 @@ fn host_shareable_types() { for ty in types.split_whitespace() { check_one_validation! { &format!("struct AStruct {{ member: array, 8> }}; - @group(0) @binding(0) var ubuf: {}; - @group(0) @binding(1) var sbuf: {};", - ty, ty), + @group(0) @binding(0) var ubuf: {ty}; + @group(0) @binding(1) var sbuf: {ty};"), Ok(_module) } } @@ -1489,8 +1483,7 @@ fn host_shareable_types() { for ty in types.split_whitespace() { check_one_validation! { &format!("struct AStruct {{ member: array, 8> }}; - @group(0) @binding(1) var sbuf: {};", - ty), + @group(0) @binding(1) var sbuf: {ty};"), Ok(_module) } } @@ -1498,7 +1491,7 @@ fn host_shareable_types() { // Types that are neither host-shareable nor constructible. for ty in "bool ptr".split_whitespace() { check_one_validation! { - &format!("@group(0) @binding(0) var sbuf: {};", ty), + &format!("@group(0) @binding(0) var sbuf: {ty};"), Err( naga::valid::ValidationError::GlobalVariable { name, @@ -1510,7 +1503,7 @@ fn host_shareable_types() { } check_one_validation! { - &format!("@group(0) @binding(0) var ubuf: {};", ty), + &format!("@group(0) @binding(0) var ubuf: {ty};"), Err(naga::valid::ValidationError::GlobalVariable { name, handle: _,