mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-11 22:02:55 +00:00
1ebdcca8b9
Previously, async constructs would be lowered to "normal" generators, with an additional `from_generator` / `GenFuture` shim in between to convert from `Generator` to `Future`. The compiler will now special-case these generators internally so that async constructs will *directly* implement `Future` without the need to go through the `from_generator` / `GenFuture` shim. The primary motivation for this change was hiding this implementation detail in stack traces and debuginfo, but it can in theory also help the optimizer as there is less abstractions to see through.
58 lines
2.5 KiB
Text
58 lines
2.5 KiB
Text
if let ExprKind::Block(block, None) = expr.kind
|
|
&& block.stmts.len() == 3
|
|
&& let StmtKind::Local(local) = block.stmts[0].kind
|
|
&& let Some(init) = local.init
|
|
&& let ExprKind::Lit(ref lit) = init.kind
|
|
&& let LitKind::Int(42, LitIntType::Signed(IntTy::I32)) = lit.node
|
|
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
|
|
&& name.as_str() == "x"
|
|
&& let StmtKind::Local(local1) = block.stmts[1].kind
|
|
&& let Some(init1) = local1.init
|
|
&& let ExprKind::Lit(ref lit1) = init1.kind
|
|
&& let LitKind::Float(_, LitFloatType::Suffixed(FloatTy::F32)) = lit1.node
|
|
&& let PatKind::Binding(BindingAnnotation::NONE, _, name1, None) = local1.pat.kind
|
|
&& name1.as_str() == "_t"
|
|
&& let StmtKind::Semi(e) = block.stmts[2].kind
|
|
&& let ExprKind::Unary(UnOp::Neg, inner) = e.kind
|
|
&& let ExprKind::Path(ref qpath) = inner.kind
|
|
&& match_qpath(qpath, &["x"])
|
|
&& block.expr.is_none()
|
|
{
|
|
// report your lint here
|
|
}
|
|
if let ExprKind::Block(block, None) = expr.kind
|
|
&& block.stmts.len() == 1
|
|
&& let StmtKind::Local(local) = block.stmts[0].kind
|
|
&& let Some(init) = local.init
|
|
&& let ExprKind::Call(func, args) = init.kind
|
|
&& let ExprKind::Path(ref qpath) = func.kind
|
|
&& match_qpath(qpath, &["String", "new"])
|
|
&& args.is_empty()
|
|
&& let PatKind::Binding(BindingAnnotation::NONE, _, name, None) = local.pat.kind
|
|
&& name.as_str() == "expr"
|
|
&& let Some(trailing_expr) = block.expr
|
|
&& let ExprKind::Call(func1, args1) = trailing_expr.kind
|
|
&& let ExprKind::Path(ref qpath1) = func1.kind
|
|
&& match_qpath(qpath1, &["drop"])
|
|
&& args1.len() == 1
|
|
&& let ExprKind::Path(ref qpath2) = args1[0].kind
|
|
&& match_qpath(qpath2, &["expr"])
|
|
{
|
|
// report your lint here
|
|
}
|
|
if let ExprKind::Closure(CaptureBy::Value, fn_decl, body_id, _, None) = expr.kind
|
|
&& let FnRetTy::DefaultReturn(_) = fn_decl.output
|
|
&& expr1 = &cx.tcx.hir().body(body_id).value
|
|
&& let ExprKind::Call(func, args) = expr1.kind
|
|
&& let ExprKind::Path(ref qpath) = func.kind
|
|
&& matches!(qpath, QPath::LangItem(LangItem::IdentityFuture, _))
|
|
&& args.len() == 1
|
|
&& let ExprKind::Closure(CaptureBy::Value, fn_decl1, body_id1, _, Some(Movability::Static)) = args[0].kind
|
|
&& let FnRetTy::DefaultReturn(_) = fn_decl1.output
|
|
&& expr2 = &cx.tcx.hir().body(body_id1).value
|
|
&& let ExprKind::Block(block, None) = expr2.kind
|
|
&& block.stmts.is_empty()
|
|
&& block.expr.is_none()
|
|
{
|
|
// report your lint here
|
|
}
|