Skip to content

Commit f73853e

Browse files
committed
Do not emit ConstEvaluatable goals if type-const
1 parent d933cf4 commit f73853e

4 files changed

Lines changed: 72 additions & 11 deletions

File tree

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,10 @@ fn const_evaluatable_predicates_of<'tcx>(
438438
return;
439439
}
440440

441+
if self.tcx.is_type_const(uv.def) {
442+
return;
443+
}
444+
441445
let span = self.tcx.def_span(uv.def);
442446
self.preds.insert((ty::ClauseKind::ConstEvaluatable(c).upcast(self.tcx), span));
443447
}

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,17 +1016,19 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
10161016
match c.kind() {
10171017
ty::ConstKind::Unevaluated(uv) => {
10181018
if !c.has_escaping_bound_vars() {
1019-
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
1020-
ty::ClauseKind::ConstEvaluatable(c),
1021-
));
1022-
let cause = self.cause(ObligationCauseCode::WellFormed(None));
1023-
self.out.push(traits::Obligation::with_depth(
1024-
tcx,
1025-
cause,
1026-
self.recursion_depth,
1027-
self.param_env,
1028-
predicate,
1029-
));
1019+
if !tcx.is_type_const(uv.def) {
1020+
let predicate = ty::Binder::dummy(ty::PredicateKind::Clause(
1021+
ty::ClauseKind::ConstEvaluatable(c),
1022+
));
1023+
let cause = self.cause(ObligationCauseCode::WellFormed(None));
1024+
self.out.push(traits::Obligation::with_depth(
1025+
tcx,
1026+
cause,
1027+
self.recursion_depth,
1028+
self.param_env,
1029+
predicate,
1030+
));
1031+
}
10301032

10311033
if matches!(tcx.def_kind(uv.def), DefKind::AssocConst { .. })
10321034
&& tcx.def_kind(tcx.parent(uv.def)) == (DefKind::Impl { of_trait: false })
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// issue: <https://github.com/rust-lang/rust/issues/151631>
2+
//@ compile-flags: -Znext-solver
3+
#![feature(min_generic_const_args)]
4+
#![expect(incomplete_features)]
5+
6+
trait SuperTrait {}
7+
trait Trait: SuperTrait {
8+
type const K: u32;
9+
}
10+
impl Trait for () { //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
11+
type const K: u32 = const { 1 };
12+
}
13+
14+
fn check(_: impl Trait<K = 0>) {}
15+
16+
fn main() {
17+
check(()); //~ ERROR: the trait bound `(): SuperTrait` is not satisfied
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
error[E0277]: the trait bound `(): SuperTrait` is not satisfied
2+
--> $DIR/type-const-ice-issue-151631.rs:10:16
3+
|
4+
LL | impl Trait for () {
5+
| ^^ the trait `SuperTrait` is not implemented for `()`
6+
|
7+
help: this trait has no implementations, consider adding one
8+
--> $DIR/type-const-ice-issue-151631.rs:6:1
9+
|
10+
LL | trait SuperTrait {}
11+
| ^^^^^^^^^^^^^^^^
12+
note: required by a bound in `Trait`
13+
--> $DIR/type-const-ice-issue-151631.rs:7:14
14+
|
15+
LL | trait Trait: SuperTrait {
16+
| ^^^^^^^^^^ required by this bound in `Trait`
17+
18+
error[E0277]: the trait bound `(): SuperTrait` is not satisfied
19+
--> $DIR/type-const-ice-issue-151631.rs:17:5
20+
|
21+
LL | check(());
22+
| ^^^^^^^^^ the trait `SuperTrait` is not implemented for `()`
23+
|
24+
help: this trait has no implementations, consider adding one
25+
--> $DIR/type-const-ice-issue-151631.rs:6:1
26+
|
27+
LL | trait SuperTrait {}
28+
| ^^^^^^^^^^^^^^^^
29+
note: required by a bound in `Trait`
30+
--> $DIR/type-const-ice-issue-151631.rs:7:14
31+
|
32+
LL | trait Trait: SuperTrait {
33+
| ^^^^^^^^^^ required by this bound in `Trait`
34+
35+
error: aborting due to 2 previous errors
36+
37+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)