Skip to content

Commit d99dc7a

Browse files
authored
Rollup merge of rust-lang#90396 - b-naber:type_flags_ices_default_anon_consts, r=lcnr
Prevent type flags assertions being thrown in default_anon_const_substs if errors occurred Fixes rust-lang#90364 Fixes rust-lang#88997 r? ``@lcnr``
2 parents 88e0bea + 87fbf3c commit d99dc7a

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> Subst
292292
// Getting this wrong can lead to ICE and unsoundness, so we assert it here.
293293
for arg in substs.iter() {
294294
let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS
295-
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE;
295+
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE
296+
| ty::TypeFlags::HAS_ERROR;
296297
assert!(!arg.has_type_flags(!allowed_flags));
297298
}
298299
substs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#![allow(incomplete_features)]
2+
#![feature(generic_const_exprs)]
3+
4+
struct ConstAssert<const COND: bool>;
5+
trait True {}
6+
impl True for ConstAssert<true> {}
7+
8+
struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
9+
//~^ ERROR the type of const parameters must not depend on other generic parameters
10+
//~| ERROR the type of const parameters must not depend on other generic parameters
11+
where
12+
ConstAssert<{ MIN <= MAX }>: True;
13+
14+
fn main() {}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0770]: the type of const parameters must not depend on other generic parameters
2+
--> $DIR/issue-88997.rs:8:40
3+
|
4+
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
5+
| ^ the type must not depend on the parameter `T`
6+
7+
error[E0770]: the type of const parameters must not depend on other generic parameters
8+
--> $DIR/issue-88997.rs:8:54
9+
|
10+
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
11+
| ^ the type must not depend on the parameter `T`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0770`.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
4+
pub struct Foo<T, const H: T>(T)
5+
//~^ ERROR the type of const parameters must not depend on other generic parameters
6+
where
7+
[(); 1]:;
8+
9+
fn main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0770]: the type of const parameters must not depend on other generic parameters
2+
--> $DIR/issue-90364.rs:4:28
3+
|
4+
LL | pub struct Foo<T, const H: T>(T)
5+
| ^ the type must not depend on the parameter `T`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0770`.

0 commit comments

Comments
 (0)