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 get_line confusable to Stdin::read_line() #131163

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions library/std/src/io/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ impl Stdin {
/// in which case it will wait for the Enter key to be pressed before
/// continuing
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_confusables("get_line")]
pub fn read_line(&self, buf: &mut String) -> io::Result<usize> {
self.lock().read_line(buf)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/attributes/rustc_confusables_std_cases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ fn main() {
//~^ HELP you might have meant to use `push_str`
String::new().append(""); //~ ERROR E0599
//~^ HELP you might have meant to use `push_str`
let mut buffer = String::new();
let stdin = std::io::stdin();
stdin.get_line(&mut buffer).unwrap(); //~ ERROR E0599
//~^ HELP you might have meant to use `read_line`
}
13 changes: 12 additions & 1 deletion tests/ui/attributes/rustc_confusables_std_cases.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,18 @@ help: you might have meant to use `push_str`
LL | String::new().push_str("");
| ~~~~~~~~

error: aborting due to 8 previous errors
error[E0599]: no method named `get_line` found for struct `Stdin` in the current scope
--> $DIR/rustc_confusables_std_cases.rs:28:11
|
LL | stdin.get_line(&mut buffer).unwrap();
| ^^^^^^^^ method not found in `Stdin`
|
help: you might have meant to use `read_line`
|
LL | stdin.read_line(&mut buffer).unwrap();
| ~~~~~~~~~

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try `rustc --explain E0308`.
Loading