Skip to content

Commit f0d331a

Browse files
committed
Auto merge of rust-lang#10109 - Niki4tap:yeet_not_return, r=flip1995
Fix FP in needless_return when using yeet Fixes rust-lang#9947 changelog: Fix: [`needless_return`]: don't lint when using `do yeet` rust-lang#10109
2 parents 065c6f7 + b6882f6 commit f0d331a

File tree

4 files changed

+63
-47
lines changed

4 files changed

+63
-47
lines changed

clippy_lints/src/returns.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use core::ops::ControlFlow;
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::FnKind;
9-
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, MatchSource, PatKind, StmtKind};
9+
use rustc_hir::{Block, Body, Expr, ExprKind, FnDecl, HirId, LangItem, MatchSource, PatKind, QPath, StmtKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_middle::ty::subst::GenericArgKind;
@@ -207,6 +207,12 @@ fn check_final_expr<'tcx>(
207207
match &peeled_drop_expr.kind {
208208
// simple return is always "bad"
209209
ExprKind::Ret(ref inner) => {
210+
// if desugar of `do yeet`, don't lint
211+
if let Some(inner_expr) = inner
212+
&& let ExprKind::Call(path_expr, _) = inner_expr.kind
213+
&& let ExprKind::Path(QPath::LangItem(LangItem::TryTraitFromYeet, _, _)) = path_expr.kind {
214+
return;
215+
}
210216
if cx.tcx.hir().attrs(expr.hir_id).is_empty() {
211217
let borrows = inner.map_or(false, |inner| last_statement_borrows(cx, inner));
212218
if !borrows {

tests/ui/needless_return.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![feature(lint_reasons)]
4+
#![feature(yeet_expr)]
45
#![allow(unused)]
56
#![allow(
67
clippy::if_same_then_else,
@@ -272,4 +273,8 @@ mod issue9416 {
272273
}
273274
}
274275

276+
fn issue9947() -> Result<(), String> {
277+
do yeet "hello";
278+
}
279+
275280
fn main() {}

tests/ui/needless_return.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// run-rustfix
22

33
#![feature(lint_reasons)]
4+
#![feature(yeet_expr)]
45
#![allow(unused)]
56
#![allow(
67
clippy::if_same_then_else,
@@ -282,4 +283,8 @@ mod issue9416 {
282283
}
283284
}
284285

286+
fn issue9947() -> Result<(), String> {
287+
do yeet "hello";
288+
}
289+
285290
fn main() {}

0 commit comments

Comments
 (0)