Skip to content

Commit c0027f6

Browse files
authored
Merge pull request #1 from JakenHerman/get_line_confusable
Add `get_line` confusable to `Stdin::read_line()`
2 parents 1d71891 + 3208f4e commit c0027f6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

library/std/src/io/stdio.rs

+1
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ impl Stdin {
394394
/// in which case it will wait for the Enter key to be pressed before
395395
/// continuing
396396
#[stable(feature = "rust1", since = "1.0.0")]
397+
#[rustc_confusables("get_line")]
397398
pub fn read_line(&self, buf: &mut String) -> io::Result<usize> {
398399
self.lock().read_line(buf)
399400
}

tests/ui/attributes/rustc_confusables_std_cases.rs

+4
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ fn main() {
2323
//~^ HELP you might have meant to use `push_str`
2424
String::new().append(""); //~ ERROR E0599
2525
//~^ HELP you might have meant to use `push_str`
26+
let mut buffer = String::new();
27+
let stdin = std::io::stdin();
28+
stdin.get_line(&mut buffer).unwrap(); //~ ERROR E0599
29+
//~^ HELP you might have meant to use `read_line`
2630
}

tests/ui/attributes/rustc_confusables_std_cases.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,18 @@ help: you might have meant to use `push_str`
106106
LL | String::new().push_str("");
107107
| ~~~~~~~~
108108

109-
error: aborting due to 8 previous errors
109+
error[E0599]: no method named `get_line` found for struct `Stdin` in the current scope
110+
--> $DIR/rustc_confusables_std_cases.rs:28:11
111+
|
112+
LL | stdin.get_line(&mut buffer).unwrap();
113+
| ^^^^^^^^ method not found in `Stdin`
114+
|
115+
help: you might have meant to use `read_line`
116+
|
117+
LL | stdin.read_line(&mut buffer).unwrap();
118+
| ~~~~~~~~~
119+
120+
error: aborting due to 9 previous errors
110121

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

0 commit comments

Comments
 (0)