From ca0996e3a04983098b0ea81c85fba2019e3eed7b Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Fri, 15 Jul 2022 23:13:04 -0400 Subject: [PATCH 1/4] Change maybe_body_owned_by to take local def id Signed-off-by: Miguel Guarniz --- clippy_lints/src/utils/author.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index bbb04c9945a..59e07313f54 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -138,7 +138,7 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir_id) { + if let Some(body_id) = hir.maybe_body_owned_by(hir.local_def_id(hir_id)) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", &hir.body(body_id).value)); }); From 29a0f69f9c5862f6c81fc7dda6065fb0a0c779b6 Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 17:06:52 -0400 Subject: [PATCH 2/4] Rename local_did to def_id Signed-off-by: Miguel Guarniz --- clippy_lints/src/utils/author.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_lints/src/utils/author.rs b/clippy_lints/src/utils/author.rs index 59e07313f54..c0726868f77 100644 --- a/clippy_lints/src/utils/author.rs +++ b/clippy_lints/src/utils/author.rs @@ -138,7 +138,7 @@ fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx hir::Stmt<'_>) { fn check_item(cx: &LateContext<'_>, hir_id: HirId) { let hir = cx.tcx.hir(); - if let Some(body_id) = hir.maybe_body_owned_by(hir.local_def_id(hir_id)) { + if let Some(body_id) = hir.maybe_body_owned_by(hir_id.expect_owner()) { check_node(cx, hir_id, |v| { v.expr(&v.bind("expr", &hir.body(body_id).value)); }); From ce5fa10cce7a0b550be87da853aef2b5f9a87b1e Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 17:47:49 -0400 Subject: [PATCH 3/4] Change enclosing_body_owner to return LocalDefId Signed-off-by: Miguel Guarniz --- clippy_utils/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clippy_utils/src/lib.rs b/clippy_utils/src/lib.rs index 34a1cdaf1d5..50bb008098d 100644 --- a/clippy_utils/src/lib.rs +++ b/clippy_utils/src/lib.rs @@ -1353,7 +1353,7 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool if is_integer_literal(e, value) { return true; } - let enclosing_body = cx.tcx.hir().local_def_id(cx.tcx.hir().enclosing_body_owner(e.hir_id)); + let enclosing_body = cx.tcx.hir().enclosing_body_owner(e.hir_id); if let Some((Constant::Int(v), _)) = constant(cx, cx.tcx.typeck(enclosing_body), e) { return value == v; } From 6c1110ef5be83670d516abcc4484c1dc19dc4dd4 Mon Sep 17 00:00:00 2001 From: Miguel Guarniz Date: Tue, 19 Jul 2022 22:51:52 -0400 Subject: [PATCH 4/4] Avoid ICE when fetching LocalDefId Signed-off-by: Miguel Guarniz --- clippy_lints/src/methods/suspicious_map.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/clippy_lints/src/methods/suspicious_map.rs b/clippy_lints/src/methods/suspicious_map.rs index 18ded291915..9c3375bf35e 100644 --- a/clippy_lints/src/methods/suspicious_map.rs +++ b/clippy_lints/src/methods/suspicious_map.rs @@ -12,7 +12,8 @@ pub fn check<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>, count_recv: &hi if_chain! { if is_trait_method(cx, count_recv, sym::Iterator); let closure = expr_or_init(cx, map_arg); - if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(closure.hir_id); + if let Some(def_id) = cx.tcx.hir().opt_local_def_id(closure.hir_id); + if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id); let closure_body = cx.tcx.hir().body(body_id); if !cx.typeck_results().expr_ty(&closure_body.value).is_unit(); then {