Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add known-bug test for unsoundness issue #109380

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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::<()>([]));
}