Remove constness from TraitPredicate
This commit is contained in:
parent
7637653b9f
commit
4fec845c3f
90 changed files with 446 additions and 390 deletions
|
@ -713,7 +713,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
);
|
||||
|
||||
debug!(?poly_trait_ref, ?assoc_bindings);
|
||||
bounds.push_trait_bound(tcx, poly_trait_ref, span, constness, polarity);
|
||||
bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity);
|
||||
|
||||
let mut dup_bindings = FxHashMap::default();
|
||||
for binding in &assoc_bindings {
|
||||
|
|
|
@ -62,11 +62,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
match bound_pred.skip_binder() {
|
||||
ty::ClauseKind::Trait(trait_pred) => {
|
||||
assert_eq!(trait_pred.polarity, ty::ImplPolarity::Positive);
|
||||
trait_bounds.push((
|
||||
bound_pred.rebind(trait_pred.trait_ref),
|
||||
span,
|
||||
trait_pred.constness,
|
||||
));
|
||||
trait_bounds.push((bound_pred.rebind(trait_pred.trait_ref), span));
|
||||
}
|
||||
ty::ClauseKind::Projection(proj) => {
|
||||
projection_bounds.push((bound_pred.rebind(proj), span));
|
||||
|
@ -86,7 +82,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
// Expand trait aliases recursively and check that only one regular (non-auto) trait
|
||||
// is used and no 'maybe' bounds are used.
|
||||
let expanded_traits =
|
||||
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b, _)| (a, b)));
|
||||
traits::expand_trait_aliases(tcx, trait_bounds.iter().map(|&(a, b)| (a, b)));
|
||||
|
||||
let (mut auto_traits, regular_traits): (Vec<_>, Vec<_>) = expanded_traits
|
||||
.filter(|i| i.trait_ref().self_ty().skip_binder() == dummy_self)
|
||||
|
@ -126,7 +122,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
if regular_traits.is_empty() && auto_traits.is_empty() {
|
||||
let trait_alias_span = trait_bounds
|
||||
.iter()
|
||||
.map(|&(trait_ref, _, _)| trait_ref.def_id())
|
||||
.map(|&(trait_ref, _)| trait_ref.def_id())
|
||||
.find(|&trait_ref| tcx.is_trait_alias(trait_ref))
|
||||
.map(|trait_ref| tcx.def_span(trait_ref));
|
||||
let reported =
|
||||
|
@ -157,10 +153,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
|
||||
let regular_traits_refs_spans = trait_bounds
|
||||
.into_iter()
|
||||
.filter(|(trait_ref, _, _)| !tcx.trait_is_auto(trait_ref.def_id()));
|
||||
.filter(|(trait_ref, _)| !tcx.trait_is_auto(trait_ref.def_id()));
|
||||
|
||||
for (base_trait_ref, span, constness) in regular_traits_refs_spans {
|
||||
assert_eq!(constness, ty::BoundConstness::NotConst);
|
||||
for (base_trait_ref, span) in regular_traits_refs_spans {
|
||||
let base_pred: ty::Predicate<'tcx> = base_trait_ref.to_predicate(tcx);
|
||||
for pred in traits::elaborate(tcx, [base_pred]) {
|
||||
debug!("conv_object_ty_poly_trait_ref: observing object predicate `{:?}`", pred);
|
||||
|
|
|
@ -42,13 +42,12 @@ impl<'tcx> Bounds<'tcx> {
|
|||
tcx: TyCtxt<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
span: Span,
|
||||
constness: ty::BoundConstness,
|
||||
polarity: ty::ImplPolarity,
|
||||
) {
|
||||
self.clauses.push((
|
||||
trait_ref
|
||||
.map_bound(|trait_ref| {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, polarity })
|
||||
})
|
||||
.to_predicate(tcx),
|
||||
span,
|
||||
|
|
|
@ -194,7 +194,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
|||
// We match on both `ty::ImplPolarity` and `ast::ImplPolarity` just to get the `!` span.
|
||||
match (tcx.impl_polarity(def_id), impl_.polarity) {
|
||||
(ty::ImplPolarity::Positive, _) => {
|
||||
check_impl(tcx, item, impl_.self_ty, &impl_.of_trait, impl_.constness);
|
||||
check_impl(tcx, item, impl_.self_ty, &impl_.of_trait);
|
||||
}
|
||||
(ty::ImplPolarity::Negative, ast::ImplPolarity::Negative(span)) => {
|
||||
// FIXME(#27579): what amount of WF checking do we need for neg impls?
|
||||
|
@ -1191,7 +1191,6 @@ fn check_impl<'tcx>(
|
|||
item: &'tcx hir::Item<'tcx>,
|
||||
ast_self_ty: &hir::Ty<'_>,
|
||||
ast_trait_ref: &Option<hir::TraitRef<'_>>,
|
||||
constness: hir::Constness,
|
||||
) {
|
||||
enter_wf_checking_ctxt(tcx, item.span, item.owner_id.def_id, |wfcx| {
|
||||
match ast_trait_ref {
|
||||
|
@ -1205,14 +1204,8 @@ fn check_impl<'tcx>(
|
|||
Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)),
|
||||
trait_ref,
|
||||
);
|
||||
let trait_pred = ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: match constness {
|
||||
hir::Constness::Const => ty::BoundConstness::ConstIfConst,
|
||||
hir::Constness::NotConst => ty::BoundConstness::NotConst,
|
||||
},
|
||||
polarity: ty::ImplPolarity::Positive,
|
||||
};
|
||||
let trait_pred =
|
||||
ty::TraitPredicate { trait_ref, polarity: ty::ImplPolarity::Positive };
|
||||
let mut obligations = traits::wf::trait_obligations(
|
||||
wfcx.infcx,
|
||||
wfcx.param_env,
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
|||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericPredicates, Generics, ImplTraitInTraitData, ToPredicate};
|
||||
use rustc_span::symbol::{sym, Ident};
|
||||
use rustc_span::symbol::Ident;
|
||||
use rustc_span::{Span, Symbol, DUMMY_SP};
|
||||
|
||||
/// Returns a list of all type predicates (explicit and implicit) for the definition with
|
||||
|
@ -37,17 +37,10 @@ pub(super) fn predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericPredic
|
|||
// from the trait itself that *shouldn't* be shown as the source of
|
||||
// an obligation and instead be skipped. Otherwise we'd use
|
||||
// `tcx.def_span(def_id);`
|
||||
|
||||
let constness = if tcx.has_attr(def_id, sym::const_trait) {
|
||||
ty::BoundConstness::ConstIfConst
|
||||
} else {
|
||||
ty::BoundConstness::NotConst
|
||||
};
|
||||
|
||||
let span = rustc_span::DUMMY_SP;
|
||||
result.predicates =
|
||||
tcx.arena.alloc_from_iter(result.predicates.iter().copied().chain(std::iter::once((
|
||||
ty::TraitRef::identity(tcx, def_id).with_constness(constness).to_predicate(tcx),
|
||||
ty::TraitRef::identity(tcx, def_id).to_predicate(tcx),
|
||||
span,
|
||||
))));
|
||||
}
|
||||
|
@ -204,7 +197,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
|
|||
// (see below). Recall that a default impl is not itself an impl, but rather a
|
||||
// set of defaults that can be incorporated into another impl.
|
||||
if let Some(trait_ref) = is_default_impl_trait {
|
||||
predicates.insert((trait_ref.without_const().to_predicate(tcx), tcx.def_span(def_id)));
|
||||
predicates.insert((trait_ref.to_predicate(tcx), tcx.def_span(def_id)));
|
||||
}
|
||||
|
||||
// Collect the region predicates that were declared inline as
|
||||
|
@ -777,8 +770,7 @@ pub(super) fn type_param_predicates(
|
|||
if param_id == item_hir_id {
|
||||
let identity_trait_ref =
|
||||
ty::TraitRef::identity(tcx, item_def_id.to_def_id());
|
||||
extend =
|
||||
Some((identity_trait_ref.without_const().to_predicate(tcx), item.span));
|
||||
extend = Some((identity_trait_ref.to_predicate(tcx), item.span));
|
||||
}
|
||||
generics
|
||||
}
|
||||
|
|
|
@ -431,45 +431,13 @@ fn check_predicates<'tcx>(
|
|||
///
|
||||
/// So we make that check in this function and try to raise a helpful error message.
|
||||
fn trait_predicates_eq<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
_tcx: TyCtxt<'tcx>,
|
||||
predicate1: ty::Predicate<'tcx>,
|
||||
predicate2: ty::Predicate<'tcx>,
|
||||
span: Span,
|
||||
_span: Span,
|
||||
) -> bool {
|
||||
let pred1_kind = predicate1.kind().skip_binder();
|
||||
let pred2_kind = predicate2.kind().skip_binder();
|
||||
let (trait_pred1, trait_pred2) = match (pred1_kind, pred2_kind) {
|
||||
(
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred1)),
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred2)),
|
||||
) => (pred1, pred2),
|
||||
// Just use plain syntactic equivalence if either of the predicates aren't
|
||||
// trait predicates or have bound vars.
|
||||
_ => return predicate1 == predicate2,
|
||||
};
|
||||
|
||||
let predicates_equal_modulo_constness = {
|
||||
let pred1_unconsted =
|
||||
ty::TraitPredicate { constness: ty::BoundConstness::NotConst, ..trait_pred1 };
|
||||
let pred2_unconsted =
|
||||
ty::TraitPredicate { constness: ty::BoundConstness::NotConst, ..trait_pred2 };
|
||||
pred1_unconsted == pred2_unconsted
|
||||
};
|
||||
|
||||
if !predicates_equal_modulo_constness {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check that the predicate on the specializing impl is at least as const as
|
||||
// the one on the base.
|
||||
match (trait_pred2.constness, trait_pred1.constness) {
|
||||
(ty::BoundConstness::ConstIfConst, ty::BoundConstness::NotConst) => {
|
||||
tcx.sess.emit_err(errors::MissingTildeConst { span });
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
true
|
||||
// FIXME(effects)
|
||||
predicate1 == predicate2
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", skip(tcx))]
|
||||
|
@ -482,7 +450,6 @@ fn check_specialization_on<'tcx>(tcx: TyCtxt<'tcx>, predicate: ty::Predicate<'tc
|
|||
// items.
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
})) => {
|
||||
if !matches!(
|
||||
|
@ -536,7 +503,6 @@ fn trait_predicate_kind<'tcx>(
|
|||
match predicate.kind().skip_binder() {
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
|
||||
trait_ref,
|
||||
constness: _,
|
||||
polarity: _,
|
||||
})) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind),
|
||||
ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(_))
|
||||
|
|
|
@ -156,7 +156,6 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
|
|||
match pred.kind().skip_binder() {
|
||||
ty::ClauseKind::Trait(ty::TraitPredicate {
|
||||
trait_ref: ty::TraitRef { def_id: _, args, .. },
|
||||
constness: _,
|
||||
polarity: _,
|
||||
}) => {
|
||||
for subst in &args[1..] {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue