-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion. Fix #133833, fix #133834.
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
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
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
18 changes: 18 additions & 0 deletions
18
tests/ui/suggestions/semi-suggestion-when-stmt-and-expr-span-equal.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,18 @@ | ||
fn foo() -> String { | ||
let mut list = { | ||
println!(); | ||
}; | ||
list //~ ERROR mismatched types | ||
} | ||
|
||
fn bar() { | ||
String::new() | ||
.chars() | ||
.filter(|x| !x.is_whitespace()) | ||
.map(|x| { | ||
println!("Child spawned with the size: {}", x); | ||
}) | ||
.collect::<String>(); //~ ERROR E0277 | ||
} | ||
|
||
fn main() {} |
50 changes: 50 additions & 0 deletions
50
tests/ui/suggestions/semi-suggestion-when-stmt-and-expr-span-equal.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,50 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/semi-suggestion-when-stmt-and-expr-span-equal.rs:5:5 | ||
| | ||
LL | fn foo() -> String { | ||
| ------ expected `String` because of return type | ||
LL | let mut list = { | ||
| ____________________- | ||
LL | | println!(); | ||
LL | | }; | ||
| |_____- this block is missing a tail expression | ||
LL | list | ||
| ^^^^ expected `String`, found `()` | ||
|
||
error[E0277]: a value of type `String` cannot be built from an iterator over elements of type `()` | ||
--> $DIR/semi-suggestion-when-stmt-and-expr-span-equal.rs:15:20 | ||
| | ||
LL | .collect::<String>(); | ||
| ------- ^^^^^^ value of type `String` cannot be built from `std::iter::Iterator<Item=()>` | ||
| | | ||
| required by a bound introduced by this call | ||
| | ||
= help: the trait `FromIterator<()>` is not implemented for `String` | ||
= help: the following other types implement trait `FromIterator<A>`: | ||
`String` implements `FromIterator<&char>` | ||
`String` implements `FromIterator<&str>` | ||
`String` implements `FromIterator<Box<str, A>>` | ||
`String` implements `FromIterator<Cow<'_, str>>` | ||
`String` implements `FromIterator<String>` | ||
`String` implements `FromIterator<char>` | ||
note: the method call chain might not have had the expected associated types | ||
--> $DIR/semi-suggestion-when-stmt-and-expr-span-equal.rs:12:10 | ||
| | ||
LL | String::new() | ||
| ------------- this expression has type `String` | ||
LL | .chars() | ||
| ------- `Iterator::Item` is `char` here | ||
LL | .filter(|x| !x.is_whitespace()) | ||
| ------------------------------ `Iterator::Item` remains `char` here | ||
LL | .map(|x| { | ||
| __________^ | ||
LL | | println!("Child spawned with the size: {}", x); | ||
LL | | }) | ||
| |__________^ `Iterator::Item` changed to `()` here | ||
note: required by a bound in `collect` | ||
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0308. | ||
For more information about an error, try `rustc --explain E0277`. |