tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

148 lignes · 3101 octetsBrut · Historique
1// Attributes are checked where they are written (E0114), and a function
2// has a body unless it is `@extern` or a trait method (E0115).
3
4// Accepted.
5@extern c "ok_plain"
6fn plain :: x: Int -> Int
7
8@extern c "ok_options" blocking owned
9fn options :: x: Int -> Int / <ffi>
10
11@test
12@should_panic "boom"
13fn panics ::
14{
15 panic "boom"
16}
17
18@thread_safe
19@derive Eq
20@derive Show
21type Kind { Kind }
22
23@derivable size_of_constructor
24trait Size<a>
25{
26 fn size :: x: a -> Int
27}
28
29fn size_of_constructor :: c: Constructor<Int> -> Int
30{
31 1
32}
33
34// Unknown attributes, ABIs and options.
35@extrn c "typo" //~ ERROR E0114 unknown attribute `@extrn`
36
37fn typo :: //~ ERROR E0115 function `typo` has no body
38 x: Int
39 -> Int
40
41@extern rust "rusty" //~ ERROR E0114 unknown ABI `rust`
42
43fn rusty :: x: Int -> Int
44
45@extern c "slow" blockng //~ ERROR E0114 unknown `@extern` option `blockng`
46
47fn slow :: x: Int -> Int
48
49// Blocking pools (ADR 0005, Revision 2): `cpu` and `io` only.
50@extern c "on_cpu" (blocking cpu)
51fn on_cpu :: x: Int -> Int
52
53@extern c "on_io" (blocking io)
54fn on_io :: x: Int -> Int
55
56@extern c "on_gpu" (blocking gpu) //~ ERROR E0114 unknown blocking pool `gpu`
57
58fn on_gpu :: x: Int -> Int
59
60@extern c "owned_io" (owned io)
61//~^ ERROR E0114 the `@extern` option `owned` takes no argument
62fn owned_io ::
63 x: Int
64 -> Int
65
66// Malformed arguments.
67@extern c //~ ERROR E0114 `@extern` needs a symbol
68
69fn no_symbol :: x: Int -> Int
70
71@extern //~ ERROR E0114 `@extern` needs an ABI and a symbol
72
73fn nothing :: x: Int -> Int
74
75@extern c bare //~ ERROR E0114 the symbol of `@extern` is a non-empty string
76
77fn bare_symbol :: x: Int -> Int
78
79@test 1 //~ ERROR E0114 `@test` takes no arguments
80
81fn test_with_argument :: {}
82
83@test
84@should_panic fragment //~ ERROR E0114 `@should_panic` takes at most one string
85
86fn bare_fragment :: {}
87
88@derive //~ ERROR E0114 `@derive` needs the traits to derive
89
90type Underived { Underived }
91
92@derivable f g
93//~^ ERROR E0114 `@derivable` takes the name of one derive function
94trait Twice<a> //~ ERROR E0412 no function `f` is in scope
95{
96 fn twice :: x: a -> Int
97}
98
99// Repeated, or on the wrong item.
100@test
101@test //~ ERROR E0114 `@test` is given twice
102
103fn twice_a_test :: {}
104
105@should_panic //~ ERROR E0114 `@should_panic` applies only to a `@test` function
106
107fn not_a_test :: {}
108
109@derive Eq //~ ERROR E0114 `@derive` does not apply to a function
110
111fn derived :: {}
112
113@extern c "on_a_type" //~ ERROR E0114 `@extern` does not apply to a type
114
115type Foreign
116
117@builtin
118//~^ ERROR E0114 `@builtin` applies only to a type without constructors in the standard library
119type Mine
120
121@intrinsic
122//~^ ERROR E0114 `@intrinsic` applies only to a function in the standard library
123fn compiled ::
124 -> Int
125{
126 1
127}
128
129trait Methods<a>
130{
131 @test //~ ERROR E0114 `@test` does not apply to a method
132
133 fn method :: x: a -> Int
134}
135
136// Bodies.
137fn forgotten :: x: Int -> Int //~ ERROR E0115 function `forgotten` has no body
138
139impl Size<Kind>
140{
141 fn size :: x: Kind -> Int //~ ERROR E0115 method `size` has no body
142}
143
144@extern c "both"
145fn both :: x: Int -> Int
146{ //~ ERROR E0115 `@extern` function `both` has a body
147 x
148}