Rollup merge of #83952 - estebank:issue-83943, r=petrochenkov
Account for `ExprKind::Block` when suggesting .into() and deref Fix #83943.
This commit is contained in:
commit
97c50d529b
5 changed files with 41 additions and 4 deletions
|
@ -205,6 +205,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
found: Ty<'tcx>,
|
found: Ty<'tcx>,
|
||||||
expected_ty_expr: Option<&'tcx hir::Expr<'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) {
|
if let Some((sp, msg, suggestion, applicability)) = self.check_ref(expr, found, expected) {
|
||||||
err.span_suggestion(sp, msg, suggestion, applicability);
|
err.span_suggestion(sp, msg, suggestion, applicability);
|
||||||
} else if let (ty::FnDef(def_id, ..), true) =
|
} else if let (ty::FnDef(def_id, ..), true) =
|
||||||
|
|
|
@ -21,10 +21,10 @@ LL | | 1
|
||||||
| | - expected because of this
|
| | - expected because of this
|
||||||
LL | | } else {
|
LL | | } else {
|
||||||
LL | | &1
|
LL | | &1
|
||||||
| | -^
|
| | ^^
|
||||||
| | |
|
| | |
|
||||||
| | expected integer, found `&{integer}`
|
| | expected integer, found `&{integer}`
|
||||||
| | help: consider removing the `&`
|
| | help: consider removing the borrow: `1`
|
||||||
LL | | };
|
LL | | };
|
||||||
| |_____- `if` and `else` have incompatible types
|
| |_____- `if` and `else` have incompatible types
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@ LL | | 1
|
||||||
| | - expected because of this
|
| | - expected because of this
|
||||||
LL | | } else {
|
LL | | } else {
|
||||||
LL | | &mut 1
|
LL | | &mut 1
|
||||||
| | -----^
|
| | ^^^^^^
|
||||||
| | |
|
| | |
|
||||||
| | expected integer, found `&mut {integer}`
|
| | expected integer, found `&mut {integer}`
|
||||||
| | help: consider removing the `&mut`
|
| | help: consider removing the borrow: `1`
|
||||||
LL | | };
|
LL | | };
|
||||||
| |_____- `if` and `else` have incompatible types
|
| |_____- `if` and `else` have incompatible types
|
||||||
|
|
||||||
|
|
9
src/test/ui/suggestions/issue-83943.fixed
Normal file
9
src/test/ui/suggestions/issue-83943.fixed
Normal file
|
@ -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
src/test/ui/suggestions/issue-83943.rs
Normal file
9
src/test/ui/suggestions/issue-83943.rs
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
// run-rustfix
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
if true {
|
||||||
|
"A".to_string()
|
||||||
|
} else {
|
||||||
|
"B" //~ ERROR `if` and `else` have incompatible types
|
||||||
|
};
|
||||||
|
}
|
18
src/test/ui/suggestions/issue-83943.stderr
Normal file
18
src/test/ui/suggestions/issue-83943.stderr
Normal file
|
@ -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`.
|
Loading…
Add table
Add a link
Reference in a new issue