diff options
| author | bors <bors@rust-lang.org> | 2022-12-22 10:40:33 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-12-22 10:40:33 +0000 |
| commit | f0d331ab36969b129648c8307622bbd746016feb (patch) | |
| tree | 276899ec10c6062f2573a9c8307aa8dbbbec6294 | |
| parent | 065c6f78e7b4089ad93eafb0c0c478bbfaa00db8 (diff) | |
| parent | b6882f6107193696e14ab21fb0ee9921a4e0b842 (diff) | |
| download | rust-f0d331ab36969b129648c8307622bbd746016feb.tar.gz rust-f0d331ab36969b129648c8307622bbd746016feb.zip | |
Auto merge of #10109 - Niki4tap:yeet_not_return, r=flip1995
Fix FP in needless_return when using yeet Fixes #9947 changelog: Fix: [`needless_return`]: don't lint when using `do yeet` #10109
| -rw-r--r-- | clippy_lints/src/returns.rs | 8 | ||||
| -rw-r--r-- | tests/ui/needless_return.fixed | 5 | ||||
| -rw-r--r-- | tests/ui/needless_return.rs | 5 | ||||
| -rw-r--r-- | tests/ui/needless_return.stderr | 92 |
4 files changed, 63 insertions, 47 deletions
diff --git a/clippy_lints/src/returns.rs b/clippy_lints/src/returns.rs index 81143d7799e..d4d50660520 100644 --- a/clippy_lints/src/returns.rs +++ b/clippy_lints/src/returns.rs @@ -6,7 +6,7 @@ use core::ops::ControlFlow; use if_chain::if_chain; use rustc_errors::Applicability; use rustc_hir::intravisit::FnKind; -use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, PatKind, StmtKind}; +use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, LangItem, MatchSource, PatKind, QPath, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_middle::lint::in_external_macro; use rustc_middle::ty::subst::GenericArgKind; @@ -207,6 +207,12 @@ fn check_final_expr<'tcx>( match &peeled_drop_expr.kind { // simple return is always "bad" ExprKind::Ret(ref inner) => { + // if desugar of `do yeet`, don't lint + if let Some(inner_expr) = inner + && let ExprKind::Call(path_expr, _) = inner_expr.kind + && let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, _, _)) = path_expr.kind { + return; + } if cx.tcx.hir().attrs(expr.hir_id).is_empty() { let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner)); if !borrows { diff --git a/tests/ui/needless_return.fixed b/tests/ui/needless_return.fixed index 4386aaec49e..d451be1f389 100644 --- a/tests/ui/needless_return.fixed +++ b/tests/ui/needless_return.fixed @@ -1,6 +1,7 @@ // run-rustfix #![feature(lint_reasons)] +#![feature(yeet_expr)] #![allow(unused)] #![allow( clippy::if_same_then_else, @@ -272,4 +273,8 @@ mod issue9416 { } } +fn issue9947() -> Result<(), String> { + do yeet "hello"; +} + fn main() {} diff --git a/tests/ui/needless_return.rs b/tests/ui/needless_return.rs index 666dc54b76b..e1a1bea2c0b 100644 --- a/tests/ui/needless_return.rs +++ b/tests/ui/needless_return.rs @@ -1,6 +1,7 @@ // run-rustfix #![feature(lint_reasons)] +#![feature(yeet_expr)] #![allow(unused)] #