Skip to content

Commit 22144c0

Browse files
committed
Auto merge of #7789 - flip1995:double_semi_if_nothing_returned, r=camsteffen
Don't trigger semicolon_if_nothing_returned in expanded code Fixes #7768 Before, this lint didn't trigger on macros. With rust-lang/rust#88175 this isn't enough anymore. In this PR a `WhileLoop` desugaring kind was introduced. This overrides the span of expanded expressions when lowering the while loop. So if a while loop is in a macro, the expressions that it expands to are no longer marked with `ExpnKind::Macro`, but with `ExpnKind::Desugaring`. In general, this is the correct behavior and the same that is done for `ForLoop`s. It just tripped up this lint. r? `@camsteffen` changelog: [`semicolon_if_nothing_returned`]: Fix regression on macros containing while loops
2 parents 78e7312 + b423b85 commit 22144c0

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

clippy_lints/src/semicolon_if_nothing_returned.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::rustc_lint::LintContext;
22
use clippy_utils::diagnostics::span_lint_and_sugg;
33
use clippy_utils::source::snippet_with_macro_callsite;
4-
use clippy_utils::{in_macro, sugg};
4+
use clippy_utils::sugg;
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::{Block, ExprKind};
@@ -39,7 +39,7 @@ declare_lint_pass!(SemicolonIfNothingReturned => [SEMICOLON_IF_NOTHING_RETURNED]
3939
impl LateLintPass<'_> for SemicolonIfNothingReturned {
4040
fn check_block(&mut self, cx: &LateContext<'tcx>, block: &'tcx Block<'tcx>) {
4141
if_chain! {
42-
if !in_macro(block.span);
42+
if !block.span.from_expansion();
4343
if let Some(expr) = block.expr;
4444
let t_expr = cx.typeck_results().expr_ty(expr);
4545
if t_expr.is_unit();

tests/ui/semicolon_if_nothing_returned.rs

+12
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,15 @@ fn unsafe_checks() {
9898
let mut s = MaybeUninit::<String>::uninit();
9999
let _d = || unsafe { ptr::drop_in_place(s.as_mut_ptr()) };
100100
}
101+
102+
// Issue #7768
103+
#[rustfmt::skip]
104+
fn macro_with_semicolon() {
105+
macro_rules! repro {
106+
() => {
107+
while false {
108+
}
109+
};
110+
}
111+
repro!();
112+
}

0 commit comments

Comments
 (0)