Skip to content

Commit 373b7a5

Browse files
authored
Replace filter_map().next() with find_map (#3620)
`rust-analyzer` emits a weak warning for this which leads to unnecessary noise in some editors. Signed-off-by: Oliver T <[email protected]>
1 parent d41202a commit 373b7a5

File tree

5 files changed

+10
-19
lines changed

5 files changed

+10
-19
lines changed

crates/cli-support/src/externref.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ fn find_call_export(instrs: &[InstructionData]) -> Option<Export> {
136136
instrs
137137
.iter()
138138
.enumerate()
139-
.filter_map(|(i, instr)| match instr.instr {
139+
.find_map(|(i, instr)| match instr.instr {
140140
Instruction::CallExport(e) => Some(Export::Export(e)),
141141
Instruction::CallTableElement(e) => Some(Export::TableElement {
142142
idx: e,
143143
call_idx: i,
144144
}),
145145
_ => None,
146146
})
147-
.next()
148147
}
149148

150149
enum Export {

crates/macro-support/src/parser.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,29 +143,27 @@ macro_rules! methods {
143143
fn $name(&self) -> Option<(&str, Span)> {
144144
self.attrs
145145
.iter()
146-
.filter_map(|a| match &a.1 {
146+
.find_map(|a| match &a.1 {
147147
BindgenAttr::$variant(_, s, span) => {
148148
a.0.set(true);
149149
Some((&s[..], *span))
150150
}
151151
_ => None,
152152
})
153-
.next()
154153
}
155154
};
156155

157156
(@method $name:ident, $variant:ident(Span, Vec<String>, Vec<Span>)) => {
158157
fn $name(&self) -> Option<(&[String], &[Span])> {
159158
self.attrs
160159
.iter()
161-
.filter_map(|a| match &a.1 {
160+
.find_map(|a| match &a.1 {
162161
BindgenAttr::$variant(_, ss, spans) => {
163162
a.0.set(true);
164163
Some((&ss[..], &spans[..]))
165164
}
166165
_ => None,
167166
})
168-
.next()
169167
}
170168
};
171169

@@ -174,14 +172,13 @@ macro_rules! methods {
174172
fn $name(&self) -> Option<&$($other)*> {
175173
self.attrs
176174
.iter()
177-
.filter_map(|a| match &a.1 {
175+
.find_map(|a| match &a.1 {
178176
BindgenAttr::$variant(_, s) => {
179177
a.0.set(true);
180178
Some(s)
181179
}
182180
_ => None,
183181
})
184-
.next()
185182
}
186183
};
187184

@@ -190,14 +187,13 @@ macro_rules! methods {
190187
fn $name(&self) -> Option<&$($other)*> {
191188
self.attrs
192189
.iter()
193-
.filter_map(|a| match &a.1 {
190+
.find_map(|a| match &a.1 {
194191
BindgenAttr::$variant(s) => {
195192
a.0.set(true);
196193
Some(s)
197194
}
198195
_ => None,
199196
})
200-
.next()
201197
}
202198
};
203199
}
@@ -1355,14 +1351,13 @@ impl<'a> MacroParse<(&'a mut TokenStream, BindgenAttrs)> for syn::ItemEnum {
13551351
values.sort();
13561352
let hole = values
13571353
.windows(2)
1358-
.filter_map(|window| {
1354+
.find_map(|window| {
13591355
if window[0] + 1 != window[1] {
13601356
Some(window[0] + 1)
13611357
} else {
13621358
None
13631359
}
13641360
})
1365-
.next()
13661361
.unwrap_or(*values.last().unwrap() + 1);
13671362
for value in values {
13681363
assert!(hole != value);

crates/threads-xform/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,10 @@ fn allocate_static_data(
249249
.exports
250250
.iter()
251251
.filter(|e| e.name == "__heap_base")
252-
.filter_map(|e| match e.item {
252+
.find_map(|e| match e.item {
253253
ExportItem::Global(id) => Some(id),
254254
_ => None,
255-
})
256-
.next();
255+
});
257256
let heap_base = match heap_base {
258257
Some(idx) => idx,
259258
None => bail!("failed to find `__heap_base` for injecting thread id"),

crates/wasm-interpreter/tests/smoke.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ fn interpret(wat: &str, name: &str, result: Option<&[u32]>) {
1212
.exports
1313
.iter()
1414
.filter(|e| e.name == name)
15-
.filter_map(|e| match e.item {
15+
.find_map(|e| match e.item {
1616
walrus::ExportItem::Function(f) => Some(f),
1717
_ => None,
1818
})
19-
.next()
2019
.unwrap();
2120
assert_eq!(i.interpret_descriptor(id, &module), result);
2221
}

crates/webidl/src/util.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,11 +602,10 @@ pub fn get_rust_deprecated<'a>(ext_attrs: &Option<ExtendedAttributeList<'a>>) ->
602602
_ => None,
603603
})
604604
.filter(|attr| attr.lhs_identifier.0 == "RustDeprecated")
605-
.filter_map(|ident| match ident.rhs {
605+
.find_map(|ident| match ident.rhs {
606606
IdentifierOrString::String(s) => Some(s),
607607
IdentifierOrString::Identifier(_) => None,
608608
})
609-
.next()
610609
.map(|s| s.0)
611610
}
612611

0 commit comments

Comments
 (0)