Skip to content

Commit d4551d2

Browse files
committed
Fixed error with more TODOs
1 parent cd2edf6 commit d4551d2

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

compiler/rustc_middle/src/ty/subst.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,16 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
612612

613613
fn fold_constness(&mut self, c: ty::ConstnessArg) -> ty::ConstnessArg {
614614
if let ty::ConstnessArg::Const | ty::ConstnessArg::Infer = c {
615-
self.substs
615+
let ret = self
616+
.substs
616617
.iter()
617618
.find_map(|param| match param.unpack() {
618619
GenericArgKind::Constness(c) => Some(c),
619620
_ => None,
620621
})
621-
.unwrap_or(c)
622+
.unwrap_or(ty::ConstnessArg::Not); // <- since there is no constness in subst, it must be non-const
623+
trace!(?c, ?ret);
624+
ret
622625
} else {
623626
c.super_fold_with(self)
624627
}

compiler/rustc_typeck/src/check/fn_ctxt/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
127127
param_env: ty::ParamEnv<'tcx>,
128128
body_id: hir::HirId,
129129
) -> FnCtxt<'a, 'tcx> {
130-
FnCtxt {
130+
let fcx = FnCtxt {
131131
body_id,
132132
param_env,
133133
err_count_on_creation: inh.tcx.sess.err_count(),
@@ -159,7 +159,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
159159
ty::ConstnessArg::Not
160160
}
161161
},
162-
}
162+
};
163+
let constness = fcx.constness;
164+
trace!(?constness);
165+
fcx
163166
}
164167

165168
pub fn cause(&self, span: Span, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> {

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ fn check_where_clauses<'tcx, 'fcx>(
13401340
// First we build the defaulted substitution.
13411341
let substs = InternalSubsts::for_item(tcx, def_id.to_def_id(), |param, _| {
13421342
match param.kind {
1343-
GenericParamDefKind::Constness | GenericParamDefKind::Lifetime => {
1343+
GenericParamDefKind::Lifetime => {
13441344
// All regions are identity.
13451345
tcx.mk_param_from_def(param)
13461346
}
@@ -1371,6 +1371,8 @@ fn check_where_clauses<'tcx, 'fcx>(
13711371

13721372
tcx.mk_param_from_def(param)
13731373
}
1374+
1375+
GenericParamDefKind::Constness => fcx.constness().into(),
13741376
}
13751377
});
13761378

@@ -1828,9 +1830,24 @@ fn check_false_global_bounds(fcx: &FnCtxt<'_, '_>, mut span: Span, id: hir::HirI
18281830
let pred = obligation.predicate;
18291831
// Match the existing behavior.
18301832
if pred.is_global() && !pred.has_late_bound_regions() {
1831-
let pred = fcx.normalize_associated_types_in(span, pred);
1833+
let /* mut */ pred = fcx.normalize_associated_types_in(span, pred);
18321834
let hir_node = fcx.tcx.hir().find(id);
18331835

1836+
if fcx.constness() == ty::ConstnessArg::Not {
1837+
struct NotConstFolder<'tcx>(TyCtxt<'tcx>); // TODO justify this hack
1838+
1839+
impl<'tcx> ty::TypeFolder<'tcx> for NotConstFolder<'tcx> {
1840+
fn tcx<'a>(&'a self) -> TyCtxt<'tcx> {
1841+
self.0
1842+
}
1843+
fn fold_constness(&mut self, _: ty::ConstnessArg) -> ty::ConstnessArg {
1844+
ty::ConstnessArg::Not
1845+
}
1846+
}
1847+
1848+
pred = pred.fold_with(&mut NotConstFolder(fcx.tcx))
1849+
}
1850+
18341851
// only use the span of the predicate clause (#90869)
18351852

18361853
if let Some(hir::Generics { predicates, .. }) =
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
#![feature(const_trait_impl)]
3+
4+
#[const_trait]
5+
trait Foo {
6+
fn foo(&self);
7+
}
8+
9+
struct S1;
10+
struct S2;
11+
12+
impl Foo for S1 {
13+
fn foo(&self) {}
14+
}
15+
16+
impl const Foo for S2 where S1: ~const Foo {
17+
fn foo(&self) {}
18+
}
19+
20+
fn main() {
21+
S2.foo();
22+
}
23+

0 commit comments

Comments
 (0)