Skip to content

Commit 37cfa17

Browse files
committed
Auto merge of rust-lang#154053 - khyperia:generalize-unevaluated, r=BoxyUwU
Properly generalize unevaluated consts - fixes rust-lang#153831 - fixes a `// FIXME(ogca)` (I am unaware of an issue for this) added in rust-lang#150823 r? @BoxyUwU
2 parents 08cd08f + 75eeece commit 37cfa17

13 files changed

Lines changed: 300 additions & 143 deletions

File tree

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 195 additions & 133 deletions
Large diffs are not rendered by default.

compiler/rustc_infer/src/infer/unify_key.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ impl<'tcx> ConstVariableValue<'tcx> {
110110
ConstVariableValue::Known { value } => Some(value),
111111
}
112112
}
113+
114+
pub(crate) fn is_unknown(&self) -> bool {
115+
match *self {
116+
ConstVariableValue::Unknown { .. } => true,
117+
ConstVariableValue::Known { .. } => false,
118+
}
119+
}
113120
}
114121

115122
#[derive(PartialEq, Copy, Clone, Debug)]

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,13 @@ impl<'tcx> Const<'tcx> {
323323
matches!(self.kind(), ty::ConstKind::Infer(_))
324324
}
325325

326+
pub fn ct_vid(self) -> Option<ty::ConstVid> {
327+
match self.kind() {
328+
ConstKind::Infer(ty::InferConst::Var(vid)) => Some(vid),
329+
_ => None,
330+
}
331+
}
332+
326333
/// Iterator that walks `self` and any types reachable from
327334
/// `self`, in depth-first order. Note that just walks the types
328335
/// that appear in `self`, it does not descend into the fields of

tests/ui/coherence/occurs-check/associated-type.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
2-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
1+
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
2+
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
33
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
44
--> $DIR/associated-type.rs:32:1
55
|

tests/ui/coherence/occurs-check/associated-type.old.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
2-
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTy { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
1+
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
2+
WARN rustc_infer::infer::relate::generalize may incompletely handle alias type: AliasTerm { args: [*const ?1t, '^0.Named(DefId(0:27 ~ associated_type[f554]::{impl#3}::'a#1))], def_id: DefId(0:5 ~ associated_type[f554]::ToUnit::Unit), .. }
33
error[E0119]: conflicting implementations of trait `Overlap<for<'a> fn(&'a (), ())>` for type `for<'a> fn(&'a (), ())`
44
--> $DIR/associated-type.rs:32:1
55
|
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Regression test for <https://github.com/rust-lang/rust/issues/153831>
2+
//@ check-fail
3+
//@compile-flags: -Znext-solver=globally --emit=obj
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
type const A: () = A;
8+
//~^ ERROR type mismatch resolving `A normalizes-to _`
9+
//~| ERROR the constant `A` is not of type `()`
10+
11+
fn main() {
12+
A;
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0271]: type mismatch resolving `A normalizes-to _`
2+
--> $DIR/free-const-recursive.rs:7:1
3+
|
4+
LL | type const A: () = A;
5+
| ^^^^^^^^^^^^^^^^ types differ
6+
7+
error: the constant `A` is not of type `()`
8+
--> $DIR/free-const-recursive.rs:7:1
9+
|
10+
LL | type const A: () = A;
11+
| ^^^^^^^^^^^^^^^^ expected `()`, found a different `()`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0271`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! See also <https://github.com/rust-lang/rust/issues/153831>
2+
//@ check-fail
3+
//@compile-flags: -Znext-solver=globally --emit=obj
4+
#![feature(min_generic_const_args)]
5+
#![expect(incomplete_features)]
6+
7+
trait Trait {
8+
type const A: ();
9+
}
10+
11+
impl Trait for () {
12+
type const A: () = <() as Trait>::A;
13+
//~^ ERROR type mismatch resolving `<() as Trait>::A normalizes-to _`
14+
//~| ERROR the constant `<() as Trait>::A` is not of type `()`
15+
}
16+
17+
fn main() {
18+
<() as Trait>::A;
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0271]: type mismatch resolving `<() as Trait>::A normalizes-to _`
2+
--> $DIR/projection-const-recursive.rs:12:5
3+
|
4+
LL | type const A: () = <() as Trait>::A;
5+
| ^^^^^^^^^^^^^^^^ types differ
6+
7+
error: the constant `<() as Trait>::A` is not of type `()`
8+
--> $DIR/projection-const-recursive.rs:12:5
9+
|
10+
LL | type const A: () = <() as Trait>::A;
11+
| ^^^^^^^^^^^^^^^^ expected `()`, found a different `()`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0271`.

tests/ui/const-generics/ogca/coherence-ambiguous.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// FIXME(ogca): this should ERROR not pass!!
2-
//@ check-pass
1+
//@ check-fail
32

43
#![feature(generic_const_items, min_generic_const_args, opaque_generic_const_args)]
54
#![expect(incomplete_features)]
@@ -12,8 +11,8 @@ trait Trait {}
1211

1312
impl Trait for [(); FOO::<1>] {}
1413
impl Trait for [(); BAR::<1>] {}
15-
// FIXME(ogca): this should ERROR!
14+
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
1615
impl Trait for [(); BAR::<2>] {}
17-
// FIXME(ogca): this should ERROR!
16+
//~^ ERROR conflicting implementations of trait `Trait` for type `[(); FOO::<1>]`
1817

1918
fn main() {}

0 commit comments

Comments
 (0)