Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2a25a16

Browse files
authoredFeb 17, 2025
Rollup merge of #137100 - fmease:hirtylow-rm-clauses-wrapper, r=compiler-errors
HIR analysis: Remove unnecessary abstraction over list of clauses `rustc_hir_analysis::bounds::Bounds` with its methods is nowadays a paper-thin wrapper around `Vec<(Clause, Span)>`s and `Vec::push` essentially. Its existence slightly annoyed me (and I keep opening its corresp. file instead of the identically named `bounds.rs` in `hir_ty_lowering/` that I actually want most of the time :P). Opening to check if you agree with inlining it. r? compiler-errors or reassign
2 parents fab3837 + 84bdc5d commit 2a25a16

File tree

8 files changed

+114
-206
lines changed

8 files changed

+114
-206
lines changed
 

‎compiler/rustc_hir_analysis/src/bounds.rs

Lines changed: 0 additions & 100 deletions
This file was deleted.

‎compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use tracing::{debug, instrument};
1313

1414
use super::ItemCtxt;
1515
use super::predicates_of::assert_only_contains_predicates_from;
16-
use crate::bounds::Bounds;
1716
use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter};
1817

1918
/// For associated types we include both bounds written on the type
@@ -38,7 +37,7 @@ fn associated_type_bounds<'tcx>(
3837
);
3938

4039
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
41-
let mut bounds = Bounds::default();
40+
let mut bounds = Vec::new();
4241
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
4342
// Associated types are implicitly sized unless a `?Sized` bound is found
4443
match filter {
@@ -68,7 +67,7 @@ fn associated_type_bounds<'tcx>(
6867
)
6968
});
7069

71-
let all_bounds = tcx.arena.alloc_from_iter(bounds.clauses().chain(bounds_from_parent));
70+
let all_bounds = tcx.arena.alloc_from_iter(bounds.into_iter().chain(bounds_from_parent));
7271
debug!(
7372
"associated_type_bounds({}) = {:?}",
7473
tcx.def_path_str(assoc_item_def_id.to_def_id()),
@@ -327,7 +326,7 @@ fn opaque_type_bounds<'tcx>(
327326
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
328327
ty::print::with_reduced_queries!({
329328
let icx = ItemCtxt::new(tcx, opaque_def_id);
330-
let mut bounds = Bounds::default();
329+
let mut bounds = Vec::new();
331330
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
332331
// Opaque types are implicitly sized unless a `?Sized` bound is found
333332
match filter {
@@ -343,7 +342,7 @@ fn opaque_type_bounds<'tcx>(
343342
}
344343
debug!(?bounds);
345344

346-
tcx.arena.alloc_from_iter(bounds.clauses())
345+
tcx.arena.alloc_slice(&bounds)
347346
})
348347
}
349348

‎compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use rustc_span::{DUMMY_SP, Ident, Span};
1313
use tracing::{debug, instrument, trace};
1414

1515
use super::item_bounds::explicit_item_bounds_with_filter;
16-
use crate::bounds::Bounds;
1716
use crate::collect::ItemCtxt;
1817
use crate::constrained_generic_params as cgp;
1918
use crate::delegation::inherit_predicates_for_delegation_item;
@@ -178,15 +177,15 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
178177
// on a trait we must also consider the bounds that follow the trait's name,
179178
// like `trait Foo: A + B + C`.
180179
if let Some(self_bounds) = is_trait {
181-
let mut bounds = Bounds::default();
180+
let mut bounds = Vec::new();
182181
icx.lowerer().lower_bounds(
183182
tcx.types.self_param,
184183
self_bounds,
185184
&mut bounds,
186185
ty::List::empty(),
187186
PredicateFilter::All,
188187
);
189-
predicates.extend(bounds.clauses());
188+
predicates.extend(bounds);
190189
}
191190

192191
// In default impls, we can assume that the self type implements
@@ -209,7 +208,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
209208
GenericParamKind::Lifetime { .. } => (),
210209
GenericParamKind::Type { .. } => {
211210
let param_ty = icx.lowerer().lower_ty_param(param.hir_id);
212-
let mut bounds = Bounds::default();
211+
let mut bounds = Vec::new();
213212
// Params are implicitly sized unless a `?Sized` bound is found
214213
icx.lowerer().add_sized_bound(
215214
&mut bounds,
@@ -219,7 +218,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
219218
param.span,
220219
);
221220
trace!(?bounds);
222-
predicates.extend(bounds.clauses());
221+
predicates.extend(bounds);
223222
trace!(?predicates);
224223
}
225224
hir::GenericParamKind::Const { .. } => {
@@ -264,15 +263,15 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
264263
}
265264
}
266265

267-
let mut bounds = Bounds::default();
266+
let mut bounds = Vec::new();
268267
icx.lowerer().lower_bounds(
269268
ty,
270269
bound_pred.bounds,
271270
&mut bounds,
272271
bound_vars,
273272
PredicateFilter::All,
274273
);
275-
predicates.extend(bounds.clauses());
274+
predicates.extend(bounds);
276275
}
277276

278277
hir::WherePredicateKind::RegionPredicate(region_pred) => {
@@ -627,15 +626,15 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
627626
let icx = ItemCtxt::new(tcx, trait_def_id);
628627

629628
let self_param_ty = tcx.types.self_param;
630-
let mut bounds = Bounds::default();
629+
let mut bounds = Vec::new();
631630
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
632631

633632
let where_bounds_that_match =
634633
icx.probe_ty_param_bounds_in_generics(generics, item.owner_id.def_id, filter);
635634

636635
// Combine the two lists to form the complete set of superbounds:
637636
let implied_bounds =
638-
&*tcx.arena.alloc_from_iter(bounds.clauses().chain(where_bounds_that_match));
637+
&*tcx.arena.alloc_from_iter(bounds.into_iter().chain(where_bounds_that_match));
639638
debug!(?implied_bounds);
640639

641640
// Now require that immediate supertraits are lowered, which will, in
@@ -904,7 +903,7 @@ impl<'tcx> ItemCtxt<'tcx> {
904903
param_def_id: LocalDefId,
905904
filter: PredicateFilter,
906905
) -> Vec<(ty::Clause<'tcx>, Span)> {
907-
let mut bounds = Bounds::default();
906+
let mut bounds = Vec::new();
908907

909908
for predicate in hir_generics.predicates {
910909
let hir_id = predicate.hir_id;
@@ -938,7 +937,7 @@ impl<'tcx> ItemCtxt<'tcx> {
938937
);
939938
}
940939

941-
bounds.clauses().collect()
940+
bounds
942941
}
943942
}
944943

@@ -1007,7 +1006,7 @@ pub(super) fn const_conditions<'tcx>(
10071006
};
10081007

10091008
let icx = ItemCtxt::new(tcx, def_id);
1010-
let mut bounds = Bounds::default();
1009+
let mut bounds = Vec::new();
10111010

10121011
for pred in generics.predicates {
10131012
match pred.kind {
@@ -1027,12 +1026,12 @@ pub(super) fn const_conditions<'tcx>(
10271026
}
10281027

10291028
if let Some((def_id, supertraits)) = trait_def_id_and_supertraits {
1030-
bounds.push_const_bound(
1031-
tcx,
1032-
ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id())),
1033-
ty::BoundConstness::Maybe,
1029+
// We've checked above that the trait is conditionally const.
1030+
bounds.push((
1031+
ty::Binder::dummy(ty::TraitRef::identity(tcx, def_id.to_def_id()))
1032+
.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
10341033
DUMMY_SP,
1035-
);
1034+
));
10361035

10371036
icx.lowerer().lower_bounds(
10381037
tcx.types.self_param,
@@ -1045,7 +1044,7 @@ pub(super) fn const_conditions<'tcx>(
10451044

10461045
ty::ConstConditions {
10471046
parent: has_parent.then(|| tcx.local_parent(def_id).to_def_id()),
1048-
predicates: tcx.arena.alloc_from_iter(bounds.clauses().map(|(clause, span)| {
1047+
predicates: tcx.arena.alloc_from_iter(bounds.into_iter().map(|(clause, span)| {
10491048
(
10501049
clause.kind().map_bound(|clause| match clause {
10511050
ty::ClauseKind::HostEffect(ty::HostEffectPredicate {

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@ use rustc_hir::HirId;
88
use rustc_hir::def::{DefKind, Res};
99
use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_middle::bug;
11-
use rustc_middle::ty::{self as ty, IsSuggestable, Ty, TyCtxt};
11+
use rustc_middle::ty::{self as ty, IsSuggestable, Ty, TyCtxt, Upcast};
1212
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
1313
use rustc_trait_selection::traits;
1414
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
1515
use smallvec::SmallVec;
1616
use tracing::{debug, instrument};
1717

1818
use super::errors::GenericsArgsErrExtend;
19-
use crate::bounds::Bounds;
2019
use crate::errors;
2120
use crate::hir_ty_lowering::{
2221
AssocItemQSelf, FeedConstTy, HirTyLowerer, PredicateFilter, RegionInferReason,
@@ -28,7 +27,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2827
/// Doesn't add the bound if the HIR bounds contain any of `Sized`, `?Sized` or `!Sized`.
2928
pub(crate) fn add_sized_bound(
3029
&self,
31-
bounds: &mut Bounds<'tcx>,
30+
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
3231
self_ty: Ty<'tcx>,
3332
hir_bounds: &'tcx [hir::GenericBound<'tcx>],
3433
self_ty_where_predicates: Option<(LocalDefId, &'tcx [hir::WherePredicate<'tcx>])>,
@@ -113,10 +112,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
113112
if seen_sized_unbound || seen_negative_sized_bound || seen_positive_sized_bound {
114113
// There was in fact a `?Sized`, `!Sized` or explicit `Sized` bound;
115114
// we don't need to do anything.
116-
} else if sized_def_id.is_some() {
115+
} else if let Some(sized_def_id) = sized_def_id {
117116
// There was no `?Sized`, `!Sized` or explicit `Sized` bound;
118117
// add `Sized` if it's available.
119-
bounds.push_sized(tcx, self_ty, span);
118+
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [self_ty]);
119+
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
120+
bounds.insert(0, (trait_ref.upcast(tcx), span));
120121
}
121122
}
122123

@@ -146,7 +147,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
146147
&self,
147148
param_ty: Ty<'tcx>,
148149
hir_bounds: I,
149-
bounds: &mut Bounds<'tcx>,
150+
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
150151
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
151152
predicate_filter: PredicateFilter,
152153
) where
@@ -189,14 +190,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
189190
}
190191

191192
let region = self.lower_lifetime(lifetime, RegionInferReason::OutlivesBound);
192-
bounds.push_region_bound(
193-
self.tcx(),
194-
ty::Binder::bind_with_vars(
195-
ty::OutlivesPredicate(param_ty, region),
196-
bound_vars,
197-
),
198-
lifetime.ident.span,
193+
let bound = ty::Binder::bind_with_vars(
194+
ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(param_ty, region)),
195+
bound_vars,
199196
);
197+
bounds.push((bound.upcast(self.tcx()), lifetime.ident.span));
200198
}
201199
hir::GenericBound::Use(..) => {
202200
// We don't actually lower `use` into the type layer.
@@ -219,7 +217,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
219217
hir_ref_id: hir::HirId,
220218
trait_ref: ty::PolyTraitRef<'tcx>,
221219
constraint: &hir::AssocItemConstraint<'tcx>,
222-
bounds: &mut Bounds<'tcx>,
220+
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
223221
duplicates: &mut FxIndexMap<DefId, Span>,
224222
path_span: Span,
225223
predicate_filter: PredicateFilter,
@@ -389,14 +387,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
389387
PredicateFilter::All
390388
| PredicateFilter::SelfOnly
391389
| PredicateFilter::SelfAndAssociatedTypeBounds => {
392-
bounds.push_projection_bound(
393-
tcx,
394-
projection_term.map_bound(|projection_term| ty::ProjectionPredicate {
390+
let bound = projection_term.map_bound(|projection_term| {
391+
ty::ClauseKind::Projection(ty::ProjectionPredicate {
395392
projection_term,
396393
term,
397-
}),
398-
constraint.span,
399-
);
394+
})
395+
});
396+
bounds.push((bound.upcast(tcx), constraint.span));
400397
}
401398
// SelfTraitThatDefines is only interested in trait predicates.
402399
PredicateFilter::SelfTraitThatDefines(_) => {}

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use smallvec::{SmallVec, smallvec};
1717
use tracing::{debug, instrument};
1818

1919
use super::HirTyLowerer;
20-
use crate::bounds::Bounds;
2120
use crate::hir_ty_lowering::{
2221
GenericArgCountMismatch, GenericArgCountResult, PredicateFilter, RegionInferReason,
2322
};
@@ -36,7 +35,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3635
let tcx = self.tcx();
3736
let dummy_self = tcx.types.trait_object_dummy_self;
3837

39-
let mut user_written_bounds = Bounds::default();
38+
let mut user_written_bounds = Vec::new();
4039
let mut potential_assoc_types = Vec::new();
4140
for trait_bound in hir_bounds.iter() {
4241
if let hir::BoundPolarity::Maybe(_) = trait_bound.modifiers.polarity {
@@ -60,15 +59,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
6059
}
6160

6261
let (trait_bounds, mut projection_bounds) =
63-
traits::expand_trait_aliases(tcx, user_written_bounds.clauses());
62+
traits::expand_trait_aliases(tcx, user_written_bounds.iter().copied());
6463
let (regular_traits, mut auto_traits): (Vec<_>, Vec<_>) = trait_bounds
6564
.into_iter()
6665
.partition(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
6766

6867
// We don't support empty trait objects.
6968
if regular_traits.is_empty() && auto_traits.is_empty() {
70-
let guar =
71-
self.report_trait_object_with_no_traits_error(span, user_written_bounds.clauses());
69+
let guar = self.report_trait_object_with_no_traits_error(
70+
span,
71+
user_written_bounds.iter().copied(),
72+
);
7273
return Ty::new_error(tcx, guar);
7374
}
7475
// We don't support >1 principal
@@ -84,7 +85,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
8485
// Check that there are no gross dyn-compatibility violations;
8586
// most importantly, that the supertraits don't contain `Self`,
8687
// to avoid ICEs.
87-
for (clause, span) in user_written_bounds.clauses() {
88+
for (clause, span) in user_written_bounds {
8889
if let Some(trait_pred) = clause.as_trait_clause() {
8990
let violations =
9091
hir_ty_lowering_dyn_compatibility_violations(tcx, trait_pred.def_id());

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 68 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw};
4949
use rustc_trait_selection::infer::InferCtxtExt;
5050
use rustc_trait_selection::traits::wf::object_region_bounds;
5151
use rustc_trait_selection::traits::{self, ObligationCtxt};
52+
use rustc_type_ir::Upcast;
5253
use tracing::{debug, instrument};
5354

54-
use crate::bounds::Bounds;
5555
use crate::check::check_abi_fn_ptr;
5656
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation, InvalidBaseType};
5757
use crate::hir_ty_lowering::errors::{GenericsArgsErrExtend, prohibit_assoc_item_constraint};
@@ -691,7 +691,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
691691
constness: hir::BoundConstness,
692692
polarity: hir::BoundPolarity,
693693
self_ty: Ty<'tcx>,
694-
bounds: &mut Bounds<'tcx>,
694+
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
695695
predicate_filter: PredicateFilter,
696696
) -> GenericArgCountResult {
697697
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
@@ -720,6 +720,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
720720
bound_vars,
721721
);
722722

723+
debug!(?poly_trait_ref);
724+
723725
let polarity = match polarity {
724726
rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive,
725727
rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,
@@ -741,6 +743,26 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
741743
}
742744
};
743745

746+
// We deal with const conditions later.
747+
match predicate_filter {
748+
PredicateFilter::All
749+
| PredicateFilter::SelfOnly
750+
| PredicateFilter::SelfTraitThatDefines(..)
751+
| PredicateFilter::SelfAndAssociatedTypeBounds => {
752+
let bound = poly_trait_ref.map_bound(|trait_ref| {
753+
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
754+
});
755+
let bound = (bound.upcast(tcx), span);
756+
// FIXME(-Znext-solver): We can likely remove this hack once the new trait solver lands.
757+
if tcx.is_lang_item(trait_def_id, rustc_hir::LangItem::Sized) {
758+
bounds.insert(0, bound);
759+
} else {
760+
bounds.push(bound);
761+
}
762+
}
763+
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {}
764+
}
765+
744766
if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness
745767
&& !self.tcx().is_const_trait(trait_def_id)
746768
{
@@ -765,58 +787,53 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
765787
suggestion_pre,
766788
suggestion,
767789
});
768-
}
769-
770-
match predicate_filter {
771-
// This is only concerned with trait predicates.
772-
PredicateFilter::SelfTraitThatDefines(..) => {
773-
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
774-
}
775-
PredicateFilter::All
776-
| PredicateFilter::SelfOnly
777-
| PredicateFilter::SelfAndAssociatedTypeBounds => {
778-
debug!(?poly_trait_ref);
779-
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
780-
781-
match constness {
782-
hir::BoundConstness::Always(span) => {
783-
if polarity == ty::PredicatePolarity::Positive {
784-
bounds.push_const_bound(
785-
tcx,
786-
poly_trait_ref,
787-
ty::BoundConstness::Const,
788-
span,
789-
);
790+
} else {
791+
match predicate_filter {
792+
// This is only concerned with trait predicates.
793+
PredicateFilter::SelfTraitThatDefines(..) => {}
794+
PredicateFilter::All
795+
| PredicateFilter::SelfOnly
796+
| PredicateFilter::SelfAndAssociatedTypeBounds => {
797+
match constness {
798+
hir::BoundConstness::Always(span) => {
799+
if polarity == ty::PredicatePolarity::Positive {
800+
bounds.push((
801+
poly_trait_ref
802+
.to_host_effect_clause(tcx, ty::BoundConstness::Const),
803+
span,
804+
));
805+
}
790806
}
807+
hir::BoundConstness::Maybe(_) => {
808+
// We don't emit a const bound here, since that would mean that we
809+
// unconditionally need to prove a `HostEffect` predicate, even when
810+
// the predicates are being instantiated in a non-const context. This
811+
// is instead handled in the `const_conditions` query.
812+
}
813+
hir::BoundConstness::Never => {}
791814
}
792-
hir::BoundConstness::Maybe(_) => {
793-
// We don't emit a const bound here, since that would mean that we
794-
// unconditionally need to prove a `HostEffect` predicate, even when
795-
// the predicates are being instantiated in a non-const context. This
796-
// is instead handled in the `const_conditions` query.
797-
}
798-
hir::BoundConstness::Never => {}
799815
}
800-
}
801-
// On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
802-
// `~const` bounds. All other predicates are handled in their respective queries.
803-
//
804-
// Note that like `PredicateFilter::SelfOnly`, we don't need to do any filtering
805-
// here because we only call this on self bounds, and deal with the recursive case
806-
// in `lower_assoc_item_constraint`.
807-
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => match constness {
808-
hir::BoundConstness::Maybe(span) => {
809-
if polarity == ty::PredicatePolarity::Positive {
810-
bounds.push_const_bound(
811-
tcx,
812-
poly_trait_ref,
813-
ty::BoundConstness::Maybe,
814-
span,
815-
);
816+
// On the flip side, when filtering `ConstIfConst` bounds, we only need to convert
817+
// `~const` bounds. All other predicates are handled in their respective queries.
818+
//
819+
// Note that like `PredicateFilter::SelfOnly`, we don't need to do any filtering
820+
// here because we only call this on self bounds, and deal with the recursive case
821+
// in `lower_assoc_item_constraint`.
822+
PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => {
823+
match constness {
824+
hir::BoundConstness::Maybe(span) => {
825+
if polarity == ty::PredicatePolarity::Positive {
826+
bounds.push((
827+
poly_trait_ref
828+
.to_host_effect_clause(tcx, ty::BoundConstness::Maybe),
829+
span,
830+
));
831+
}
832+
}
833+
hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
816834
}
817835
}
818-
hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {}
819-
},
836+
}
820837
}
821838

822839
let mut dup_constraints = FxIndexMap::default();
@@ -2382,19 +2399,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
23822399
// Impl trait in bindings lower as an infer var with additional
23832400
// set of type bounds.
23842401
let self_ty = self.ty_infer(None, hir_ty.span);
2385-
let mut bounds = Bounds::default();
2402+
let mut bounds = Vec::new();
23862403
self.lower_bounds(
23872404
self_ty,
23882405
hir_bounds.iter(),
23892406
&mut bounds,
23902407
ty::List::empty(),
23912408
PredicateFilter::All,
23922409
);
2393-
self.register_trait_ascription_bounds(
2394-
bounds.clauses().collect(),
2395-
hir_ty.hir_id,
2396-
hir_ty.span,
2397-
);
2410+
self.register_trait_ascription_bounds(bounds, hir_ty.hir_id, hir_ty.span);
23982411
self_ty
23992412
}
24002413
// If we encounter a type relative path with RTN generics, then it must have

‎compiler/rustc_hir_analysis/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ This API is completely unstable and subject to change.
8080
pub mod check;
8181

8282
pub mod autoderef;
83-
mod bounds;
8483
mod check_unused;
8584
mod coherence;
8685
mod collect;

‎compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'tcx> GenericArgs<'tcx> {
495495
self.iter().filter_map(|k| k.as_const())
496496
}
497497

498-
/// Returns generic arguments that are not lifetimes or host effect params.
498+
/// Returns generic arguments that are not lifetimes.
499499
#[inline]
500500
pub fn non_erasable_generics(
501501
&'tcx self,

0 commit comments

Comments
 (0)
Please sign in to comment.