Skip to content

Commit

Permalink
do not ICE on ty::Bound in Layout::compute
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Sep 11, 2020
1 parent 80ce7fa commit ae85bbb
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,11 +1259,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.layout_raw(param_env.and(normalized))?
}

ty::Bound(..) | ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
bug!("Layout::compute: unexpected type `{}`", ty)
}

ty::Param(_) | ty::Error(_) => {
ty::Bound(..) | ty::Param(_) | ty::Error(_) => {
return Err(LayoutError::Unknown(ty));
}
})
Expand Down
18 changes: 18 additions & 0 deletions src/test/ui/const-generics/issues/issue-76595.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]

struct Bool<const B: bool>;

trait True {}

impl True for Bool<true> {}

fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
todo!()
}

fn main() {
test::<2>();
//~^ ERROR wrong number of type
//~| ERROR constant expression depends
}
21 changes: 21 additions & 0 deletions src/test/ui/const-generics/issues/issue-76595.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
error[E0107]: wrong number of type arguments: expected 1, found 0
--> $DIR/issue-76595.rs:15:5
|
LL | test::<2>();
| ^^^^^^^^^ expected 1 type argument

error: constant expression depends on a generic parameter
--> $DIR/issue-76595.rs:15:5
|
LL | fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
| ---- required by a bound in this
...
LL | test::<2>();
| ^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
= note: required by this bound in `test`

error: aborting due to 2 previous errors

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

0 comments on commit ae85bbb

Please sign in to comment.