Rollup merge of #131981 - compiler-errors:bound-constness, r=cjgillot
Remove the `BoundConstness::NotConst` variant I find it easier to represent `BoundConstness::NotConst` as just `None` for some refactorings I'm doing.
This commit is contained in:
commit
62b7293a90
7 changed files with 46 additions and 41 deletions
|
@ -51,7 +51,7 @@ impl<'tcx> Bounds<'tcx> {
|
|||
bound_trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
span: Span,
|
||||
polarity: ty::PredicatePolarity,
|
||||
constness: ty::BoundConstness,
|
||||
constness: Option<ty::BoundConstness>,
|
||||
predicate_filter: PredicateFilter,
|
||||
) {
|
||||
let clause = (
|
||||
|
@ -88,19 +88,20 @@ impl<'tcx> Bounds<'tcx> {
|
|||
// associated type of `<T as Tr>` and make sure that the effect is compatible.
|
||||
let compat_val = match (tcx.def_kind(defining_def_id), constness) {
|
||||
// FIXME(effects): revisit the correctness of this
|
||||
(_, ty::BoundConstness::Const) => tcx.consts.false_,
|
||||
(_, Some(ty::BoundConstness::Const)) => tcx.consts.false_,
|
||||
// body owners that can have trait bounds
|
||||
(DefKind::Const | DefKind::Fn | DefKind::AssocFn, ty::BoundConstness::ConstIfConst) => {
|
||||
tcx.expected_host_effect_param_for_body(defining_def_id)
|
||||
}
|
||||
(
|
||||
DefKind::Const | DefKind::Fn | DefKind::AssocFn,
|
||||
Some(ty::BoundConstness::ConstIfConst),
|
||||
) => tcx.expected_host_effect_param_for_body(defining_def_id),
|
||||
|
||||
(_, ty::BoundConstness::NotConst) => {
|
||||
(_, None) => {
|
||||
if !tcx.is_const_trait(bound_trait_ref.def_id()) {
|
||||
return;
|
||||
}
|
||||
tcx.consts.true_
|
||||
}
|
||||
(DefKind::Trait, ty::BoundConstness::ConstIfConst) => {
|
||||
(DefKind::Trait, Some(ty::BoundConstness::ConstIfConst)) => {
|
||||
// we are in a trait, where `bound_trait_ref` could be:
|
||||
// (1) a super trait `trait Foo: ~const Bar`.
|
||||
// - This generates `<Self as Foo>::Effects: TyCompat<<Self as Bar>::Effects>`
|
||||
|
@ -138,7 +139,7 @@ impl<'tcx> Bounds<'tcx> {
|
|||
return;
|
||||
}
|
||||
|
||||
(DefKind::Impl { of_trait: true }, ty::BoundConstness::ConstIfConst) => {
|
||||
(DefKind::Impl { of_trait: true }, Some(ty::BoundConstness::ConstIfConst)) => {
|
||||
// this is a where clause on an impl header.
|
||||
// push `<T as Tr>::Effects` into the set for the `Min` bound.
|
||||
let Some(assoc) = tcx.associated_type_for_effects(bound_trait_ref.def_id()) else {
|
||||
|
@ -172,12 +173,12 @@ impl<'tcx> Bounds<'tcx> {
|
|||
//
|
||||
// FIXME(effects) this is equality for now, which wouldn't be helpful for a non-const implementor
|
||||
// that uses a `Bar` that implements `Trait` with `Maybe` effects.
|
||||
(DefKind::AssocTy, ty::BoundConstness::ConstIfConst) => {
|
||||
(DefKind::AssocTy, Some(ty::BoundConstness::ConstIfConst)) => {
|
||||
// FIXME(effects): implement this
|
||||
return;
|
||||
}
|
||||
// probably illegal in this position.
|
||||
(_, ty::BoundConstness::ConstIfConst) => {
|
||||
(_, Some(ty::BoundConstness::ConstIfConst)) => {
|
||||
tcx.dcx().span_delayed_bug(span, "invalid `~const` encountered");
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -171,16 +171,15 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
hir::GenericBound::Trait(poly_trait_ref) => {
|
||||
let (constness, polarity) = match poly_trait_ref.modifiers {
|
||||
hir::TraitBoundModifier::Const => {
|
||||
(ty::BoundConstness::Const, ty::PredicatePolarity::Positive)
|
||||
}
|
||||
hir::TraitBoundModifier::MaybeConst => {
|
||||
(ty::BoundConstness::ConstIfConst, ty::PredicatePolarity::Positive)
|
||||
}
|
||||
hir::TraitBoundModifier::None => {
|
||||
(ty::BoundConstness::NotConst, ty::PredicatePolarity::Positive)
|
||||
(Some(ty::BoundConstness::Const), ty::PredicatePolarity::Positive)
|
||||
}
|
||||
hir::TraitBoundModifier::MaybeConst => (
|
||||
Some(ty::BoundConstness::ConstIfConst),
|
||||
ty::PredicatePolarity::Positive,
|
||||
),
|
||||
hir::TraitBoundModifier::None => (None, ty::PredicatePolarity::Positive),
|
||||
hir::TraitBoundModifier::Negative => {
|
||||
(ty::BoundConstness::NotConst, ty::PredicatePolarity::Negative)
|
||||
(None, ty::PredicatePolarity::Negative)
|
||||
}
|
||||
hir::TraitBoundModifier::Maybe => continue,
|
||||
};
|
||||
|
|
|
@ -51,7 +51,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
} = self.lower_poly_trait_ref(
|
||||
&trait_bound.trait_ref,
|
||||
trait_bound.span,
|
||||
ty::BoundConstness::NotConst,
|
||||
None,
|
||||
ty::PredicatePolarity::Positive,
|
||||
dummy_self,
|
||||
&mut bounds,
|
||||
|
|
|
@ -652,7 +652,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
&self,
|
||||
trait_ref: &hir::TraitRef<'tcx>,
|
||||
span: Span,
|
||||
constness: ty::BoundConstness,
|
||||
constness: Option<ty::BoundConstness>,
|
||||
polarity: ty::PredicatePolarity,
|
||||
self_ty: Ty<'tcx>,
|
||||
bounds: &mut Bounds<'tcx>,
|
||||
|
@ -675,7 +675,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||
Some(self_ty),
|
||||
);
|
||||
|
||||
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
|
||||
if let Some(constness) = constness
|
||||
&& !self.tcx().is_const_trait(trait_def_id)
|
||||
{
|
||||
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue