diff options
| author | bors <bors@rust-lang.org> | 2025-01-17 09:03:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-01-17 09:03:22 +0000 |
| commit | 73c0ae6aec8f3d07467dfb9339761fa2eec92a44 (patch) | |
| tree | 63609aaa5bbc9a876366bfc42e077315183d7370 /compiler/rustc_trait_selection/src | |
| parent | 0c2c096e1ac471b0c34629f9820a7cb1e6d4695d (diff) | |
| parent | 1360e76329a1e3b4590f9f1998779d663e0da003 (diff) | |
| download | rust-73c0ae6aec8f3d07467dfb9339761fa2eec92a44.tar.gz rust-73c0ae6aec8f3d07467dfb9339761fa2eec92a44.zip | |
Auto merge of #135615 - matthiaskrgr:rollup-ra7vftt, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #131806 (Treat other items as functions for the purpose of type-based search) - #134980 (Location-sensitive polonius prototype: endgame) - #135558 (Detect if-else chains with a missing final else in type errors) - #135594 (fix error for when results in a rustdoc-js test are in the wrong order) - #135601 (Fix suggestion to convert dereference of raw pointer to ref) - #135604 (Expand docs for `E0207` with additional example) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 7032f7b9d31..9778299eb19 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -620,6 +620,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { }) => { let then_span = self.find_block_span_from_hir_id(then_id); let else_span = self.find_block_span_from_hir_id(else_id); + if let hir::Node::Expr(e) = self.tcx.hir_node(else_id) + && let hir::ExprKind::If(_cond, _then, None) = e.kind + && else_ty.is_unit() + { + // Account for `let x = if a { 1 } else if b { 2 };` + err.note("`if` expressions without `else` evaluate to `()`"); + err.note("consider adding an `else` block that evaluates to the expected type"); + } err.span_label(then_span, "expected because of this"); if let Some(sp) = outer_span { err.span_label(sp, "`if` and `else` have incompatible types"); |
