Skip to content

Commit 2cded97

Browse files
authored
Rollup merge of #131967 - compiler-errors:lower-mono, r=fmease
Remove `lower_mono_bounds` I'm not convinced about the usefulness of `lower_mono_bounds`, especially since we have *so* many lower-bound-like fns in HIR lowering, so I've just inlined it into its callers.
2 parents 7fbed7b + 10b0796 commit 2cded97

File tree

3 files changed

+20
-42
lines changed

3 files changed

+20
-42
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use tracing::{debug, instrument};
1313

1414
use super::ItemCtxt;
1515
use super::predicates_of::assert_only_contains_predicates_from;
16+
use crate::bounds::Bounds;
1617
use crate::hir_ty_lowering::{HirTyLowerer, PredicateFilter};
1718

1819
/// For associated types we include both bounds written on the type
@@ -36,7 +37,8 @@ fn associated_type_bounds<'tcx>(
3637
);
3738

3839
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
39-
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
40+
let mut bounds = Bounds::default();
41+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
4042
// Associated types are implicitly sized unless a `?Sized` bound is found
4143
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
4244

@@ -303,7 +305,8 @@ fn opaque_type_bounds<'tcx>(
303305
) -> &'tcx [(ty::Clause<'tcx>, Span)] {
304306
ty::print::with_reduced_queries!({
305307
let icx = ItemCtxt::new(tcx, opaque_def_id);
306-
let mut bounds = icx.lowerer().lower_mono_bounds(item_ty, hir_bounds, filter);
308+
let mut bounds = Bounds::default();
309+
icx.lowerer().lower_bounds(item_ty, hir_bounds, &mut bounds, ty::List::empty(), filter);
307310
// Opaque types are implicitly sized unless a `?Sized` bound is found
308311
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
309312
debug!(?bounds);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
181181
// on a trait we must also consider the bounds that follow the trait's name,
182182
// like `trait Foo: A + B + C`.
183183
if let Some(self_bounds) = is_trait {
184-
let bounds = icx.lowerer().lower_mono_bounds(
184+
let mut bounds = Bounds::default();
185+
icx.lowerer().lower_bounds(
185186
tcx.types.self_param,
186187
self_bounds,
188+
&mut bounds,
189+
ty::List::empty(),
187190
PredicateFilter::All,
188191
);
189192
predicates.extend(bounds.clauses(tcx));
@@ -265,9 +268,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
265268
}
266269

267270
let mut bounds = Bounds::default();
268-
icx.lowerer().lower_poly_bounds(
271+
icx.lowerer().lower_bounds(
269272
ty,
270-
bound_pred.bounds.iter(),
273+
bound_pred.bounds,
271274
&mut bounds,
272275
bound_vars,
273276
PredicateFilter::All,
@@ -626,7 +629,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
626629
bug!("trait_def_id {trait_def_id:?} is not an item");
627630
};
628631

629-
let (generics, bounds) = match item.kind {
632+
let (generics, superbounds) = match item.kind {
630633
hir::ItemKind::Trait(.., generics, supertraits, _) => (generics, supertraits),
631634
hir::ItemKind::TraitAlias(generics, supertraits) => (generics, supertraits),
632635
_ => span_bug!(item.span, "super_predicates invoked on non-trait"),
@@ -635,7 +638,8 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
635638
let icx = ItemCtxt::new(tcx, trait_def_id);
636639

637640
let self_param_ty = tcx.types.self_param;
638-
let superbounds = icx.lowerer().lower_mono_bounds(self_param_ty, bounds, filter);
641+
let mut bounds = Bounds::default();
642+
icx.lowerer().lower_bounds(self_param_ty, superbounds, &mut bounds, ty::List::empty(), filter);
639643

640644
let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics(
641645
generics,
@@ -646,7 +650,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
646650

647651
// Combine the two lists to form the complete set of superbounds:
648652
let implied_bounds =
649-
&*tcx.arena.alloc_from_iter(superbounds.clauses(tcx).chain(where_bounds_that_match));
653+
&*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match));
650654
debug!(?implied_bounds);
651655

652656
// Now require that immediate supertraits are lowered, which will, in
@@ -834,9 +838,9 @@ impl<'tcx> ItemCtxt<'tcx> {
834838
};
835839

836840
let bound_vars = self.tcx.late_bound_vars(predicate.hir_id);
837-
self.lowerer().lower_poly_bounds(
841+
self.lowerer().lower_bounds(
838842
bound_ty,
839-
predicate.bounds.iter(),
843+
predicate.bounds,
840844
&mut bounds,
841845
bound_vars,
842846
filter,

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

+3-32
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
142142
/// There is an implied binder around `param_ty` and `hir_bounds`.
143143
/// See `lower_poly_trait_ref` for more details.
144144
#[instrument(level = "debug", skip(self, hir_bounds, bounds))]
145-
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir hir::GenericBound<'tcx>>>(
145+
pub(crate) fn lower_bounds<'hir, I: IntoIterator<Item = &'hir hir::GenericBound<'tcx>>>(
146146
&self,
147147
param_ty: Ty<'tcx>,
148148
hir_bounds: I,
@@ -212,35 +212,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
212212
}
213213
}
214214

215-
/// Lower HIR bounds into `bounds` given the self type `param_ty` and *no* overarching late-bound vars.
216-
///
217-
/// ### Example
218-
///
219-
/// ```ignore (illustrative)
220-
/// fn foo<T: Bar + Baz>() { }
221-
/// // ^ ^^^^^^^^^ hir_bounds
222-
/// // param_ty
223-
/// ```
224-
pub(crate) fn lower_mono_bounds(
225-
&self,
226-
param_ty: Ty<'tcx>,
227-
hir_bounds: &[hir::GenericBound<'tcx>],
228-
predicate_filter: PredicateFilter,
229-
) -> Bounds<'tcx> {
230-
let mut bounds = Bounds::default();
231-
232-
self.lower_poly_bounds(
233-
param_ty,
234-
hir_bounds.iter(),
235-
&mut bounds,
236-
ty::List::empty(),
237-
predicate_filter,
238-
);
239-
debug!(?bounds);
240-
241-
bounds
242-
}
243-
244215
/// Lower an associated item constraint from the HIR into `bounds`.
245216
///
246217
/// ### A Note on Binders
@@ -444,9 +415,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
444415
// parameter to have a skipped binder.
445416
let param_ty =
446417
Ty::new_alias(tcx, ty::Projection, projection_ty.skip_binder());
447-
self.lower_poly_bounds(
418+
self.lower_bounds(
448419
param_ty,
449-
hir_bounds.iter(),
420+
hir_bounds,
450421
bounds,
451422
projection_ty.bound_vars(),
452423
predicate_filter,

0 commit comments

Comments
 (0)