Skip to content

Commit f019b6c

Browse files
committed
Overhaul 100222 test; wf always remap to nonconst
1 parent 460daf3 commit f019b6c

File tree

2 files changed

+22
-20
lines changed

2 files changed

+22
-20
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,11 @@ impl<'tcx> WfCheckingCtxt<'_, 'tcx> {
6666
span: Span,
6767
loc: Option<WellFormedLoc>,
6868
arg: ty::GenericArg<'tcx>,
69-
override_constness: Option<hir::Constness>,
7069
) {
7170
let cause =
7271
traits::ObligationCause::new(span, self.body_id, ObligationCauseCode::WellFormed(loc));
73-
let param_env = if let Some(constness) = override_constness {
74-
self.param_env.with_constness(constness)
75-
} else {
76-
self.param_env
77-
};
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();
7874
self.ocx.register_obligation(traits::Obligation::new(
7975
cause,
8076
param_env,
@@ -991,7 +987,7 @@ fn check_associated_item(
991987
ty::AssocKind::Const => {
992988
let ty = tcx.type_of(item.def_id);
993989
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
994-
wfcx.register_wf_obligation(span, loc, ty.into(), None);
990+
wfcx.register_wf_obligation(span, loc, ty.into());
995991
}
996992
ty::AssocKind::Fn => {
997993
let sig = tcx.fn_sig(item.def_id);
@@ -1012,7 +1008,7 @@ fn check_associated_item(
10121008
if item.defaultness(tcx).has_value() {
10131009
let ty = tcx.type_of(item.def_id);
10141010
let ty = wfcx.normalize(span, Some(WellFormedLoc::Ty(item_id)), ty);
1015-
wfcx.register_wf_obligation(span, loc, ty.into(), None);
1011+
wfcx.register_wf_obligation(span, loc, ty.into());
10161012
}
10171013
}
10181014
}
@@ -1048,7 +1044,6 @@ fn check_type_defn<'tcx, F>(
10481044
field.span,
10491045
Some(WellFormedLoc::Ty(field.def_id)),
10501046
field.ty.into(),
1051-
None,
10521047
)
10531048
}
10541049

@@ -1202,7 +1197,6 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_fo
12021197
ty_span,
12031198
Some(WellFormedLoc::Ty(item_id)),
12041199
item_ty.into(),
1205-
None,
12061200
);
12071201
if forbid_unsized {
12081202
wfcx.register_bound(
@@ -1272,7 +1266,6 @@ fn check_impl<'tcx>(
12721266
ast_self_ty.span,
12731267
Some(WellFormedLoc::Ty(item.hir_id().expect_owner())),
12741268
self_ty.into(),
1275-
None,
12761269
);
12771270
}
12781271
}
@@ -1317,7 +1310,6 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13171310
tcx.def_span(param.def_id),
13181311
None,
13191312
ty.into(),
1320-
None,
13211313
);
13221314
}
13231315
}
@@ -1334,7 +1326,6 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
13341326
tcx.def_span(param.def_id),
13351327
None,
13361328
default_ct.into(),
1337-
None,
13381329
);
13391330
}
13401331
}
@@ -1463,7 +1454,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
14631454
assert_eq!(predicates.predicates.len(), predicates.spans.len());
14641455
let wf_obligations =
14651456
iter::zip(&predicates.predicates, &predicates.spans).flat_map(|(&p, &sp)| {
1466-
traits::wf::predicate_obligations(infcx, wfcx.param_env, wfcx.body_id, p, sp)
1457+
traits::wf::predicate_obligations(infcx, wfcx.param_env.without_const(), wfcx.body_id, p, sp)
14671458
});
14681459

14691460
let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect();
@@ -1515,15 +1506,13 @@ fn check_fn_or_method<'tcx>(
15151506
ty.span,
15161507
Some(WellFormedLoc::Param { function: def_id, param_idx: i.try_into().unwrap() }),
15171508
input_ty.into(),
1518-
None,
15191509
);
15201510
}
15211511

15221512
wfcx.register_wf_obligation(
15231513
hir_decl.output.span(),
15241514
None,
15251515
sig.output().into(),
1526-
Some(hir::Constness::NotConst),
15271516
);
15281517

15291518
check_where_clauses(wfcx, span, def_id);
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
1+
// revisions: nn ny yn yy
12
// check-pass
2-
#![feature(const_trait_impl)]
3+
#![feature(const_trait_impl, associated_type_defaults, const_mut_refs)]
34

4-
#[const_trait]
5+
#[cfg_attr(any(yn, yy), const_trait)]
56
pub trait Index {
67
type Output;
78
}
89

9-
#[const_trait]
10+
#[cfg_attr(any(ny, yy), const_trait)]
1011
pub trait IndexMut where Self: Index {
11-
fn foo(&mut self) -> <Self as Index>::Output;
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;
1215
}
1316

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 where <Self as Index>::Output: {}
23+
}
24+
25+
const C: <() as Index>::Output = ();
26+
1427
fn main() {}

0 commit comments

Comments
 (0)