Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lines_filter_map_ok should respect MSRV #14127

Closed
taiki-e opened this issue Feb 1, 2025 · 0 comments · Fixed by #14130
Closed

lines_filter_map_ok should respect MSRV #14127

taiki-e opened this issue Feb 1, 2025 · 0 comments · Fixed by #14130
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@taiki-e
Copy link
Member

taiki-e commented Feb 1, 2025

Summary

Iterator::map_while requires Rust 1.57, but this lint also suggests using it for code with MSRV less than 1.57.

Lint Name

lines_filter_map_ok

Reproducer

I tried this code:

#![warn(clippy::lines_filter_map_ok)]

use std::{fs::File, io::*};

#[clippy::msrv = "1.56"]
fn _f() {
    let _lines = BufReader::new(File::open("some-path").unwrap())
        .lines()
        .filter_map(Result::ok);
}

I saw this happen:

warning: `filter_map()` will run forever if the iterator repeatedly produces an `Err`
 --> src/lib.rs:9:10
  |
9 |         .filter_map(Result::ok);
  |          ^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)`
  |
note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error
 --> src/lib.rs:7:18
  |
7 |       let _lines = BufReader::new(File::open("some-path").unwrap())
  |  __________________^
8 | |         .lines()
  | |________________^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::lines_filter_map_ok)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^

However, the suggested code cases compile error on MSRV (Rust 1.56): https://godbolt.org/z/4KT7M4WTr

error[E0658]: use of unstable library feature 'iter_map_while': recently added
 --> <source>:9:10
  |
9 |         .map_while(Result::ok);
  |          ^^^^^^^^^
  |
  = note: see issue #68537 <https://github.com/rust-lang/rust/issues/68537> for more information

I expected to see this happen: no warning or another suggestion

playground

Version

rustc 1.86.0-nightly (854f22563 2025-01-31)
binary: rustc
commit-hash: 854f22563c8daf92709fae18ee6aed52953835cd
commit-date: 2025-01-31
host: aarch64-apple-darwin
release: 1.86.0-nightly
LLVM version: 19.1.7

Additional Labels

No response

@taiki-e taiki-e added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Feb 1, 2025
taiki-e added a commit to eupn/macrotest that referenced this issue Feb 1, 2025
rust-lang/rust-clippy#14127

```
warning: `filter_map()` will run forever if the iterator repeatedly produces an `Err`
  --> src/cargo.rs:95:10
   |
95 |         .filter_map(|line| line.ok())
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)`
   |
note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error
  --> src/cargo.rs:93:5
   |
93 | /     reader
94 | |         .lines()
   | |________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok
   = note: `#[warn(clippy::lines_filter_map_ok)]` on by default
```
taiki-e added a commit to eupn/macrotest that referenced this issue Feb 1, 2025
rust-lang/rust-clippy#14127

```
warning: `filter_map()` will run forever if the iterator repeatedly produces an `Err`
  --> src/cargo.rs:95:10
   |
95 |         .filter_map(|line| line.ok())
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `map_while(Result::ok)`
   |
note: this expression returning a `std::io::Lines` may produce an infinite number of `Err` in case of a read error
  --> src/cargo.rs:93:5
   |
93 | /     reader
94 | |         .lines()
   | |________________^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#lines_filter_map_ok
   = note: `#[warn(clippy::lines_filter_map_ok)]` on by default
```
github-merge-queue bot pushed a commit that referenced this issue Feb 7, 2025
fixes #14127

changelog: [`lines_filter_map_ok`]: respect MSRV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant