Skip to content

Commit 9673f39

Browse files
authored
A whole host of minor tweaks and clippy fixes (#824)
1 parent 7a60181 commit 9673f39

File tree

20 files changed

+32
-70
lines changed

20 files changed

+32
-70
lines changed

crates/rustc_codegen_spirv/src/builder/builder_methods.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -797,8 +797,6 @@ impl<'a, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'tcx> {
797797
val
798798
}
799799

800-
// silly clippy, we can't rename this!
801-
#[allow(clippy::wrong_self_convention)]
802800
fn to_immediate_scalar(&mut self, val: Self::Value, _scalar: Scalar) -> Self::Value {
803801
val
804802
}

crates/rustc_codegen_spirv/src/builder/byte_addressable_buffer.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::Builder;
22
use crate::builder_spirv::{SpirvValue, SpirvValueExt};
33
use crate::spirv_type::SpirvType;
4-
use core::array::IntoIter;
54
use rspirv::spirv::Word;
65
use rustc_codegen_ssa::traits::{BaseTypeMethods, BuilderMethods};
76
use rustc_span::DUMMY_SP;
@@ -39,12 +38,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3938
let u32_ptr = self.type_ptr_to(u32_ty);
4039
let ptr = self
4140
.emit()
42-
.in_bounds_access_chain(
43-
u32_ptr,
44-
None,
45-
array.def(self),
46-
IntoIter::new([actual_index.def(self)]),
47-
)
41+
.in_bounds_access_chain(u32_ptr, None, array.def(self), [actual_index.def(self)])
4842
.unwrap()
4943
.with_type(u32_ptr);
5044
self.load(u32_ty, ptr, Align::ONE)
@@ -218,12 +212,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
218212
let u32_ptr = self.type_ptr_to(u32_ty);
219213
let ptr = self
220214
.emit()
221-
.in_bounds_access_chain(
222-
u32_ptr,
223-
None,
224-
array.def(self),
225-
IntoIter::new([actual_index.def(self)]),
226-
)
215+
.in_bounds_access_chain(u32_ptr, None, array.def(self), [actual_index.def(self)])
227216
.unwrap()
228217
.with_type(u32_ptr);
229218
self.store(value, ptr, Align::ONE);

crates/rustc_codegen_spirv/src/builder_spirv.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,16 +518,16 @@ impl BuilderSpirv {
518518

519519
SpirvConst::Composite(ref v) => v.iter().fold(Ok(()), |composite_legal, field| {
520520
let field_entry = &self.id_to_const.borrow()[field];
521-
let field_legal_in_composite = field_entry.legal.and_then(|()| {
521+
let field_legal_in_composite = field_entry.legal.and(
522522
// `field` is itself some legal `SpirvConst`, but can we have
523523
// it as part of an `OpConstantComposite`?
524524
match field_entry.val {
525525
SpirvConst::PtrTo { .. } => Err(IllegalConst::Shallow(
526526
LeafIllegalConst::CompositeContainsPtrTo,
527527
)),
528528
_ => Ok(()),
529-
}
530-
});
529+
},
530+
);
531531

532532
match (composite_legal, field_legal_in_composite) {
533533
(Ok(()), Ok(())) => Ok(()),

crates/rustc_codegen_spirv/src/codegen_cx/declare.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@ impl<'tcx> CodegenCx<'tcx> {
113113
let entry_name = entry
114114
.name
115115
.as_ref()
116-
.map(ToString::to_string)
117-
.unwrap_or_else(|| instance.to_string());
116+
.map_or_else(|| instance.to_string(), ToString::to_string);
118117
self.entry_stub(&instance, fn_abi, declared, entry_name, entry);
119118
}
120119
if attrs.unroll_loops.is_some() {

crates/rustc_codegen_spirv/src/compile_result.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,9 @@ pub const a: &str = "x::a";
120120
#[cfg(test)]
121121
mod test {
122122
use super::*;
123-
use std::array::IntoIter;
124123

125124
fn test<const N: usize>(arr: [&str; N], expected: &str) {
126-
let trie = Trie::create_from(IntoIter::new(arr));
125+
let trie = Trie::create_from(IntoIterator::into_iter(arr));
127126
let mut builder = String::new();
128127
trie.emit(&mut builder, String::new(), 0);
129128
assert_eq!(builder, expected);

crates/rustc_codegen_spirv/src/lib.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,11 @@
8989
// END - Embark standard lints v0.4
9090
// crate-specific exceptions:
9191
#![allow(
92-
unsafe_code, // still quite a bit of unsafe
93-
clippy::map_unwrap_or, // TODO: test enabling
94-
clippy::match_on_vec_items, // TODO: test enabling
95-
clippy::enum_glob_use,
92+
unsafe_code, // rustc_codegen_ssa requires unsafe functions in traits to be impl'd
93+
clippy::match_on_vec_items, // rustc_codegen_spirv has less strict panic requirements than other embark projects
94+
clippy::enum_glob_use, // pretty useful pattern with some codegen'd enums (e.g. rspirv::spirv::Op)
9695
clippy::todo, // still lots to implement :)
9796
)]
98-
#![deny(clippy::unimplemented, clippy::ok_expect)]
9997

10098
// Unfortunately, this will not fail fast when compiling, but rather will wait for
10199
// rustc_codegen_spirv to be compiled. Putting this in build.rs will solve that problem, however,

crates/rustc_codegen_spirv/src/link.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ fn do_link(
548548

549549
/// As of right now, this is essentially a no-op, just plumbing through all the files.
550550
// TODO: WorkProduct impl
551-
#[allow(clippy::unnecessary_wraps)]
552551
pub(crate) fn run_thin(
553552
cgcx: &CodegenContext<SpirvCodegenBackend>,
554553
modules: Vec<(String, SpirvThinBuffer)>,

crates/rustc_codegen_spirv/src/linker/inline.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ pub fn inline(sess: &Session, module: &mut Module) -> super::Result<()> {
3131
.types_global_values
3232
.iter()
3333
.find(|inst| inst.class.opcode == Op::TypeVoid)
34-
.map(|inst| inst.result_id.unwrap())
35-
.unwrap_or(0);
34+
.map_or(0, |inst| inst.result_id.unwrap());
3635
// Drop all the functions we'll be inlining. (This also means we won't waste time processing
3736
// inlines in functions that will get inlined)
3837
let mut dropped_ids = FxHashSet::default();

crates/rustc_codegen_spirv/src/linker/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ fn get_names(module: &Module) -> FxHashMap<Word, &str> {
9595
}
9696

9797
fn get_name<'a>(names: &FxHashMap<Word, &'a str>, id: Word) -> Cow<'a, str> {
98-
names
99-
.get(&id)
100-
.map(|&s| Cow::Borrowed(s))
101-
.unwrap_or_else(|| Cow::Owned(format!("Unnamed function ID %{}", id)))
98+
names.get(&id).map_or_else(
99+
|| Cow::Owned(format!("Unnamed function ID %{}", id)),
100+
|&s| Cow::Borrowed(s),
101+
)
102102
}
103103

104104
pub fn link(sess: &Session, mut inputs: Vec<Module>, opts: &Options) -> Result<LinkResult> {

crates/rustc_codegen_spirv/src/linker/peephole_opts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ fn match_operands(
289289
let parameters = (2..results[0].operands.len())
290290
.map(|i| match_vector_or_scalars_operand(types, defs, results, i, vector_width));
291291
// Do some trickery to reduce allocations.
292-
let operands = std::array::IntoIter::new([
292+
let operands = IntoIterator::into_iter([
293293
Some(IdentifiedOperand::NonValue(set)),
294294
Some(IdentifiedOperand::NonValue(instruction)),
295295
])

0 commit comments

Comments
 (0)