mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
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:
commit
14c8a68e49
@ -69,9 +69,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
|
|||||||
) {
|
) {
|
||||||
let cause =
|
let cause =
|
||||||
traits::ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc));
|
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(
|
self.ocx.register_obligation(traits::Obligation::new(
|
||||||
cause,
|
cause,
|
||||||
self.param_env,
|
param_env,
|
||||||
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx()),
|
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());
|
assert_eq!(predicates.predicates.len(), predicates.spans.len());
|
||||||
let wf_obligations =
|
let wf_obligations =
|
||||||
iter::zip(&predicates.predicates, &predicates.spans).flat_map(|(&p, &sp)| {
|
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();
|
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
|
||||||
|
29
src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
Normal file
29
src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user