This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn main() { | ||
enqueue::<(), _>(|_result| {}); | ||
} | ||
|
||
trait Query<'a> { | ||
type Result: 'a; | ||
fn execute() -> Self::Result; | ||
} | ||
|
||
impl<'a> Query<'a> for () { | ||
type Result = (); | ||
fn execute() -> () { | ||
() | ||
} | ||
} | ||
|
||
fn enqueue<Q: for<'q> Query<'q>, F: 'static + for<'r> FnOnce(<Q as Query<'r>>::Result)>(f: F) { | ||
let _: Box<dyn FnOnce()> = Box::new(move || f(Q::execute())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
union PtrRepr<T: ?Sized> { | ||
const_ptr: *const T, | ||
mut_ptr: *mut T, | ||
components: <T as Pointee>::Metadata | ||
} | ||
|
||
pub trait Pointee { | ||
type Metadata; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/bin/sh | ||
|
||
cat > out.rs <<'EOF' | ||
#![feature(auto_traits, negative_impls)] | ||
auto trait AutoTrait {} | ||
pub struct Struct<K, V> { | ||
k: K, | ||
v: V | ||
} | ||
impl<T> !AutoTrait for *const T {} | ||
impl<K, V> AutoTrait for Struct<K, V> | ||
where | ||
K: AutoTrait, | ||
V: AutoTrait, | ||
{ | ||
} | ||
impl AutoTrait for Struct<usize, *const usize> {} | ||
pub struct Wrap<'a> { | ||
inner: &'a Struct<usize, *const usize>, | ||
} | ||
fn main() {} | ||
EOF | ||
|
||
rustdoc out.rs --output-format json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
use std::ops::Index; | ||
|
||
pub trait Indexable { | ||
type Index; | ||
} | ||
struct Foo; | ||
struct Bar; | ||
impl Indexable for Foo { type Index = u8; } | ||
impl Indexable for Bar { type Index = u16; } | ||
|
||
pub trait Indexer<T: Indexable>: Index<T::Index, Output=T> {} | ||
|
||
struct Store; | ||
|
||
impl Index<u8> for Store { | ||
type Output = Foo; | ||
fn index(&self, _: u8) -> &Foo { panic!() } | ||
} | ||
impl Index<u16> for Store { | ||
type Output = Bar; | ||
fn index(&self, _: u16) -> &Bar { panic!() } | ||
} | ||
impl Indexer<Foo> for Store { } | ||
impl Indexer<Bar> for Store { } | ||
|
||
// implies StoreIndex: Index<u8, Output=Foo> + Index<u16, Output=Bar> | ||
trait StoreIndex: Indexer<Foo> + Indexer<Bar> {} | ||
|
||
impl StoreIndex for Store {} | ||
|
||
struct Collection { | ||
stores: Vec<Store>, | ||
} | ||
|
||
trait StoreCollection { | ||
fn get_store(&self, _: usize) -> Option<&dyn StoreIndex>; | ||
} | ||
|
||
impl StoreCollection for Collection { | ||
// Fails to compile: | ||
// expected: | ||
// Option<&dyn StoreIndex<Output = Bar, Output = Foo> | ||
// found: | ||
// Option<&Store> | ||
/* | ||
fn get_store(&self, i: usize) -> Option<&dyn StoreIndex> { | ||
self.stores.get(i) | ||
} | ||
*/ | ||
|
||
// ICE | ||
fn get_store(&self, i: usize) -> Option<&dyn StoreIndex> { | ||
if let Some(s) = self.stores.get(i) { | ||
Some(s as &dyn StoreIndex) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
// However, if the above is removed in favor of Indexing | ||
// type checking succeeds and the type of `&self.stores[i]` | ||
// is properly inferred | ||
/* | ||
fn get_store(&self, i: usize) -> Option<&dyn StoreIndex> { | ||
if i < self.stores.len() { | ||
Some(&self.stores[i]) | ||
} else { | ||
None | ||
} | ||
} | ||
*/ | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const _CONST: &[u8] = &f(&[], |_| {}); | ||
|
||
const fn f<F>(_: &[u8], _: F) -> &[u8] | ||
where | ||
F: FnMut(&u8), | ||
{ | ||
panic!() | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#![a = {enum b { |