Skip to content

Commit c4c2986

Browse files
committed
Auto merge of #87815 - BoxyUwU:cec-generics-of-ice, r=eddyb
encode `generics_of` for fields and ty params Fixes #87674 Fixes #87603 ICE was caused by calling `generics_of` on a `DefId` without any `generics_of` results. This was happening when we call `generics_of` on parent `DefId`s of an unevaluated const when we evaluate it. r? `@lcnr`
2 parents 2d10c2a + 8ff2ecc commit c4c2986

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,12 @@ fn should_encode_generics(def_kind: DefKind) -> bool {
918918
| DefKind::AnonConst
919919
| DefKind::OpaqueTy
920920
| DefKind::Impl
921+
| DefKind::Field
922+
| DefKind::TyParam
921923
| DefKind::Closure
922924
| DefKind::Generator => true,
923925
DefKind::Mod
924-
| DefKind::Field
925926
| DefKind::ForeignMod
926-
| DefKind::TyParam
927927
| DefKind::ConstParam
928928
| DefKind::Macro(..)
929929
| DefKind::Use
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#![feature(const_generics, const_evaluatable_checked)]
2+
#![allow(incomplete_features)]
3+
4+
// library portion of regression test for #87674
5+
pub struct Foo<const N: usize>([(); N + 1])
6+
where
7+
[(); N + 1]: ;
8+
9+
// library portion of regression test for #87603
10+
pub struct S<T: Copy + Default, const N: usize>
11+
where
12+
[T; N * 2]: Sized,
13+
{
14+
pub s: [T; N * 2],
15+
}
16+
impl<T: Default + Copy, const N: usize> S<T, N>
17+
where
18+
[T; N * 2]: Sized,
19+
{
20+
pub fn test() -> Self {
21+
S { s: [T::default(); N * 2] }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(const_generics, const_evaluatable_checked)]
2+
#![allow(incomplete_features)]
3+
4+
// library portion of testing that `impl Trait<{ expr }>` doesnt
5+
// ice because of a `DefKind::TyParam` parent
6+
pub fn foo<const N: usize>(foo: impl Into<[(); N + 1]>) {
7+
foo.into();
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// aux-build:generics_of_parent.rs
2+
// check-pass
3+
#![feature(const_generics, const_evaluatable_checked)]
4+
#![allow(incomplete_features)]
5+
6+
extern crate generics_of_parent;
7+
8+
use generics_of_parent::{Foo, S};
9+
10+
fn main() {
11+
// regression test for #87603
12+
const N: usize = 2;
13+
let x: S<u8, N> = S::test();
14+
}
15+
16+
// regression test for #87674
17+
fn new<U>(a: U) -> U {
18+
a
19+
}
20+
fn foo<const N: usize>(bar: &mut Foo<N>)
21+
where
22+
[(); N + 1]: ,
23+
{
24+
*bar = new(loop {});
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build:generics_of_parent_impl_trait.rs
2+
#![feature(const_generics, const_evaluatable_checked)]
3+
#![allow(incomplete_features)]
4+
5+
extern crate generics_of_parent_impl_trait;
6+
7+
fn main() {
8+
// check for `impl Trait<{ const }>` which has a parent of a `DefKind::TyParam`
9+
generics_of_parent_impl_trait::foo([()]);
10+
//~^ error: type annotations needed:
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0284]: type annotations needed: cannot satisfy `the constant `foo::{opaque#0}::{constant#0}` can be evaluated`
2+
--> $DIR/parent_generics_of_encoding_impl_trait.rs:9:5
3+
|
4+
LL | generics_of_parent_impl_trait::foo([()]);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `the constant `foo::{opaque#0}::{constant#0}` can be evaluated`
6+
|
7+
::: $DIR/auxiliary/generics_of_parent_impl_trait.rs:6:48
8+
|
9+
LL | pub fn foo<const N: usize>(foo: impl Into<[(); N + 1]>) {
10+
| ----- required by this bound in `foo`
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0284`.

0 commit comments

Comments
 (0)