mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
Fix nightly clippy suggestions
This commit is contained in:
committed by
Dzmitry Malyshau
parent
be2231f6d9
commit
54af830855
@@ -853,7 +853,7 @@ impl<W: Write> Writer<W> {
|
||||
members,
|
||||
span,
|
||||
index as usize,
|
||||
&context.module,
|
||||
context.module,
|
||||
),
|
||||
_ => None,
|
||||
}
|
||||
@@ -2080,7 +2080,7 @@ impl<W: Write> Writer<W> {
|
||||
_ => continue,
|
||||
};
|
||||
varying_count += 1;
|
||||
let name = &self.names[&name_key];
|
||||
let name = &self.names[name_key];
|
||||
let ty_name = TypeContext {
|
||||
handle: ty,
|
||||
arena: &module.types,
|
||||
@@ -2177,7 +2177,7 @@ impl<W: Write> Writer<W> {
|
||||
Some(ref binding @ &crate::Binding::BuiltIn(..)) => binding,
|
||||
_ => continue,
|
||||
};
|
||||
let name = &self.names[&name_key];
|
||||
let name = &self.names[name_key];
|
||||
let ty_name = TypeContext {
|
||||
handle: ty,
|
||||
arena: &module.types,
|
||||
|
||||
@@ -118,13 +118,13 @@ impl<W: Write> Writer<W> {
|
||||
// Write all constants
|
||||
for (handle, constant) in module.constants.iter() {
|
||||
if constant.name.is_some() {
|
||||
self.write_global_constant(&module, &constant.inner, handle)?;
|
||||
self.write_global_constant(module, &constant.inner, handle)?;
|
||||
}
|
||||
}
|
||||
|
||||
// Write all globals
|
||||
for (ty, global) in module.global_variables.iter() {
|
||||
self.write_global(&module, &global, ty)?;
|
||||
self.write_global(module, global, ty)?;
|
||||
}
|
||||
|
||||
if !module.global_variables.is_empty() {
|
||||
@@ -144,7 +144,7 @@ impl<W: Write> Writer<W> {
|
||||
};
|
||||
|
||||
// Write the function
|
||||
self.write_function(&module, &function, &func_ctx)?;
|
||||
self.write_function(module, function, &func_ctx)?;
|
||||
|
||||
writeln!(self.out)?;
|
||||
}
|
||||
@@ -165,11 +165,11 @@ impl<W: Write> Writer<W> {
|
||||
|
||||
let func_ctx = FunctionCtx {
|
||||
ty: FunctionType::EntryPoint(index as u16),
|
||||
info: &info.get_entry_point(index),
|
||||
info: info.get_entry_point(index),
|
||||
expressions: &ep.function.expressions,
|
||||
named_expressions: &ep.function.named_expressions,
|
||||
};
|
||||
self.write_function(&module, &ep.function, &func_ctx)?;
|
||||
self.write_function(module, &ep.function, &func_ctx)?;
|
||||
|
||||
if index < module.entry_points.len() - 1 {
|
||||
writeln!(self.out)?;
|
||||
@@ -288,7 +288,7 @@ impl<W: Write> Writer<W> {
|
||||
write!(self.out, "var {}: ", self.names[&func_ctx.name_key(handle)])?;
|
||||
|
||||
// Write the local type
|
||||
self.write_type(&module, local.ty)?;
|
||||
self.write_type(module, local.ty)?;
|
||||
|
||||
// Write the local initializer if needed
|
||||
if let Some(init) = local.init {
|
||||
@@ -312,7 +312,7 @@ impl<W: Write> Writer<W> {
|
||||
// Write the function body (statement list)
|
||||
for sta in func.body.iter() {
|
||||
// The indentation should always be 1 when writing the function body
|
||||
self.write_stmt(&module, sta, &func_ctx, 1)?;
|
||||
self.write_stmt(module, sta, func_ctx, 1)?;
|
||||
}
|
||||
|
||||
writeln!(self.out, "}}")?;
|
||||
@@ -607,7 +607,7 @@ impl<W: Write> Writer<W> {
|
||||
base,
|
||||
index,
|
||||
module,
|
||||
&func_ctx.info,
|
||||
func_ctx.info,
|
||||
) {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -622,8 +622,8 @@ impl<W: Write> Writer<W> {
|
||||
|
||||
if let Some(name) = expr_name {
|
||||
write!(self.out, "{}", INDENT.repeat(indent))?;
|
||||
self.start_named_expr(module, handle, &func_ctx, &name)?;
|
||||
self.write_expr(module, handle, &func_ctx)?;
|
||||
self.start_named_expr(module, handle, func_ctx, &name)?;
|
||||
self.write_expr(module, handle, func_ctx)?;
|
||||
self.named_expressions.insert(handle, name);
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
@@ -664,7 +664,7 @@ impl<W: Write> Writer<W> {
|
||||
if let Some(return_value) = value {
|
||||
// The leading space is important
|
||||
write!(self.out, " ")?;
|
||||
self.write_expr(module, return_value, &func_ctx)?;
|
||||
self.write_expr(module, return_value, func_ctx)?;
|
||||
}
|
||||
writeln!(self.out, ";")?;
|
||||
}
|
||||
@@ -678,7 +678,7 @@ impl<W: Write> Writer<W> {
|
||||
// We already skip them when we generate struct type.
|
||||
// Now we need to find expression that used struct with ignored builtins
|
||||
if let Expression::AccessIndex { base, index } = func_ctx.expressions[pointer] {
|
||||
if access_to_unsupported_builtin(base, index, module, &func_ctx.info) {
|
||||
if access_to_unsupported_builtin(base, index, module, func_ctx.info) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
@@ -880,7 +880,7 @@ impl<W: Write> Writer<W> {
|
||||
match *expression {
|
||||
Expression::Constant(constant) => self.write_constant(module, constant)?,
|
||||
Expression::Compose { ty, ref components } => {
|
||||
self.write_type(&module, ty)?;
|
||||
self.write_type(module, ty)?;
|
||||
write!(self.out, "(")?;
|
||||
// !spv-in specific notes!
|
||||
// WGSL does not support all SPIR-V builtins and we should skip it in generated shaders.
|
||||
@@ -900,7 +900,7 @@ impl<W: Write> Writer<W> {
|
||||
if let Expression::AccessIndex { base, index } =
|
||||
func_ctx.expressions[pointer]
|
||||
{
|
||||
if access_to_unsupported_builtin(base, index, module, &func_ctx.info) {
|
||||
if access_to_unsupported_builtin(base, index, module, func_ctx.info) {
|
||||
skip_component = true;
|
||||
}
|
||||
}
|
||||
@@ -915,7 +915,7 @@ impl<W: Write> Writer<W> {
|
||||
// non spv-in specific notes!
|
||||
// Real `Expression::Compose` logic generates here.
|
||||
for (index, component) in components_to_write.iter().enumerate() {
|
||||
self.write_expr(module, *component, &func_ctx)?;
|
||||
self.write_expr(module, *component, func_ctx)?;
|
||||
// Only write a comma if isn't the last element
|
||||
if index != components_to_write.len().saturating_sub(1) {
|
||||
// The leading space is for readability only
|
||||
|
||||
@@ -121,13 +121,13 @@ impl<'a> Program<'a> {
|
||||
constants: &self.module.constants,
|
||||
types: &self.module.types,
|
||||
global_vars: &self.module.global_variables,
|
||||
local_vars: &context.locals,
|
||||
local_vars: context.locals,
|
||||
functions: &self.module.functions,
|
||||
arguments: &context.arguments,
|
||||
arguments: context.arguments,
|
||||
};
|
||||
match context
|
||||
.typifier
|
||||
.grow(handle, &context.expressions, &resolve_ctx)
|
||||
.grow(handle, context.expressions, &resolve_ctx)
|
||||
{
|
||||
//TODO: better error report
|
||||
Err(error) => Err(ErrorKind::SemanticError(
|
||||
@@ -148,13 +148,13 @@ impl<'a> Program<'a> {
|
||||
constants: &self.module.constants,
|
||||
types: &self.module.types,
|
||||
global_vars: &self.module.global_variables,
|
||||
local_vars: &context.locals,
|
||||
local_vars: context.locals,
|
||||
functions: &self.module.functions,
|
||||
arguments: &context.arguments,
|
||||
arguments: context.arguments,
|
||||
};
|
||||
match context
|
||||
.typifier
|
||||
.grow(handle, &context.expressions, &resolve_ctx)
|
||||
.grow(handle, context.expressions, &resolve_ctx)
|
||||
{
|
||||
//TODO: better error report
|
||||
Err(error) => Err(ErrorKind::SemanticError(
|
||||
@@ -286,11 +286,11 @@ impl<'function> Context<'function> {
|
||||
}
|
||||
|
||||
pub fn emit_start(&mut self) {
|
||||
self.emitter.start(&self.expressions)
|
||||
self.emitter.start(self.expressions)
|
||||
}
|
||||
|
||||
pub fn emit_flush(&mut self, body: &mut Block) {
|
||||
body.extend(self.emitter.finish(&self.expressions))
|
||||
body.extend(self.emitter.finish(self.expressions))
|
||||
}
|
||||
|
||||
pub fn add_expression(&mut self, expr: Expression, body: &mut Block) -> Handle<Expression> {
|
||||
|
||||
@@ -513,9 +513,8 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
// TODO: Should we try to make constants here?
|
||||
// This is mostly a hack because we don't yet support adding
|
||||
// bodies to entry points for variable initialization
|
||||
let maybe_constant = init
|
||||
.clone()
|
||||
.and_then(|(root, meta)| self.program.solve_constant(ctx.ctx, root, meta).ok());
|
||||
let maybe_constant =
|
||||
init.and_then(|(root, meta)| self.program.solve_constant(ctx.ctx, root, meta).ok());
|
||||
|
||||
let pointer = ctx.add_var(self.program, ty, name, maybe_constant, meta)?;
|
||||
|
||||
@@ -1283,7 +1282,7 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
|
||||
let expr = self.parse_expression(ctx, body)?;
|
||||
let (root, meta) =
|
||||
ctx.lower_expect(self.program, expr, false, body)?;
|
||||
let constant = self.program.solve_constant(&ctx, root, meta)?;
|
||||
let constant = self.program.solve_constant(ctx, root, meta)?;
|
||||
|
||||
match self.program.module.constants[constant].inner {
|
||||
ConstantInner::Scalar {
|
||||
|
||||
@@ -521,7 +521,7 @@ impl FlowGraph {
|
||||
lookup_expression: &FastHashMap<spirv::Word, LookupExpression>,
|
||||
) {
|
||||
for node_index in self.flow.node_indices() {
|
||||
let phis = std::mem::replace(&mut self.flow[node_index].phis, Vec::new());
|
||||
let phis = std::mem::take(&mut self.flow[node_index].phis);
|
||||
for phi in phis.iter() {
|
||||
for &(variable_id, parent_id) in phi.variables.iter() {
|
||||
let variable = &lookup_expression[&variable_id];
|
||||
@@ -612,8 +612,7 @@ impl FlowGraph {
|
||||
intended_merge
|
||||
};
|
||||
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
|
||||
let mut accept_stop_nodes = stop_nodes.clone();
|
||||
accept_stop_nodes.insert(merge_node_index);
|
||||
@@ -673,8 +672,7 @@ impl FlowGraph {
|
||||
} => {
|
||||
let merge_node_index =
|
||||
self.block_to_node[&self.flow[node_index].merge.unwrap().merge_block_id];
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
let mut cases = Vec::with_capacity(targets.len());
|
||||
|
||||
let mut stop_nodes_cases = stop_nodes.clone();
|
||||
@@ -731,11 +729,10 @@ impl FlowGraph {
|
||||
.unwrap()
|
||||
.target();
|
||||
|
||||
std::mem::replace(&mut self.flow[continue_edge].block, Vec::new())
|
||||
std::mem::take(&mut self.flow[continue_edge].block)
|
||||
};
|
||||
|
||||
let mut body: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut body: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
|
||||
let mut stop_nodes_merge = stop_nodes.clone();
|
||||
stop_nodes_merge.insert(merge_node_index);
|
||||
@@ -780,8 +777,7 @@ impl FlowGraph {
|
||||
Ok(result)
|
||||
}
|
||||
Some(ControlFlowNodeType::Break) => {
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
match self.flow[node_index].terminator {
|
||||
Terminator::BranchConditional {
|
||||
condition,
|
||||
@@ -838,12 +834,11 @@ impl FlowGraph {
|
||||
};
|
||||
Ok(result)
|
||||
}
|
||||
Some(ControlFlowNodeType::Continue) | Some(ControlFlowNodeType::Back) => Ok(
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new()),
|
||||
),
|
||||
Some(ControlFlowNodeType::Continue) | Some(ControlFlowNodeType::Back) => {
|
||||
Ok(std::mem::take(&mut self.flow[node_index].block))
|
||||
}
|
||||
Some(ControlFlowNodeType::Kill) => {
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
result.push(crate::Statement::Kill);
|
||||
Ok(result)
|
||||
}
|
||||
@@ -852,24 +847,19 @@ impl FlowGraph {
|
||||
Terminator::Return { value } => value,
|
||||
_ => return Err(Error::InvalidTerminator),
|
||||
};
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
result.push(crate::Statement::Return { value });
|
||||
Ok(result)
|
||||
}
|
||||
Some(ControlFlowNodeType::Merge) | None => match self.flow[node_index].terminator {
|
||||
Terminator::Branch { target_id } => {
|
||||
let mut result: crate::Block =
|
||||
std::mem::replace(&mut self.flow[node_index].block, Vec::new());
|
||||
let mut result: crate::Block = std::mem::take(&mut self.flow[node_index].block);
|
||||
result.extend(
|
||||
self.convert_to_naga_traverse(self.block_to_node[&target_id], stop_nodes)?,
|
||||
);
|
||||
Ok(result)
|
||||
}
|
||||
_ => Ok(std::mem::replace(
|
||||
&mut self.flow[node_index].block,
|
||||
Vec::new(),
|
||||
)),
|
||||
_ => Ok(std::mem::take(&mut self.flow[node_index].block)),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2215,7 +2215,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
} => {
|
||||
if let [S::Break] = reject[..] {
|
||||
// uplift "accept" into the parent
|
||||
let extracted = mem::replace(accept, Vec::new());
|
||||
let extracted = mem::take(accept);
|
||||
statements.splice(i + 1..i + 1, extracted.into_iter());
|
||||
} else {
|
||||
self.patch_statements(reject)?;
|
||||
@@ -2229,7 +2229,7 @@ impl<I: Iterator<Item = u32>> Parser<I> {
|
||||
} => {
|
||||
if cases.is_empty() {
|
||||
// uplift "default" into the parent
|
||||
let extracted = mem::replace(default, Vec::new());
|
||||
let extracted = mem::take(default);
|
||||
statements.splice(i + 1..i + 1, extracted.into_iter());
|
||||
} else {
|
||||
for case in cases.iter_mut() {
|
||||
|
||||
@@ -1511,8 +1511,8 @@ impl Parser {
|
||||
(to_type, from_type) => {
|
||||
return Err(Error::BadTypeCast {
|
||||
span: arguments_span,
|
||||
from_type: from_type.to_wgsl(&ctx.types, &ctx.constants),
|
||||
to_type: to_type.to_wgsl(&ctx.types, &ctx.constants),
|
||||
from_type: from_type.to_wgsl(ctx.types, ctx.constants),
|
||||
to_type: to_type.to_wgsl(ctx.types, ctx.constants),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1542,14 +1542,9 @@ impl Parser {
|
||||
let inner = match first_token_span {
|
||||
(Token::Word("true"), _) => crate::ConstantInner::boolean(true),
|
||||
(Token::Word("false"), _) => crate::ConstantInner::boolean(false),
|
||||
(
|
||||
Token::Number {
|
||||
ref value,
|
||||
ref ty,
|
||||
ref width,
|
||||
},
|
||||
_,
|
||||
) => Self::get_constant_inner(*value, *ty, *width, first_token_span)?,
|
||||
(Token::Number { value, ty, width }, _) => {
|
||||
Self::get_constant_inner(value, ty, width, first_token_span)?
|
||||
}
|
||||
(Token::Word(name), name_span) => {
|
||||
// look for an existing constant first
|
||||
for (handle, var) in const_arena.iter() {
|
||||
@@ -3213,7 +3208,7 @@ impl Parser {
|
||||
}
|
||||
(Token::Word("fn"), _) => {
|
||||
let (function, name) =
|
||||
self.parse_function_decl(lexer, module, &lookup_global_expression)?;
|
||||
self.parse_function_decl(lexer, module, lookup_global_expression)?;
|
||||
match stage {
|
||||
Some(stage) => module.entry_points.push(crate::EntryPoint {
|
||||
name: name.to_string(),
|
||||
|
||||
@@ -55,8 +55,8 @@ impl crate::Module {
|
||||
//
|
||||
// So, temporarily swap the member list out its type, assign appropriate
|
||||
// interpolations to its members, and then swap the list back in.
|
||||
use std::mem::replace;
|
||||
let mut members = replace(m, vec![]);
|
||||
use std::mem;
|
||||
let mut members = mem::take(m);
|
||||
|
||||
for member in &mut members {
|
||||
default_binding_or_struct(&mut member.binding, member.ty, types);
|
||||
@@ -68,7 +68,7 @@ impl crate::Module {
|
||||
match types.get_mut(ty).inner {
|
||||
TypeInner::Struct {
|
||||
members: ref mut m, ..
|
||||
} => replace(m, members),
|
||||
} => mem::replace(m, members),
|
||||
_ => unreachable!("ty must be a struct"),
|
||||
};
|
||||
|
||||
|
||||
@@ -413,7 +413,7 @@ impl super::Validator {
|
||||
crate::ShaderStage::Compute => ShaderStages::COMPUTE,
|
||||
};
|
||||
|
||||
let info = self.validate_function(&ep.function, module, &mod_info)?;
|
||||
let info = self.validate_function(&ep.function, module, mod_info)?;
|
||||
|
||||
if !info.available_stages.contains(stage_bit) {
|
||||
return Err(EntryPointError::ForbiddenStageOperations);
|
||||
|
||||
Reference in New Issue
Block a user