Skip to content

Commit 8de9931

Browse files
committed
HIR ty lowering: Simplify signature of lower_poly_trait_ref
1 parent 1bb3352 commit 8de9931

File tree

3 files changed

+17
-26
lines changed

3 files changed

+17
-26
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
480480

481481
match hir_bound {
482482
hir::GenericBound::Trait(poly_trait_ref) => {
483-
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
484483
let _ = self.lower_poly_trait_ref(
485-
&poly_trait_ref.trait_ref,
486-
poly_trait_ref.span,
487-
constness,
488-
polarity,
484+
poly_trait_ref,
489485
param_ty,
490486
bounds,
491487
predicate_filter,

compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ use tracing::{debug, instrument};
1717

1818
use super::HirTyLowerer;
1919
use crate::errors::SelfInTypeAlias;
20-
use crate::hir_ty_lowering::{
21-
GenericArgCountMismatch, GenericArgCountResult, PredicateFilter, RegionInferReason,
22-
};
20+
use crate::hir_ty_lowering::{GenericArgCountMismatch, PredicateFilter, RegionInferReason};
2321

2422
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
2523
/// Lower a trait object type from the HIR to our internal notion of a type.
@@ -37,24 +35,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
3735

3836
let mut user_written_bounds = Vec::new();
3937
let mut potential_assoc_types = Vec::new();
40-
for trait_bound in hir_bounds.iter() {
41-
if let hir::BoundPolarity::Maybe(_) = trait_bound.modifiers.polarity {
38+
for poly_trait_ref in hir_bounds.iter() {
39+
if let hir::BoundPolarity::Maybe(_) = poly_trait_ref.modifiers.polarity {
4240
continue;
4341
}
44-
if let GenericArgCountResult {
45-
correct:
46-
Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }),
47-
..
48-
} = self.lower_poly_trait_ref(
49-
&trait_bound.trait_ref,
50-
trait_bound.span,
51-
hir::BoundConstness::Never,
52-
hir::BoundPolarity::Positive,
42+
let result = self.lower_poly_trait_ref(
43+
poly_trait_ref,
5344
dummy_self,
5445
&mut user_written_bounds,
5546
PredicateFilter::SelfOnly,
56-
) {
57-
potential_assoc_types.extend(cur_potential_assoc_types);
47+
);
48+
if let Err(GenericArgCountMismatch { invalid_args, .. }) = result.correct {
49+
potential_assoc_types.extend(invalid_args);
5850
}
5951
}
6052

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
735735
/// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
736736
/// where `'a` is a bound region at depth 0. Similarly, the `trait_ref` would be `Bar<'a>`.
737737
/// The lowered poly-trait-ref will track this binder explicitly, however.
738-
#[instrument(level = "debug", skip(self, span, constness, bounds))]
738+
#[instrument(level = "debug", skip(self, bounds))]
739739
pub(crate) fn lower_poly_trait_ref(
740740
&self,
741-
trait_ref: &hir::TraitRef<'tcx>,
742-
span: Span,
743-
constness: hir::BoundConstness,
744-
polarity: hir::BoundPolarity,
741+
poly_trait_ref: &hir::PolyTraitRef<'tcx>,
745742
self_ty: Ty<'tcx>,
746743
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
747744
predicate_filter: PredicateFilter,
748745
) -> GenericArgCountResult {
746+
// We use the *resolved* bound vars later instead of the HIR ones since the former
747+
// also include the bound vars of the overarching predicate if applicable.
748+
let hir::PolyTraitRef { bound_generic_params: _, modifiers, ref trait_ref, span } =
749+
*poly_trait_ref;
750+
let hir::TraitBoundModifiers { constness, polarity } = modifiers;
751+
749752
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
750753
let trait_segment = trait_ref.path.segments.last().unwrap();
751754

0 commit comments

Comments
 (0)