Skip to content

Commit

Permalink
Rollup merge of rust-lang#90396 - b-naber:type_flags_ices_default_ano…
Browse files Browse the repository at this point in the history
…n_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`
  • Loading branch information
matthiaskrgr authored Oct 30, 2021
2 parents 0a87c7f + 87fbf3c commit 309a72b
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ pub(super) fn default_anon_const_substs(tcx: TyCtxt<'_>, def_id: DefId) -> Subst
// Getting this wrong can lead to ICE and unsoundness, so we assert it here.
for arg in substs.iter() {
let allowed_flags = ty::TypeFlags::MAY_NEED_DEFAULT_CONST_SUBSTS
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE;
| ty::TypeFlags::STILL_FURTHER_SPECIALIZABLE
| ty::TypeFlags::HAS_ERROR;
assert!(!arg.has_type_flags(!allowed_flags));
}
substs
Expand Down
14 changes: 14 additions & 0 deletions src/test/ui/const-generics/issues/issue-88997.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

struct ConstAssert<const COND: bool>;
trait True {}
impl True for ConstAssert<true> {}

struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
//~^ ERROR the type of const parameters must not depend on other generic parameters
//~| ERROR the type of const parameters must not depend on other generic parameters
where
ConstAssert<{ MIN <= MAX }>: True;

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/issues/issue-88997.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-88997.rs:8:40
|
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
| ^ the type must not depend on the parameter `T`

error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-88997.rs:8:54
|
LL | struct Range<T: PartialOrd, const MIN: T, const MAX: T>(T)
| ^ the type must not depend on the parameter `T`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0770`.
9 changes: 9 additions & 0 deletions src/test/ui/const-generics/issues/issue-90364.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub struct Foo<T, const H: T>(T)
//~^ ERROR the type of const parameters must not depend on other generic parameters
where
[(); 1]:;

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/const-generics/issues/issue-90364.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0770]: the type of const parameters must not depend on other generic parameters
--> $DIR/issue-90364.rs:4:28
|
LL | pub struct Foo<T, const H: T>(T)
| ^ the type must not depend on the parameter `T`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0770`.

0 comments on commit 309a72b

Please sign in to comment.