Skip to content

Commit

Permalink
Obey clippy::filter_next
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kulp committed Apr 11, 2020
1 parent fa62777 commit ca57155
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
8 changes: 4 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::filter_next)]

use std::error::Error;
use std::fs;
use std::path::Path;
Expand Down Expand Up @@ -47,10 +49,8 @@ fn main() -> Result<(), Box<dyn Error>> {
// [wrote RegularFileObject[xyz/interesting/module/name/Packaged.class]]
// This lets us copy the .tas file to the right location alongside the .class.
let all = std::str::from_utf8(&output.stderr)?;
let lines = all.lines();
let wrote = lines
.filter(|x| x.starts_with(&"[wrote"))
.next()
let wrote = all.lines()
.find(|x| x.starts_with(&"[wrote"))
.expect("unexpected output from javac");
// Different versions of javac use different syntaxes for demarcating paths
let first = wrote
Expand Down
1 change: 1 addition & 0 deletions tyrga-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#![deny(clippy::inefficient_to_string)]
#![deny(clippy::comparison_chain)]
#![deny(clippy::redundant_clone)]
#![deny(clippy::filter_next)]

// make macros visible to later modules
#[macro_use]
Expand Down

0 comments on commit ca57155

Please sign in to comment.