Auto merge of #11401 - y21:issue11394, r=xFrednet
[`if_then_some_else_none`]: look into local initializers for early returns Fixes #11394 As the PR title says, problem was that it only looked for early returns in semi statements. Local variables don't count as such, so it didn't count `let _v = x?;` (or even just `let _ = return;`) as a possible early return and didn't realize that it can't lint then. Imo the `stmts_contains_early_return` function that was used before is redundant. `contains_return` could already do that if we just made the parameter a bit more generic, just like `for_each_expr`, which can already accept `&[Stmt]` changelog: [`if_then_some_else_none`]: look into local initializers for early returns
This commit is contained in:
commit
4118738998
3 changed files with 16 additions and 17 deletions
|
|
@ -111,6 +111,7 @@ use rustc_span::source_map::SourceMap;
|
|||
use rustc_span::symbol::{kw, Ident, Symbol};
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_target::abi::Integer;
|
||||
use visitors::Visitable;
|
||||
|
||||
use crate::consts::{constant, miri_to_const, Constant};
|
||||
use crate::higher::Range;
|
||||
|
|
@ -1287,7 +1288,7 @@ pub fn contains_name<'tcx>(name: Symbol, expr: &'tcx Expr<'_>, cx: &LateContext<
|
|||
}
|
||||
|
||||
/// Returns `true` if `expr` contains a return expression
|
||||
pub fn contains_return(expr: &hir::Expr<'_>) -> bool {
|
||||
pub fn contains_return<'tcx>(expr: impl Visitable<'tcx>) -> bool {
|
||||
for_each_expr(expr, |e| {
|
||||
if matches!(e.kind, hir::ExprKind::Ret(..)) {
|
||||
ControlFlow::Break(())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue