mirror of
https://github.com/rust-lang/rust-clippy
synced 2025-03-07 00:37:25 +00:00
Fix bug found during review
https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
This commit is contained in:
parent
5c2f6db289
commit
51b527266e
3 changed files with 52 additions and 14 deletions
|
@ -6,12 +6,12 @@ use rustc_errors::Applicability;
|
||||||
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_arg, 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_item, 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::{
|
||||||
BareFnTy, BodyId, FnDecl, FnSig, GenericArg, GenericBound, GenericParam, GenericParamKind, Generics, Impl,
|
BareFnTy, BodyId, FnDecl, FnSig, GenericArg, GenericArgs, GenericBound, GenericParam, GenericParamKind, Generics,
|
||||||
ImplItem, ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, LifetimeParamKind, Node, PolyTraitRef,
|
Impl, ImplItem, ImplItemKind, Item, ItemKind, Lifetime, LifetimeName, LifetimeParamKind, Node, PolyTraitRef,
|
||||||
PredicateOrigin, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, lang_items,
|
PredicateOrigin, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WherePredicate, lang_items,
|
||||||
};
|
};
|
||||||
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||||
|
@ -494,14 +494,14 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, generics: &'tcx Generics<'_
|
||||||
struct Usage {
|
struct Usage {
|
||||||
lifetime: Lifetime,
|
lifetime: Lifetime,
|
||||||
in_where_predicate: bool,
|
in_where_predicate: bool,
|
||||||
in_generic_arg: bool,
|
in_generics_arg: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LifetimeChecker<'cx, 'tcx, F> {
|
struct LifetimeChecker<'cx, 'tcx, F> {
|
||||||
cx: &'cx LateContext<'tcx>,
|
cx: &'cx LateContext<'tcx>,
|
||||||
map: FxHashMap<LocalDefId, Vec<Usage>>,
|
map: FxHashMap<LocalDefId, Vec<Usage>>,
|
||||||
where_predicate_depth: usize,
|
where_predicate_depth: usize,
|
||||||
generic_arg_depth: usize,
|
generic_args_depth: usize,
|
||||||
phantom: std::marker::PhantomData<F>,
|
phantom: std::marker::PhantomData<F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,7 +512,7 @@ impl<'cx, 'tcx, F> LifetimeChecker<'cx, 'tcx, F> {
|
||||||
cx,
|
cx,
|
||||||
map,
|
map,
|
||||||
where_predicate_depth: 0,
|
where_predicate_depth: 0,
|
||||||
generic_arg_depth: 0,
|
generic_args_depth: 0,
|
||||||
phantom: std::marker::PhantomData,
|
phantom: std::marker::PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -533,7 +533,7 @@ where
|
||||||
usages.push(Usage {
|
usages.push(Usage {
|
||||||
lifetime: *lifetime,
|
lifetime: *lifetime,
|
||||||
in_where_predicate: self.where_predicate_depth != 0,
|
in_where_predicate: self.where_predicate_depth != 0,
|
||||||
in_generic_arg: self.generic_arg_depth != 0,
|
in_generics_arg: self.generic_args_depth != 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -544,10 +544,10 @@ where
|
||||||
self.where_predicate_depth -= 1;
|
self.where_predicate_depth -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn visit_generic_arg(&mut self, generic_arg: &'tcx GenericArg<'tcx>) -> Self::Result {
|
fn visit_generic_args(&mut self, generic_args: &'tcx GenericArgs<'tcx>) -> Self::Result {
|
||||||
self.generic_arg_depth += 1;
|
self.generic_args_depth += 1;
|
||||||
walk_generic_arg(self, generic_arg);
|
walk_generic_args(self, generic_args);
|
||||||
self.generic_arg_depth -= 1;
|
self.generic_args_depth -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nested_visit_map(&mut self) -> Self::Map {
|
fn nested_visit_map(&mut self) -> Self::Map {
|
||||||
|
@ -574,7 +574,7 @@ fn report_extra_lifetimes<'tcx>(cx: &LateContext<'tcx>, func: &'tcx FnDecl<'_>,
|
||||||
for (def_id, usages) in checker.map {
|
for (def_id, usages) in checker.map {
|
||||||
if usages
|
if usages
|
||||||
.iter()
|
.iter()
|
||||||
.all(|usage| usage.in_where_predicate && !usage.in_generic_arg)
|
.all(|usage| usage.in_where_predicate && !usage.in_generics_arg)
|
||||||
{
|
{
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
|
@ -612,7 +612,7 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
|
||||||
for (&def_id, usages) in &checker.map {
|
for (&def_id, usages) in &checker.map {
|
||||||
if usages
|
if usages
|
||||||
.iter()
|
.iter()
|
||||||
.all(|usage| usage.in_where_predicate && !usage.in_generic_arg)
|
.all(|usage| usage.in_where_predicate && !usage.in_generics_arg)
|
||||||
{
|
{
|
||||||
span_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
|
@ -646,7 +646,7 @@ fn report_elidable_impl_lifetimes<'tcx>(
|
||||||
}
|
}
|
||||||
| Usage {
|
| Usage {
|
||||||
lifetime,
|
lifetime,
|
||||||
in_generic_arg: false,
|
in_generics_arg: false,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
] = usages.as_slice()
|
] = usages.as_slice()
|
||||||
|
|
|
@ -543,4 +543,23 @@ mod issue5787 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
|
||||||
|
mod rayon {
|
||||||
|
trait ParallelIterator {
|
||||||
|
type Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Copied<I: ParallelIterator> {
|
||||||
|
base: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T, I> ParallelIterator for Copied<I>
|
||||||
|
where
|
||||||
|
I: ParallelIterator<Item = &'a T>,
|
||||||
|
T: 'a + Copy + Send + Sync,
|
||||||
|
{
|
||||||
|
type Item = T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -543,4 +543,23 @@ mod issue5787 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://github.com/rust-lang/rust-clippy/pull/13286#issuecomment-2374245772
|
||||||
|
mod rayon {
|
||||||
|
trait ParallelIterator {
|
||||||
|
type Item;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Copied<I: ParallelIterator> {
|
||||||
|
base: I,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a, T, I> ParallelIterator for Copied<I>
|
||||||
|
where
|
||||||
|
I: ParallelIterator<Item = &'a T>,
|
||||||
|
T: 'a + Copy + Send + Sync,
|
||||||
|
{
|
||||||
|
type Item = T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue