Skip to content

Commit dc49aa3

Browse files
committed
Support ?Trait bounds in supertraits and dyn Trait under a feature gate
1 parent 6d67468 commit dc49aa3

File tree

4 files changed

+16
-12
lines changed

4 files changed

+16
-12
lines changed

clippy_lints/src/lifetimes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> {
545545
if !lt.is_elided() {
546546
self.unelided_trait_object_lifetime = true;
547547
}
548-
for bound in bounds {
548+
for (bound, _) in bounds {
549549
self.visit_poly_trait_ref(bound);
550550
}
551551
},

clippy_lints/src/trait_bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
181181

182182
// Iterate the bounds and add them to our seen hash
183183
// If we haven't yet seen it, add it to the fixed traits
184-
for bound in bounds {
184+
for (bound, _) in bounds {
185185
let Some(def_id) = bound.trait_ref.trait_def_id() else {
186186
continue;
187187
};
@@ -196,9 +196,9 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
196196
// If the number of unique traits isn't the same as the number of traits in the bounds,
197197
// there must be 1 or more duplicates
198198
if bounds.len() != unique_traits.len() {
199-
let mut bounds_span = bounds[0].span;
199+
let mut bounds_span = bounds[0].0.span;
200200

201-
for bound in bounds.iter().skip(1) {
201+
for (bound, _) in bounds.iter().skip(1) {
202202
bounds_span = bounds_span.to(bound.span);
203203
}
204204

clippy_lints/src/types/borrowed_box.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
8181

8282
// Returns true if given type is `Any` trait.
8383
fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
84-
if let TyKind::TraitObject(traits, ..) = t.kind
85-
&& !traits.is_empty()
86-
&& let Some(trait_did) = traits[0].trait_ref.trait_def_id()
87-
// Only Send/Sync can be used as additional traits, so it is enough to
88-
// check only the first trait.
89-
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
90-
{
91-
return true;
84+
if let TyKind::TraitObject(traits, ..) = t.kind {
85+
return traits
86+
.iter()
87+
.any(|(bound, _)| {
88+
if let Some(trait_did) = bound.trait_ref.trait_def_id()
89+
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
90+
{
91+
return true;
92+
}
93+
false
94+
});
9295
}
9396

9497
false

clippy_lints/src/types/type_complexity.rs

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
5555
TyKind::TraitObject(param_bounds, _, _) => {
5656
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
5757
bound
58+
.0
5859
.bound_generic_params
5960
.iter()
6061
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))

0 commit comments

Comments
 (0)