diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:43 +0000 |
commit | 3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245 (patch) | |
tree | daf049b282ab10e8c3d03e409b3cd84ff3f7690c /tests/ui/const-generics | |
parent | Adding debian version 1.68.2+dfsg1-1. (diff) | |
download | rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.tar.xz rustc-3e3e70d529d8c7d7c4d7bc4fefc9f109393b9245.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/const-generics')
60 files changed, 567 insertions, 104 deletions
diff --git a/tests/ui/const-generics/bad-const-generic-exprs.rs b/tests/ui/const-generics/bad-const-generic-exprs.rs index ca91643ed..423752ca2 100644 --- a/tests/ui/const-generics/bad-const-generic-exprs.rs +++ b/tests/ui/const-generics/bad-const-generic-exprs.rs @@ -13,10 +13,34 @@ fn main() { let _: Wow<A.0>; //~^ ERROR expected one of //~| HELP expressions must be enclosed in braces to be used as const generic arguments - - // FIXME(compiler-errors): This one is still unsatisfying, - // and probably a case I could see someone typing by accident.. + let _: Wow<[]>; + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments let _: Wow<[12]>; - //~^ ERROR expected type, found - //~| ERROR type provided when a constant was expected + //~^ ERROR expected type + //~| ERROR invalid const generic expression + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<[0, 1, 3]>; + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<[0xff; 8]>; + //~^ ERROR expected type + //~| ERROR invalid const generic expression + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<[1, 2]>; // Regression test for issue #81698. + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<&0>; + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<("", 0)>; + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + let _: Wow<(1 + 2) * 3>; + //~^ ERROR expected type + //~| HELP expressions must be enclosed in braces to be used as const generic arguments + // FIXME(fmease): This one is pretty bad. + let _: Wow<!0>; + //~^ ERROR expected one of + //~| HELP you might have meant to end the type parameters here } diff --git a/tests/ui/const-generics/bad-const-generic-exprs.stderr b/tests/ui/const-generics/bad-const-generic-exprs.stderr index 24668b08b..17a63a96f 100644 --- a/tests/ui/const-generics/bad-const-generic-exprs.stderr +++ b/tests/ui/const-generics/bad-const-generic-exprs.stderr @@ -42,18 +42,118 @@ help: expressions must be enclosed in braces to be used as const generic argumen LL | let _: Wow<{ A.0 }>; | + + +error: expected type, found `]` + --> $DIR/bad-const-generic-exprs.rs:16:17 + | +LL | let _: Wow<[]>; + | ^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ [] }>; + | + + + error: expected type, found `12` --> $DIR/bad-const-generic-exprs.rs:19:17 | LL | let _: Wow<[12]>; | ^^ expected type -error[E0747]: type provided when a constant was expected +error: invalid const generic expression --> $DIR/bad-const-generic-exprs.rs:19:16 | LL | let _: Wow<[12]>; | ^^^^ + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ [12] }>; + | + + + +error: expected type, found `0` + --> $DIR/bad-const-generic-exprs.rs:23:17 + | +LL | let _: Wow<[0, 1, 3]>; + | ^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ [0, 1, 3] }>; + | + + + +error: expected type, found `0xff` + --> $DIR/bad-const-generic-exprs.rs:26:17 + | +LL | let _: Wow<[0xff; 8]>; + | ^^^^ expected type + +error: invalid const generic expression + --> $DIR/bad-const-generic-exprs.rs:26:16 + | +LL | let _: Wow<[0xff; 8]>; + | ^^^^^^^^^ + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ [0xff; 8] }>; + | + + + +error: expected type, found `1` + --> $DIR/bad-const-generic-exprs.rs:30:17 + | +LL | let _: Wow<[1, 2]>; // Regression test for issue #81698. + | ^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ [1, 2] }>; // Regression test for issue #81698. + | + + + +error: expected type, found `0` + --> $DIR/bad-const-generic-exprs.rs:33:17 + | +LL | let _: Wow<&0>; + | ^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ &0 }>; + | + + + +error: expected type, found `""` + --> $DIR/bad-const-generic-exprs.rs:36:17 + | +LL | let _: Wow<("", 0)>; + | ^^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ ("", 0) }>; + | + + + +error: expected type, found `1` + --> $DIR/bad-const-generic-exprs.rs:39:17 + | +LL | let _: Wow<(1 + 2) * 3>; + | ^ expected type + | +help: expressions must be enclosed in braces to be used as const generic arguments + | +LL | let _: Wow<{ (1 + 2) * 3 }>; + | + + + +error: expected one of `,` or `>`, found `0` + --> $DIR/bad-const-generic-exprs.rs:43:17 + | +LL | let _: Wow<!0>; + | - ^ expected one of `,` or `>` + | | + | while parsing the type for `_` + | +help: you might have meant to end the type parameters here + | +LL | let _: Wow<!>0>; + | + -error: aborting due to 6 previous errors +error: aborting due to 15 previous errors -For more information about this error, try `rustc --explain E0747`. diff --git a/tests/ui/const-generics/const-argument-non-static-lifetime.min.stderr b/tests/ui/const-generics/const-argument-non-static-lifetime.min.stderr index f1f3a9c3d..82030731c 100644 --- a/tests/ui/const-generics/const-argument-non-static-lifetime.min.stderr +++ b/tests/ui/const-generics/const-argument-non-static-lifetime.min.stderr @@ -1,5 +1,5 @@ error[E0658]: a non-static lifetime is not allowed in a `const` - --> $DIR/const-argument-non-static-lifetime.rs:15:17 + --> $DIR/const-argument-non-static-lifetime.rs:14:17 | LL | let _: &'a (); | ^^ diff --git a/tests/ui/const-generics/const-argument-non-static-lifetime.rs b/tests/ui/const-generics/const-argument-non-static-lifetime.rs index 36a569784..0357e4ed5 100644 --- a/tests/ui/const-generics/const-argument-non-static-lifetime.rs +++ b/tests/ui/const-generics/const-argument-non-static-lifetime.rs @@ -2,7 +2,6 @@ // revisions: full min // regression test for #78180 -// compile-flags: -Zsave-analysis #![cfg_attr(full, feature(generic_const_exprs))] #![cfg_attr(full, allow(incomplete_features))] diff --git a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr index 4bba42c77..656bc2946 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.min.stderr +++ b/tests/ui/const-generics/const-param-elided-lifetime.min.stderr @@ -28,7 +28,7 @@ error[E0637]: `&` without an explicit lifetime name cannot be used here LL | fn bar<const N: &u8>() {} | ^ explicit lifetime name needed here -error: `&'static u8` is forbidden as the type of a const generic parameter +error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:9:19 | LL | struct A<const N: &u8>; @@ -37,7 +37,7 @@ LL | struct A<const N: &u8>; = note: the only supported types are integers, `bool` and `char` = help: more complex types are supported with `#![feature(adt_const_params)]` -error: `&'static u8` is forbidden as the type of a const generic parameter +error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:14:15 | LL | impl<const N: &u8> A<N> { @@ -46,7 +46,7 @@ LL | impl<const N: &u8> A<N> { = note: the only supported types are integers, `bool` and `char` = help: more complex types are supported with `#![feature(adt_const_params)]` -error: `&'static u8` is forbidden as the type of a const generic parameter +error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:22:15 | LL | impl<const N: &u8> B for A<N> {} @@ -55,7 +55,7 @@ LL | impl<const N: &u8> B for A<N> {} = note: the only supported types are integers, `bool` and `char` = help: more complex types are supported with `#![feature(adt_const_params)]` -error: `&'static u8` is forbidden as the type of a const generic parameter +error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:26:17 | LL | fn bar<const N: &u8>() {} @@ -64,7 +64,7 @@ LL | fn bar<const N: &u8>() {} = note: the only supported types are integers, `bool` and `char` = help: more complex types are supported with `#![feature(adt_const_params)]` -error: `&'static u8` is forbidden as the type of a const generic parameter +error: `&u8` is forbidden as the type of a const generic parameter --> $DIR/const-param-elided-lifetime.rs:17:21 | LL | fn foo<const M: &u8>(&self) {} diff --git a/tests/ui/const-generics/const-param-elided-lifetime.rs b/tests/ui/const-generics/const-param-elided-lifetime.rs index 487b82dbf..45611d6bf 100644 --- a/tests/ui/const-generics/const-param-elided-lifetime.rs +++ b/tests/ui/const-generics/const-param-elided-lifetime.rs @@ -8,23 +8,23 @@ struct A<const N: &u8>; //~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&'static u8` is forbidden +//[min]~^^ ERROR `&u8` is forbidden trait B {} impl<const N: &u8> A<N> { //~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&'static u8` is forbidden +//[min]~^^ ERROR `&u8` is forbidden fn foo<const M: &u8>(&self) {} //~^ ERROR `&` without an explicit lifetime name cannot be used here - //[min]~^^ ERROR `&'static u8` is forbidden + //[min]~^^ ERROR `&u8` is forbidden } impl<const N: &u8> B for A<N> {} //~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&'static u8` is forbidden +//[min]~^^ ERROR `&u8` is forbidden fn bar<const N: &u8>() {} //~^ ERROR `&` without an explicit lifetime name cannot be used here -//[min]~^^ ERROR `&'static u8` is forbidden +//[min]~^^ ERROR `&u8` is forbidden fn main() {} diff --git a/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs b/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs index 781f50e61..b776f2017 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs +++ b/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.rs @@ -1,6 +1,3 @@ -// compile-flags: -Zsave-analysis -// Regression test for #69414 ^ - use std::marker::PhantomData; struct B<T, const N: T>(PhantomData<[T; N]>); diff --git a/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr b/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr index 8e14defd6..9c5c97bef 100644 --- a/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr +++ b/tests/ui/const-generics/const-param-type-depends-on-type-param-ungated.stderr @@ -1,5 +1,5 @@ error[E0770]: the type of const parameters must not depend on other generic parameters - --> $DIR/const-param-type-depends-on-type-param-ungated.rs:6:22 + --> $DIR/const-param-type-depends-on-type-param-ungated.rs:3:22 | LL | struct B<T, const N: T>(PhantomData<[T; N]>); | ^ the type must not depend on the parameter `T` diff --git a/tests/ui/const-generics/defaults/mismatch.stderr b/tests/ui/const-generics/defaults/mismatch.stderr index 52c54aace..9c4f0bc95 100644 --- a/tests/ui/const-generics/defaults/mismatch.stderr +++ b/tests/ui/const-generics/defaults/mismatch.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/mismatch.rs:7:26 | LL | let e: Example<13> = (); - | ----------- ^^ expected struct `Example`, found `()` + | ----------- ^^ expected `Example`, found `()` | | | expected due to this | @@ -13,7 +13,7 @@ error[E0308]: mismatched types --> $DIR/mismatch.rs:10:32 | LL | let e: Example2<u32, 13> = (); - | ----------------- ^^ expected struct `Example2`, found `()` + | ----------------- ^^ expected `Example2`, found `()` | | | expected due to this | @@ -24,7 +24,7 @@ error[E0308]: mismatched types --> $DIR/mismatch.rs:13:32 | LL | let e: Example3<13, u32> = (); - | ----------------- ^^ expected struct `Example3`, found `()` + | ----------------- ^^ expected `Example3`, found `()` | | | expected due to this | @@ -35,7 +35,7 @@ error[E0308]: mismatched types --> $DIR/mismatch.rs:16:26 | LL | let e: Example3<7> = (); - | ----------- ^^ expected struct `Example3`, found `()` + | ----------- ^^ expected `Example3<7>`, found `()` | | | expected due to this | @@ -46,7 +46,7 @@ error[E0308]: mismatched types --> $DIR/mismatch.rs:19:26 | LL | let e: Example4<7> = (); - | ----------- ^^ expected struct `Example4`, found `()` + | ----------- ^^ expected `Example4<7>`, found `()` | | | expected due to this | diff --git a/tests/ui/const-generics/defaults/wfness.stderr b/tests/ui/const-generics/defaults/wfness.stderr index 25038f830..bd9bfcd7d 100644 --- a/tests/ui/const-generics/defaults/wfness.stderr +++ b/tests/ui/const-generics/defaults/wfness.stderr @@ -23,7 +23,7 @@ note: required by a bound in `WhereClause` --> $DIR/wfness.rs:8:9 | LL | struct WhereClause<const N: u8 = 2> - | ----------- required by a bound in this + | ----------- required by a bound in this struct LL | where LL | (): Trait<N>; | ^^^^^^^^ required by this bound in `WhereClause` diff --git a/tests/ui/const-generics/early/invalid-const-arguments.stderr b/tests/ui/const-generics/early/invalid-const-arguments.stderr index b46e7e24f..cee34e3b7 100644 --- a/tests/ui/const-generics/early/invalid-const-arguments.stderr +++ b/tests/ui/const-generics/early/invalid-const-arguments.stderr @@ -49,12 +49,9 @@ error[E0747]: type provided when a constant was expected --> $DIR/invalid-const-arguments.rs:10:19 | LL | impl<N> Foo for B<N> {} - | ^ - | -help: consider changing this type parameter to be a `const` generic - | -LL | impl<const N: u8> Foo for B<N> {} - | ~~~~~~~~~~~ + | - ^ + | | + | help: consider changing this type parameter to a const parameter: `const N: u8` error[E0747]: unresolved item provided when a constant was expected --> $DIR/invalid-const-arguments.rs:14:32 diff --git a/tests/ui/const-generics/ensure_is_evaluatable.stderr b/tests/ui/const-generics/ensure_is_evaluatable.stderr index bf6c35ad8..ab2871ff2 100644 --- a/tests/ui/const-generics/ensure_is_evaluatable.stderr +++ b/tests/ui/const-generics/ensure_is_evaluatable.stderr @@ -9,7 +9,7 @@ note: required by a bound in `bar` --> $DIR/ensure_is_evaluatable.rs:15:10 | LL | fn bar<const N: usize>() -> [(); N] - | --- required by a bound in this + | --- required by a bound in this function LL | where LL | [(); N + 1]:, | ^^^^^ required by this bound in `bar` diff --git a/tests/ui/const-generics/fn_with_two_const_inputs.stderr b/tests/ui/const-generics/fn_with_two_const_inputs.stderr index 614e7e0d2..c124010aa 100644 --- a/tests/ui/const-generics/fn_with_two_const_inputs.stderr +++ b/tests/ui/const-generics/fn_with_two_const_inputs.stderr @@ -9,7 +9,7 @@ note: required by a bound in `bar` --> $DIR/fn_with_two_const_inputs.rs:18:10 | LL | fn bar<const N: usize>() -> [(); N] - | --- required by a bound in this + | --- required by a bound in this function LL | where LL | [(); N + 1]:, | ^^^^^ required by this bound in `bar` diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.rs new file mode 100644 index 000000000..fd52fc355 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.rs @@ -0,0 +1,18 @@ +// checks that when we relate a `Expr::Binop` we also relate the types of the +// const arguments. +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +struct Bar<const B: bool>; + +const fn make_generic(_: usize, a: bool) -> bool { + a +} + +fn foo<const N: usize>() -> Bar<{ make_generic(N, true == false) }> { + Bar::<{ make_generic(N, 1_u8 == 0_u8) }> + //~^ error: mismatched types + //~| error: unconstrained generic constant +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.stderr new file mode 100644 index 000000000..ba824e84a --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/relate_binop_arg_tys.rs:13:5 + | +LL | Bar::<{ make_generic(N, 1_u8 == 0_u8) }> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{ make_generic(N, true == false) }`, found `{ make_generic(N, 1_u8 == 0_u8) }` + | + = note: expected constant `{ make_generic(N, true == false) }` + found constant `{ make_generic(N, 1_u8 == 0_u8) }` + +error: unconstrained generic constant + --> $DIR/relate_binop_arg_tys.rs:13:11 + | +LL | Bar::<{ make_generic(N, 1_u8 == 0_u8) }> + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); { make_generic(N, 1_u8 == 0_u8) }]:` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.rs new file mode 100644 index 000000000..bef9d4b9e --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.rs @@ -0,0 +1,12 @@ +// checks that when we relate a `Expr::Cast` we also relate the type of the +// const argument. +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +fn foo<const N: usize>() -> [(); (true as usize) + N] { + [(); (1_u8 as usize) + N] + //~^ error: mismatched types + //~| error: unconstrained generic constant +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.stderr b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.stderr new file mode 100644 index 000000000..d3ba870a2 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.stderr @@ -0,0 +1,20 @@ +error[E0308]: mismatched types + --> $DIR/relate_cast_arg_ty.rs:7:5 + | +LL | [(); (1_u8 as usize) + N] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `(true as usize) + N`, found `(1_u8 as usize) + N` + | + = note: expected constant `(true as usize) + N` + found constant `(1_u8 as usize) + N` + +error: unconstrained generic constant + --> $DIR/relate_cast_arg_ty.rs:7:10 + | +LL | [(); (1_u8 as usize) + N] + | ^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); (1_u8 as usize) + N]:` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_1.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_1.rs new file mode 100644 index 000000000..1e2484118 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_1.rs @@ -0,0 +1,30 @@ +// check-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +// issue #107899 +// We end up relating `Const(ty: size_of<?0>, kind: Value(Branch([])))` with +// `Const(ty: size_of<T>, kind: Value(Branch([])))` which if you were to `==` +// the `ty` fields would return `false` and ICE. This test checks that we use +// actual semantic equality that takes into account aliases and infer vars. + +use std::mem::size_of; + +trait X<T> { + fn f(self); + fn g(self); +} + +struct Y; + +impl<T> X<T> for Y +where + [(); size_of::<T>()]: Sized, +{ + fn f(self) { + self.g(); + } + fn g(self) {} +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_2.rs b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_2.rs new file mode 100644 index 000000000..91a8a7c4a --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_2.rs @@ -0,0 +1,151 @@ +// check-pass +#![feature(inline_const, generic_const_exprs)] +#![allow(incomplete_features)] +use std::marker::PhantomData; + +pub struct Equal<const T: usize, const R: usize>(); +pub trait True {} +impl<const T: usize> True for Equal<T, T> {} + +// replacement for generativity +pub struct Id<'id>(PhantomData<fn(&'id ()) -> &'id ()>); +pub struct Guard<'id>(Id<'id>); +fn make_guard<'id>(i: &'id Id<'id>) -> Guard<'id> { + Guard(Id(PhantomData)) +} + +impl<'id> Into<Id<'id>> for Guard<'id> { + fn into(self) -> Id<'id> { + self.0 + } +} + +pub struct Arena<'life> { + bytes: *mut [u8], + //bitmap: RefCell<RoaringBitmap>, + _token: PhantomData<Id<'life>>, +} + +#[repr(transparent)] +pub struct Item<'life, T> { + data: T, + _phantom: PhantomData<Id<'life>>, +} + +#[repr(transparent)] +pub struct Token<'life, 'borrow, 'compact, 'reborrow, T> +where + 'life: 'reborrow, + T: Tokenize<'life, 'borrow, 'compact, 'reborrow>, +{ + //ptr: *mut <T as Tokenize>::Tokenized, + ptr: core::ptr::NonNull<T::Tokenized>, + _phantom: PhantomData<Id<'life>>, + _compact: PhantomData<&'borrow Guard<'compact>>, + _result: PhantomData<&'reborrow T::Untokenized>, +} + +impl<'life> Arena<'life> { + pub fn tokenize<'before, 'compact, 'borrow, 'reborrow, T, U>( + &self, + guard: &'borrow Guard<'compact>, + item: Item<'life, &'before mut T>, + ) -> Token<'life, 'borrow, 'compact, 'reborrow, U> + where + T: Tokenize<'life, 'borrow, 'compact, 'reborrow, Untokenized = U>, + T::Untokenized: Tokenize<'life, 'borrow, 'compact, 'reborrow>, + Equal<{ core::mem::size_of::<T>() }, { core::mem::size_of::<U>() }>: True, + 'compact: 'borrow, + 'life: 'reborrow, + 'life: 'compact, + 'life: 'borrow, + // 'borrow: 'before ?? + { + let dst = item.data as *mut T as *mut T::Tokenized; + Token { + ptr: core::ptr::NonNull::new(dst as *mut _).unwrap(), + _phantom: PhantomData, + _compact: PhantomData, + _result: PhantomData, + } + } +} + +pub trait Tokenize<'life, 'borrow, 'compact, 'reborrow> +where + 'compact: 'borrow, + 'life: 'reborrow, + 'life: 'borrow, + 'life: 'compact, +{ + type Tokenized; + type Untokenized; + const TO: fn(&Arena<'life>, &'borrow Guard<'compact>, Self) -> Self::Tokenized; + const FROM: fn(&'reborrow Arena<'life>, Self::Tokenized) -> Self::Untokenized; +} + +macro_rules! tokenize { + ($to:expr, $from:expr) => { + const TO: fn(&Arena<'life>, &'borrow Guard<'compact>, Self) -> Self::Tokenized = $to; + const FROM: fn(&'reborrow Arena<'life>, Self::Tokenized) -> Self::Untokenized = $from; + }; +} + +struct Foo<'life, 'borrow>(Option<Item<'life, &'borrow mut Bar>>); +struct TokenFoo<'life, 'borrow, 'compact, 'reborrow>( + Option<Token<'life, 'borrow, 'compact, 'reborrow, Bar>>, +); +struct Bar(u8); + +impl<'life, 'before, 'borrow, 'compact, 'reborrow> Tokenize<'life, 'borrow, 'compact, 'reborrow> + for Foo<'life, 'before> +where + 'compact: 'borrow, + 'life: 'reborrow, + 'life: 'borrow, + 'life: 'compact, +{ + type Tokenized = TokenFoo<'life, 'borrow, 'compact, 'reborrow>; + type Untokenized = Foo<'life, 'reborrow>; + tokenize!(foo_to, foo_from); +} + +impl<'life, 'borrow, 'compact, 'reborrow> Tokenize<'life, 'borrow, 'compact, 'reborrow> for Bar +where + 'compact: 'borrow, + 'life: 'reborrow, + 'life: 'borrow, + 'life: 'compact, +{ + type Tokenized = Bar; + type Untokenized = Bar; + tokenize!(bar_to, bar_from); +} + +fn bar_to<'life, 'borrow, 'compact>( + arena: &Arena<'life>, + guard: &'borrow Guard<'compact>, + s: Bar, +) -> Bar { + s +} +fn bar_from<'life, 'reborrow>(arena: &'reborrow Arena<'life>, s: Bar) -> Bar { + s +} + +fn foo_to<'life, 'borrow, 'compact, 'reborrow, 'before>( + arena: &'before Arena<'life>, + guard: &'borrow Guard<'compact>, + s: Foo<'life, 'before>, +) -> TokenFoo<'life, 'borrow, 'compact, 'reborrow> { + let Foo(bar) = s; + TokenFoo(bar.map(|bar| arena.tokenize(guard, bar))) +} +fn foo_from<'life, 'borrow, 'compact, 'reborrow>( + arena: &'reborrow Arena<'life>, + s: TokenFoo<'life, 'borrow, 'compact, 'reborrow>, +) -> Foo<'life, 'reborrow> { + Foo(s.0.map(|bar| panic!())) +} + +fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/issue-102768.rs b/tests/ui/const-generics/generic_const_exprs/issue-102768.rs index 7aea0d30d..18a9b53cf 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-102768.rs +++ b/tests/ui/const-generics/generic_const_exprs/issue-102768.rs @@ -7,8 +7,8 @@ trait X { const _: () = { fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {} - //~^ ERROR this associated type takes 1 lifetime argument but 0 lifetime arguments - //~| ERROR this associated type takes 0 generic arguments but 1 generic argument + //~^ ERROR associated type takes 1 lifetime argument but 0 lifetime arguments + //~| ERROR associated type takes 0 generic arguments but 1 generic argument }; fn main() {} diff --git a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr index 8278edabe..175d54e41 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-102768.stderr @@ -1,4 +1,4 @@ -error[E0107]: this associated type takes 1 lifetime argument but 0 lifetime arguments were supplied +error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {} @@ -14,7 +14,7 @@ help: add missing lifetime argument LL | fn f2<'a>(arg: Box<dyn X<Y<'_, 1> = &'a ()>>) {} | +++ -error[E0107]: this associated type takes 0 generic arguments but 1 generic argument was supplied +error[E0107]: associated type takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-102768.rs:9:30 | LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {} diff --git a/tests/ui/const-generics/generic_const_exprs/issue-105608.stderr b/tests/ui/const-generics/generic_const_exprs/issue-105608.stderr index 0be4c43da..827dd59d9 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-105608.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-105608.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/issue-105608.rs:13:22 | LL | Combination::<0>.and::<_>().and::<_>(); - | ^^^ cannot infer type of the type parameter `M` declared on the associated function `and` + | ^^^ cannot infer type of the type parameter `M` declared on the method `and` | help: consider specifying the generic argument | diff --git a/tests/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr b/tests/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr index f2fddfbfb..996b75493 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-72819-generic-in-const-eval.full.stderr @@ -10,7 +10,7 @@ note: required by a bound in `Arr` --> $DIR/issue-72819-generic-in-const-eval.rs:8:39 | LL | struct Arr<const N: usize> - | --- required by a bound in this + | --- required by a bound in this struct LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, | ^^^^^^ required by this bound in `Arr` @@ -26,7 +26,7 @@ note: required by a bound in `Arr` --> $DIR/issue-72819-generic-in-const-eval.rs:8:39 | LL | struct Arr<const N: usize> - | --- required by a bound in this + | --- required by a bound in this struct LL | where Assert::<{N < usize::MAX / 2}>: IsTrue, | ^^^^^^ required by this bound in `Arr` diff --git a/tests/ui/const-generics/generic_const_exprs/issue-76595.stderr b/tests/ui/const-generics/generic_const_exprs/issue-76595.stderr index c587a7e15..302da5965 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-76595.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-76595.stderr @@ -1,4 +1,4 @@ -error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied +error[E0107]: function takes 2 generic arguments but 1 generic argument was supplied --> $DIR/issue-76595.rs:15:5 | LL | test::<2>(); diff --git a/tests/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr b/tests/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr index 9baf9790e..511ae58a1 100644 --- a/tests/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr +++ b/tests/ui/const-generics/generic_const_exprs/issue-79518-default_trait_method_normalization.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-79518-default_trait_method_normalization.rs:16:32 | LL | Self::AssocInstance == [(); std::mem::size_of::<Self::Assoc>()]; - | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found array `[(); std::mem::size_of::<Self::Assoc>()]` + | ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected associated type, found `[(); std::mem::size_of::<Self::Assoc>()]` | | | expected because this is `<Self as Foo>::Assoc` | diff --git a/tests/ui/const-generics/generic_const_exprs/obligation-cause.stderr b/tests/ui/const-generics/generic_const_exprs/obligation-cause.stderr index a253ec676..63e6fcc8e 100644 --- a/tests/ui/const-generics/generic_const_exprs/obligation-cause.stderr +++ b/tests/ui/const-generics/generic_const_exprs/obligation-cause.stderr @@ -10,7 +10,7 @@ note: required by a bound in `g` --> $DIR/obligation-cause.rs:13:44 | LL | fn g<T>() - | - required by a bound in this + | - required by a bound in this function ... LL | Is<{ std::mem::size_of::<T>() == 0 }>: True, | ^^^^ required by this bound in `g` diff --git a/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs b/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs new file mode 100644 index 000000000..0ba0c5a72 --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/single-satisfied-ConstEvaluatable-in-probe.rs @@ -0,0 +1,39 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(generic_const_exprs)] + +use std::marker::PhantomData; + +pub trait Bytes { + const BYTES: usize; +} + +#[derive(Clone, Debug)] +pub struct Conster<OT> +where + OT: Bytes, + [(); OT::BYTES]: Sized, +{ + _offset_type: PhantomData<fn(OT) -> OT>, +} + +impl<OT> Conster<OT> +where + OT: Bytes, + [(); OT::BYTES]: Sized, +{ + pub fn new() -> Self { + Conster { _offset_type: PhantomData } + } +} + +pub fn make_conster<COT>() -> Conster<COT> +where + COT: Bytes, + [(); COT::BYTES]: Sized, +{ + Conster::new() +} + +fn main() {} diff --git a/tests/ui/const-generics/incorrect-number-of-const-args.stderr b/tests/ui/const-generics/incorrect-number-of-const-args.stderr index a845454f7..01ac4e69a 100644 --- a/tests/ui/const-generics/incorrect-number-of-const-args.stderr +++ b/tests/ui/const-generics/incorrect-number-of-const-args.stderr @@ -1,4 +1,4 @@ -error[E0107]: this function takes 2 generic arguments but 1 generic argument was supplied +error[E0107]: function takes 2 generic arguments but 1 generic argument was supplied --> $DIR/incorrect-number-of-const-args.rs:6:5 | LL | foo::<0>(); @@ -16,7 +16,7 @@ help: add missing generic argument LL | foo::<0, Y>(); | +++ -error[E0107]: this function takes 2 generic arguments but 3 generic arguments were supplied +error[E0107]: function takes 2 generic arguments but 3 generic arguments were supplied --> $DIR/incorrect-number-of-const-args.rs:9:5 | LL | foo::<0, 0, 0>(); diff --git a/tests/ui/const-generics/infer/method-chain.stderr b/tests/ui/const-generics/infer/method-chain.stderr index ff6da535b..f527ee6e4 100644 --- a/tests/ui/const-generics/infer/method-chain.stderr +++ b/tests/ui/const-generics/infer/method-chain.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/method-chain.rs:15:33 | LL | Foo.bar().bar().bar().bar().baz(); - | ^^^ cannot infer the value of the const parameter `N` declared on the associated function `baz` + | ^^^ cannot infer the value of the const parameter `N` declared on the method `baz` | help: consider specifying the generic argument | diff --git a/tests/ui/const-generics/infer/uninferred-consts.stderr b/tests/ui/const-generics/infer/uninferred-consts.stderr index 3980ecea8..20daf4570 100644 --- a/tests/ui/const-generics/infer/uninferred-consts.stderr +++ b/tests/ui/const-generics/infer/uninferred-consts.stderr @@ -2,7 +2,7 @@ error[E0282]: type annotations needed --> $DIR/uninferred-consts.rs:9:9 | LL | Foo.foo(); - | ^^^ cannot infer the value of the const parameter `A` declared on the associated function `foo` + | ^^^ cannot infer the value of the const parameter `A` declared on the method `foo` | help: consider specifying the generic arguments | diff --git a/tests/ui/const-generics/invalid-const-arg-for-type-param.rs b/tests/ui/const-generics/invalid-const-arg-for-type-param.rs index 7d4dc98f3..bf10f471d 100644 --- a/tests/ui/const-generics/invalid-const-arg-for-type-param.rs +++ b/tests/ui/const-generics/invalid-const-arg-for-type-param.rs @@ -4,11 +4,11 @@ struct S; fn main() { let _: u32 = 5i32.try_into::<32>().unwrap(); - //~^ ERROR this associated function takes + //~^ ERROR method takes S.f::<0>(); //~^ ERROR no method named `f` S::<0>; - //~^ ERROR this struct takes 0 + //~^ ERROR struct takes 0 } diff --git a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr index 8c76ca690..4a649d8a7 100644 --- a/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr +++ b/tests/ui/const-generics/invalid-const-arg-for-type-param.stderr @@ -1,4 +1,4 @@ -error[E0107]: this associated function takes 0 generic arguments but 1 generic argument was supplied +error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied --> $DIR/invalid-const-arg-for-type-param.rs:6:23 | LL | let _: u32 = 5i32.try_into::<32>().unwrap(); @@ -23,7 +23,7 @@ LL | struct S; LL | S.f::<0>(); | ^ method not found in `S` -error[E0107]: this struct takes 0 generic arguments but 1 generic argument was supplied +error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied --> $DIR/invalid-const-arg-for-type-param.rs:12:5 | LL | S::<0>; diff --git a/tests/ui/const-generics/invalid-constant-in-args.rs b/tests/ui/const-generics/invalid-constant-in-args.rs index 7419d4a25..fd259197d 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.rs +++ b/tests/ui/const-generics/invalid-constant-in-args.rs @@ -2,5 +2,5 @@ use std::cell::Cell; fn main() { let _: Cell<&str, "a"> = Cell::new(""); - //~^ ERROR this struct takes 1 generic argument but 2 generic arguments were supplied + //~^ ERROR struct takes 1 generic argument but 2 generic arguments were supplied } diff --git a/tests/ui/const-generics/invalid-constant-in-args.stderr b/tests/ui/const-generics/invalid-constant-in-args.stderr index 993b63518..2545cc6f3 100644 --- a/tests/ui/const-generics/invalid-constant-in-args.stderr +++ b/tests/ui/const-generics/invalid-constant-in-args.stderr @@ -1,4 +1,4 @@ -error[E0107]: this struct takes 1 generic argument but 2 generic arguments were supplied +error[E0107]: struct takes 1 generic argument but 2 generic arguments were supplied --> $DIR/invalid-constant-in-args.rs:4:12 | LL | let _: Cell<&str, "a"> = Cell::new(""); diff --git a/tests/ui/const-generics/issues/issue-105821.rs b/tests/ui/const-generics/issues/issue-105821.rs new file mode 100644 index 000000000..cba2e22c4 --- /dev/null +++ b/tests/ui/const-generics/issues/issue-105821.rs @@ -0,0 +1,23 @@ +// check-pass + +#![allow(incomplete_features)] +#![feature(adt_const_params, const_ptr_read, generic_const_exprs)] +#![allow(dead_code)] + +const fn catone<const M: usize>(_a: &[u8; M]) -> [u8; M + 1] +where + [(); M + 1]:, +{ + unimplemented!() +} + +struct Catter<const A: &'static [u8]>; +impl<const A: &'static [u8]> Catter<A> +where + [(); A.len() + 1]:, +{ + const ZEROS: &'static [u8; A.len()] = &[0_u8; A.len()]; + const R: &'static [u8] = &catone(Self::ZEROS); +} + +fn main() {} diff --git a/tests/ui/const-generics/issues/issue-56445-1.min.stderr b/tests/ui/const-generics/issues/issue-56445-1.min.stderr index 43a5df117..9f8801341 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.min.stderr +++ b/tests/ui/const-generics/issues/issue-56445-1.min.stderr @@ -6,7 +6,7 @@ LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); | = note: for more information, see issue #74052 <https://github.com/rust-lang/rust/issues/74052> -error: `&'static str` is forbidden as the type of a const generic parameter +error: `&str` is forbidden as the type of a const generic parameter --> $DIR/issue-56445-1.rs:9:25 | LL | struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); diff --git a/tests/ui/const-generics/issues/issue-56445-1.rs b/tests/ui/const-generics/issues/issue-56445-1.rs index 13eb2ea9f..0741c3796 100644 --- a/tests/ui/const-generics/issues/issue-56445-1.rs +++ b/tests/ui/const-generics/issues/issue-56445-1.rs @@ -8,6 +8,6 @@ use std::marker::PhantomData; struct Bug<'a, const S: &'a str>(PhantomData<&'a ()>); //~^ ERROR: use of non-static lifetime `'a` in const generic -//[min]~| ERROR: `&'static str` is forbidden as the type of a const generic parameter +//[min]~| ERROR: `&str` is forbidden as the type of a const generic parameter impl Bug<'_, ""> {} diff --git a/tests/ui/const-generics/issues/issue-67185-2.stderr b/tests/ui/const-generics/issues/issue-67185-2.stderr index c7be8e14a..032b0c410 100644 --- a/tests/ui/const-generics/issues/issue-67185-2.stderr +++ b/tests/ui/const-generics/issues/issue-67185-2.stderr @@ -35,7 +35,7 @@ note: required by a bound in `Foo` --> $DIR/issue-67185-2.rs:15:25 | LL | trait Foo - | --- required by a bound in this + | --- required by a bound in this trait ... LL | <u8 as Baz>::Quaks: Bar, | ^^^ required by this bound in `Foo` @@ -53,7 +53,7 @@ note: required by a bound in `Foo` --> $DIR/issue-67185-2.rs:14:30 | LL | trait Foo - | --- required by a bound in this + | --- required by a bound in this trait LL | where LL | [<u8 as Baz>::Quaks; 2]: Bar, | ^^^ required by this bound in `Foo` @@ -71,7 +71,7 @@ note: required by a bound in `Foo` --> $DIR/issue-67185-2.rs:14:30 | LL | trait Foo - | --- required by a bound in this + | --- required by a bound in this trait LL | where LL | [<u8 as Baz>::Quaks; 2]: Bar, | ^^^ required by this bound in `Foo` @@ -89,7 +89,7 @@ note: required by a bound in `Foo` --> $DIR/issue-67185-2.rs:15:25 | LL | trait Foo - | --- required by a bound in this + | --- required by a bound in this trait ... LL | <u8 as Baz>::Quaks: Bar, | ^^^ required by this bound in `Foo` diff --git a/tests/ui/const-generics/issues/issue-67945-1.full.stderr b/tests/ui/const-generics/issues/issue-67945-1.full.stderr index 8e18fcdff..8879aec35 100644 --- a/tests/ui/const-generics/issues/issue-67945-1.full.stderr +++ b/tests/ui/const-generics/issues/issue-67945-1.full.stderr @@ -5,7 +5,7 @@ LL | struct Bug<S> { | - this type parameter ... LL | let x: S = MaybeUninit::uninit(); - | - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found union `MaybeUninit` + | - ^^^^^^^^^^^^^^^^^^^^^ expected type parameter `S`, found `MaybeUninit<_>` | | | expected due to this | diff --git a/tests/ui/const-generics/issues/issue-73260.rs b/tests/ui/const-generics/issues/issue-73260.rs index d762f9c8b..aa7ae90a3 100644 --- a/tests/ui/const-generics/issues/issue-73260.rs +++ b/tests/ui/const-generics/issues/issue-73260.rs @@ -1,4 +1,3 @@ -// compile-flags: -Zsave-analysis #![feature(generic_const_exprs)] #![allow(incomplete_features)] struct Arr<const N: usize> diff --git a/tests/ui/const-generics/issues/issue-73260.stderr b/tests/ui/const-generics/issues/issue-73260.stderr index 7670032e5..c56b45cc8 100644 --- a/tests/ui/const-generics/issues/issue-73260.stderr +++ b/tests/ui/const-generics/issues/issue-73260.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-73260.rs:16:12 + --> $DIR/issue-73260.rs:15:12 | LL | let x: Arr<{usize::MAX}> = Arr {}; | ^^^^^^^^^^^^^^^^^ expected `false`, found `true` @@ -7,16 +7,16 @@ LL | let x: Arr<{usize::MAX}> = Arr {}; = note: expected constant `false` found constant `true` note: required by a bound in `Arr` - --> $DIR/issue-73260.rs:6:37 + --> $DIR/issue-73260.rs:5:37 | LL | struct Arr<const N: usize> - | --- required by a bound in this + | --- required by a bound in this struct LL | where LL | Assert::<{N < usize::MAX / 2}>: IsTrue, | ^^^^^^ required by this bound in `Arr` error[E0308]: mismatched types - --> $DIR/issue-73260.rs:16:32 + --> $DIR/issue-73260.rs:15:32 | LL | let x: Arr<{usize::MAX}> = Arr {}; | ^^^ expected `false`, found `true` @@ -24,10 +24,10 @@ LL | let x: Arr<{usize::MAX}> = Arr {}; = note: expected constant `false` found constant `true` note: required by a bound in `Arr` - --> $DIR/issue-73260.rs:6:37 + --> $DIR/issue-73260.rs:5:37 | LL | struct Arr<const N: usize> - | --- required by a bound in this + | --- required by a bound in this struct LL | where LL | Assert::<{N < usize::MAX / 2}>: IsTrue, | ^^^^^^ required by this bound in `Arr` diff --git a/tests/ui/const-generics/issues/issue-79674.stderr b/tests/ui/const-generics/issues/issue-79674.stderr index 02b48b55f..ba7fd2ca3 100644 --- a/tests/ui/const-generics/issues/issue-79674.stderr +++ b/tests/ui/const-generics/issues/issue-79674.stderr @@ -10,7 +10,7 @@ note: required by a bound in `requires_distinct` --> $DIR/issue-79674.rs:23:37 | LL | fn requires_distinct<A, B>(_a: A, _b: B) where - | ----------------- required by a bound in this + | ----------------- required by a bound in this function LL | A: MiniTypeId, B: MiniTypeId, LL | Lift<{is_same_type::<A, B>()}>: IsFalse {} | ^^^^^^^ required by this bound in `requires_distinct` diff --git a/tests/ui/const-generics/issues/issue-86530.stderr b/tests/ui/const-generics/issues/issue-86530.stderr index c63857b23..620ed4f0f 100644 --- a/tests/ui/const-generics/issues/issue-86530.stderr +++ b/tests/ui/const-generics/issues/issue-86530.stderr @@ -10,7 +10,7 @@ note: required by a bound in `z` --> $DIR/issue-86530.rs:10:8 | LL | fn z<T>(t: T) - | - required by a bound in this + | - required by a bound in this function LL | where LL | T: X, | ^ required by this bound in `z` diff --git a/tests/ui/const-generics/issues/issue-87493.rs b/tests/ui/const-generics/issues/issue-87493.rs index d8599ab22..80472e6bd 100644 --- a/tests/ui/const-generics/issues/issue-87493.rs +++ b/tests/ui/const-generics/issues/issue-87493.rs @@ -7,7 +7,7 @@ where S: MyTrait, T: MyTrait<Assoc == S::Assoc>, //~^ ERROR: expected one of `,` or `>`, found `==` - //~| ERROR: this trait takes 0 generic arguments but 1 generic argument was supplied + //~| ERROR: trait takes 0 generic arguments but 1 generic argument was supplied { } diff --git a/tests/ui/const-generics/issues/issue-87493.stderr b/tests/ui/const-generics/issues/issue-87493.stderr index 653afae21..73bd6ed73 100644 --- a/tests/ui/const-generics/issues/issue-87493.stderr +++ b/tests/ui/const-generics/issues/issue-87493.stderr @@ -9,7 +9,7 @@ help: if you meant to use an associated type binding, replace `==` with `=` LL | T: MyTrait<Assoc = S::Assoc>, | ~ -error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied +error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied --> $DIR/issue-87493.rs:8:8 | LL | T: MyTrait<Assoc == S::Assoc>, diff --git a/tests/ui/const-generics/min_const_generics/macro-fail.stderr b/tests/ui/const-generics/min_const_generics/macro-fail.stderr index 9f73b91aa..cc629fd92 100644 --- a/tests/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/tests/ui/const-generics/min_const_generics/macro-fail.stderr @@ -8,7 +8,7 @@ LL | fn make_marker() -> impl Marker<gimme_a_const!(marker)> { | in this macro invocation ... LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type + | ^ expected type | = note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -22,26 +22,21 @@ LL | Example::<gimme_a_const!(marker)> | in this macro invocation ... LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type + | ^ expected type | = note: this error originates in the macro `gimme_a_const` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected type, found `{` --> $DIR/macro-fail.rs:4:10 | -LL | () => {{ - | __________^ -LL | | -LL | | const X: usize = 1337; -LL | | X -LL | | }} - | |___^ expected type +LL | () => {{ + | ^ expected type ... -LL | let _fail = Example::<external_macro!()>; - | ----------------- - | | - | this macro call doesn't expand to a type - | in this macro invocation +LL | let _fail = Example::<external_macro!()>; + | ----------------- + | | + | this macro call doesn't expand to a type + | in this macro invocation | = note: this error originates in the macro `external_macro` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/tests/ui/const-generics/nested-type.min.stderr b/tests/ui/const-generics/nested-type.min.stderr index cff02b0d4..257a9e31e 100644 --- a/tests/ui/const-generics/nested-type.min.stderr +++ b/tests/ui/const-generics/nested-type.min.stderr @@ -1,3 +1,11 @@ +error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17>::value` in constants + --> $DIR/nested-type.rs:15:5 + | +LL | Foo::<17>::value() + | ^^^^^^^^^^^^^^^^^^ + | + = note: calls in constants are limited to constant functions, tuple structs and tuple variants + error: `[u8; { struct Foo<const N: usize>; @@ -24,5 +32,6 @@ LL | | }]>; = note: the only supported types are integers, `bool` and `char` = help: more complex types are supported with `#![feature(adt_const_params)]` -error: aborting due to previous error +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/const-generics/nested-type.rs b/tests/ui/const-generics/nested-type.rs index 742340f43..5240f5c3b 100644 --- a/tests/ui/const-generics/nested-type.rs +++ b/tests/ui/const-generics/nested-type.rs @@ -13,7 +13,7 @@ struct Foo<const N: [u8; { //[min]~ ERROR `[u8; _]` is forbidden } Foo::<17>::value() - //[full]~^ ERROR cannot call non-const fn + //~^ ERROR cannot call non-const fn }]>; fn main() {} diff --git a/tests/ui/const-generics/occurs-check/unused-substs-1.stderr b/tests/ui/const-generics/occurs-check/unused-substs-1.stderr index a3c011d92..51ef354e3 100644 --- a/tests/ui/const-generics/occurs-check/unused-substs-1.stderr +++ b/tests/ui/const-generics/occurs-check/unused-substs-1.stderr @@ -9,7 +9,7 @@ note: required by a bound in `A` --> $DIR/unused-substs-1.rs:9:11 | LL | struct A<const N: usize> - | - required by a bound in this + | - required by a bound in this unit struct LL | where LL | A<N>: Bar<N>; | ^^^^^^ required by this bound in `A` diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs index b126b2485..79743abe4 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.rs @@ -7,7 +7,7 @@ struct Bar; const T: usize = 42; impl Foo<N = 3> for Bar { -//~^ ERROR this trait takes 1 generic argument but 0 generic arguments were supplied +//~^ ERROR trait takes 1 generic argument but 0 generic arguments were supplied //~| ERROR associated type bindings are not allowed here //~| ERROR associated const equality is incomplete fn do_x(&self) -> [u8; 3] { diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr index acfdde8e1..4f4e1aa3a 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013-no-kw.stderr @@ -7,7 +7,7 @@ LL | impl Foo<N = 3> for Bar { = note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable -error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied +error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-89013-no-kw.rs:9:6 | LL | impl Foo<N = 3> for Bar { diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013.rs b/tests/ui/const-generics/parser-error-recovery/issue-89013.rs index 9431779fa..335d0d94e 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013.rs +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013.rs @@ -8,7 +8,7 @@ const T: usize = 42; impl Foo<N = const 3> for Bar { //~^ ERROR expected lifetime, type, or constant, found keyword `const` -//~| ERROR this trait takes 1 generic +//~| ERROR trait takes 1 generic //~| ERROR associated type bindings are not allowed here //~| ERROR associated const equality is incomplete fn do_x(&self) -> [u8; 3] { diff --git a/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr b/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr index 583749a85..3d2b98feb 100644 --- a/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr +++ b/tests/ui/const-generics/parser-error-recovery/issue-89013.stderr @@ -19,7 +19,7 @@ LL | impl Foo<N = const 3> for Bar { = note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information = help: add `#![feature(associated_const_equality)]` to the crate attributes to enable -error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied +error[E0107]: trait takes 1 generic argument but 0 generic arguments were supplied --> $DIR/issue-89013.rs:9:6 | LL | impl Foo<N = const 3> for Bar { diff --git a/tests/ui/const-generics/type_mismatch.stderr b/tests/ui/const-generics/type_mismatch.stderr index 8d779bee2..b28ae8f7e 100644 --- a/tests/ui/const-generics/type_mismatch.stderr +++ b/tests/ui/const-generics/type_mismatch.stderr @@ -8,7 +8,7 @@ error[E0308]: mismatched types --> $DIR/type_mismatch.rs:5:26 | LL | fn bar<const N: u8>() -> [u8; N] {} - | --- ^^^^^^^ expected array `[u8; N]`, found `()` + | --- ^^^^^^^ expected `[u8; N]`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression diff --git a/tests/ui/const-generics/type_not_in_scope.stderr b/tests/ui/const-generics/type_not_in_scope.stderr index 16796acb3..5f45550a6 100644 --- a/tests/ui/const-generics/type_not_in_scope.stderr +++ b/tests/ui/const-generics/type_not_in_scope.stderr @@ -14,7 +14,7 @@ error[E0308]: mismatched types --> $DIR/type_not_in_scope.rs:7:33 | LL | fn getn<const N: cfg_attr>() -> [u8; N] {} - | ---- ^^^^^^^ expected array `[u8; N]`, found `()` + | ---- ^^^^^^^ expected `[u8; N]`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression diff --git a/tests/ui/const-generics/types-mismatch-const-args.full.stderr b/tests/ui/const-generics/types-mismatch-const-args.full.stderr index b6a22df74..13cd5d17d 100644 --- a/tests/ui/const-generics/types-mismatch-const-args.full.stderr +++ b/tests/ui/const-generics/types-mismatch-const-args.full.stderr @@ -11,7 +11,7 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:16:41 | LL | let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData }; - | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32` + | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `A<'_, u16, 2, 3>`, found `A<'_, u32, 2, 3>` | | | expected due to this | @@ -22,7 +22,7 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:18:41 | LL | let _: A<'a, u16, {4u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData }; - | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32` + | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `A<'_, u16, 4, 3>`, found `A<'_, u32, 2, 3>` | | | expected due to this | diff --git a/tests/ui/const-generics/types-mismatch-const-args.min.stderr b/tests/ui/const-generics/types-mismatch-const-args.min.stderr index 6ac93a08d..cae3adfa1 100644 --- a/tests/ui/const-generics/types-mismatch-const-args.min.stderr +++ b/tests/ui/const-generics/types-mismatch-const-args.min.stderr @@ -13,7 +13,7 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:16:41 | LL | let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData }; - | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32` + | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `A<'_, u16, 2, 3>`, found `A<'_, u32, 2, 3>` | | | expected due to this | @@ -24,7 +24,7 @@ error[E0308]: mismatched types --> $DIR/types-mismatch-const-args.rs:18:41 | LL | let _: A<'a, u16, {4u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData }; - | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `u16`, found `u32` + | -------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `A<'_, u16, 4, 3>`, found `A<'_, u32, 2, 3>` | | | expected due to this | diff --git a/tests/ui/const-generics/unify_with_nested_expr.stderr b/tests/ui/const-generics/unify_with_nested_expr.stderr index 8bab0dff7..d4d78b596 100644 --- a/tests/ui/const-generics/unify_with_nested_expr.stderr +++ b/tests/ui/const-generics/unify_with_nested_expr.stderr @@ -8,7 +8,7 @@ note: required by a bound in `bar` --> $DIR/unify_with_nested_expr.rs:14:10 | LL | fn bar<const N: usize>() - | --- required by a bound in this + | --- required by a bound in this function LL | where LL | [(); N + 1]:, | ^^^^^ required by this bound in `bar` diff --git a/tests/ui/const-generics/wrong-normalization.rs b/tests/ui/const-generics/wrong-normalization.rs new file mode 100644 index 000000000..f1ce317b3 --- /dev/null +++ b/tests/ui/const-generics/wrong-normalization.rs @@ -0,0 +1,19 @@ +// This test ensures that if implementation on projections is supported, +// it doesn't end in very weird cycle error. + +#![crate_type = "lib"] + +pub trait Identity { + type Identity: ?Sized; +} + +impl<T: ?Sized> Identity for T { + type Identity = Self; +} + +pub struct I8<const F: i8>; + +impl <I8<{i8::MIN}> as Identity>::Identity { +//~^ ERROR no nominal type found for inherent implementation + pub fn foo(&self) {} +} diff --git a/tests/ui/const-generics/wrong-normalization.stderr b/tests/ui/const-generics/wrong-normalization.stderr new file mode 100644 index 000000000..658a84066 --- /dev/null +++ b/tests/ui/const-generics/wrong-normalization.stderr @@ -0,0 +1,11 @@ +error[E0118]: no nominal type found for inherent implementation + --> $DIR/wrong-normalization.rs:16:1 + | +LL | impl <I8<{i8::MIN}> as Identity>::Identity { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type + | + = note: either implement a trait on it or create a newtype to wrap it instead + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0118`. |