Support ?Trait bounds in supertraits and dyn Trait under a feature gate

This commit is contained in:
Bryanskiy 2024-02-23 16:39:57 +03:00
parent 6d674685ae
commit dc49aa3884
4 changed files with 16 additions and 12 deletions

View File

@ -545,7 +545,7 @@ fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
if !lt.is_elided() {
self.unelided_trait_object_lifetime = true;
}
for bound in bounds {
for (bound, _) in bounds {
self.visit_poly_trait_ref(bound);
}
},

View File

@ -181,7 +181,7 @@ fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
// Iterate the bounds and add them to our seen hash
// If we haven't yet seen it, add it to the fixed traits
for bound in bounds {
for (bound, _) in bounds {
let Some(def_id) = bound.trait_ref.trait_def_id() else {
continue;
};
@ -196,9 +196,9 @@ fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &'tcx Ty<'tcx>) {
// If the number of unique traits isn't the same as the number of traits in the bounds,
// there must be 1 or more duplicates
if bounds.len() != unique_traits.len() {
let mut bounds_span = bounds[0].span;
let mut bounds_span = bounds[0].0.span;
for bound in bounds.iter().skip(1) {
for (bound, _) in bounds.iter().skip(1) {
bounds_span = bounds_span.to(bound.span);
}

View File

@ -81,14 +81,17 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
// Returns true if given type is `Any` trait.
fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
if let TyKind::TraitObject(traits, ..) = t.kind
&& !traits.is_empty()
&& let Some(trait_did) = traits[0].trait_ref.trait_def_id()
// Only Send/Sync can be used as additional traits, so it is enough to
// check only the first trait.
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
{
return true;
if let TyKind::TraitObject(traits, ..) = t.kind {
return traits
.iter()
.any(|(bound, _)| {
if let Some(trait_did) = bound.trait_ref.trait_def_id()
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
{
return true;
}
false
});
}
false

View File

@ -55,6 +55,7 @@ fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
TyKind::TraitObject(param_bounds, _, _) => {
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
bound
.0
.bound_generic_params
.iter()
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))