Skip to content

Commit eba3563

Browse files
Inline lower_mono_bounds into lower_poly_bounds
1 parent b922ae0 commit eba3563

File tree

3 files changed

+25
-35
lines changed

3 files changed

+25
-35
lines changed

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

Lines changed: 11 additions & 2 deletions
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_poly_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,14 @@ 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_poly_bounds(
310+
item_ty,
311+
hir_bounds,
312+
&mut bounds,
313+
ty::List::empty(),
314+
filter,
315+
);
307316
// Opaque types are implicitly sized unless a `?Sized` bound is found
308317
icx.lowerer().add_sized_bound(&mut bounds, item_ty, hir_bounds, None, span);
309318
debug!(?bounds);

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 14 additions & 4 deletions
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_poly_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));
@@ -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,14 @@ 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_poly_bounds(
643+
self_param_ty,
644+
superbounds,
645+
&mut bounds,
646+
ty::List::empty(),
647+
filter,
648+
);
639649

640650
let where_bounds_that_match = icx.probe_ty_param_bounds_in_generics(
641651
generics,
@@ -646,7 +656,7 @@ pub(super) fn implied_predicates_with_filter<'tcx>(
646656

647657
// Combine the two lists to form the complete set of superbounds:
648658
let implied_bounds =
649-
&*tcx.arena.alloc_from_iter(superbounds.clauses(tcx).chain(where_bounds_that_match));
659+
&*tcx.arena.alloc_from_iter(bounds.clauses(tcx).chain(where_bounds_that_match));
650660
debug!(?implied_bounds);
651661

652662
// Now require that immediate supertraits are lowered, which will, in

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
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

0 commit comments

Comments
 (0)