Skip to content

Commit a456519

Browse files
fix(let_and_return): disallow _any_ text between let and return (#16006)
Fixes #15987 changelog: [`let_and_return`]: disallow _any_ text between let and return
2 parents e121ab8 + 6bc8d21 commit a456519

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

clippy_lints/src/returns/let_and_return.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::res::MaybeResPath;
33
use clippy_utils::source::SpanRangeExt;
44
use clippy_utils::sugg::has_enclosing_paren;
55
use clippy_utils::visitors::for_each_expr;
6-
use clippy_utils::{binary_expr_needs_parentheses, fn_def_id, span_contains_cfg};
6+
use clippy_utils::{binary_expr_needs_parentheses, fn_def_id, span_contains_non_whitespace};
77
use core::ops::ControlFlow;
88
use rustc_errors::Applicability;
99
use rustc_hir::{Block, Expr, PatKind, StmtKind};
@@ -27,7 +27,7 @@ pub(super) fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>)
2727
&& !initexpr.span.in_external_macro(cx.sess().source_map())
2828
&& !retexpr.span.in_external_macro(cx.sess().source_map())
2929
&& !local.span.from_expansion()
30-
&& !span_contains_cfg(cx, stmt.span.between(retexpr.span))
30+
&& !span_contains_non_whitespace(cx, stmt.span.between(retexpr.span), true)
3131
{
3232
span_lint_hir_and_then(
3333
cx,

tests/ui/let_and_return.edition2021.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,14 @@ fn issue14164() -> Result<u32, ()> {
261261
//~[edition2024]^ let_and_return
262262
}
263263

264+
fn issue15987() -> i32 {
265+
macro_rules! sample {
266+
( $( $args:expr ),+ ) => {};
267+
}
268+
269+
let r = 5;
270+
sample!(r);
271+
r
272+
}
273+
264274
fn main() {}

tests/ui/let_and_return.edition2024.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,14 @@ fn issue14164() -> Result<u32, ()> {
261261
//~[edition2024]^ let_and_return
262262
}
263263

264+
fn issue15987() -> i32 {
265+
macro_rules! sample {
266+
( $( $args:expr ),+ ) => {};
267+
}
268+
269+
let r = 5;
270+
sample!(r);
271+
r
272+
}
273+
264274
fn main() {}

tests/ui/let_and_return.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,14 @@ fn issue14164() -> Result<u32, ()> {
261261
//~[edition2024]^ let_and_return
262262
}
263263

264+
fn issue15987() -> i32 {
265+
macro_rules! sample {
266+
( $( $args:expr ),+ ) => {};
267+
}
268+
269+
let r = 5;
270+
sample!(r);
271+
r
272+
}
273+
264274
fn main() {}

0 commit comments

Comments
 (0)