summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_trait_selection/src/traits/wf.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /compiler/rustc_trait_selection/src/traits/wf.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits/wf.rs')
-rw-r--r--compiler/rustc_trait_selection/src/traits/wf.rs66
1 files changed, 29 insertions, 37 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs
index b04008d9e..fe5b625e4 100644
--- a/compiler/rustc_trait_selection/src/traits/wf.rs
+++ b/compiler/rustc_trait_selection/src/traits/wf.rs
@@ -105,13 +105,13 @@ pub fn unnormalized_obligations<'tcx>(
/// Returns the obligations that make this trait reference
/// well-formed. For example, if there is a trait `Set` defined like
-/// `trait Set<K:Eq>`, then the trait reference `Foo: Set<Bar>` is WF
+/// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
/// if `Bar: Eq`.
pub fn trait_obligations<'tcx>(
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
- trait_pred: &ty::TraitPredicate<'tcx>,
+ trait_pred: ty::TraitPredicate<'tcx>,
span: Span,
item: &'tcx hir::Item<'tcx>,
) -> Vec<traits::PredicateObligation<'tcx>> {
@@ -129,12 +129,17 @@ pub fn trait_obligations<'tcx>(
wf.normalize(infcx)
}
+/// Returns the requirements for `clause` to be well-formed.
+///
+/// For example, if there is a trait `Set` defined like
+/// `trait Set<K: Eq>`, then the trait bound `Foo: Set<Bar>` is WF
+/// if `Bar: Eq`.
#[instrument(skip(infcx), ret)]
-pub fn predicate_obligations<'tcx>(
+pub fn clause_obligations<'tcx>(
infcx: &InferCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
body_id: LocalDefId,
- predicate: ty::Predicate<'tcx>,
+ clause: ty::Clause<'tcx>,
span: Span,
) -> Vec<traits::PredicateObligation<'tcx>> {
let mut wf = WfPredicates {
@@ -148,45 +153,32 @@ pub fn predicate_obligations<'tcx>(
};
// It's ok to skip the binder here because wf code is prepared for it
- match predicate.kind().skip_binder() {
- ty::PredicateKind::Clause(ty::ClauseKind::Trait(t)) => {
- wf.compute_trait_pred(&t, Elaborate::None);
+ match clause.kind().skip_binder() {
+ ty::ClauseKind::Trait(t) => {
+ wf.compute_trait_pred(t, Elaborate::None);
}
- ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..)) => {}
- ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(
- ty,
- _reg,
- ))) => {
+ ty::ClauseKind::RegionOutlives(..) => {}
+ ty::ClauseKind::TypeOutlives(ty::OutlivesPredicate(ty, _reg)) => {
wf.compute(ty.into());
}
- ty::PredicateKind::Clause(ty::ClauseKind::Projection(t)) => {
+ ty::ClauseKind::Projection(t) => {
wf.compute_projection(t.projection_ty);
wf.compute(match t.term.unpack() {
ty::TermKind::Ty(ty) => ty.into(),
ty::TermKind::Const(c) => c.into(),
})
}
- ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(ct, ty)) => {
+ ty::ClauseKind::ConstArgHasType(ct, ty) => {
wf.compute(ct.into());
wf.compute(ty.into());
}
- ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {
+ ty::ClauseKind::WellFormed(arg) => {
wf.compute(arg);
}
- ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(ct)) => {
+ ty::ClauseKind::ConstEvaluatable(ct) => {
wf.compute(ct.into());
}
-
- ty::PredicateKind::ObjectSafe(_)
- | ty::PredicateKind::ClosureKind(..)
- | ty::PredicateKind::Subtype(..)
- | ty::PredicateKind::Coerce(..)
- | ty::PredicateKind::ConstEquate(..)
- | ty::PredicateKind::Ambiguous
- | ty::PredicateKind::AliasRelate(..) => {
- bug!("We should only wf check where clauses, unexpected predicate: {predicate:?}")
- }
}
wf.normalize(infcx)
@@ -233,7 +225,7 @@ enum Elaborate {
fn extend_cause_with_original_assoc_item_obligation<'tcx>(
tcx: TyCtxt<'tcx>,
- trait_ref: &ty::TraitRef<'tcx>,
+ trait_ref: ty::TraitRef<'tcx>,
item: Option<&hir::Item<'tcx>>,
cause: &mut traits::ObligationCause<'tcx>,
pred: ty::Predicate<'tcx>,
@@ -262,7 +254,8 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
// projection coming from another associated type. See
// `tests/ui/associated-types/point-at-type-on-obligation-failure.rs` and
// `traits-assoc-type-in-supertrait-bad.rs`.
- if let Some(ty::Alias(ty::Projection, projection_ty)) = proj.term.ty().map(|ty| ty.kind())
+ if let Some(ty::Alias(ty::Projection, projection_ty)) =
+ proj.term.ty().map(|ty| ty.kind())
&& let Some(&impl_item_id) =
tcx.impl_item_implementor_ids(impl_def_id).get(&projection_ty.def_id)
&& let Some(impl_item_span) = items
@@ -278,8 +271,7 @@ fn extend_cause_with_original_assoc_item_obligation<'tcx>(
// can be seen in `ui/associated-types/point-at-type-on-obligation-failure-2.rs`.
debug!("extended_cause_with_original_assoc_item_obligation trait proj {:?}", pred);
if let ty::Alias(ty::Projection, ty::AliasTy { def_id, .. }) = *pred.self_ty().kind()
- && let Some(&impl_item_id) =
- tcx.impl_item_implementor_ids(impl_def_id).get(&def_id)
+ && let Some(&impl_item_id) = tcx.impl_item_implementor_ids(impl_def_id).get(&def_id)
&& let Some(impl_item_span) = items
.iter()
.find(|item| item.id.owner_id.to_def_id() == impl_item_id)
@@ -336,9 +328,9 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
}
/// Pushes the obligations required for `trait_ref` to be WF into `self.out`.
- fn compute_trait_pred(&mut self, trait_pred: &ty::TraitPredicate<'tcx>, elaborate: Elaborate) {
+ fn compute_trait_pred(&mut self, trait_pred: ty::TraitPredicate<'tcx>, elaborate: Elaborate) {
let tcx = self.tcx();
- let trait_ref = &trait_pred.trait_ref;
+ let trait_ref = trait_pred.trait_ref;
// Negative trait predicates don't require supertraits to hold, just
// that their args are WF.
@@ -411,7 +403,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
// Compute the obligations that are required for `trait_ref` to be WF,
// given that it is a *negative* trait predicate.
- fn compute_negative_trait_pred(&mut self, trait_ref: &ty::TraitRef<'tcx>) {
+ fn compute_negative_trait_pred(&mut self, trait_ref: ty::TraitRef<'tcx>) {
for arg in trait_ref.args {
self.compute(arg);
}
@@ -608,7 +600,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
| ty::Float(..)
| ty::Error(_)
| ty::Str
- | ty::GeneratorWitness(..)
+ | ty::CoroutineWitness(..)
| ty::Never
| ty::Param(_)
| ty::Bound(..)
@@ -680,14 +672,14 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
}
}
- ty::Generator(did, args, ..) => {
- // Walk ALL the types in the generator: this will
+ ty::Coroutine(did, args, ..) => {
+ // Walk ALL the types in the coroutine: this will
// include the upvar types as well as the yield
// type. Note that this is mildly distinct from
// the closure case, where we have to be careful
// about the signature of the closure. We don't
// have the problem of implied bounds here since
- // generators don't take arguments.
+ // coroutines don't take arguments.
let obligations = self.nominal_obligations(did, args);
self.out.extend(obligations);
}