Skip to content

Commit f113225

Browse files
committed
Fix clippy warnings across workspace
1 parent e3c1b77 commit f113225

5 files changed

Lines changed: 39 additions & 36 deletions

File tree

rust/spirv-tools-core/src/assembly/parser.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,20 @@ pub struct ImageOperandsOperand<'a> {
157157
}
158158

159159
impl<'a> ImageOperandsOperand<'a> {
160+
/// Creates a new image operands operand from a mask and dependent ids.
160161
pub const fn new(mask: spirv::ImageOperands, dependent_ids: Vec<IdRef<'a>>) -> Self {
161162
Self {
162163
mask,
163164
dependent_ids,
164165
}
165166
}
166167

168+
/// Returns the image operands mask.
167169
pub const fn mask(&self) -> spirv::ImageOperands {
168170
self.mask
169171
}
170172

173+
/// Returns the dependent id operands following the mask.
171174
pub fn dependent_ids(&self) -> &[IdRef<'a>] {
172175
&self.dependent_ids
173176
}

rust/spirv-tools-core/src/validation/cfg_analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ impl ControlFlowGraph {
249249
let exit_blocks: Vec<Id> = blocks
250250
.iter()
251251
.filter(|b| {
252-
successors.get(b).map_or(true, |s| {
252+
successors.get(b).is_none_or(|s| {
253253
s.is_empty() || s.iter().all(|t| !blocks.contains(t))
254254
})
255255
})

rust/spirv-tools-core/src/validation/rules/dot_product.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ fn get_operand_type_id(
4141
}
4242

4343
/// Looks up a type instruction by its ID.
44-
fn get_type_inst<'a>(
44+
fn get_type_inst(
4545
type_id: u32,
46-
definitions: &'a HashMap<ResultId, Instruction>,
47-
) -> Option<&'a Instruction> {
46+
definitions: &HashMap<ResultId, Instruction>,
47+
) -> Option<&Instruction> {
4848
let type_rid = ResultId::try_from(type_id).ok()?;
4949
definitions.get(&type_rid)
5050
}

rust/spirv-tools-core/src/validation/rules/group.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ fn get_operand_type_inst<'a>(
5151
}
5252

5353
/// Gets the type instruction for a result type ID.
54-
fn get_type_inst<'a>(
54+
fn get_type_inst(
5555
type_id: u32,
56-
definitions: &'a HashMap<ResultId, Instruction>,
57-
) -> Option<&'a Instruction> {
56+
definitions: &HashMap<ResultId, Instruction>,
57+
) -> Option<&Instruction> {
5858
let type_rid = ResultId::try_from(type_id).ok()?;
5959
definitions.get(&type_rid)
6060
}

rust/spirv-tools-core/src/validation/rules/image.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl ValidationRule for ImageTypeRule {
172172
}
173173

174174
// Extract Sampled Type (operand 0)
175-
let sampled_type_id = match &inst.operands.get(0) {
175+
let sampled_type_id = match &inst.operands.first() {
176176
Some(Operand::IdRef(id)) => Some(*id),
177177
_ => None,
178178
};
@@ -645,9 +645,9 @@ impl ValidationRule for ImageOperandTypeRule {
645645
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
646646
{
647647
word_idx += 1;
648-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
649-
if !resolver.is_float_scalar(type_id, &ctx.definitions)
650-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
648+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
649+
if !resolver.is_float_scalar(type_id, ctx.definitions)
650+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
651651
{
652652
return Err(
653653
ValidationError::ImageOperandBiasNotFloat32Scalar {
@@ -684,15 +684,15 @@ impl ValidationRule for ImageOperandTypeRule {
684684
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
685685
{
686686
word_idx += 1;
687-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
687+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
688688
let is_explicit = opcode.is_explicit_lod();
689689
let is_gather_lod_bias_amd = opcode.is_gather()
690690
&& ctx.has_capability(Capability::ImageGatherBiasLodAMD);
691691

692692
if is_explicit || is_gather_lod_bias_amd {
693693
// Must be 32-bit float scalar
694-
if !resolver.is_float_scalar(type_id, &ctx.definitions)
695-
|| resolver.get_bit_width(type_id, &ctx.definitions)
694+
if !resolver.is_float_scalar(type_id, ctx.definitions)
695+
|| resolver.get_bit_width(type_id, ctx.definitions)
696696
!= Some(32)
697697
{
698698
return Err(
@@ -706,8 +706,8 @@ impl ValidationRule for ImageOperandTypeRule {
706706
}
707707
} else {
708708
// Must be 32-bit int scalar (for Fetch)
709-
if !resolver.is_int_scalar(type_id, &ctx.definitions)
710-
|| resolver.get_bit_width(type_id, &ctx.definitions)
709+
if !resolver.is_int_scalar(type_id, ctx.definitions)
710+
|| resolver.get_bit_width(type_id, ctx.definitions)
711711
!= Some(32)
712712
{
713713
return Err(
@@ -756,13 +756,13 @@ impl ValidationRule for ImageOperandTypeRule {
756756
word_idx += 1;
757757

758758
if let (Some(dx_id), Some(dy_id)) = (dx_id, dy_id) {
759-
let dx_type = get_value_type_id(dx_id, &ctx.definitions);
760-
let dy_type = get_value_type_id(dy_id, &ctx.definitions);
759+
let dx_type = get_value_type_id(dx_id, ctx.definitions);
760+
let dy_type = get_value_type_id(dy_id, ctx.definitions);
761761

762762
// Both must be 32-bit float scalar or vector
763763
for type_id in [dx_type, dy_type].into_iter().flatten() {
764-
if !resolver.is_float_scalar_or_vector(type_id, &ctx.definitions)
765-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
764+
if !resolver.is_float_scalar_or_vector(type_id, ctx.definitions)
765+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
766766
{
767767
return Err(ValidationError::ImageOperandGradNotFloat32 {
768768
function: function_id,
@@ -777,7 +777,7 @@ impl ValidationRule for ImageOperandTypeRule {
777777
if let Some(ref info) = image_type_info {
778778
let plane_size = get_plane_coord_size(info);
779779
for type_id in [dx_type, dy_type].into_iter().flatten() {
780-
let dim = resolver.get_dimension(type_id, &ctx.definitions);
780+
let dim = resolver.get_dimension(type_id, ctx.definitions);
781781
if plane_size != dim {
782782
return Err(
783783
ValidationError::ImageOperandGradComponentCountMismatch {
@@ -801,9 +801,9 @@ impl ValidationRule for ImageOperandTypeRule {
801801
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
802802
{
803803
word_idx += 1;
804-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
805-
if !resolver.is_int_scalar_or_vector(type_id, &ctx.definitions)
806-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
804+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
805+
if !resolver.is_int_scalar_or_vector(type_id, ctx.definitions)
806+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
807807
{
808808
return Err(ValidationError::ImageOperandOffsetNotInt32 {
809809
function: function_id,
@@ -816,7 +816,7 @@ impl ValidationRule for ImageOperandTypeRule {
816816

817817
if let Some(ref info) = image_type_info {
818818
let plane_size = get_plane_coord_size(info);
819-
let dim = resolver.get_dimension(type_id, &ctx.definitions);
819+
let dim = resolver.get_dimension(type_id, ctx.definitions);
820820
if plane_size != dim {
821821
return Err(
822822
ValidationError::ImageOperandOffsetComponentCountMismatch {
@@ -834,7 +834,7 @@ impl ValidationRule for ImageOperandTypeRule {
834834
}
835835

836836
// Must be a constant
837-
if !is_constant_id(operand_id, &ctx.definitions) {
837+
if !is_constant_id(operand_id, ctx.definitions) {
838838
return Err(ValidationError::ImageOperandConstOffsetNotConstant {
839839
function: function_id,
840840
block: block_id,
@@ -853,9 +853,9 @@ impl ValidationRule for ImageOperandTypeRule {
853853
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
854854
{
855855
word_idx += 1;
856-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
857-
if !resolver.is_int_scalar_or_vector(type_id, &ctx.definitions)
858-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
856+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
857+
if !resolver.is_int_scalar_or_vector(type_id, ctx.definitions)
858+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
859859
{
860860
return Err(ValidationError::ImageOperandOffsetNotInt32 {
861861
function: function_id,
@@ -868,7 +868,7 @@ impl ValidationRule for ImageOperandTypeRule {
868868

869869
if let Some(ref info) = image_type_info {
870870
let plane_size = get_plane_coord_size(info);
871-
let dim = resolver.get_dimension(type_id, &ctx.definitions);
871+
let dim = resolver.get_dimension(type_id, ctx.definitions);
872872
if plane_size != dim {
873873
return Err(
874874
ValidationError::ImageOperandOffsetComponentCountMismatch {
@@ -900,9 +900,9 @@ impl ValidationRule for ImageOperandTypeRule {
900900
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
901901
{
902902
word_idx += 1;
903-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
904-
if !resolver.is_int_scalar(type_id, &ctx.definitions)
905-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
903+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
904+
if !resolver.is_int_scalar(type_id, ctx.definitions)
905+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
906906
{
907907
return Err(
908908
ValidationError::ImageOperandSampleNotInt32Scalar {
@@ -937,9 +937,9 @@ impl ValidationRule for ImageOperandTypeRule {
937937
inst.operands.get(word_idx).and_then(|o| o.id_ref_any())
938938
{
939939
let _ = word_idx; // last operand we check
940-
if let Some(type_id) = get_value_type_id(operand_id, &ctx.definitions) {
941-
if !resolver.is_float_scalar(type_id, &ctx.definitions)
942-
|| resolver.get_bit_width(type_id, &ctx.definitions) != Some(32)
940+
if let Some(type_id) = get_value_type_id(operand_id, ctx.definitions) {
941+
if !resolver.is_float_scalar(type_id, ctx.definitions)
942+
|| resolver.get_bit_width(type_id, ctx.definitions) != Some(32)
943943
{
944944
return Err(
945945
ValidationError::ImageOperandMinLodNotFloat32Scalar {

0 commit comments

Comments
 (0)