mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 13:13:34 +00:00
Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrieril
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
This commit is contained in:
commit
8299d4947a
14 changed files with 21 additions and 22 deletions
|
@ -49,7 +49,7 @@ declare_clippy_lint! {
|
|||
declare_lint_pass!(DefaultNumericFallback => [DEFAULT_NUMERIC_FALLBACK]);
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for DefaultNumericFallback {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
let hir = cx.tcx.hir();
|
||||
let is_parent_const = matches!(
|
||||
hir.body_const_context(hir.body_owner_def_id(body.id())),
|
||||
|
|
|
@ -641,7 +641,7 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
|
||||
if Some(body.id()) == self.current_body {
|
||||
for pat in self.ref_locals.drain(..).filter_map(|(_, x)| x) {
|
||||
let replacements = pat.replacements;
|
||||
|
|
|
@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
|||
impl<'a, 'b, 'tcx> Visitor<'tcx> for ImplicitHasherConstructorVisitor<'a, 'b, 'tcx> {
|
||||
type NestedFilter = nested_filter::OnlyBodies;
|
||||
|
||||
fn visit_body(&mut self, body: &'tcx Body<'_>) {
|
||||
fn visit_body(&mut self, body: &Body<'tcx>) {
|
||||
let old_maybe_typeck_results = self.maybe_typeck_results.replace(self.cx.tcx.typeck_body(body.id()));
|
||||
walk_body(self, body);
|
||||
self.maybe_typeck_results = old_maybe_typeck_results;
|
||||
|
|
|
@ -186,7 +186,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BodyVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx rustc_hir::Body<'tcx>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &rustc_hir::Body<'tcx>) {
|
||||
if is_lint_allowed(cx, MACRO_METAVARS_IN_UNSAFE, body.value.hir_id) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -59,8 +59,8 @@ pub(super) fn check<'tcx>(
|
|||
};
|
||||
|
||||
let map = cx.tcx.hir();
|
||||
let body = map.body(map.body_owned_by(map.enclosing_body_owner(expr.hir_id)));
|
||||
reference_visitor.visit_body(body);
|
||||
let body = map.body_owned_by(map.enclosing_body_owner(expr.hir_id));
|
||||
reference_visitor.visit_body(&body);
|
||||
|
||||
if reference_visitor.found_reference {
|
||||
return;
|
||||
|
|
|
@ -129,7 +129,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrowsForGenericArgs<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'_>) {
|
||||
if self.possible_borrowers.last().map_or(false, |&(local_def_id, _)| {
|
||||
local_def_id == cx.tcx.hir().body_owner_def_id(body.id())
|
||||
}) {
|
||||
|
|
|
@ -221,7 +221,7 @@ pub struct OnlyUsedInRecursion {
|
|||
}
|
||||
|
||||
impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
if body.value.span.from_expansion() {
|
||||
return;
|
||||
}
|
||||
|
@ -350,7 +350,7 @@ impl<'tcx> LateLintPass<'tcx> for OnlyUsedInRecursion {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
if self.entered_body == Some(body.value.hir_id) {
|
||||
self.entered_body = None;
|
||||
self.params.flag_for_linting();
|
||||
|
|
|
@ -868,11 +868,11 @@ impl<'tcx> LateLintPass<'tcx> for Operators {
|
|||
self.arithmetic_context.expr_post(e.hir_id);
|
||||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
|
||||
self.arithmetic_context.enter_body(cx, b);
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &'tcx Body<'_>) {
|
||||
fn check_body_post(&mut self, cx: &LateContext<'tcx>, b: &Body<'_>) {
|
||||
self.arithmetic_context.body_post(cx, b);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ impl<'tcx> LateLintPass<'tcx> for Ptr {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &'tcx Body<'_>) {
|
||||
fn check_body(&mut self, cx: &LateContext<'tcx>, body: &Body<'tcx>) {
|
||||
let hir = cx.tcx.hir();
|
||||
let mut parents = hir.parent_iter(body.value.hir_id);
|
||||
let (item_id, sig, is_trait_item) = match parents.next() {
|
||||
|
@ -525,7 +525,7 @@ fn check_fn_args<'cx, 'tcx: 'cx>(
|
|||
})
|
||||
}
|
||||
|
||||
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&'tcx Body<'_>>) {
|
||||
fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Option<&Body<'tcx>>) {
|
||||
if let FnRetTy::Return(ty) = sig.decl.output
|
||||
&& let Some((out, Mutability::Mut, _)) = get_ref_lm(ty)
|
||||
{
|
||||
|
@ -559,7 +559,7 @@ fn check_mut_from_ref<'tcx>(cx: &LateContext<'tcx>, sig: &FnSig<'_>, body: Optio
|
|||
}
|
||||
|
||||
#[expect(clippy::too_many_lines)]
|
||||
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'_>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
|
||||
fn check_ptr_arg_usage<'tcx>(cx: &LateContext<'tcx>, body: &Body<'tcx>, args: &[PtrArg<'tcx>]) -> Vec<PtrArgResult> {
|
||||
struct V<'cx, 'tcx> {
|
||||
cx: &'cx LateContext<'tcx>,
|
||||
/// Map from a local id to which argument it came from (index into `Self::args` and
|
||||
|
|
|
@ -370,11 +370,11 @@ impl<'tcx> LateLintPass<'tcx> for QuestionMark {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
fn check_body(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
|
||||
self.try_block_depth_stack.push(0);
|
||||
}
|
||||
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &'tcx Body<'tcx>) {
|
||||
fn check_body_post(&mut self, _: &LateContext<'tcx>, _: &Body<'tcx>) {
|
||||
self.try_block_depth_stack.pop();
|
||||
}
|
||||
|
||||
|
|
|
@ -79,7 +79,6 @@ impl SingleCallFn {
|
|||
.tcx
|
||||
.hir()
|
||||
.maybe_body_owned_by(fn_def_id)
|
||||
.map(|body| cx.tcx.hir().body(body))
|
||||
.map_or(true, |body| is_in_test_function(cx.tcx, body.value.hir_id))
|
||||
|| match cx.tcx.hir_node(fn_hir_id) {
|
||||
Node::Item(item) => is_from_proc_macro(cx, item),
|
||||
|
|
|
@ -30,8 +30,8 @@ fn get_parent_local_binding_ty<'tcx>(cx: &LateContext<'tcx>, expr_hir_id: HirId)
|
|||
|
||||
fn is_function_block(cx: &LateContext<'_>, expr_hir_id: HirId) -> bool {
|
||||
let def_id = cx.tcx.hir().enclosing_body_owner(expr_hir_id);
|
||||
if let Some(body_id) = cx.tcx.hir().maybe_body_owned_by(def_id) {
|
||||
let body = cx.tcx.hir().body(body_id);
|
||||
if let Some(body) = cx.tcx.hir().maybe_body_owned_by(def_id) {
|
||||
let body = cx.tcx.hir().body(body.id());
|
||||
return body.value.peel_blocks().hir_id == expr_hir_id;
|
||||
}
|
||||
false
|
||||
|
|
|
@ -336,7 +336,7 @@ impl UnconditionalRecursion {
|
|||
// We need to use typeck here to infer the actual function being called.
|
||||
&& let body_def_id = cx.tcx.hir().enclosing_body_owner(call_expr.hir_id)
|
||||
&& let Some(body_owner) = cx.tcx.hir().maybe_body_owned_by(body_def_id)
|
||||
&& let typeck = cx.tcx.typeck_body(body_owner)
|
||||
&& let typeck = cx.tcx.typeck_body(body_owner.id())
|
||||
&& let Some(call_def_id) = typeck.type_dependent_def_id(call_expr.hir_id)
|
||||
{
|
||||
self.default_impl_for_type.insert(self_def_id, call_def_id);
|
||||
|
|
|
@ -137,9 +137,9 @@ impl<'tcx> LateLintPass<'tcx> for Author {
|
|||
|
||||
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.expect_owner().def_id) {
|
||||
if let Some(body) = hir.maybe_body_owned_by(hir_id.expect_owner().def_id) {
|
||||
check_node(cx, hir_id, |v| {
|
||||
v.expr(&v.bind("expr", hir.body(body_id).value));
|
||||
v.expr(&v.bind("expr", body.value));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue