use rustc_span::sym;
declare_clippy_lint! {
- /// **What it does:** Checks for `let`-bindings, which are subsequently
+ /// ### What it does
+ /// Checks for `let`-bindings, which are subsequently
/// returned.
///
- /// **Why is this bad?** It is just extraneous code. Remove it to make your code
+ /// ### Why is this bad?
+ /// It is just extraneous code. Remove it to make your code
/// more rusty.
///
- /// **Known problems:** None.
- ///
- /// **Example:**
+ /// ### Example
/// ```rust
/// fn foo() -> String {
/// let x = String::new();
}
declare_clippy_lint! {
- /// **What it does:** Checks for return statements at the end of a block.
+ /// ### What it does
+ /// Checks for return statements at the end of a block.
///
- /// **Why is this bad?** Removing the `return` and semicolon will make the code
+ /// ### Why is this bad?
+ /// Removing the `return` and semicolon will make the code
/// more rusty.
///
- /// **Known problems:** None.
- ///
- /// **Example:**
+ /// ### Example
/// ```rust
/// fn foo(x: usize) -> usize {
/// return x;
} else {
RetReplacement::Empty
};
- check_final_expr(cx, &body.value, Some(body.value.span), replacement)
+ check_final_expr(cx, &body.value, Some(body.value.span), replacement);
},
FnKind::ItemFn(..) | FnKind::Method(..) => {
if let ExprKind::Block(block, _) = body.value.kind {
// an if/if let expr, check both exprs
// note, if without else is going to be a type checking error anyways
// (except for unit type functions) so we don't match it
- ExprKind::Match(_, arms, source) => match source {
- MatchSource::Normal => {
- for arm in arms.iter() {
- check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
- }
- },
- MatchSource::IfLetDesugar {
- contains_else_clause: true,
- } => {
- if let ExprKind::Block(ifblock, _) = arms[0].body.kind {
- check_block_return(cx, ifblock);
- }
- check_final_expr(cx, arms[1].body, None, RetReplacement::Empty);
- },
- _ => (),
+ ExprKind::Match(_, arms, MatchSource::Normal) => {
+ for arm in arms.iter() {
+ check_final_expr(cx, arm.body, Some(arm.body.span), RetReplacement::Block);
+ }
},
ExprKind::DropTemps(expr) => check_final_expr(cx, expr, None, RetReplacement::Empty),
_ => (),
if let Some(snippet) = snippet_opt(cx, inner_span) {
diag.span_suggestion(ret_span, "remove `return`", snippet, Applicability::MachineApplicable);
}
- })
+ });
},
None => match replacement {
RetReplacement::Empty => {
.fn_sig(def_id)
.output()
.skip_binder()
- .walk()
+ .walk(self.cx.tcx)
.any(|arg| matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
}