@@ -48,28 +48,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48
48
/// Produces warning on the given node, if the current point in the
49
49
/// function is unreachable, and there hasn't been another warning.
50
50
pub(crate) fn warn_if_unreachable(&self, id: HirId, span: Span, kind: &str) {
51
- // If span arose from a desugaring of `if` or `while`, then it is the condition itself,
52
- // which diverges, that we are about to lint on. This gives suboptimal diagnostics.
53
- // Instead, stop here so that the `if`- or `while`-expression's block is linted instead.
54
- if span.is_desugaring(DesugaringKind::CondTemporary) {
51
+ let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() else {
55
52
return;
56
- }
53
+ };
57
54
58
- // Don't lint if the result of an async block or async function is `!`.
59
- // This does not affect the unreachable lints *within* the body.
60
- if span.is_desugaring(DesugaringKind::Async) {
61
- return;
62
- }
55
+ match span.desugaring_kind() {
56
+ // If span arose from a desugaring of `if` or `while`, then it is the condition
57
+ // itself, which diverges, that we are about to lint on. This gives suboptimal
58
+ // diagnostics. Instead, stop here so that the `if`- or `while`-expression's
59
+ // block is linted instead.
60
+ Some(DesugaringKind::CondTemporary) => return,
63
61
64
- // Don't lint *within* the `.await` operator, since that's all just desugaring junk.
65
- // We only want to lint if there is a subsequent expression after the `.await`.
66
- if span.is_desugaring(DesugaringKind::Await) {
67
- return;
68
- }
62
+ // Don't lint if the result of an async block or async function is `!`.
63
+ // This does not affect the unreachable lints *within* the body.
64
+ Some(DesugaringKind::Async) => return,
69
65
70
- let Diverges::Always { span: orig_span, custom_note } = self.diverges.get() else {
71
- return;
72
- };
66
+ // Don't lint *within* the `.await` operator, since that's all just desugaring
67
+ // junk. We only want to lint if there is a subsequent expression after the
68
+ // `.await` operator.
69
+ Some(DesugaringKind::Await) => return,
70
+
71
+ _ => {}
72
+ }
73
73
74
74
// Don't warn twice.
75
75
self.diverges.set(Diverges::WarnedAlways);
0 commit comments