diff options
| author | Evgenii Zheltonozhskii <zheltonozhskiy@gmail.com> | 2023-03-20 16:38:38 +0200 |
|---|---|---|
| committer | Evgenii Zheltonozhskii <zheltonozhskiy@gmail.com> | 2023-03-20 16:38:38 +0200 |
| commit | 009ed88789d5351c763cd6d1056fe2c1a040bf33 (patch) | |
| tree | 0cfdfa2d53180a27179f695ca4b2a51ade01ccba /tests | |
| parent | 9d0eac4d02da8a1b139ff3dca7fc4b458fb99eb6 (diff) | |
| download | rust-009ed88789d5351c763cd6d1056fe2c1a040bf33.tar.gz rust-009ed88789d5351c763cd6d1056fe2c1a040bf33.zip | |
Add `known-bug` test for typeid unsoundness issue
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs b/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs new file mode 100644 index 00000000000..64317b9d39a --- /dev/null +++ b/tests/ui/const-generics/generic_const_exprs/typeid-equality-by-subtyping.rs @@ -0,0 +1,52 @@ +// check-pass +// known-bug: #97156 + +#![feature(const_type_id, generic_const_exprs)] +#![allow(incomplete_features)] + +use std::any::TypeId; +// `One` and `Two` are currently considered equal types, as both +// `One <: Two` and `One :> Two` holds. +type One = for<'a> fn(&'a (), &'a ()); +type Two = for<'a, 'b> fn(&'a (), &'b ()); +trait AssocCt { + const ASSOC: usize; +} +const fn to_usize<T: 'static>() -> usize { + const WHAT_A_TYPE: TypeId = TypeId::of::<One>(); + match TypeId::of::<T>() { + WHAT_A_TYPE => 0, + _ => 1000, + } +} +impl<T: 'static> AssocCt for T { + const ASSOC: usize = to_usize::<T>(); +} + +trait WithAssoc<U> { + type Assoc; +} +impl<T: 'static> WithAssoc<()> for T where [(); <T as AssocCt>::ASSOC]: { + type Assoc = [u8; <T as AssocCt>::ASSOC]; +} + +fn generic<T: 'static, U>(x: <T as WithAssoc<U>>::Assoc) -> <T as WithAssoc<U>>::Assoc +where + [(); <T as AssocCt>::ASSOC]:, + T: WithAssoc<U>, +{ + x +} + + +fn unsound<T>(x: <One as WithAssoc<T>>::Assoc) -> <Two as WithAssoc<T>>::Assoc +where + One: WithAssoc<T>, +{ + let x: <Two as WithAssoc<T>>::Assoc = generic::<One, T>(x); + x +} + +fn main() { + println!("{:?}", unsound::<()>([])); +} |
