@@ -849,6 +849,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
849
849
fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
850
850
let scope = Scope::TraitRefBoundary { s: self.scope };
851
851
self.with(scope, |this| {
852
+ walk_list!(this, visit_generic_param, generics.params);
852
853
for param in generics.params {
853
854
match param.kind {
854
855
GenericParamKind::Lifetime { .. } => {}
@@ -865,90 +866,86 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
865
866
}
866
867
}
867
868
}
868
- for predicate in generics.predicates {
869
- match predicate {
870
- &hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
871
- hir_id,
872
- bounded_ty,
873
- bounds,
874
- bound_generic_params,
875
- origin,
876
- ..
877
- }) => {
878
- let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
879
- bound_generic_params
880
- .iter()
881
- .enumerate()
882
- .map(|(late_bound_idx, param)| {
883
- let pair = ResolvedArg::late(late_bound_idx as u32, param);
884
- let r = late_arg_as_bound_arg(this.tcx, &pair.1, param);
885
- (pair, r)
886
- })
887
- .unzip();
888
- this.record_late_bound_vars(hir_id, binders.clone());
889
- // Even if there are no lifetimes defined here, we still wrap it in a binder
890
- // scope. If there happens to be a nested poly trait ref (an error), that
891
- // will be `Concatenating` anyways, so we don't have to worry about the depth
892
- // being wrong.
893
- let scope = Scope::Binder {
894
- hir_id,
895
- bound_vars,
896
- s: this.scope,
897
- scope_type: BinderScopeType::Normal,
898
- where_bound_origin: Some(origin),
899
- };
900
- this.with(scope, |this| {
901
- this.visit_ty(&bounded_ty);
902
- walk_list!(this, visit_param_bound, bounds);
869
+ walk_list!(this, visit_where_predicate, generics.predicates);
870
+ })
871
+ }
872
+
873
+ fn visit_where_predicate(&mut self, predicate: &'tcx hir::WherePredicate<'tcx>) {
874
+ match predicate {
875
+ &hir::WherePredicate::BoundPredicate(hir::WhereBoundPredicate {
876
+ hir_id,
877
+ bounded_ty,
878
+ bounds,
879
+ bound_generic_params,
880
+ origin,
881
+ ..
882
+ }) => {
883
+ let (bound_vars, binders): (FxIndexMap<LocalDefId, ResolvedArg>, Vec<_>) =
884
+ bound_generic_params
885
+ .iter()
886
+ .enumerate()
887
+ .map(|(late_bound_idx, param)| {
888
+ let pair = ResolvedArg::late(late_bound_idx as u32, param);
889
+ let r = late_arg_as_bound_arg(self.tcx, &pair.1, param);
890
+ (pair, r)
903
891
})
904
- }
905
- &hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
906
- lifetime,
907
- bounds,
908
- ..
909
- }) => {
910
- this.visit_lifetime(lifetime);
911
- walk_list!(this, visit_param_bound, bounds);
912
-
913
- if lifetime.res != hir::LifetimeName::Static {
914
- for bound in bounds {
915
- let hir::GenericBound::Outlives(lt) = bound else {
916
- continue;
917
- };
918
- if lt.res != hir::LifetimeName::Static {
919
- continue;
920
- }
921
- this.insert_lifetime(lt, ResolvedArg::StaticLifetime);
922
- this.tcx.struct_span_lint_hir(
923
- lint::builtin::UNUSED_LIFETIMES,
924
- lifetime.hir_id,
925
- lifetime.ident.span,
926
- format!(
927
- "unnecessary lifetime parameter `{}`",
928
- lifetime.ident
929
- ),
930
- |lint| {
931
- let help = format!(
932
- "you can use the `'static` lifetime directly, in place of `{}`",
933
- lifetime.ident,
934
- );
935
- lint.help(help)
936
- },
937
- );
938
- }
892
+ .unzip();
893
+ self.record_late_bound_vars(hir_id, binders.clone());
894
+ // Even if there are no lifetimes defined here, we still wrap it in a binder
895
+ // scope. If there happens to be a nested poly trait ref (an error), that
896
+ // will be `Concatenating` anyways, so we don't have to worry about the depth
897
+ // being wrong.
898
+ let scope = Scope::Binder {
899
+ hir_id,
900
+ bound_vars,
901
+ s: self.scope,
902
+ scope_type: BinderScopeType::Normal,
903
+ where_bound_origin: Some(origin),
904
+ };
905
+ self.with(scope, |this| {
906
+ walk_list!(this, visit_generic_param, bound_generic_params);
907
+ this.visit_ty(&bounded_ty);
908
+ walk_list!(this, visit_param_bound, bounds);
909
+ })
910
+ }
911
+ &hir::WherePredicate::RegionPredicate(hir::WhereRegionPredicate {
912
+ lifetime,
913
+ bounds,
914
+ ..
915
+ }) => {
916
+ self.visit_lifetime(lifetime);
917
+ walk_list!(self, visit_param_bound, bounds);
918
+
919
+ if lifetime.res != hir::LifetimeName::Static {
920
+ for bound in bounds {
921
+ let hir::GenericBound::Outlives(lt) = bound else {
922
+ continue;
923
+ };
924
+ if lt.res != hir::LifetimeName::Static {
925
+ continue;
939
926
}
940
- }
941
- &hir::WherePredicate::EqPredicate(hir::WhereEqPredicate {
942
- lhs_ty,
943
- rhs_ty,
944
- ..
945
- }) => {
946
- this.visit_ty(lhs_ty);
947
- this.visit_ty(rhs_ty);
927
+ self.insert_lifetime(lt, ResolvedArg::StaticLifetime);
928
+ self.tcx.struct_span_lint_hir(
929
+ lint::builtin::UNUSED_LIFETIMES,
930
+ lifetime.hir_id,
931
+ lifetime.ident.span,
932
+ format!("unnecessary lifetime parameter `{}`", lifetime.ident),
933
+ |lint| {
934
+ let help = format!(
935
+ "you can use the `'static` lifetime directly, in place of `{}`",
936
+ lifetime.ident,
937
+ );
938
+ lint.help(help)
939
+ },
940
+ );
948
941
}
949
942
}
950
943
}
951
- })
944
+ &hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { lhs_ty, rhs_ty, .. }) => {
945
+ self.visit_ty(lhs_ty);
946
+ self.visit_ty(rhs_ty);
947
+ }
948
+ }
952
949
}
953
950
954
951
fn visit_param_bound(&mut self, bound: &'tcx hir::GenericBound<'tcx>) {
@@ -986,6 +983,18 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
986
983
intravisit::walk_anon_const(this, c);
987
984
});
988
985
}
986
+
987
+ fn visit_generic_param(&mut self, p: &'tcx GenericParam<'tcx>) {
988
+ match p.kind {
989
+ GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
990
+ self.resolve_type_ref(p.def_id, p.hir_id);
991
+ }
992
+ GenericParamKind::Lifetime { .. } => {
993
+ // No need to resolve lifetime params, we don't use them for things
994
+ // like implicit `?Sized` or const-param-has-ty predicates.
995
+ }
996
+ }
997
+ }
989
998
}
990
999
991
1000
fn object_lifetime_default(tcx: TyCtxt<'_>, param_def_id: LocalDefId) -> ObjectLifetimeDefault {
0 commit comments