Skip to content

Commit 7782194

Browse files
committed
Adapt clippy.
1 parent 7f711b3 commit 7782194

9 files changed

+16
-40
lines changed

src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_errors::Applicability;
66
use rustc_hir::intravisit::{walk_impl_item, walk_item, walk_param_bound, walk_ty, Visitor};
77
use rustc_hir::{
88
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
9-
PredicateOrigin, Ty, TyKind, WherePredicate,
9+
PredicateOrigin, Ty, WherePredicate,
1010
};
1111
use rustc_lint::{LateContext, LateLintPass, LintContext};
1212
use rustc_middle::hir::nested_filter;
@@ -199,12 +199,6 @@ impl<'cx, 'tcx> Visitor<'tcx> for TypeWalker<'cx, 'tcx> {
199199
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
200200
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
201201
self.ty_params.remove(&def_id);
202-
} else if let TyKind::OpaqueDef(id, _, _) = t.kind {
203-
// Explicitly walk OpaqueDef. Normally `walk_ty` would do the job, but it calls
204-
// `visit_nested_item`, which checks that `Self::NestedFilter::INTER` is set. We're
205-
// using `OnlyBodies`, so the check ends up failing and the type isn't fully walked.
206-
let item = self.nested_visit_map().item(id);
207-
walk_item(self, item);
208202
} else {
209203
walk_ty(self, t);
210204
}

src/tools/clippy/clippy_lints/src/implied_bounds_in_impls.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use clippy_utils::source::snippet;
33
use rustc_errors::{Applicability, SuggestionStyle};
44
use rustc_hir::def_id::DefId;
55
use rustc_hir::{
6-
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier,
6+
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifier,
77
TyKind, WherePredicate,
88
};
99
use rustc_hir_analysis::lower_ty;
@@ -342,11 +342,8 @@ impl<'tcx> LateLintPass<'tcx> for ImpliedBoundsInImpls {
342342
}
343343
}
344344

345-
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &rustc_hir::Ty<'_>) {
346-
if let TyKind::OpaqueDef(item_id, ..) = ty.kind
347-
&& let item = cx.tcx.hir().item(item_id)
348-
&& let ItemKind::OpaqueTy(opaque_ty) = item.kind
349-
{
345+
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx>) {
346+
if let TyKind::OpaqueDef(opaque_ty, ..) = ty.kind {
350347
check(cx, opaque_ty.bounds);
351348
}
352349
}

src/tools/clippy/clippy_lints/src/len_zero.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,7 @@ enum LenOutput {
295295

296296
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
297297
if let ty::Alias(_, alias_ty) = ty.kind()
298-
&& let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
299-
&& let Item {
300-
kind: ItemKind::OpaqueTy(opaque),
301-
..
302-
} = item
298+
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
303299
&& let OpaqueTyOrigin::AsyncFn(_) = opaque.origin
304300
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
305301
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()

src/tools/clippy/clippy_lints/src/lifetimes.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
55
use rustc_errors::Applicability;
66
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
77
use rustc_hir::intravisit::{
8-
walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
8+
walk_fn_decl, walk_generic_param, walk_generics, walk_impl_item_ref, walk_param_bound,
99
walk_poly_trait_ref, walk_trait_ref, walk_ty, Visitor,
1010
};
1111
use rustc_hir::FnRetTy::Return;
@@ -523,11 +523,9 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
523523

524524
fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
525525
match ty.kind {
526-
TyKind::OpaqueDef(item, bounds, _) => {
527-
let map = self.cx.tcx.hir();
528-
let item = map.item(item);
526+
TyKind::OpaqueDef(opaque, bounds) => {
529527
let len = self.lts.len();
530-
walk_item(self, item);
528+
self.visit_opaque_ty(opaque);
531529
self.lts.truncate(len);
532530
self.lts.extend(bounds.iter().filter_map(|bound| match bound {
533531
GenericArg::Lifetime(&l) => Some(l),

src/tools/clippy/clippy_lints/src/manual_async_fn.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_errors::Applicability;
44
use rustc_hir::intravisit::FnKind;
55
use rustc_hir::{
66
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
7-
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind,
7+
FnRetTy, GenericArg, GenericBound, ImplItem, Item, LifetimeName, Node, TraitRef, Ty, TyKind,
88
};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_session::declare_lint_pass;
@@ -105,9 +105,8 @@ fn future_trait_ref<'tcx>(
105105
cx: &LateContext<'tcx>,
106106
ty: &'tcx Ty<'tcx>,
107107
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
108-
if let TyKind::OpaqueDef(item_id, bounds, false) = ty.kind
109-
&& let item = cx.tcx.hir().item(item_id)
110-
&& let ItemKind::OpaqueTy(opaque) = &item.kind
108+
if let TyKind::OpaqueDef(opaque, bounds) = ty.kind
109+
&& !opaque.in_trait
111110
&& let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
112111
if let GenericBound::Trait(poly, _) = bound {
113112
Some(&poly.trait_ref)

src/tools/clippy/clippy_lints/src/missing_doc.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
193193
| hir::ItemKind::Trait(..)
194194
| hir::ItemKind::TraitAlias(..)
195195
| hir::ItemKind::TyAlias(..)
196-
| hir::ItemKind::Union(..)
197-
| hir::ItemKind::OpaqueTy(..) => {},
196+
| hir::ItemKind::Union(..) => {}
198197
hir::ItemKind::ExternCrate(..)
199198
| hir::ItemKind::ForeignMod { .. }
200199
| hir::ItemKind::GlobalAsm(..)

src/tools/clippy/clippy_lints/src/missing_inline.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
130130
| hir::ItemKind::GlobalAsm(..)
131131
| hir::ItemKind::TyAlias(..)
132132
| hir::ItemKind::Union(..)
133-
| hir::ItemKind::OpaqueTy(..)
134133
| hir::ItemKind::ExternCrate(..)
135134
| hir::ItemKind::ForeignMod { .. }
136135
| hir::ItemKind::Impl { .. }

src/tools/clippy/clippy_lints/src/use_self.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
8585

8686
impl<'tcx> LateLintPass<'tcx> for UseSelf {
8787
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
88-
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
89-
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
90-
return;
91-
}
9288
// We push the self types of `impl`s on a stack here. Only the top type on the stack is
9389
// relevant for linting, since this is the self type of the `impl` we're currently in. To
9490
// avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that
@@ -130,10 +126,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
130126
self.stack.push(stack_item);
131127
}
132128

133-
fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
134-
if !matches!(item.kind, ItemKind::OpaqueTy(_)) {
135-
self.stack.pop();
136-
}
129+
fn check_item_post(&mut self, _: &LateContext<'_>, _: &Item<'_>) {
130+
self.stack.pop();
137131
}
138132

139133
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {

src/tools/clippy/clippy_utils/src/hir_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1115,9 +1115,9 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
11151115
}
11161116
},
11171117
TyKind::Path(ref qpath) => self.hash_qpath(qpath),
1118-
TyKind::OpaqueDef(_, arg_list, in_trait) => {
1118+
TyKind::OpaqueDef(opaque, arg_list) => {
11191119
self.hash_generic_args(arg_list);
1120-
in_trait.hash(&mut self.s);
1120+
opaque.in_trait.hash(&mut self.s);
11211121
},
11221122
TyKind::TraitObject(_, lifetime, _) => {
11231123
self.hash_lifetime(lifetime);

0 commit comments

Comments
 (0)