From 2c004a228751aed8a271e16d74c96d8037b6e655 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 6 Aug 2021 14:20:59 +0100 Subject: [PATCH 1/3] encode `generics_of` of fields and ty params --- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 +-- .../auxiliary/generics_of_parent.rs | 23 +++++++++++++++++ .../generics_of_parent_impl_trait.rs | 7 ++++++ .../parent_generics_of_encoding.rs | 25 +++++++++++++++++++ .../parent_generics_of_encoding_impl_trait.rs | 11 ++++++++ ...ent_generics_of_encoding_impl_trait.stderr | 14 +++++++++++ 6 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/const-generics/auxiliary/generics_of_parent.rs create mode 100644 src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs create mode 100644 src/test/ui/const-generics/parent_generics_of_encoding.rs create mode 100644 src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs create mode 100644 src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 45a4762c700..b7921c403bb 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -918,12 +918,12 @@ fn should_encode_generics(def_kind: DefKind) -> bool { | DefKind::AnonConst | DefKind::OpaqueTy | DefKind::Impl + | DefKind::Field + | DefKind::TyParam | DefKind::Closure | DefKind::Generator => true, DefKind::Mod - | DefKind::Field | DefKind::ForeignMod - | DefKind::TyParam | DefKind::ConstParam | DefKind::Macro(..) | DefKind::Use diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs new file mode 100644 index 00000000000..576276d902d --- /dev/null +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent.rs @@ -0,0 +1,23 @@ +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +// library portion of regression test for #87674 +pub struct Foo([(); N + 1]) +where + [(); N + 1]: ; + +// library portion of regression test for #87603 +pub struct S +where + [T; N * 2]: Sized, +{ + pub s: [T; N * 2], +} +impl S +where + [T; N * 2]: Sized, +{ + pub fn test() -> Self { + S { s: [T::default(); N * 2] } + } +} diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs new file mode 100644 index 00000000000..83e0c5566be --- /dev/null +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs @@ -0,0 +1,7 @@ +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +// library portion of testing that `impl Trait<{ expr }>` doesnt ice because of a `DefKind::TyParam` parent +pub fn foo(foo: impl Into<[(); N + 1]>) { + foo.into(); +} diff --git a/src/test/ui/const-generics/parent_generics_of_encoding.rs b/src/test/ui/const-generics/parent_generics_of_encoding.rs new file mode 100644 index 00000000000..31be8e7d111 --- /dev/null +++ b/src/test/ui/const-generics/parent_generics_of_encoding.rs @@ -0,0 +1,25 @@ +// aux-build:generics_of_parent.rs +// check-pass +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +extern crate generics_of_parent; + +use generics_of_parent::{Foo, S}; + +fn main() { + // regression test for #87603 + const N: usize = 2; + let x: S = S::test(); +} + +// regression test for #87674 +fn new(a: U) -> U { + a +} +fn foo(bar: &mut Foo) +where + [(); N + 1]: , +{ + *bar = new(loop {}); +} diff --git a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs new file mode 100644 index 00000000000..988777b1c90 --- /dev/null +++ b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.rs @@ -0,0 +1,11 @@ +// aux-build:generics_of_parent_impl_trait.rs +#![feature(const_generics, const_evaluatable_checked)] +#![allow(incomplete_features)] + +extern crate generics_of_parent_impl_trait; + +fn main() { + // check for `impl Trait<{ const }>` which has a parent of a `DefKind::TyParam` + generics_of_parent_impl_trait::foo([()]); + //~^ error: type annotations needed: +} diff --git a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr new file mode 100644 index 00000000000..f23c262d34d --- /dev/null +++ b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr @@ -0,0 +1,14 @@ +error[E0284]: type annotations needed: cannot satisfy `the constant `foo::{opaque#0}::{constant#0}` can be evaluated` + --> $DIR/parent_generics_of_encoding_impl_trait.rs:9:5 + | +LL | generics_of_parent_impl_trait::foo([()]); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `the constant `foo::{opaque#0}::{constant#0}` can be evaluated` + | + ::: $DIR/auxiliary/generics_of_parent_impl_trait.rs:5:48 + | +LL | pub fn foo(foo: impl Into<[(); N + 1]>) { + | ----- required by this bound in `foo` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0284`. From 9a5fc0d9110108e79e5b0dc5c6dfb5392a74bb13 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 6 Aug 2021 14:55:53 +0100 Subject: [PATCH 2/3] *sprinkles some dust everywhere* --- .../const-generics/auxiliary/generics_of_parent_impl_trait.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs index 83e0c5566be..0d03f56854a 100644 --- a/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs +++ b/src/test/ui/const-generics/auxiliary/generics_of_parent_impl_trait.rs @@ -1,7 +1,8 @@ #![feature(const_generics, const_evaluatable_checked)] #![allow(incomplete_features)] -// library portion of testing that `impl Trait<{ expr }>` doesnt ice because of a `DefKind::TyParam` parent +// library portion of testing that `impl Trait<{ expr }>` doesnt +// ice because of a `DefKind::TyParam` parent pub fn foo(foo: impl Into<[(); N + 1]>) { foo.into(); } From 8ff2eccd80248030d66c7f4466935df85dfa36b0 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 6 Aug 2021 15:17:21 +0100 Subject: [PATCH 3/3] uwu --- .../parent_generics_of_encoding_impl_trait.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr index f23c262d34d..6c0d5c4f079 100644 --- a/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr +++ b/src/test/ui/const-generics/parent_generics_of_encoding_impl_trait.stderr @@ -4,7 +4,7 @@ error[E0284]: type annotations needed: cannot satisfy `the constant `foo::{opaqu LL | generics_of_parent_impl_trait::foo([()]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot satisfy `the constant `foo::{opaque#0}::{constant#0}` can be evaluated` | - ::: $DIR/auxiliary/generics_of_parent_impl_trait.rs:5:48 + ::: $DIR/auxiliary/generics_of_parent_impl_trait.rs:6:48 | LL | pub fn foo(foo: impl Into<[(); N + 1]>) { | ----- required by this bound in `foo`