mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
44d8ecbfb8
Instead of ``` error[E0308]: mismatched types --> tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.rs:9:5 | 4 | fn get_name() -> String { | ------ expected `String` because of return type ... 9 | your_name.trim() //~ ERROR E0308 | ^^^^^^^^^^^^^^^^ expected `String`, found `&str` | help: try removing the method call | 9 - your_name.trim() 9 + your_name ``` output ``` error[E0308]: mismatched types --> $DIR/only-suggest-removal-of-conversion-method-calls.rs:9:5 | LL | fn get_name() -> String { | ------ expected `String` because of return type ... LL | your_name.trim() | ^^^^^^^^^^^^^^^^- help: try using a conversion method: `.to_string()` | | | expected `String`, found `&str` ``` Fix #114329.
17 lines
375 B
Rust
17 lines
375 B
Rust
// run-rustfix
|
|
use std::io::stdin;
|
|
|
|
fn get_name() -> String {
|
|
let mut your_name = String::new();
|
|
stdin()
|
|
.read_line(&mut your_name)
|
|
.expect("Failed to read the line for some reason");
|
|
your_name.trim() //~ ERROR E0308
|
|
}
|
|
|
|
fn main() {
|
|
println!("Hello, What is your name? ");
|
|
let your_name = get_name();
|
|
println!("Hello, {}", your_name)
|
|
}
|