From 321779979a47cd09ae88a76924c85fd3cde7b269 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 19 Jun 2019 16:59:25 +0700 Subject: [PATCH 1/2] Fix missing field in ExprKind::Yield Rustup rust-lang/rust#61941 --- clippy_lints/src/loops.rs | 2 +- clippy_lints/src/utils/author.rs | 2 +- clippy_lints/src/utils/hir_utils.rs | 2 +- clippy_lints/src/utils/inspector.rs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index c563fcae3669..d82663841919 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -736,7 +736,7 @@ fn never_loop_expr(expr: &Expr, main_loop_id: HirId) -> NeverLoopResult { } }, ExprKind::Struct(_, _, None) - | ExprKind::Yield(_) + | ExprKind::Yield(_, _) | ExprKind::Closure(_, _, _, _, _) | ExprKind::InlineAsm(_, _, _) | ExprKind::Path(_) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index d66e2b5f8640..3e3a5c48dabf 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -377,7 +377,7 @@ impl<'tcx> Visitor<'tcx> for PrintVisitor { println!("Closure(ref capture_clause, ref func, _, _, _) = {};", current); println!(" // unimplemented: `ExprKind::Closure` is not further destructured at the moment"); }, - ExprKind::Yield(ref sub) => { + ExprKind::Yield(ref sub, _) => { let sub_pat = self.next("sub"); println!("Yield(ref sub) = {};", current); self.current = sub_pat; diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index 7e4f46d92ecd..7f58d21a3158 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -436,7 +436,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { self.hash_expr(&*j); } }, - ExprKind::Box(ref e) | ExprKind::DropTemps(ref e) | ExprKind::Yield(ref e) => { + ExprKind::Box(ref e) | ExprKind::DropTemps(ref e) | ExprKind::Yield(ref e, _) => { self.hash_expr(e); }, ExprKind::Call(ref fun, ref args) => { diff --git a/clippy_lints/src/utils/inspector.rs b/clippy_lints/src/utils/inspector.rs index 633ebb3dd423..f7b865bd2ca2 100644 --- a/clippy_lints/src/utils/inspector.rs +++ b/clippy_lints/src/utils/inspector.rs @@ -227,7 +227,7 @@ fn print_expr(cx: &LateContext<'_, '_>, expr: &hir::Expr, indent: usize) { println!("{}Closure", ind); println!("{}clause: {:?}", ind, clause); }, - hir::ExprKind::Yield(ref sub) => { + hir::ExprKind::Yield(ref sub, _) => { println!("{}Yield", ind); print_expr(cx, sub, indent + 1); }, From 5e887b2a6a133cb85bc540ffe58840cd6d7cb5a8 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Wed, 19 Jun 2019 17:16:42 +0700 Subject: [PATCH 2/2] Fix lifetime mismatch between LateContext and Ty --- clippy_lints/src/loops.rs | 9 +++++++-- clippy_lints/src/methods/mod.rs | 2 +- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/clippy_lints/src/loops.rs b/clippy_lints/src/loops.rs index d82663841919..882f9a1af1bc 100644 --- a/clippy_lints/src/loops.rs +++ b/clippy_lints/src/loops.rs @@ -1245,7 +1245,12 @@ fn is_len_call(expr: &Expr, var: Name) -> bool { false } -fn is_end_eq_array_len(cx: &LateContext<'_, '_>, end: &Expr, limits: ast::RangeLimits, indexed_ty: Ty<'_>) -> bool { +fn is_end_eq_array_len<'tcx>( + cx: &LateContext<'_, 'tcx>, + end: &Expr, + limits: ast::RangeLimits, + indexed_ty: Ty<'tcx>, +) -> bool { if_chain! { if let ExprKind::Lit(ref lit) = end.node; if let ast::LitKind::Int(end_int, _) = lit.node; @@ -1982,7 +1987,7 @@ fn is_ref_iterable_type(cx: &LateContext<'_, '_>, e: &Expr) -> bool { match_type(cx, ty, &paths::BTREESET) } -fn is_iterable_array(ty: Ty<'_>, cx: &LateContext<'_, '_>) -> bool { +fn is_iterable_array<'tcx>(ty: Ty<'tcx>, cx: &LateContext<'_, 'tcx>) -> bool { // IntoIterator is currently only implemented for array sizes <= 32 in rustc match ty.sty { ty::Array(_, n) => (0..=32).contains(&n.assert_usize(cx.tcx).expect("array length")), diff --git a/clippy_lints/src/methods/mod.rs b/clippy_lints/src/methods/mod.rs index d91d7ecc2b8e..29ea6d018ad5 100644 --- a/clippy_lints/src/methods/mod.rs +++ b/clippy_lints/src/methods/mod.rs @@ -1773,7 +1773,7 @@ fn derefs_to_slice<'a, 'tcx>( expr: &'tcx hir::Expr, ty: Ty<'tcx>, ) -> Option<&'tcx hir::Expr> { - fn may_slice(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool { + fn may_slice<'a>(cx: &LateContext<'_, 'a>, ty: Ty<'a>) -> bool { match ty.sty { ty::Slice(_) => true, ty::Adt(def, _) if def.is_box() => may_slice(cx, ty.boxed_ty()),