HIR ty lowering: Simplify signature of lower_poly_trait_ref

This commit is contained in:
León Orell Valerian Liehr 2025-06-18 15:35:22 +02:00
parent 9cd918bcbb
commit 2ce0b665d3
No known key found for this signature in database
GPG key ID: D17A07215F68E713
5 changed files with 54 additions and 32 deletions

View file

@ -482,12 +482,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
match hir_bound {
hir::GenericBound::Trait(poly_trait_ref) => {
let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers;
let _ = self.lower_poly_trait_ref(
&poly_trait_ref.trait_ref,
poly_trait_ref.span,
constness,
polarity,
poly_trait_ref,
param_ty,
bounds,
predicate_filter,

View file

@ -18,9 +18,7 @@ use tracing::{debug, instrument};
use super::HirTyLowerer;
use crate::errors::SelfInTypeAlias;
use crate::hir_ty_lowering::{
GenericArgCountMismatch, GenericArgCountResult, PredicateFilter, RegionInferReason,
};
use crate::hir_ty_lowering::{GenericArgCountMismatch, PredicateFilter, RegionInferReason};
impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// Lower a trait object type from the HIR to our internal notion of a type.
@ -38,24 +36,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let mut user_written_bounds = Vec::new();
let mut potential_assoc_types = Vec::new();
for trait_bound in hir_bounds.iter() {
if let hir::BoundPolarity::Maybe(_) = trait_bound.modifiers.polarity {
for poly_trait_ref in hir_bounds.iter() {
if let hir::BoundPolarity::Maybe(_) = poly_trait_ref.modifiers.polarity {
continue;
}
if let GenericArgCountResult {
correct:
Err(GenericArgCountMismatch { invalid_args: cur_potential_assoc_types, .. }),
..
} = self.lower_poly_trait_ref(
&trait_bound.trait_ref,
trait_bound.span,
trait_bound.modifiers.constness,
hir::BoundPolarity::Positive,
let result = self.lower_poly_trait_ref(
poly_trait_ref,
dummy_self,
&mut user_written_bounds,
PredicateFilter::SelfOnly,
) {
potential_assoc_types.extend(cur_potential_assoc_types);
);
if let Err(GenericArgCountMismatch { invalid_args, .. }) = result.correct {
potential_assoc_types.extend(invalid_args);
}
}

View file

@ -747,17 +747,20 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
/// If for example you had `for<'a> Foo<'a>: Bar<'a>`, then the `self_ty` would be `Foo<'a>`
/// where `'a` is a bound region at depth 0. Similarly, the `trait_ref` would be `Bar<'a>`.
/// The lowered poly-trait-ref will track this binder explicitly, however.
#[instrument(level = "debug", skip(self, span, constness, bounds))]
#[instrument(level = "debug", skip(self, bounds))]
pub(crate) fn lower_poly_trait_ref(
&self,
trait_ref: &hir::TraitRef<'tcx>,
span: Span,
constness: hir::BoundConstness,
polarity: hir::BoundPolarity,
poly_trait_ref: &hir::PolyTraitRef<'tcx>,
self_ty: Ty<'tcx>,
bounds: &mut Vec<(ty::Clause<'tcx>, Span)>,
predicate_filter: PredicateFilter,
) -> GenericArgCountResult {
// We use the *resolved* bound vars later instead of the HIR ones since the former
// also include the bound vars of the overarching predicate if applicable.
let hir::PolyTraitRef { bound_generic_params: _, modifiers, ref trait_ref, span } =
*poly_trait_ref;
let hir::TraitBoundModifiers { constness, polarity } = modifiers;
let trait_def_id = trait_ref.trait_def_id().unwrap_or_else(|| FatalError.raise());
let trait_segment = trait_ref.path.segments.last().unwrap();

View file

@ -2,9 +2,12 @@
const fn maybe_const_maybe<T: [const] ?Sized>() {}
//~^ ERROR `[const]` trait not allowed with `?` trait polarity modifier
//~| ERROR `[const]` can only be applied to `const` traits
//~| ERROR `[const]` can only be applied to `const` traits
fn const_maybe<T: const ?Sized>() {}
//~^ ERROR `const` trait not allowed with `?` trait polarity modifier
//~| ERROR `const` can only be applied to `const` traits
const fn maybe_const_negative<T: [const] !Trait>() {}
//~^ ERROR `[const]` trait not allowed with `!` trait polarity modifier

View file

@ -7,7 +7,7 @@ LL | const fn maybe_const_maybe<T: [const] ?Sized>() {}
| there is not a well-defined meaning for a `[const] ?` trait
error: `const` trait not allowed with `?` trait polarity modifier
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:6:25
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:8:25
|
LL | fn const_maybe<T: const ?Sized>() {}
| ----- ^
@ -15,7 +15,7 @@ LL | fn const_maybe<T: const ?Sized>() {}
| there is not a well-defined meaning for a `const ?` trait
error: `[const]` trait not allowed with `!` trait polarity modifier
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:42
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:12:42
|
LL | const fn maybe_const_negative<T: [const] !Trait>() {}
| ------- ^
@ -23,7 +23,7 @@ LL | const fn maybe_const_negative<T: [const] !Trait>() {}
| there is not a well-defined meaning for a `[const] !` trait
error: `const` trait not allowed with `!` trait polarity modifier
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:28
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:16:28
|
LL | fn const_negative<T: const !Trait>() {}
| ----- ^
@ -31,16 +31,44 @@ LL | fn const_negative<T: const !Trait>() {}
| there is not a well-defined meaning for a `const !` trait
error: negative bounds are not supported
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:9:42
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:12:42
|
LL | const fn maybe_const_negative<T: [const] !Trait>() {}
| ^
error: negative bounds are not supported
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:13:28
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:16:28
|
LL | fn const_negative<T: const !Trait>() {}
| ^
error: aborting due to 6 previous errors
error: `[const]` can only be applied to `const` traits
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:3:31
|
LL | const fn maybe_const_maybe<T: [const] ?Sized>() {}
| ^^^^^^^ can't be applied to `Sized`
|
note: `Sized` can't be used with `[const]` because it isn't `const`
--> $SRC_DIR/core/src/marker.rs:LL:COL
error: `[const]` can only be applied to `const` traits
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:3:31
|
LL | const fn maybe_const_maybe<T: [const] ?Sized>() {}
| ^^^^^^^ can't be applied to `Sized`
|
note: `Sized` can't be used with `[const]` because it isn't `const`
--> $SRC_DIR/core/src/marker.rs:LL:COL
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: `const` can only be applied to `const` traits
--> $DIR/mutually-exclusive-trait-bound-modifiers.rs:8:19
|
LL | fn const_maybe<T: const ?Sized>() {}
| ^^^^^ can't be applied to `Sized`
|
note: `Sized` can't be used with `const` because it isn't `const`
--> $SRC_DIR/core/src/marker.rs:LL:COL
error: aborting due to 9 previous errors