Skip to content

Commit 14c8a68

Browse files
authored
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.
2 parents 382ba73 + f1db3be commit 14c8a68

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
6969
) {
7070
let cause =
7171
traits::ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc));
72+
// for a type to be WF, we do not need to check if const trait predicates satisfy.
73+
let param_env = self.param_env.without_const();
7274
self.ocx.register_obligation(traits::Obligation::new(
7375
cause,
74-
self.param_env,
76+
param_env,
7577
ty::Binder::dummy(ty::PredicateKind::WellFormed(arg)).to_predicate(self.tcx()),
7678
));
7779
}
@@ -1449,7 +1451,13 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14491451
assert_eq!(predicates.predicates.len(), predicates.spans.len());
14501452
let wf_obligations =
14511453
iter::zip(&predicates.predicates, &predicates.spans).flat_map(|(&p, &sp)| {
1452-
traits::wf::predicate_obligations(infcx, wfcx.param_env, wfcx.body_id, p, sp)
1454+
traits::wf::predicate_obligations(
1455+
infcx,
1456+
wfcx.param_env.without_const(),
1457+
wfcx.body_id,
1458+
p,
1459+
sp,
1460+
)
14531461
});
14541462

14551463
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// revisions: nn ny yn yy
2+
// check-pass
3+
#![feature(const_trait_impl, associated_type_defaults, const_mut_refs)]
4+
5+
#[cfg_attr(any(yn, yy), const_trait)]
6+
pub trait Index {
7+
type Output;
8+
}
9+
10+
#[cfg_attr(any(ny, yy), const_trait)]
11+
pub trait IndexMut where Self: Index {
12+
const C: <Self as Index>::Output;
13+
type Assoc = <Self as Index>::Output;
14+
fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output;
15+
}
16+
17+
impl Index for () { type Output = (); }
18+
19+
impl const IndexMut for <() as Index>::Output {
20+
const C: <Self as Index>::Output = ();
21+
type Assoc = <Self as Index>::Output;
22+
fn foo(&mut self, x: <Self as Index>::Output) -> <Self as Index>::Output
23+
where <Self as Index>::Output:,
24+
{}
25+
}
26+
27+
const C: <() as Index>::Output = ();
28+
29+
fn main() {}

0 commit comments

Comments
 (0)