Skip to content

Commit 535c168

Browse files
committed
Fix the tests that got broken by the fixes
1 parent c83fd39 commit 535c168

File tree

3 files changed

+39
-33
lines changed

3 files changed

+39
-33
lines changed

clippy_lints/src/lifetimes.rs

+31-29
Original file line numberDiff line numberDiff line change
@@ -101,38 +101,40 @@ fn check_fn_inner<'a, 'tcx>(
101101
}
102102

103103
let mut bounds_lts = Vec::new();
104-
generics.params.iter().for_each(|param| match param.kind {
105-
GenericParamKind::Lifetime { .. } => {},
106-
GenericParamKind::Type { .. } => {
107-
for bound in &param.bounds {
108-
let mut visitor = RefVisitor::new(cx);
109-
walk_param_bound(&mut visitor, bound);
110-
if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) {
111-
return;
112-
}
113-
if let GenericBound::Trait(ref trait_ref, _) = *bound {
114-
let params = &trait_ref
115-
.trait_ref
116-
.path
117-
.segments
118-
.last()
119-
.expect("a path must have at least one segment")
120-
.args;
121-
if let Some(ref params) = *params {
122-
params.args.iter().for_each(|param| match param {
123-
GenericArg::Lifetime(bound) => {
124-
if bound.name.name() != "'static" && !bound.is_elided() {
125-
return;
126-
}
127-
bounds_lts.push(bound);
128-
},
129-
_ => {},
130-
});
104+
let types = generics.params.iter().filter_map(|param| match param.kind {
105+
GenericParamKind::Type { .. } => Some(param),
106+
GenericParamKind::Lifetime { .. } => None,
107+
});
108+
for typ in types {
109+
for bound in &typ.bounds {
110+
let mut visitor = RefVisitor::new(cx);
111+
walk_param_bound(&mut visitor, bound);
112+
if visitor.lts.iter().any(|lt| matches!(lt, RefLt::Named(_))) {
113+
return;
114+
}
115+
if let GenericBound::Trait(ref trait_ref, _) = *bound {
116+
let params = &trait_ref
117+
.trait_ref
118+
.path
119+
.segments
120+
.last()
121+
.expect("a path must have at least one segment")
122+
.args;
123+
if let Some(ref params) = *params {
124+
let lifetimes = params.args.iter().filter_map(|arg| match arg {
125+
GenericArg::Lifetime(lt) => Some(lt),
126+
GenericArg::Type(_) => None,
127+
});
128+
for bound in lifetimes {
129+
if bound.name.name() != "'static" && !bound.is_elided() {
130+
return;
131+
}
132+
bounds_lts.push(bound);
131133
}
132134
}
133135
}
134-
},
135-
});
136+
}
137+
}
136138
if could_use_elision(cx, decl, body, &generics.params, bounds_lts) {
137139
span_lint(
138140
cx,

clippy_lints/src/ptr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ fn check_fn(cx: &LateContext, decl: &FnDecl, fn_id: NodeId, opt_body_id: Option<
225225
if let [ref bx] = *pp.segments;
226226
if let Some(ref params) = bx.args;
227227
if !params.parenthesized;
228-
if let [ref inner] = *params.args;
229-
if let GenericArg::Type(inner) = inner;
228+
if let Some(inner) = params.args.iter().find_map(|arg| match arg {
229+
GenericArg::Type(ty) => Some(ty),
230+
GenericArg::Lifetime(_) => None,
231+
});
230232
then {
231233
let replacement = snippet_opt(cx, inner.span);
232234
if let Some(r) = replacement {

clippy_lints/src/types.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,10 @@ fn check_ty_rptr(cx: &LateContext, ast_ty: &hir::Ty, is_local: bool, lt: &Lifeti
304304
if let [ref bx] = *path.segments;
305305
if let Some(ref params) = bx.args;
306306
if !params.parenthesized;
307-
if let [ref inner] = *params.args;
308-
if let GenericArg::Type(inner) = inner;
307+
if let Some(inner) = params.args.iter().find_map(|arg| match arg {
308+
GenericArg::Type(ty) => Some(ty),
309+
GenericArg::Lifetime(_) => None,
310+
});
309311
then {
310312
if is_any_trait(inner) {
311313
// Ignore `Box<Any>` types, see #1884 for details.

0 commit comments

Comments
 (0)