Skip to content

Commit ca57155

Browse files
committed
Obey clippy::filter_next
It was not initially clear to me why, after changing `.filter(...).next()` to `.find(...)`, the borrow checker as of Rust 1.41.1 required me to inline `all.lines()` at this point : error[E0596]: cannot borrow `lines` as mutable, as it is not declared as mutable --> tyrga-bin/../build.rs:53:33 | 52 | let lines = all.lines(); | ----- help: consider changing this to be mutable: `mut lines` 53 | let wrote = lines | ^^^^^ cannot borrow as mutable error: aborting due to previous error For more information about this error, try `rustc --explain E0596`. but it [appears][0] that the new error is [expected][1], and that if I had been using `.find()` previously instead of `.filter(...).next()`, I would have seen a non-fatal "compat" lint under previous compiler versions, leading me in the same direction. [0]: rust-lang/rust#68729 [1]: rust-lang/rust#65785
1 parent fa62777 commit ca57155

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

build.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![deny(clippy::filter_next)]
2+
13
use std::error::Error;
24
use std::fs;
35
use std::path::Path;
@@ -47,10 +49,8 @@ fn main() -> Result<(), Box<dyn Error>> {
4749
// [wrote RegularFileObject[xyz/interesting/module/name/Packaged.class]]
4850
// This lets us copy the .tas file to the right location alongside the .class.
4951
let all = std::str::from_utf8(&output.stderr)?;
50-
let lines = all.lines();
51-
let wrote = lines
52-
.filter(|x| x.starts_with(&"[wrote"))
53-
.next()
52+
let wrote = all.lines()
53+
.find(|x| x.starts_with(&"[wrote"))
5454
.expect("unexpected output from javac");
5555
// Different versions of javac use different syntaxes for demarcating paths
5656
let first = wrote

tyrga-lib/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#![deny(clippy::inefficient_to_string)]
1919
#![deny(clippy::comparison_chain)]
2020
#![deny(clippy::redundant_clone)]
21+
#![deny(clippy::filter_next)]
2122

2223
// make macros visible to later modules
2324
#[macro_use]

0 commit comments

Comments
 (0)