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

Add compiler hint for stdin().get_line() -> stdin().read_line() #131091

Open
myclevorname opened this issue Oct 1, 2024 · 2 comments
Open

Add compiler hint for stdin().get_line() -> stdin().read_line() #131091

myclevorname opened this issue Oct 1, 2024 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@myclevorname
Copy link

myclevorname commented Oct 1, 2024

Code

I am learning Rust, and I keep typing std::io::stdin().get_line() instead of std::io::stdin().read_line() and the compiler doesn't give any useful hints.

Current output

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `get_line` found for struct `Stdin` in the current scope
 --> src/main.rs:5:13
  |
5 |     stdin().get_line(&mut string);
  |             ^^^^^^^^ method not found in `Stdin`

Desired output

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `get_line` found for struct `Stdin` in the current scope
 --> src/main.rs:5:13
  |
5 |     stdin().get_line(&mut string);
  |             ^^^^^^^^
  |
help: there is a method `read_line` with a similar name
  |
5 |     stdin().read_line(&mut string);
  |             ~~~~~~~~~

Rationale and extra context

I keep accidentally making this mistake because I am a beginner.

Other cases

No response

Rust Version

rustc version 1.81.0 via https://play.rust-lang.org/?version=stable&mode=debug&edition=2021
I am not able to access my laptop right now, and it uses 1.80.1 anyway.

Anything else?

No response

@myclevorname myclevorname added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 1, 2024
@ChayimFriedman2
Copy link
Contributor

I think putting #[doc(alias = "get_line")] on read_line() should be enough for that.

@GrigorenkoPV
Copy link
Contributor

I tried slapping #[rustc_confusables("read_line")] onto it, but it only seems to support inherent methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants