Skip to content

Commit 1a92d96

Browse files
authored
Rollup merge of rust-lang#100336 - fee1-dead-contrib:fix-wf-const-trait, r=oli-obk
Fix two const_trait_impl issues r? `@oli-obk` Fixes rust-lang#100222. Fixes rust-lang#100543.
2 parents b6f82a2 + f1db3be commit 1a92d96

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

Diff for: 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
}
@@ -1444,7 +1446,13 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14441446
assert_eq!(predicates.predicates.len(), predicates.spans.len());
14451447
let wf_obligations =
14461448
iter::zip(&predicates.predicates, &predicates.spans).flat_map(|(&p, &sp)| {
1447-
traits::wf::predicate_obligations(infcx, wfcx.param_env, wfcx.body_id, p, sp)
1449+
traits::wf::predicate_obligations(
1450+
infcx,
1451+
wfcx.param_env.without_const(),
1452+
wfcx.body_id,
1453+
p,
1454+
sp,
1455+
)
14481456
});
14491457

14501458
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
+29
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)