Don't special-case while block type mismatch

67ea84d erroneously added this special-case when introducing `DesugaringKind::WhileLoop`.
It had the unintended effect of emitting erroneous diagnostics in certain `while` blocks.
This commit is contained in:
Alan Egerton 2026-01-09 12:48:19 +00:00
parent 4586feb998
commit 7c7cf45dcf
No known key found for this signature in database
GPG key ID: 3D7EA7527916B438
2 changed files with 6 additions and 11 deletions

View file

@ -54,7 +54,7 @@ use rustc_middle::ty::adjustment::{
};
use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span};
use rustc_span::{BytePos, DUMMY_SP, Span};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::solve::inspect::{self, InferCtxtProofTreeExt, ProofTreeVisitor};
use rustc_trait_selection::solve::{Certainty, Goal, NoSolution};
@ -1828,10 +1828,9 @@ impl<'tcx> CoerceMany<'tcx> {
// If the block is from an external macro or try (`?`) desugaring, then
// do not suggest adding a semicolon, because there's nowhere to put it.
// See issues #81943 and #87051.
&& matches!(
cond_expr.span.desugaring_kind(),
None | Some(DesugaringKind::WhileLoop)
)
// Similarly, if the block is from a loop desugaring, then also do not
// suggest adding a semicolon. See issue #150850.
&& cond_expr.span.desugaring_kind().is_none()
&& !cond_expr.span.in_external_macro(fcx.tcx.sess.source_map())
&& !matches!(
cond_expr.kind,

View file

@ -9,12 +9,8 @@ LL | while true {
error[E0308]: mismatched types
--> $DIR/block-must-not-have-result-while.rs:5:9
|
LL | / while true {
LL | | true
| | ^^^^ expected `()`, found `bool`
LL | |
LL | | }
| |_____- expected this to be `()`
LL | true
| ^^^^ expected `()`, found `bool`
error: aborting due to 1 previous error; 1 warning emitted