Skip to content

Commit f4a6f51

Browse files
committed
---
yaml --- r: 206271 b: refs/heads/beta c: c634ec2 h: refs/heads/master i: 206269: 860cac8 206267: 0df8791 206263: e21cb77 206255: 1eae5ca 206239: bdb4b83 206207: 78dedd1 v: v3
1 parent 0d9ebcf commit f4a6f51

File tree

11 files changed

+199
-37
lines changed

11 files changed

+199
-37
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
2929
refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3030
refs/heads/batch: b7fd822592a4fb577552d93010c4a4e14f314346
3131
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
32-
refs/heads/beta: 543b910f9be6b4d8d757f0471f00ba0a691bc5f6
32+
refs/heads/beta: c634ec2e88a85d7f553ec0d6746e24a886bc6fd4
3333
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3434
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
3535
refs/heads/tmp: 579e31929feff51dcaf8d444648eff8de735f91a

branches/beta/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"
547+
opt debug 0 "debug mode; disables optimization unless \`--enable-optimize\` given"
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/beta/src/doc/grammar.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ 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 ] lit_suffix ?;
179+
literal : [ string_lit | char_lit | byte_string_lit | byte_lit | num_lit | bool_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+
182188
#### Character and string literals
183189

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

239245
#### Boolean literals
240246

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

243251
The two values of the boolean type are written `true` and `false`.
244252

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

298306
```antlr
299307
item : mod_item | fn_item | type_item | struct_item | enum_item
300-
| static_item | trait_item | impl_item | extern_block ;
308+
| const_item | static_item | trait_item | impl_item | extern_block ;
301309
```
302310

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

370378
**FIXME:** grammar?
371379

380+
### Enumerations
381+
382+
**FIXME:** grammar?
383+
372384
### Constant items
373385

374386
```antlr

branches/beta/src/doc/reference.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ 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-
138133
#### Examples
139134

140135
##### Characters and strings

branches/beta/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-
[intrinsic]: intrinsics.html
46+
[intrinsics]: 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/beta/src/doc/trpl/inline-assembly.md

Lines changed: 32 additions & 5 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:
80+
expressions must be mutable lvalues, or not yet assigned:
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 mut c = 0;
86+
let c: i32;
8787
unsafe {
8888
asm!("add $2, $0"
8989
: "=r"(c)
@@ -100,6 +100,22 @@ 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+
103119
## Clobbers
104120

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

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

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/beta/src/librustc/diagnostics.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ 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+
171177
E0013: r##"
172178
Static and const variables can refer to other const variables. But a const
173179
variable cannot refer to a static variable. For example, `Y` cannot refer to `X`
@@ -221,6 +227,31 @@ This error indicates that an attempt was made to divide by zero (or take the
221227
remainder of a zero divisor) in a static or constant expression.
222228
"##,
223229

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

496527
register_diagnostics! {
497-
E0010,
498528
E0011,
499529
E0012,
500530
E0014,
501531
E0016,
502532
E0017,
503533
E0019,
504534
E0022,
505-
E0079, // enum variant: expected signed integer constant
506-
E0080, // enum variant: constant evaluation error
507535
E0109,
508536
E0110,
509537
E0134,

branches/beta/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/beta/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)