Skip to content

Commit

Permalink
Fix clippy errors
Browse files Browse the repository at this point in the history
  • Loading branch information
zetanumbers committed Dec 12, 2023
1 parent d5c435e commit d1d899b
Show file tree
Hide file tree
Showing 18 changed files with 24 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/absolute_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths {
} = self;

if !path.span.from_expansion()
&& let Some(node) = cx.tcx.hir_node(hir_id)
&& let Some(node) = cx.tcx.opt_hir_node(hir_id)
&& !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _)))
&& let [first, rest @ ..] = path.segments
// Handle `::std`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
let map = cx.tcx.hir();
if let Some(parent_id) = map.opt_parent_id(expr.hir_id)
&& let Some(parent) = map.find(parent_id)
&& let Some(parent) = cx.tcx.opt_hir_node(parent_id)
{
let expr = match parent {
Node::Block(block) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/derivable_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
&& let Some(def_id) = trait_ref.trait_def_id()
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
&& let impl_item_hir = child.id.hir_id()
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.hir_node(impl_item_hir)
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/empty_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl LateLintPass<'_> for EmptyDrop {
}) = item.kind
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
&& let impl_item_hir = child.id.hir_id()
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.hir_node(impl_item_hir)
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
&& let func_expr = peel_blocks(func_expr)
Expand Down
10 changes: 5 additions & 5 deletions src/tools/clippy/clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::FakeReadCause;
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, TraitRef, Ty};
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LocalDefId;
use rustc_span::symbol::kw;
Expand Down Expand Up @@ -122,16 +122,16 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
}

// TODO: Replace with Map::is_argument(..) when it's fixed
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
match map.find(id) {
fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool {
match tcx.opt_hir_node(id) {
Some(Node::Pat(Pat {
kind: PatKind::Binding(..),
..
})) => (),
_ => return false,
}

matches!(map.find_parent(id), Some(Node::Param(_)))
matches!(tcx.hir().find_parent(id), Some(Node::Param(_)))
}

impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
Expand All @@ -154,7 +154,7 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
if cmt.place.projections.is_empty() {
let map = &self.cx.tcx.hir();
if is_argument(*map, cmt.hir_id) {
if is_argument(self.cx.tcx, cmt.hir_id) {
// Skip closure arguments
let parent_id = map.parent_id(cmt.hir_id);
if let Some(Node::Expr(..)) = map.find_parent(parent_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
// Find id of the local that expr_end_of_block resolves to
&& let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind
&& let Res::Local(expr_res) = expr_path.res
&& let Some(Node::Pat(res_pat)) = cx.tcx.hir_node(expr_res)
&& let Some(Node::Pat(res_pat)) = cx.tcx.opt_hir_node(expr_res)

// Find id of the local we found in the block
&& let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/index_refutable_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,15 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {

// Checking for slice indexing
&& let parent_id = map.parent_id(expr.hir_id)
&& let Some(hir::Node::Expr(parent_expr)) = map.find(parent_id)
&& let Some(hir::Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id)
&& let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind
&& let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr)
&& let Ok(index_value) = index_value.try_into()
&& index_value < max_suggested_slice

// Make sure that this slice index is read only
&& let maybe_addrof_id = map.parent_id(parent_id)
&& let Some(hir::Node::Expr(maybe_addrof_expr)) = map.find(maybe_addrof_id)
&& let Some(hir::Node::Expr(maybe_addrof_expr)) = cx.tcx.opt_hir_node(maybe_addrof_id)
&& let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind
{
use_info.index_use.push((index_value, map.span(parent_expr.hir_id)));
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
&& let Some(output) =
parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder())
{
let (name, kind) = match cx.tcx.hir_node(ty_hir_id) {
let (name, kind) = match cx.tcx.opt_hir_node(ty_hir_id) {
Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"),
Some(Node::Item(x)) => match x.kind {
ItemKind::Struct(..) => (x.ident.name, "struct"),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/loops/same_item_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ pub(super) fn check<'tcx>(
&& let PatKind::Binding(bind_ann, ..) = pat.kind
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
&& let parent_node = cx.tcx.hir().parent_id(hir_id)
&& let Some(Node::Local(parent_let_expr)) = cx.tcx.hir_node(parent_node)
&& let Some(Node::Local(parent_let_expr)) = cx.tcx.opt_hir_node(parent_node)
&& let Some(init) = parent_let_expr.init
{
match init.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/manual_rem_euclid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
// Also ensures the const is nonzero since zero can't be a divisor
&& const1 == const2 && const2 == const3
&& let Some(hir_id) = path_to_local(expr3)
&& let Some(Node::Pat(_)) = cx.tcx.hir_node(hir_id)
&& let Some(Node::Pat(_)) = cx.tcx.opt_hir_node(hir_id)
{
// Apply only to params or locals with annotated types
match cx.tcx.hir().find_parent(hir_id) {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/methods/filter_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub(super) fn check<'tcx>(
// add note if not multi-line
span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| {
let (applicability, pat) = if let Some(id) = path_to_local(recv)
&& let Some(hir::Node::Pat(pat)) = cx.tcx.hir_node(id)
&& let Some(hir::Node::Pat(pat)) = cx.tcx.opt_hir_node(id)
&& let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind
{
(Applicability::Unspecified, Some((pat.span, ident)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {

fn visit_path(&mut self, path: &Path<'tcx>, _: HirId) {
if let Res::Local(local_id) = path.res
&& let Some(Node::Pat(pat)) = self.cx.tcx.hir_node(local_id)
&& let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id)
&& let PatKind::Binding(_, local_id, ..) = pat.kind
{
self.identifiers.insert(local_id);
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReferenceVisitor<'a, 'tcx> {
&& let ExprKind::Path(ref path) = expr.kind
&& let QPath::Resolved(_, path) = path
&& let Res::Local(local_id) = path.res
&& let Some(Node::Pat(pat)) = self.cx.tcx.hir_node(local_id)
&& let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id)
&& let PatKind::Binding(_, local_id, ..) = pat.kind
&& self.identifiers.contains(&local_id)
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/min_ident_chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
let node = if hir_id.local_id == ItemLocalId::from_u32(0) {
// In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't
// reimplement it even if we wanted to
cx.tcx.hir_node(hir_id)
cx.tcx.opt_hir_node(hir_id)
} else {
let Some(owner) = cx.tcx.hir_owner_nodes(hir_id.owner).as_owner() else {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
if parent_id == cur_id {
break;
}
let Some(parent_node) = map.find(parent_id) else { break };
let Some(parent_node) = vis.cx.tcx.opt_hir_node(parent_id) else { break };

let stop_early = match parent_node {
Node::Expr(expr) => check_expr(vis, expr),
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/non_copy_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
if parent_id == cur_expr.hir_id {
break;
}
if let Some(Node::Expr(parent_expr)) = cx.tcx.hir_node(parent_id) {
if let Some(Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) {
match &parent_expr.kind {
ExprKind::AddrOf(..) => {
// `&e` => `e` must be referenced.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
{
let mut non_send_fields = Vec::new();

let hir_map = cx.tcx.hir();
for variant in adt_def.variants() {
for field in &variant.fields {
if let Some(field_hir_id) = field
Expand All @@ -104,7 +103,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy {
&& !is_lint_allowed(cx, NON_SEND_FIELDS_IN_SEND_TY, field_hir_id)
&& let field_ty = field.ty(cx.tcx, impl_trait_args)
&& !ty_allowed_in_send(cx, field_ty, send_trait)
&& let Node::Field(field_def) = hir_map.get(field_hir_id)
&& let Node::Field(field_def) = cx.tcx.hir_node(field_hir_id)
{
non_send_fields.push(NonSendField {
def: field_def,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/same_name_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
Some(trait_ref) => {
let mut methods_in_trait: BTreeSet<Symbol> = if let Some(Node::TraitRef(TraitRef {
path, ..
})) = cx.tcx.hir_node(trait_ref.hir_ref_id)
})) = cx.tcx.opt_hir_node(trait_ref.hir_ref_id)
&& let Res::Def(DefKind::Trait, did) = path.res
{
// FIXME: if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
if let Some(self_def) = self_ty.ty_adt_def()
&& let Some(self_local_did) = self_def.did().as_local()
&& let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did)
&& let Some(Node::Item(x)) = cx.tcx.hir_node(self_id)
&& let Some(Node::Item(x)) = cx.tcx.opt_hir_node(self_id)
&& let type_name = x.ident.name.as_str().to_lowercase()
&& (impl_item.ident.name.as_str() == type_name
|| impl_item.ident.name.as_str().replace('_', "") == type_name)
Expand Down

0 comments on commit d1d899b

Please sign in to comment.