forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120473 - estebank:issue-114329, r=TaKO8Ki Only suggest removal of `as_*` and `to_` conversion methods on E0308 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() | ^^^^^^^^^^^^^^^^ 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 rust-lang#114329.
- Loading branch information
Showing
4 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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().to_string() //~ ERROR E0308 | ||
} | ||
|
||
fn main() { | ||
println!("Hello, What is your name? "); | ||
let your_name = get_name(); | ||
println!("Hello, {}", your_name) | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// 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) | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/ui/suggestions/only-suggest-removal-of-conversion-method-calls.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
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` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |