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

Account for ExprKind::Block when suggesting .into() and deref #83952

Merged
merged 1 commit into from
Apr 8, 2021
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 compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
found: Ty<'tcx>,
expected_ty_expr: Option<&'tcx hir::Expr<'tcx>>,
) {
let expr = expr.peel_blocks();
if let Some((sp, msg, suggestion, applicability)) = self.check_ref(expr, found, expected) {
err.span_suggestion(sp, msg, suggestion, applicability);
} else if let (ty::FnDef(def_id, ..), true) =
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/suggestions/issue-82361.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ LL | | 1
| | - expected because of this
LL | | } else {
LL | | &1
| | -^
| | ^^
| | |
| | expected integer, found `&{integer}`
| | help: consider removing the `&`
| | help: consider removing the borrow: `1`
LL | | };
| |_____- `if` and `else` have incompatible types

Expand All @@ -36,10 +36,10 @@ LL | | 1
| | - expected because of this
LL | | } else {
LL | | &mut 1
| | -----^
| | ^^^^^^
| | |
| | expected integer, found `&mut {integer}`
| | help: consider removing the `&mut`
| | help: consider removing the borrow: `1`
LL | | };
| |_____- `if` and `else` have incompatible types

Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/issue-83943.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-rustfix

fn main() {
if true {
"A".to_string()
} else {
"B".to_string() //~ ERROR `if` and `else` have incompatible types
};
}
9 changes: 9 additions & 0 deletions src/test/ui/suggestions/issue-83943.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// run-rustfix

fn main() {
if true {
"A".to_string()
} else {
"B" //~ ERROR `if` and `else` have incompatible types
};
}
18 changes: 18 additions & 0 deletions src/test/ui/suggestions/issue-83943.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0308]: `if` and `else` have incompatible types
--> $DIR/issue-83943.rs:7:9
|
LL | / if true {
LL | | "A".to_string()
| | --------------- expected because of this
LL | | } else {
LL | | "B"
| | ^^^
| | |
| | expected struct `String`, found `&str`
| | help: try using a conversion method: `"B".to_string()`
LL | | };
| |_____- `if` and `else` have incompatible types

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.