Skip to content

Commit 657dda7

Browse files
committed
let_and_return: look for non-static references in expansion as well
One cannot avoid descending into expansion results when looking for non-static references, or there is a risk of false negative which would then trigger the `let_and_return` lint.
1 parent d7fd1c8 commit 657dda7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

clippy_lints/src/returns.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::{span_lint_and_sugg, span_lint_hir_and_then};
22
use clippy_utils::source::{SpanRangeExt, snippet_with_context};
33
use clippy_utils::sugg::has_enclosing_paren;
4-
use clippy_utils::visitors::{Descend, for_each_expr};
4+
use clippy_utils::visitors::for_each_expr;
55
use clippy_utils::{
66
binary_expr_needs_parentheses, fn_def_id, is_from_proc_macro, is_inside_let_else, is_res_lang_ctor,
77
leaks_droppable_temporary_with_limited_lifetime, path_res, path_to_local_id, span_contains_cfg,
@@ -483,7 +483,7 @@ fn last_statement_borrows<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>)
483483
{
484484
ControlFlow::Break(())
485485
} else {
486-
ControlFlow::Continue(Descend::from(!e.span.from_expansion()))
486+
ControlFlow::Continue(())
487487
}
488488
})
489489
.is_some()

tests/ui/let_and_return.fixed

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@ fn issue12801() {
244244
}
245245
}
246246

247+
// Do not lint
248+
fn issue14164() -> Result<u32, ()> {
249+
let v = std::cell::RefCell::new(Some(vec![1]));
250+
let r = match &*v.borrow() {
251+
Some(v) => Ok(Ok(v[0])),
252+
None => Ok(Ok(0)),
253+
}?;
254+
r
255+
}
256+
247257
fn main() {}

tests/ui/let_and_return.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,14 @@ fn issue12801() {
244244
}
245245
}
246246

247+
// Do not lint
248+
fn issue14164() -> Result<u32, ()> {
249+
let v = std::cell::RefCell::new(Some(vec![1]));
250+
let r = match &*v.borrow() {
251+
Some(v) => Ok(Ok(v[0])),
252+
None => Ok(Ok(0)),
253+
}?;
254+
r
255+
}
256+
247257
fn main() {}

0 commit comments

Comments
 (0)