Skip to content

Commit

Permalink
Rollup merge of rust-lang#100336 - fee1-dead-contrib:fix-wf-const-tra…
Browse files Browse the repository at this point in the history
…it, r=oli-obk

Fix two const_trait_impl issues

r? `@oli-obk`

Fixes rust-lang#100222.
Fixes rust-lang#100543.
  • Loading branch information
Dylan-DPC authored Aug 22, 2022
2 parents b6f82a2 + f1db3be commit 1a92d96
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
));
}
Expand Down Expand Up @@ -1444,7 +1446,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();
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/rfc-2632-const-trait-impl/issue-100222.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 1a92d96

Please sign in to comment.