Skip to content

Commit f719b74

Browse files
committed
---
yaml --- r: 129004 b: refs/heads/master c: 171c542 h: refs/heads/master v: v3
1 parent 2b331d8 commit f719b74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+331
-855
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: c9cf3b3cc4d1d4eed359be54f08ba2b5fe961bf1
2+
refs/heads/master: 171c54296586bd08f0cfd49098515bef045a059b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: a86d9ad15e339ab343a12513f9c90556f677b9ca
55
refs/heads/try: 961753763fb87ddcbbccaec4ea87648608d19a58

trunk/src/doc/guide-ffi.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,12 @@ Rust code:
263263
264264
~~~~no_run
265265
266-
#[repr(C)]
267266
struct RustObject {
268267
a: i32,
269268
// other members
270269
}
271270
272-
extern "C" fn callback(target: *mut RustObject, a:i32) {
271+
extern fn callback(target: *mut RustObject, a:i32) {
273272
println!("I'm called from C with value {0}", a);
274273
unsafe {
275274
// Update the value in RustObject with the value received from the callback
@@ -507,16 +506,16 @@ to define a block for all windows systems, not just x86 ones.
507506
508507
# Interoperability with foreign code
509508
510-
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C
511-
only if the `#[repr(C)]` attribute is applied to it. `#[repr(C, packed)]` can be used to lay out
512-
struct members without padding. `#[repr(C)]` can also be applied to an enum.
509+
Rust guarantees that the layout of a `struct` is compatible with the platform's representation in C.
510+
A `#[packed]` attribute is available, which will lay out the struct members without padding.
511+
However, there are currently no guarantees about the layout of an `enum`.
513512
514-
Rust's owned boxes (`Box<T>`) use non-nullable pointers as handles which point to the contained
513+
Rust's owned and managed boxes use non-nullable pointers as handles which point to the contained
515514
object. However, they should not be manually created because they are managed by internal
516-
allocators. References can safely be assumed to be non-nullable pointers directly to the type.
517-
However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so prefer
518-
using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions about
519-
them.
515+
allocators. References can safely be assumed to be non-nullable pointers directly to the
516+
type. However, breaking the borrow checking or mutability rules is not guaranteed to be safe, so
517+
prefer using raw pointers (`*`) if that's needed because the compiler can't make as many assumptions
518+
about them.
520519
521520
Vectors and strings share the same basic memory layout, and utilities are available in the `vec` and
522521
`str` modules for working with C APIs. However, strings are not terminated with `\0`. If you need a

trunk/src/doc/guide.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,8 +1073,8 @@ destructuring `let`.
10731073
## Enums
10741074

10751075
Finally, Rust has a "sum type", an **enum**. Enums are an incredibly useful
1076-
feature of Rust, and are used throughout the standard library. This is an enum
1077-
that is provided by the Rust standard library:
1076+
feature of Rust, and are used throughout the standard library. Enums look
1077+
like this:
10781078

10791079
```{rust}
10801080
enum Ordering {
@@ -1084,8 +1084,9 @@ enum Ordering {
10841084
}
10851085
```
10861086

1087-
An `Ordering` can only be _one_ of `Less`, `Equal`, or `Greater` at any given
1088-
time. Here's an example:
1087+
This is an enum that is provided by the Rust standard library. An `Ordering`
1088+
can only be _one_ of `Less`, `Equal`, or `Greater` at any given time. Here's
1089+
an example:
10891090

10901091
```{rust}
10911092
fn cmp(a: int, b: int) -> Ordering {
@@ -2896,11 +2897,9 @@ pub fn print_hello() {
28962897
}
28972898
```
28982899

2899-
When we include a module like this, we don't need to make the `mod` declaration
2900-
in `hello.rs`, because it's already been declared in `lib.rs`. `hello.rs` just
2901-
contains the body of the module which is defined (by the `pub mod hello`) in
2902-
`lib.rs`. This helps prevent 'rightward drift': when you end up indenting so
2903-
many times that your code is hard to read.
2900+
When we include a module like this, we don't need to make the `mod` declaration,
2901+
it's just understood. This helps prevent 'rightward drift': when you end up
2902+
indenting so many times that your code is hard to read.
29042903

29052904
Finally, make a new directory, `src/goodbye`, and make a new file in it,
29062905
`src/goodbye/mod.rs`:

trunk/src/doc/rust.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,9 +1308,6 @@ struct Cookie;
13081308
let c = [Cookie, Cookie, Cookie, Cookie];
13091309
~~~~
13101310

1311-
The precise memory layout of a structure is not specified. One can specify a
1312-
particular layout using the [`repr` attribute](#ffi-attributes).
1313-
13141311
By using the `struct_inherit` feature gate, structures may use single inheritance. A Structure may only
13151312
inherit from a single other structure, called the _super-struct_. The inheriting structure (sub-struct)
13161313
acts as if all fields in the super-struct were present in the sub-struct. Fields declared in a sub-struct
@@ -1944,23 +1941,6 @@ interpreted:
19441941
- `linkage` - on a static, this specifies the [linkage
19451942
type](http://llvm.org/docs/LangRef.html#linkage-types).
19461943

1947-
On `enum`s:
1948-
1949-
- `repr` - on C-like enums, this sets the underlying type used for
1950-
representation. Takes one argument, which is the primitive
1951-
type this enum should be represented for, or `C`, which specifies that it
1952-
should be the default `enum` size of the C ABI for that platform. Note that
1953-
enum representation in C is undefined, and this may be incorrect when the C
1954-
code is compiled with certain flags.
1955-
1956-
On `struct`s:
1957-
1958-
- `repr` - specifies the representation to use for this struct. Takes a list
1959-
of options. The currently accepted ones are `C` and `packed`, which may be
1960-
combined. `C` will use a C ABI comptible struct layout, and `packed` will
1961-
remove any padding between fields (note that this is very fragile and may
1962-
break platforms which require aligned access).
1963-
19641944
### Miscellaneous attributes
19651945

19661946
- `export_name` - on statics and functions, this determines the name of the
@@ -1978,6 +1958,12 @@ On `struct`s:
19781958
crate at compile-time and use any syntax extensions or lints that the crate
19791959
defines. They can both be specified, `#[phase(link, plugin)]` to use a crate
19801960
both at runtime and compiletime.
1961+
- `repr` - on C-like enums, this sets the underlying type used for
1962+
representation. Useful for FFI. Takes one argument, which is the primitive
1963+
type this enum should be represented for, or `C`, which specifies that it
1964+
should be the default `enum` size of the C ABI for that platform. Note that
1965+
enum representation in C is undefined, and this may be incorrect when the C
1966+
code is compiled with certain flags.
19811967
- `simd` - on certain tuple structs, derive the arithmetic operators, which
19821968
lower to the target's SIMD instructions, if any; the `simd` feature gate
19831969
is necessary to use this attribute.

trunk/src/libcore/mem.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,6 @@ use ptr;
1919

2020
pub use intrinsics::transmute;
2121

22-
/// Moves a thing into the void.
23-
///
24-
/// The forget function will take ownership of the provided value but neglect
25-
/// to run any required cleanup or memory management operations on it.
26-
///
27-
/// This function is the unsafe version of the `drop` function because it does
28-
/// not run any destructors.
29-
#[stable]
30-
pub use intrinsics::forget;
31-
3222
/// Returns the size of a type in bytes.
3323
#[inline]
3424
#[stable]
@@ -347,6 +337,17 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
347337
#[stable]
348338
pub fn drop<T>(_x: T) { }
349339

340+
/// Moves a thing into the void.
341+
///
342+
/// The forget function will take ownership of the provided value but neglect
343+
/// to run any required cleanup or memory management operations on it.
344+
///
345+
/// This function is the unsafe version of the `drop` function because it does
346+
/// not run any destructors.
347+
#[inline]
348+
#[stable]
349+
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
350+
350351
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
351352
/// value.
352353
///

trunk/src/libcore/simd.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
#[experimental]
4141
#[simd]
4242
#[deriving(Show)]
43-
#[repr(C)]
4443
pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4544
pub i8, pub i8, pub i8, pub i8,
4645
pub i8, pub i8, pub i8, pub i8,
@@ -49,26 +48,22 @@ pub struct i8x16(pub i8, pub i8, pub i8, pub i8,
4948
#[experimental]
5049
#[simd]
5150
#[deriving(Show)]
52-
#[repr(C)]
5351
pub struct i16x8(pub i16, pub i16, pub i16, pub i16,
5452
pub i16, pub i16, pub i16, pub i16);
5553

5654
#[experimental]
5755
#[simd]
5856
#[deriving(Show)]
59-
#[repr(C)]
6057
pub struct i32x4(pub i32, pub i32, pub i32, pub i32);
6158

6259
#[experimental]
6360
#[simd]
6461
#[deriving(Show)]
65-
#[repr(C)]
6662
pub struct i64x2(pub i64, pub i64);
6763

6864
#[experimental]
6965
#[simd]
7066
#[deriving(Show)]
71-
#[repr(C)]
7267
pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
7368
pub u8, pub u8, pub u8, pub u8,
7469
pub u8, pub u8, pub u8, pub u8,
@@ -77,30 +72,25 @@ pub struct u8x16(pub u8, pub u8, pub u8, pub u8,
7772
#[experimental]
7873
#[simd]
7974
#[deriving(Show)]
80-
#[repr(C)]
8175
pub struct u16x8(pub u16, pub u16, pub u16, pub u16,
8276
pub u16, pub u16, pub u16, pub u16);
8377

8478
#[experimental]
8579
#[simd]
8680
#[deriving(Show)]
87-
#[repr(C)]
8881
pub struct u32x4(pub u32, pub u32, pub u32, pub u32);
8982

9083
#[experimental]
9184
#[simd]
9285
#[deriving(Show)]
93-
#[repr(C)]
9486
pub struct u64x2(pub u64, pub u64);
9587

9688
#[experimental]
9789
#[simd]
9890
#[deriving(Show)]
99-
#[repr(C)]
10091
pub struct f32x4(pub f32, pub f32, pub f32, pub f32);
10192

10293
#[experimental]
10394
#[simd]
10495
#[deriving(Show)]
105-
#[repr(C)]
10696
pub struct f64x2(pub f64, pub f64);

trunk/src/libgetopts/lib.rs

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
571571
}
572572
} else {
573573
let mut j = 1;
574+
let mut last_valid_opt_id = None;
574575
names = Vec::new();
575576
while j < curlen {
576577
let range = cur.as_slice().char_range_at(j);
@@ -583,24 +584,27 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
583584
interpreted correctly
584585
*/
585586

586-
let opt_id = match find_opt(opts.as_slice(), opt.clone()) {
587-
Some(id) => id,
588-
None => return Err(UnrecognizedOption(opt.to_string()))
589-
};
590-
591-
names.push(opt);
592-
593-
let arg_follows = match opts[opt_id].hasarg {
594-
Yes | Maybe => true,
595-
No => false
596-
};
597-
598-
if arg_follows && range.next < curlen {
599-
i_arg = Some(cur.as_slice()
600-
.slice(range.next, curlen).to_string());
601-
break;
587+
match find_opt(opts.as_slice(), opt.clone()) {
588+
Some(id) => last_valid_opt_id = Some(id),
589+
None => {
590+
let arg_follows =
591+
last_valid_opt_id.is_some() &&
592+
match opts[last_valid_opt_id.unwrap()]
593+
.hasarg {
594+
595+
Yes | Maybe => true,
596+
No => false
597+
};
598+
if arg_follows && j < curlen {
599+
i_arg = Some(cur.as_slice()
600+
.slice(j, curlen).to_string());
601+
break;
602+
} else {
603+
last_valid_opt_id = None;
604+
}
605+
}
602606
}
603-
607+
names.push(opt);
604608
j = range.next;
605609
}
606610
}
@@ -613,7 +617,7 @@ pub fn getopts(args: &[String], optgrps: &[OptGroup]) -> Result {
613617
};
614618
match opts[optid].hasarg {
615619
No => {
616-
if name_pos == names.len() && !i_arg.is_none() {
620+
if !i_arg.is_none() {
617621
return Err(UnexpectedArgument(nm.to_string()));
618622
}
619623
vals.get_mut(optid).push(Given);
@@ -1437,21 +1441,6 @@ mod tests {
14371441

14381442
}
14391443

1440-
#[test]
1441-
fn test_nospace_conflict() {
1442-
let args = vec!("-vvLverbose".to_string(), "-v".to_string() );
1443-
let opts = vec!(optmulti("L", "", "library directory", "LIB"),
1444-
optflagmulti("v", "verbose", "Verbose"));
1445-
let matches = &match getopts(args.as_slice(), opts.as_slice()) {
1446-
result::Ok(m) => m,
1447-
result::Err(e) => fail!( "{}", e )
1448-
};
1449-
assert!(matches.opts_present(["L".to_string()]));
1450-
assert_eq!(matches.opts_str(["L".to_string()]).unwrap(), "verbose".to_string());
1451-
assert!(matches.opts_present(["v".to_string()]));
1452-
assert_eq!(3, matches.opt_count("v"));
1453-
}
1454-
14551444
#[test]
14561445
fn test_long_to_short() {
14571446
let mut short = Opt {

0 commit comments

Comments
 (0)