TypeWellFormedInEnv

This commit is contained in:
Michael Goulet 2023-06-22 17:43:19 +00:00
parent fbdef58414
commit 374173cd99
26 changed files with 75 additions and 74 deletions

View File

@ -965,7 +965,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
ty::ClauseKind::RegionOutlives(_)
| ty::ClauseKind::ConstArgHasType(..)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => {
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => {
bug!()
}
}

View File

@ -554,6 +554,6 @@ fn trait_predicate_kind<'tcx>(
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => None,
}
}

View File

@ -53,7 +53,8 @@ impl<'tcx> ExplicitPredicatesMap<'tcx> {
| ty::ClauseKind::Projection(_)
| ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => {}
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => {}
}
}

View File

@ -683,7 +683,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// inference variable.
| ty::PredicateKind::ClosureKind(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => None,
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => None,
},
)
}

View File

@ -847,7 +847,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
| ty::ClauseKind::Projection(_)
| ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => None,
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => None,
}
});

View File

@ -31,7 +31,8 @@ pub fn explicit_outlives_bounds<'tcx>(
| ty::ClauseKind::Projection(_)
| ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => None,
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => None,
})
}

View File

@ -368,7 +368,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
.map(|predicate| elaboratable.child(predicate)),
);
}
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
// Nothing to elaborate
}
ty::PredicateKind::Ambiguous => {}

View File

@ -1610,7 +1610,8 @@ impl<'tcx> LateLintPass<'tcx> for TrivialConstraints {
// Ignore bounds that a user can't type
| ClauseKind::WellFormed(..)
// FIXME(generic_const_exprs): `ConstEvaluatable` can be written
| ClauseKind::ConstEvaluatable(..) => continue,
| ClauseKind::ConstEvaluatable(..)
| ClauseKind::TypeWellFormedFromEnv(_) => continue,
};
if predicate.is_global() {
cx.emit_spanned_lint(

View File

@ -287,7 +287,7 @@ impl FlagComputation {
self.add_const(expected);
self.add_const(found);
}
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(ty)) => {
self.add_ty(ty);
}
ty::PredicateKind::Ambiguous => {}

View File

@ -555,7 +555,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(_))
| PredicateKind::ConstEquate(_, _)
| PredicateKind::Ambiguous
| PredicateKind::TypeWellFormedFromEnv(_) => true,
| PredicateKind::Clause(ClauseKind::TypeWellFormedFromEnv(_)) => true,
}
}
}
@ -661,6 +661,11 @@ pub enum ClauseKind<'tcx> {
/// Constant initializer must evaluate successfully.
ConstEvaluatable(ty::Const<'tcx>),
/// Represents a type found in the environment that we can use for implied bounds.
///
/// Only used for Chalk.
TypeWellFormedFromEnv(Ty<'tcx>),
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable)]
@ -697,11 +702,6 @@ pub enum PredicateKind<'tcx> {
/// Constants must be equal. The first component is the const that is expected.
ConstEquate(Const<'tcx>, Const<'tcx>),
/// Represents a type found in the environment that we can use for implied bounds.
///
/// Only used for Chalk.
TypeWellFormedFromEnv(Ty<'tcx>),
/// A marker predicate that is always ambiguous.
/// Used for coherence to mark opaque types as possibly equal to each other but ambiguous.
Ambiguous,
@ -1425,7 +1425,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
| PredicateKind::ConstEquate(..)
| PredicateKind::Ambiguous
| PredicateKind::TypeWellFormedFromEnv(..) => None,
| PredicateKind::Clause(ClauseKind::TypeWellFormedFromEnv(..)) => None,
}
}
@ -1446,7 +1446,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
| PredicateKind::ConstEquate(..)
| PredicateKind::Ambiguous
| PredicateKind::TypeWellFormedFromEnv(..) => None,
| PredicateKind::Clause(ClauseKind::TypeWellFormedFromEnv(..)) => None,
}
}
@ -1467,7 +1467,7 @@ impl<'tcx> Predicate<'tcx> {
| PredicateKind::Clause(ClauseKind::ConstEvaluatable(..))
| PredicateKind::ConstEquate(..)
| PredicateKind::Ambiguous
| PredicateKind::TypeWellFormedFromEnv(..) => None,
| PredicateKind::Clause(ClauseKind::TypeWellFormedFromEnv(..)) => None,
}
}
@ -1483,7 +1483,7 @@ impl<'tcx> Predicate<'tcx> {
pub fn expect_clause(self) -> Clause<'tcx> {
match self.kind().skip_binder() {
PredicateKind::Clause(..) => Clause(self.0),
_ => bug!(),
_ => bug!("{self} is not a clause"),
}
}
}

View File

@ -2883,6 +2883,9 @@ define_print_and_forward_display! {
ty::ClauseKind::ConstEvaluatable(ct) => {
p!("the constant `", print(ct), "` can be evaluated")
}
ty::ClauseKind::TypeWellFormedFromEnv(ty) => {
p!("the type `", print(ty), "` is found in the environment")
}
}
}
@ -2904,9 +2907,6 @@ define_print_and_forward_display! {
ty::PredicateKind::ConstEquate(c1, c2) => {
p!("the constant `", print(c1), "` equals `", print(c2), "`")
}
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
p!("the type `", print(ty), "` is found in the environment")
}
ty::PredicateKind::Ambiguous => p!("ambiguous"),
ty::PredicateKind::AliasRelate(t1, t2, dir) => p!(print(t1), write(" {} ", dir), print(t2)),
}

View File

@ -189,6 +189,9 @@ impl<'tcx> fmt::Debug for ty::ClauseKind<'tcx> {
ty::ClauseKind::ConstEvaluatable(ct) => {
write!(f, "ConstEvaluatable({ct:?})")
}
ty::ClauseKind::TypeWellFormedFromEnv(ty) => {
write!(f, "TypeWellFormedFromEnv({:?})", ty)
}
}
}
}
@ -206,9 +209,6 @@ impl<'tcx> fmt::Debug for ty::PredicateKind<'tcx> {
write!(f, "ClosureKind({:?}, {:?}, {:?})", closure_def_id, closure_substs, kind)
}
ty::PredicateKind::ConstEquate(c1, c2) => write!(f, "ConstEquate({:?}, {:?})", c1, c2),
ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
write!(f, "TypeWellFormedFromEnv({:?})", ty)
}
ty::PredicateKind::Ambiguous => write!(f, "Ambiguous"),
ty::PredicateKind::AliasRelate(t1, t2, dir) => {
write!(f, "AliasRelate({t1:?}, {dir:?}, {t2:?})")

View File

@ -182,6 +182,7 @@ where
}
ty::ClauseKind::ConstEvaluatable(ct) => ct.visit_with(self),
ty::ClauseKind::WellFormed(arg) => arg.visit_with(self),
ty::ClauseKind::TypeWellFormedFromEnv(_) => bug!("unexpected clause: {clause}"),
}
}

View File

@ -395,7 +395,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
ty::PredicateKind::ConstEquate(_, _) => {
bug!("ConstEquate should not be emitted when `-Ztrait-solver=next` is active")
}
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
ty::PredicateKind::AliasRelate(lhs, rhs, direction) => self

View File

@ -132,8 +132,7 @@ impl<'tcx> TraitEngine<'tcx> for FulfillmentCtxt<'tcx> {
SelectionError::Unimplemented,
)
}
ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(_) => {
ty::PredicateKind::ConstEquate(..) => {
bug!("unexpected goal: {goal:?}")
}
},

View File

@ -836,7 +836,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
// FIXME(generic_const_exprs): you can absolutely add this as a where clauses
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::Coerce(..) => {}
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("predicate should only exist in the environment: {bound_predicate:?}")
}
ty::PredicateKind::Ambiguous => return false,

View File

@ -1094,10 +1094,12 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ty::PredicateKind::Ambiguous => span_bug!(span, "ambiguous"),
ty::PredicateKind::TypeWellFormedFromEnv(..) => span_bug!(
span,
"TypeWellFormedFromEnv predicate should only exist in the environment"
),
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
span_bug!(
span,
"TypeWellFormedFromEnv predicate should only exist in the environment"
)
}
ty::PredicateKind::AliasRelate(..) => span_bug!(
span,

View File

@ -366,7 +366,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
ProcessResult::Changed(mk_pending(vec![obligation.with(infcx.tcx, pred)]))
}
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
ty::PredicateKind::AliasRelate(..) => {
@ -634,7 +634,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
}
}
ty::PredicateKind::Ambiguous => ProcessResult::Unchanged,
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("TypeWellFormedFromEnv is only used for Chalk")
}
ty::PredicateKind::AliasRelate(..) => {

View File

@ -310,7 +310,8 @@ fn predicate_references_self<'tcx>(
| ty::ClauseKind::TypeOutlives(..)
| ty::ClauseKind::RegionOutlives(..)
// FIXME(generic_const_exprs): this can mention `Self`
| ty::ClauseKind::ConstEvaluatable(..) => None,
| ty::ClauseKind::ConstEvaluatable(..)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => None,
}
}
@ -350,7 +351,8 @@ fn generics_require_sized_self(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
| ty::ClauseKind::Projection(_)
| ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => false,
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => false,
})
}

View File

@ -134,7 +134,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {}
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {}
// We need to search through *all* WellFormed predicates
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(arg)) => {

View File

@ -967,7 +967,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
}
ty::PredicateKind::TypeWellFormedFromEnv(..) => {
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("TypeWellFormedFromEnv is only used for chalk")
}
ty::PredicateKind::AliasRelate(..) => {

View File

@ -185,7 +185,7 @@ pub fn predicate_obligations<'tcx>(
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::AliasRelate(..)
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("We should only wf check where clauses, unexpected predicate: {predicate:?}")
}
}
@ -1005,7 +1005,8 @@ pub(crate) fn required_region_bounds<'tcx>(
| ty::ClauseKind::Projection(_)
| ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) => None,
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::TypeWellFormedFromEnv(_) => None,
}
})
.collect()

View File

@ -93,10 +93,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, predicate.kind());
let consequence = match predicate {
// TODO: FIXME
/*ty::PredicateKind::TypeWellFormedFromEnv(ty) => {
ty::ClauseKind::TypeWellFormedFromEnv(ty) => {
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner)))
}*/
}
ty::ClauseKind::Trait(predicate) => chalk_ir::DomainGoal::FromEnv(
chalk_ir::FromEnv::Trait(predicate.trait_ref.lower_into(interner)),
),
@ -223,9 +222,11 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
| ty::PredicateKind::ConstEquate(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
ty::PredicateKind::TypeWellFormedFromEnv(ty) => chalk_ir::GoalData::DomainGoal(
chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(ty.lower_into(interner))),
),
ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(ty)) => {
chalk_ir::GoalData::DomainGoal(chalk_ir::DomainGoal::FromEnv(
chalk_ir::FromEnv::Ty(ty.lower_into(interner)),
))
}
};
chalk_ir::GoalData::Quantified(
@ -670,7 +671,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_ir::QuantifiedWhereClause<RustInterner<'
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("unexpected predicate {self}")
}
};
@ -806,7 +807,7 @@ impl<'tcx> LowerInto<'tcx, Option<chalk_solve::rust_ir::QuantifiedInlineBound<Ru
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => {
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => {
bug!("unexpected predicate {}", &self)
}
}

View File

@ -70,6 +70,6 @@ fn not_outlives_predicate(p: ty::Predicate<'_>) -> bool {
| ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
| ty::PredicateKind::ConstEquate(..)
| ty::PredicateKind::Ambiguous
| ty::PredicateKind::TypeWellFormedFromEnv(..) => true,
| ty::PredicateKind::Clause(ty::ClauseKind::TypeWellFormedFromEnv(..)) => true,
}
}

View File

@ -427,21 +427,18 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<ty::Cla
NodeKind::Other => (),
}
let input_clauses = inputs.into_iter().filter_map(|_arg| {
// TODO: FIXME
/*match arg.unpack() {
GenericArgKind::Type(ty) => {
let binder = Binder::dummy(PredicateKind::TypeWellFormedFromEnv(ty));
Some(tcx.mk_predicate(binder))
let input_clauses = inputs.into_iter().filter_map(|arg| {
match arg.unpack() {
ty::GenericArgKind::Type(ty) => {
Some(ty::ClauseKind::TypeWellFormedFromEnv(ty).to_predicate(tcx))
}
// FIXME(eddyb) no WF conditions from lifetimes?
GenericArgKind::Lifetime(_) => None,
ty::GenericArgKind::Lifetime(_) => None,
// FIXME(eddyb) support const generics in Chalk
GenericArgKind::Const(_) => None,
}*/
None
ty::GenericArgKind::Const(_) => None,
}
});
tcx.mk_clauses_from_iter(clauses.chain(input_clauses))

View File

@ -1,21 +1,14 @@
error[E0277]: the trait bound `S: Bar` is not satisfied
--> $DIR/recursive_where_clause_on_type.rs:14:14
error: the type `S` is not well-formed
--> $DIR/recursive_where_clause_on_type.rs:28:11
|
LL | impl Foo for S {
| ^ the trait `Bar` is not implemented for `S`
|
note: required by a bound in `Foo`
--> $DIR/recursive_where_clause_on_type.rs:10:12
|
LL | trait Foo: Bar { }
| ^^^ required by this bound in `Foo`
LL | foo::<S>()
| ^
error: the type `S` is not well-formed
--> $DIR/recursive_where_clause_on_type.rs:14:14
--> $DIR/recursive_where_clause_on_type.rs:28:5
|
LL | impl Foo for S {
| ^
LL | foo::<S>()
| ^^^^^^^^
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0277`.