Rollup merge of #100336 - fee1-dead-contrib:fix-wf-const-trait, r=oli-obk

Fix two const_trait_impl issues

r? ``@oli-obk``

Fixes #100222.
Fixes #100543.
This commit is contained in:
Dylan DPC 2022-08-22 20:34:13 +05:30 committed by GitHub
commit 14c8a68e49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 2 deletions

View File

@ -69,9 +69,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
) {
let cause =
traits::ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc));
// for a type to be WF, we do not need to check if const trait predicates satisfy.
let param_env = self.param_env.without_const();
self.ocx.register_obligation(traits::Obligation::new(
cause,
self.param_env,
param_env,
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx()),
));
}
@ -1449,7 +1451,13 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
assert_eq!(predicates.predicates.len(), predicates.spans.len());
let wf_obligations =
iter::zip(&predicates.predicates, &predicates.spans).flat_map(|(&p, &sp)| {
traits::wf::predicate_obligations(infcx, wfcx.param_env, wfcx.body_id, p, sp)
traits::wf::predicate_obligations(
infcx,
wfcx.param_env.without_const(),
wfcx.body_id,
p,
sp,
)
});
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();

View File

@ -0,0 +1,29 @@
// revisions: nn ny yn yy
// check-pass
#![feature(const_trait_impl, associated_type_defaults, const_mut_refs)]
#[cfg_attr(any(yn, yy), const_trait)]
pub trait Index {
type Output;
}
#[cfg_attr(any(ny, yy), const_trait)]
pub trait IndexMut where Self: Index {
const C: <Self as Index>::Output;
type Assoc = <Self as Index>::Output;
fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output;
}
impl Index for () { type Output = (); }
impl const IndexMut for <() as Index>::Output {
const C: <Self as Index>::Output = ();
type Assoc = <Self as Index>::Output;
fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output
where <Self as Index>::Output:,
{}
}
const C: <() as Index>::Output = ();
fn main() {}