Skip to content

Conversation

yawara
Copy link
Contributor

@yawara yawara commented Nov 13, 2024

changelog: [bufreader_stdin]: new lint

fixes #6755

@rustbot
Copy link
Collaborator

rustbot commented Nov 13, 2024

r? @Manishearth

rustbot has assigned @Manishearth.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 13, 2024
@yawara yawara changed the title new lint: bufreader_stdin new lint: bufreader_stdin Nov 13, 2024
@yawara yawara changed the title new lint: bufreader_stdin [WIP] new lint: bufreader_stdin Nov 13, 2024
@yawara yawara force-pushed the new-lint-bufreader-stdin branch from 11c3cce to c266263 Compare November 13, 2024 06:46
@yawara yawara changed the title [WIP] new lint: bufreader_stdin new lint: bufreader_stdin Nov 13, 2024
Copy link
Member

@J-ZhengLi J-ZhengLi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~

/// let reader = stdin.lock();
/// ```
#[clippy::version = "1.84.0"]
pub BUFREADER_STDIN,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think Buf and Reader should be separated words? no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, this is BufReader + Stdin, so I'd keep BufReader as a single atomic unit in the name

let reader = a.lock();

let b = io::stdin().lock();
let reader = b;
Copy link
Member

@J-ZhengLi J-ZhengLi Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be very careful dealing with suggestions where type changes occur, this suggestion won't work if the resulting variable is used somewhere else, for example:

use std::io::{self, BufReader};
use std::io::StdinLock;

fn main() {
    let b = io::stdin().lock();
    let reader = BufReader::new(b);
    // let reader = b; // does not work
    
    i_want_buf_reader(reader);
}

fn i_want_buf_reader(reader: BufReader<StdinLock>) {
    // do something with the reader
    drop(reader);
}

this will not compile, and another example would be

static READER_ONCE: OnceLock<BufReader<Stdin>> = OnceLock::new();
let a = READER_ONCE.get_or_init(|| BufReader::new(io::stdin()));

although these are very unlikely to happen, but you can never be too careful~ So I'd say at least changing the applicability to MaybeIncorrect?

Also, it would be nice to run lintcheck to see if there are any false positive cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these suggestions aren't MachineApplicable. MaybeIncorrect, unfortunately.

Comment on lines +1 to +8
error: unknown lint: `clippy::BUFREADER_STDIN`
--> tests/ui/bufreader_stdin.rs:1:9
|
LL | #![warn(clippy::BUFREADER_STDIN)]
| ^^^^^^^^^^^^^^^^^^^^^^^ help: did you mean: `clippy::bufreader_stdin`
|
= note: `-D unknown-lints` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unknown_lints)]`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like an accident, make sure to change it to lowercase name

@rustbot
Copy link
Collaborator

rustbot commented Mar 31, 2025

☔ The latest upstream changes (possibly d28d234) made this pull request unmergeable. Please resolve the merge conflicts.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 31, 2025
@Jarcho
Copy link
Contributor

Jarcho commented Sep 17, 2025

Ping @yawara from triage. Do you plan to return to working on this?

@Jarcho
Copy link
Contributor

Jarcho commented Oct 1, 2025

Closing since there's been no response. @yawara if you wish to return to this feel free to reopen or create a new PR.

@Jarcho Jarcho closed this Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BufReader Stdin or StdinLock

5 participants