Adapt clippy.

This commit is contained in:
Camille GILLOT 2024-08-18 16:43:39 +00:00
parent 98941f76ff
commit ef17eb79bb
8 changed files with 13 additions and 38 deletions

View File

@ -6,7 +6,7 @@
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty}; use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty};
use rustc_hir::{ use rustc_hir::{
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind, BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
PredicateOrigin, Ty, TyKind, WherePredicate, PredicateOrigin, Ty, WherePredicate,
}; };
use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
@ -199,12 +199,6 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) { fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
if let Some((def_id, _)) = t.peel_refs().as_generic_param() { if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
self.ty_params.remove(&def_id); self.ty_params.remove(&def_id);
} else if let TyKind::OpaqueDef(id, _) = t.kind {
// Explicitly walk OpaqueDef. Normally `walk_ty` would do the job, but it calls
// `visit_nested_item`, which checks that `Self::NestedFilter::INTER` is set. We're
// using `OnlyBodies`, so the check ends up failing and the type isn't fully walked.
let item = self.nested_visit_map().item(id);
walk_item(self, item);
} else { } else {
walk_ty(self, t); walk_ty(self, t);
} }

View File

@ -3,7 +3,7 @@
use rustc_errors::{Applicability, SuggestionStyle}; use rustc_errors::{Applicability, SuggestionStyle};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_hir::{ use rustc_hir::{
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier, AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifier,
TyKind, WherePredicate, TyKind, WherePredicate,
}; };
use rustc_hir_analysis::lower_ty; use rustc_hir_analysis::lower_ty;
@ -342,11 +342,8 @@ fn check_generics(&mut self, cx: &LateContext<'tcx>, generics: &rustc_hir::Gener
} }
} }
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &rustc_hir::Ty<'_>) { fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx>) {
if let TyKind::OpaqueDef(item_id, ..) = ty.kind if let TyKind::OpaqueDef(opaque_ty, ..) = ty.kind {
&& let item = cx.tcx.hir().item(item_id)
&& let ItemKind::OpaqueTy(opaque_ty) = item.kind
{
check(cx, opaque_ty.bounds); check(cx, opaque_ty.bounds);
} }
} }

View File

@ -308,11 +308,7 @@ enum LenOutput {
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> { fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
if let ty::Alias(_, alias_ty) = ty.kind() if let ty::Alias(_, alias_ty) = ty.kind()
&& let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(alias_ty.def_id) && let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
&& let Item {
kind: ItemKind::OpaqueTy(opaque),
..
} = item
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin && let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds && let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
&& let Some(segment) = trait_ref.trait_ref.path.segments.last() && let Some(segment) = trait_ref.trait_ref.path.segments.last()

View File

@ -6,7 +6,7 @@
use rustc_hir::FnRetTy::Return; use rustc_hir::FnRetTy::Return;
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter}; use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
use rustc_hir::intravisit::{ use rustc_hir::intravisit::{
Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound, Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_param_bound,
walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_where_predicate, walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_where_predicate,
}; };
use rustc_hir::{ use rustc_hir::{
@ -420,11 +420,9 @@ fn visit_poly_trait_ref(&mut self, poly_tref: &'tcx PolyTraitRef<'tcx>) {
fn visit_ty(&mut self, ty: &'tcx Ty<'_>) { fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
match ty.kind { match ty.kind {
TyKind::OpaqueDef(item, bounds) => { TyKind::OpaqueDef(opaque, bounds) => {
let map = self.cx.tcx.hir();
let item = map.item(item);
let len = self.lts.len(); let len = self.lts.len();
walk_item(self, item); self.visit_opaque_ty(opaque);
self.lts.truncate(len); self.lts.truncate(len);
self.lts.extend(bounds.iter().filter_map(|bound| match bound { self.lts.extend(bounds.iter().filter_map(|bound| match bound {
GenericArg::Lifetime(&l) => Some(l), GenericArg::Lifetime(&l) => Some(l),

View File

@ -4,7 +4,7 @@
use rustc_hir::intravisit::FnKind; use rustc_hir::intravisit::FnKind;
use rustc_hir::{ use rustc_hir::{
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl, Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind, FnRetTy, GenericArg, GenericBound, ImplItem, Item, LifetimeName, Node, TraitRef, Ty, TyKind,
}; };
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass; use rustc_session::declare_lint_pass;
@ -105,9 +105,7 @@ fn future_trait_ref<'tcx>(
cx: &LateContext<'tcx>, cx: &LateContext<'tcx>,
ty: &'tcx Ty<'tcx>, ty: &'tcx Ty<'tcx>,
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> { ) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
if let TyKind::OpaqueDef(item_id, bounds) = ty.kind if let TyKind::OpaqueDef(opaque, bounds) = ty.kind
&& let item = cx.tcx.hir().item(item_id)
&& let ItemKind::OpaqueTy(opaque) = &item.kind
&& let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| { && let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
if let GenericBound::Trait(poly, _) = bound { if let GenericBound::Trait(poly, _) = bound {
Some(&poly.trait_ref) Some(&poly.trait_ref)

View File

@ -193,8 +193,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
| hir::ItemKind::Trait(..) | hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..) | hir::ItemKind::TraitAlias(..)
| hir::ItemKind::TyAlias(..) | hir::ItemKind::TyAlias(..)
| hir::ItemKind::Union(..) | hir::ItemKind::Union(..) => {}
| hir::ItemKind::OpaqueTy(..) => {},
hir::ItemKind::ExternCrate(..) hir::ItemKind::ExternCrate(..)
| hir::ItemKind::ForeignMod { .. } | hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::GlobalAsm(..) | hir::ItemKind::GlobalAsm(..)

View File

@ -130,7 +130,6 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx hir::Item<'_>) {
| hir::ItemKind::GlobalAsm(..) | hir::ItemKind::GlobalAsm(..)
| hir::ItemKind::TyAlias(..) | hir::ItemKind::TyAlias(..)
| hir::ItemKind::Union(..) | hir::ItemKind::Union(..)
| hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::ExternCrate(..) | hir::ItemKind::ExternCrate(..)
| hir::ItemKind::ForeignMod { .. } | hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::Impl { .. } | hir::ItemKind::Impl { .. }

View File

@ -85,10 +85,6 @@ enum StackItem {
impl<'tcx> LateLintPass<'tcx> for UseSelf { impl<'tcx> LateLintPass<'tcx> for UseSelf {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
return;
}
// We push the self types of `impl`s on a stack here. Only the top type on the stack is // We push the self types of `impl`s on a stack here. Only the top type on the stack is
// relevant for linting, since this is the self type of the `impl` we're currently in. To // relevant for linting, since this is the self type of the `impl` we're currently in. To
// avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that // avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that
@ -130,10 +126,8 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
self.stack.push(stack_item); self.stack.push(stack_item);
} }
fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) { fn check_item_post(&mut self, _: &LateContext<'_>, _: &Item<'_>) {
if !matches!(item.kind, ItemKind::OpaqueTy(_)) { self.stack.pop();
self.stack.pop();
}
} }
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) { fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {