forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconst-fns-are-early-bound.rs
145 lines (120 loc) · 3.65 KB
/
const-fns-are-early-bound.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//@ known-bug: #110395
// FIXME(effects) check-pass
//@ compile-flags: -Znext-solver
#![crate_type = "lib"]
#![allow(internal_features, incomplete_features)]
#![no_std]
#![no_core]
#![feature(
auto_traits,
const_trait_impl,
effects,
lang_items,
no_core,
staged_api,
unboxed_closures,
rustc_attrs,
marker_trait_attr,
)]
#![stable(feature = "minicore", since = "1.0.0")]
fn test() {
fn is_const_fn<F>(_: F)
where
F: const FnOnce<()>,
{
}
const fn foo() {}
is_const_fn(foo);
}
/// ---------------------------------------------------------------------- ///
/// Const fn trait definitions
#[const_trait]
#[lang = "fn"]
#[rustc_paren_sugar]
trait Fn<Args: Tuple>: ~const FnMut<Args> {
extern "rust-call" fn call(&self, args: Args) -> Self::Output;
}
#[const_trait]
#[lang = "fn_mut"]
#[rustc_paren_sugar]
trait FnMut<Args: Tuple>: ~const FnOnce<Args> {
extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output;
}
#[const_trait]
#[lang = "fn_once"]
#[rustc_paren_sugar]
trait FnOnce<Args: Tuple> {
#[lang = "fn_once_output"]
type Output;
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
/// ---------------------------------------------------------------------- ///
/// All this other stuff needed for core. Unrelated to test.
#[lang = "destruct"]
#[const_trait]
trait Destruct {}
#[lang = "freeze"]
unsafe auto trait Freeze {}
#[lang = "drop"]
#[const_trait]
trait Drop {
fn drop(&mut self);
}
#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
#[lang = "tuple_trait"]
trait Tuple {}
#[lang = "receiver"]
trait Receiver {}
impl<T: ?Sized> Receiver for &T {}
impl<T: ?Sized> Receiver for &mut T {}
#[stable(feature = "minicore", since = "1.0.0")]
pub mod effects {
use super::Sized;
#[lang = "EffectsNoRuntime"]
#[stable(feature = "minicore", since = "1.0.0")]
pub struct NoRuntime;
#[lang = "EffectsMaybe"]
#[stable(feature = "minicore", since = "1.0.0")]
pub struct Maybe;
#[lang = "EffectsRuntime"]
#[stable(feature = "minicore", since = "1.0.0")]
pub struct Runtime;
#[lang = "EffectsParam"]
#[stable(feature = "minicore", since = "1.0.0")]
pub struct Param<const RUNTIME: bool>;
#[lang = "EffectsCompat"]
#[stable(feature = "minicore", since = "1.0.0")]
pub trait Compat<#[rustc_runtime] const RUNTIME: bool> {}
#[stable(feature = "minicore", since = "1.0.0")]
impl Compat<false> for NoRuntime {}
#[stable(feature = "minicore", since = "1.0.0")]
impl Compat<true> for Runtime {}
#[stable(feature = "minicore", since = "1.0.0")]
impl<#[rustc_runtime] const RUNTIME: bool> Compat<RUNTIME> for Maybe {}
#[lang = "EffectsTyCompat"]
#[marker]
#[stable(feature = "minicore", since = "1.0.0")]
pub trait TyCompat<T: ?Sized> {}
#[stable(feature = "minicore", since = "1.0.0")]
impl<T: ?Sized> TyCompat<T> for T {}
#[stable(feature = "minicore", since = "1.0.0")]
impl<T: ?Sized> TyCompat<Maybe> for T {}
#[stable(feature = "minicore", since = "1.0.0")]
impl TyCompat<Param<true>> for Runtime {}
#[stable(feature = "minicore", since = "1.0.0")]
impl TyCompat<Runtime> for Param<true> {}
#[stable(feature = "minicore", since = "1.0.0")]
impl TyCompat<Param<false>> for NoRuntime {}
#[stable(feature = "minicore", since = "1.0.0")]
impl TyCompat<NoRuntime> for Param<false> {}
#[lang = "EffectsIntersection"]
#[stable(feature = "minicore", since = "1.0.0")]
pub trait Intersection {
#[lang = "EffectsIntersectionOutput"]
#[stable(feature = "minicore", since = "1.0.0")]
type Output: ?Sized;
}
}