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

Closed
myclevorname opened this issue Oct 1, 2024 · 4 comments · Fixed by JakenHerman/rust#1 or #131163
Closed

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

myclevorname opened this issue Oct 1, 2024 · 4 comments · Fixed by JakenHerman/rust#1 or #131163
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.

@ChayimFriedman2
Copy link
Contributor

@GrigorenkoPV It is an inherent method though? (Though not for StdinLock).

@GrigorenkoPV
Copy link
Contributor

Oh, yes, you are right. I did confuse it with BufRead's one for StdinLock.

@bors bors closed this as completed in aedf14b Oct 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 3, 2024
Rollup merge of rust-lang#131163 - JakenHerman:master, r=Nadrieril

Add `get_line` confusable to `Stdin::read_line()`

This pull request resolves rust-lang#131091

---

I've updated tests for `tests/ui/attributes/rustc_confusables_std_cases` in order to verify this change is working as intended.

Before I submitted this pull request, I had a pull request to my local fork. If you're interested in seeing the conversation on that PR, go to JakenHerman#1.

---

**Testing**:
Run `./x.py test tests/ui/attributes/rustc_confusables_std_cases.rs`
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
3 participants