Skip to content

Commit c80d9b8

Browse files
Don't ICE when encountering placeholders in layout computation
1 parent aba23fd commit c80d9b8

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

compiler/rustc_ty_utils/src/layout.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ fn layout_of_uncached<'tcx>(
611611
}
612612

613613
// Types with no meaningful known layout.
614-
ty::Param(_) => {
614+
ty::Param(_) | ty::Placeholder(..) => {
615615
return Err(error(cx, LayoutError::TooGeneric(ty)));
616616
}
617617

@@ -628,11 +628,7 @@ fn layout_of_uncached<'tcx>(
628628
return Err(error(cx, err));
629629
}
630630

631-
ty::Placeholder(..)
632-
| ty::Bound(..)
633-
| ty::CoroutineWitness(..)
634-
| ty::Infer(_)
635-
| ty::Error(_) => {
631+
ty::Bound(..) | ty::CoroutineWitness(..) | ty::Infer(_) | ty::Error(_) => {
636632
// `ty::Error` is handled at the top of this function.
637633
bug!("layout_of: unexpected type `{ty}`")
638634
}

tests/ui/consts/too_generic_eval_ice.stderr renamed to tests/ui/consts/too_generic_eval_ice.current.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error: constant expression depends on a generic parameter
2-
--> $DIR/too_generic_eval_ice.rs:7:13
2+
--> $DIR/too_generic_eval_ice.rs:11:13
33
|
44
LL | [5; Self::HOST_SIZE] == [6; 0]
55
| ^^^^^^^^^^^^^^^
66
|
77
= note: this may fail depending on what value the parameter takes
88

99
error: constant expression depends on a generic parameter
10-
--> $DIR/too_generic_eval_ice.rs:7:9
10+
--> $DIR/too_generic_eval_ice.rs:11:9
1111
|
1212
LL | [5; Self::HOST_SIZE] == [6; 0]
1313
| ^^^^^^^^^^^^^^^^^^^^
1414
|
1515
= note: this may fail depending on what value the parameter takes
1616

1717
error: constant expression depends on a generic parameter
18-
--> $DIR/too_generic_eval_ice.rs:7:30
18+
--> $DIR/too_generic_eval_ice.rs:11:30
1919
|
2020
LL | [5; Self::HOST_SIZE] == [6; 0]
2121
| ^^
2222
|
2323
= note: this may fail depending on what value the parameter takes
2424

2525
error[E0277]: can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
26-
--> $DIR/too_generic_eval_ice.rs:7:30
26+
--> $DIR/too_generic_eval_ice.rs:11:30
2727
|
2828
LL | [5; Self::HOST_SIZE] == [6; 0]
2929
| ^^ no implementation for `[{integer}; Self::HOST_SIZE] == [{integer}; 0]`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0284]: type annotations needed: cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated`
2+
--> $DIR/too_generic_eval_ice.rs:11:13
3+
|
4+
LL | [5; Self::HOST_SIZE] == [6; 0]
5+
| ^^^^^^^^^^^^^^^ cannot satisfy `the constant `Self::HOST_SIZE` can be evaluated`
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0284`.

tests/ui/consts/too_generic_eval_ice.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
15
pub struct Foo<A, B>(A, B);
26

37
impl<A, B> Foo<A, B> {
48
const HOST_SIZE: usize = std::mem::size_of::<B>();
59

610
pub fn crash() -> bool {
711
[5; Self::HOST_SIZE] == [6; 0]
8-
//~^ ERROR constant expression depends on a generic parameter
9-
//~| ERROR constant expression depends on a generic parameter
10-
//~| ERROR constant expression depends on a generic parameter
11-
//~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
12+
//[current]~^ ERROR constant expression depends on a generic parameter
13+
//[current]~| ERROR constant expression depends on a generic parameter
14+
//[current]~| ERROR constant expression depends on a generic parameter
15+
//[current]~| ERROR can't compare `[{integer}; Self::HOST_SIZE]` with `[{integer}; 0]`
16+
//[next]~^^^^^ ERROR type annotations needed
1217
}
1318
}
1419

0 commit comments

Comments
 (0)