Skip to content

Commit 129fe78

Browse files
committed
---
yaml --- r: 207868 b: refs/heads/snap-stage3 c: 63e6321 h: refs/heads/master v: v3
1 parent a21979b commit 129fe78

File tree

9 files changed

+124
-63
lines changed

9 files changed

+124
-63
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 38a97becdf3e6a6157f6f7ec2d98ade8d8edc193
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 2568a4d8c57d184326ee6974c0a769bbb93c1b22
4+
refs/heads/snap-stage3: 63e63218a123bbda1ed47cbe5e8bac62b7e48e97
55
refs/heads/try: 7b4ef47b7805a402d756fb8157101f64880a522f
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@ fi
544544
BOOL_OPTIONS=""
545545
VAL_OPTIONS=""
546546

547-
opt debug 0 "debug mode; disables optimization unless \`--enable-optimize\` given"
547+
opt debug 0 "debug mode"
548548
opt valgrind 0 "run tests with valgrind (memcheck by default)"
549549
opt helgrind 0 "run tests with helgrind instead of memcheck"
550550
opt valgrind-rpass 1 "run rpass-valgrind tests with valgrind"

branches/snap-stage3/src/doc/grammar.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,9 @@ excluded from the `ident` rule.
176176

177177
```antlr
178178
lit_suffix : ident;
179-
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit | bool_lit ] lit_suffix ?;
179+
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit ] lit_suffix ?;
180180
```
181181

182-
The optional `lit_suffix` production is only used for certain numeric literals,
183-
but is reserved for future extension. That is, the above gives the lexical
184-
grammar, but a Rust parser will reject everything but the 12 special cases
185-
mentioned in [Number literals](reference.html#number-literals) in the
186-
reference.
187-
188182
#### Character and string literals
189183

190184
```antlr
@@ -244,9 +238,7 @@ dec_lit : [ dec_digit | '_' ] + ;
244238

245239
#### Boolean literals
246240

247-
```antlr
248-
bool_lit : [ "true" | "false" ] ;
249-
```
241+
**FIXME:** write grammar
250242

251243
The two values of the boolean type are written `true` and `false`.
252244

@@ -305,7 +297,7 @@ transcriber : '(' transcriber * ')' | '[' transcriber * ']'
305297

306298
```antlr
307299
item : mod_item | fn_item | type_item | struct_item | enum_item
308-
| const_item | static_item | trait_item | impl_item | extern_block ;
300+
| static_item | trait_item | impl_item | extern_block ;
309301
```
310302

311303
### Type Parameters
@@ -377,10 +369,6 @@ path_item : ident | "mod" ;
377369

378370
**FIXME:** grammar?
379371

380-
### Enumerations
381-
382-
**FIXME:** grammar?
383-
384372
### Constant items
385373

386374
```antlr

branches/snap-stage3/src/doc/reference.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ of tokens, that immediately and directly denotes the value it evaluates to,
130130
rather than referring to it by name or some other evaluation rule. A literal is
131131
a form of constant expression, so is evaluated (primarily) at compile time.
132132

133+
The optional suffix is only used for certain numeric literals, but is
134+
reserved for future extension, that is, the above gives the lexical
135+
grammar, but a Rust parser will reject everything but the 12 special
136+
cases mentioned in [Number literals](#number-literals) below.
137+
133138
#### Examples
134139

135140
##### Characters and strings

branches/snap-stage3/src/doc/trpl/casting-between-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ what it does is very simple, but very scary. It tells Rust to treat a value of
4343
one type as though it were another type. It does this regardless of the
4444
typechecking system, and just completely trusts you.
4545

46-
[intrinsics]: intrinsics.html
46+
[intrinsic]: intrinsics.html
4747

4848
In our previous example, we know that an array of four `u8`s represents a `u32`
4949
properly, and so we want to do the cast. Using `transmute` instead of `as`,

branches/snap-stage3/src/doc/trpl/inline-assembly.md

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ but you must add the right number of `:` if you skip them:
5858
asm!("xor %eax, %eax"
5959
:
6060
:
61-
: "{eax}"
61+
: "eax"
6262
);
6363
# } }
6464
```
@@ -69,21 +69,21 @@ Whitespace also doesn't matter:
6969
# #![feature(asm)]
7070
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
7171
# fn main() { unsafe {
72-
asm!("xor %eax, %eax" ::: "{eax}");
72+
asm!("xor %eax, %eax" ::: "eax");
7373
# } }
7474
```
7575

7676
## Operands
7777

7878
Input and output operands follow the same format: `:
7979
"constraints1"(expr1), "constraints2"(expr2), ..."`. Output operand
80-
expressions must be mutable lvalues, or not yet assigned:
80+
expressions must be mutable lvalues:
8181

8282
```
8383
# #![feature(asm)]
8484
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
8585
fn add(a: i32, b: i32) -> i32 {
86-
let c: i32;
86+
let mut c = 0;
8787
unsafe {
8888
asm!("add $2, $0"
8989
: "=r"(c)
@@ -100,22 +100,6 @@ fn main() {
100100
}
101101
```
102102

103-
If you would like to use real operands in this position, however,
104-
you are required to put curly braces `{}` around the register that
105-
you want, and you are required to put the specific size of the
106-
operand. This is useful for very low level programming, where
107-
which register you use is important:
108-
109-
```
110-
# #![feature(asm)]
111-
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
112-
# unsafe fn read_byte_in(port: u16) -> u8 {
113-
let result: u8;
114-
asm!("in %dx, %al" : "={al}"(result) : "{dx}"(port));
115-
result
116-
# }
117-
```
118-
119103
## Clobbers
120104

121105
Some instructions modify registers which might otherwise have held
@@ -128,7 +112,7 @@ stay valid.
128112
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
129113
# fn main() { unsafe {
130114
// Put the value 0x200 in eax
131-
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "{eax}");
115+
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "eax");
132116
# } }
133117
```
134118

@@ -155,14 +139,3 @@ Current valid options are:
155139
the compiler to insert its usual stack alignment code
156140
3. *intel* - use intel syntax instead of the default AT&T.
157141

158-
```
159-
# #![feature(asm)]
160-
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
161-
# fn main() {
162-
let result: i32;
163-
unsafe {
164-
asm!("mov eax, 2" : "={eax}"(result) : : : "intel")
165-
}
166-
println!("eax is currently {}", result);
167-
# }
168-
```

branches/snap-stage3/src/librustc/diagnostics.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,6 @@ match x {
168168
```
169169
"##,
170170

171-
E0010: r##"
172-
The value of statics and constants must be known at compile time, and they live
173-
for the entire lifetime of a program. Creating a boxed value allocates memory on
174-
the heap at runtime, and therefore cannot be done at compile time.
175-
"##,
176-
177171
E0013: r##"
178172
Static and const variables can refer to other const variables. But a const
179173
variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
@@ -227,6 +221,31 @@ This error indicates that an attempt was made to divide by zero (or take the
227221
remainder of a zero divisor) in a static or constant expression.
228222
"##,
229223

224+
E0079: r##"
225+
Enum variants which contain no data can be given a custom integer
226+
representation. This error indicates that the value provided is not an
227+
integer literal and is therefore invalid.
228+
"##,
229+
230+
E0080: r##"
231+
This error indicates that the compiler was unable to sensibly evaluate an
232+
integer expression provided as an enum discriminant. Attempting to divide by 0
233+
or causing integer overflow are two ways to induce this error. For example:
234+
235+
```
236+
enum Enum {
237+
X = (1 << 500),
238+
Y = (1 / 0)
239+
}
240+
```
241+
242+
Ensure that the expressions given can be evaluated as the desired integer type.
243+
See the FFI section of the Reference for more information about using a custom
244+
integer type:
245+
246+
http://doc.rust-lang.org/reference.html#ffi-attributes
247+
"##,
248+
230249
E0133: r##"
231250
Using unsafe functionality, such as dereferencing raw pointers and calling
232251
functions via FFI or marked as unsafe, is potentially dangerous and disallowed
@@ -500,15 +519,14 @@ a compile-time constant.
500519
}
501520

502521
register_diagnostics! {
522+
E0010,
503523
E0011,
504524
E0012,
505525
E0014,
506526
E0016,
507527
E0017,
508528
E0019,
509529
E0022,
510-
E0079, // enum variant: expected signed integer constant
511-
E0080, // enum variant: constant evaluation error
512530
E0109,
513531
E0110,
514532
E0134,

branches/snap-stage3/src/librustc/middle/ty.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5732,8 +5732,10 @@ fn compute_enum_variants<'tcx>(cx: &ctxt<'tcx>,
57325732
Ok(const_eval::const_int(val)) => current_disr_val = val as Disr,
57335733
Ok(const_eval::const_uint(val)) => current_disr_val = val as Disr,
57345734
Ok(_) => {
5735+
let sign_desc = if repr_type.is_signed() { "signed" } else { "unsigned" };
57355736
span_err!(cx.sess, e.span, E0079,
5736-
"expected signed integer constant");
5737+
"expected {} integer constant",
5738+
sign_desc);
57375739
current_disr_val = attempt_fresh_value();
57385740
}
57395741
Err(ref err) => {

branches/snap-stage3/src/librustc_typeck/diagnostics.rs

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,85 @@
1010

1111
#![allow(non_snake_case)]
1212

13+
register_long_diagnostics! {
14+
15+
E0081: r##"
16+
Enum discriminants are used to differentiate enum variants stored in memory.
17+
This error indicates that the same value was used for two or more variants,
18+
making them impossible to tell apart.
19+
20+
```
21+
// Good.
22+
enum Enum {
23+
P,
24+
X = 3,
25+
Y = 5
26+
}
27+
28+
// Bad.
29+
enum Enum {
30+
P = 3,
31+
X = 3,
32+
Y = 5
33+
}
34+
```
35+
36+
Note that variants without a manually specified discriminant are numbered from
37+
top to bottom starting from 0, so clashes can occur with seemingly unrelated
38+
variants.
39+
40+
```
41+
enum Bad {
42+
X,
43+
Y = 0
44+
}
45+
```
46+
47+
Here `X` will have already been assigned the discriminant 0 by the time `Y` is
48+
encountered, so a conflict occurs.
49+
"##,
50+
51+
E0082: r##"
52+
The default type for enum discriminants is `isize`, but it can be adjusted by
53+
adding the `repr` attribute to the enum declaration. This error indicates that
54+
an integer literal given as a discriminant is not a member of the discriminant
55+
type. For example:
56+
57+
```
58+
#[repr(u8)]
59+
enum Thing {
60+
A = 1024,
61+
B = 5
62+
}
63+
```
64+
65+
Here, 1024 lies outside the valid range for `u8`, so the discriminant for `A` is
66+
invalid. You may want to change representation types to fix this, or else change
67+
invalid discriminant values so that they fit within the existing type.
68+
69+
Note also that without a representation manually defined, the compiler will
70+
optimize by using the smallest integer type possible.
71+
"##,
72+
73+
E0083: r##"
74+
At present, it's not possible to define a custom representation for an enum with
75+
a single variant. As a workaround you can add a `Dummy` variant.
76+
77+
See: https://github.com/rust-lang/rust/issues/10292
78+
"##,
79+
80+
E0084: r##"
81+
It is impossible to define an integer type to be used to represent zero-variant
82+
enum values because there are no zero-variant enum values. There is no way to
83+
construct an instance of the following type using only safe code:
84+
85+
```
86+
enum Empty {}
87+
```
88+
"##
89+
90+
}
91+
1392
register_diagnostics! {
1493
E0023,
1594
E0024,
@@ -51,10 +130,6 @@ register_diagnostics! {
51130
E0075,
52131
E0076,
53132
E0077,
54-
E0081,
55-
E0082,
56-
E0083,
57-
E0084,
58133
E0085,
59134
E0086,
60135
E0087,

0 commit comments

Comments
 (0)