From 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:50 +0200 Subject: Merging upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- .../const_kind_expr/relate_binop_arg_tys.rs | 18 +++ .../const_kind_expr/relate_binop_arg_tys.stderr | 20 +++ .../const_kind_expr/relate_cast_arg_ty.rs | 12 ++ .../const_kind_expr/relate_cast_arg_ty.stderr | 20 +++ .../const_kind_expr/relate_ty_with_infer_1.rs | 30 ++++ .../const_kind_expr/relate_ty_with_infer_2.rs | 151 +++++++++++++++++++++ 6 files changed, 251 insertions(+) create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_binop_arg_tys.stderr create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_cast_arg_ty.stderr create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_1.rs create mode 100644 tests/ui/const-generics/generic_const_exprs/const_kind_expr/relate_ty_with_infer_2.rs (limited to 'tests/ui/const-generics/generic_const_exprs/const_kind_expr') 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 fn make_generic(_: usize, a: bool) -> bool { + a +} + +fn foo() -> 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() -> [(); (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, kind: Value(Branch([])))` with +// `Const(ty: size_of, 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 { + fn f(self); + fn g(self); +} + +struct Y; + +impl X for Y +where + [(); size_of::()]: 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(); +pub trait True {} +impl True for Equal {} + +// replacement for generativity +pub struct Id<'id>(PhantomData &'id ()>); +pub struct Guard<'id>(Id<'id>); +fn make_guard<'id>(i: &'id Id<'id>) -> Guard<'id> { + Guard(Id(PhantomData)) +} + +impl<'id> Into> for Guard<'id> { + fn into(self) -> Id<'id> { + self.0 + } +} + +pub struct Arena<'life> { + bytes: *mut [u8], + //bitmap: RefCell, + _token: PhantomData>, +} + +#[repr(transparent)] +pub struct Item<'life, T> { + data: T, + _phantom: PhantomData>, +} + +#[repr(transparent)] +pub struct Token<'life, 'borrow, 'compact, 'reborrow, T> +where + 'life: 'reborrow, + T: Tokenize<'life, 'borrow, 'compact, 'reborrow>, +{ + //ptr: *mut ::Tokenized, + ptr: core::ptr::NonNull, + _phantom: PhantomData>, + _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::() }, { core::mem::size_of::() }>: 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>); +struct TokenFoo<'life, 'borrow, 'compact, 'reborrow>( + Option>, +); +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() {} -- cgit v1.2.3