Commit Graph

28045 Commits

Author SHA1 Message Date
Kevin Butler
888517df4d libsyntax: update helper to stringify TyU* and TyI* to take into account having a value.
Fixes #13359.
2014-04-13 02:39:19 +01:00
bors
82cd9ac884 auto merge of #13459 : alexcrichton/rust/stop-ignoring-ffi, r=sfackler
Using some strategically-placed `#` markers most of the examples are testable
(and their contents are nontrivial).

Closes #13445
2014-04-12 14:46:59 -07:00
Alex Crichton
28ba3a7bc3 native: Remove timerfd implementation on linux
Rust advertises itself as being compatible with linux 2.6.18, but the timerfd
set of syscalls weren't added until linux 2.6.25. There is no real need for a
specialized timer implementation beyond being a "little more accurate", but the
select() implementation will suffice for now.

If it is later deemed that an accurate timerfd implementation is needed, it can
be added then through some method which will allow the standard distribution to
continue to be compatible with 2.6.18

Closes #13447
2014-04-12 13:42:07 -07:00
bors
ab0d847277 auto merge of #13448 : alexcrichton/rust/rework-chan-return-values, r=brson
There are currently a number of return values from the std::comm methods, not
all of which are necessarily completely expressive:

 * `Sender::try_send(t: T) -> bool`
    This method currently doesn't transmit back the data `t` if the send fails
    due to the other end having disconnected. Additionally, this shares the name
    of the synchronous try_send method, but it differs in semantics in that it
    only has one failure case, not two (the buffer can never be full).

 * `SyncSender::try_send(t: T) -> TrySendResult<T>`
    This method accurately conveys all possible information, but it uses a
    custom type to the std::comm module with no convenience methods on it.
    Additionally, if you want to inspect the result you're forced to import
    something from `std::comm`.

 * `SyncSender::send_opt(t: T) -> Option<T>`
    This method uses Some(T) as an "error value" and None as a "success value",
    but almost all other uses of Option<T> have Some/None the other way

 * `Receiver::try_recv(t: T) -> TryRecvResult<T>`
    Similarly to the synchronous try_send, this custom return type is lacking in
    terms of usability (no convenience methods).

With this number of drawbacks in mind, I believed it was time to re-work the
return types of these methods. The new API for the comm module is:

    Sender::send(t: T) -> ()
    Sender::send_opt(t: T) -> Result<(), T>
    SyncSender::send(t: T) -> ()
    SyncSender::send_opt(t: T) -> Result<(), T>
    SyncSender::try_send(t: T) -> Result<(), TrySendError<T>>
    Receiver::recv() -> T
    Receiver::recv_opt() -> Result<T, ()>
    Receiver::try_recv() -> Result<T, TryRecvError>

The notable changes made are:

* Sender::try_send => Sender::send_opt. This renaming brings the semantics in
  line with the SyncSender::send_opt method. An asychronous send only has one
  failure case, unlike the synchronous try_send method which has two failure
  cases (full/disconnected).

* Sender::send_opt returns the data back to the caller if the send is guaranteed
  to fail. This method previously returned `bool`, but then it was unable to
  retrieve the data if the data was guaranteed to fail to send. There is still a
  race such that when `Ok(())` is returned the data could still fail to be
  received, but that's inherent to an asynchronous channel.

* Result is now the basis of all return values. This not only adds lots of
  convenience methods to all return values for free, but it also means that you
  can inspect the return values with no extra imports (Ok/Err are in the
  prelude). Additionally, it's now self documenting when something failed or not
  because the return value has "Err" in the name.

Things I'm a little uneasy about:

* The methods send_opt and recv_opt are not returning options, but rather
  results. I felt more strongly that Option was the wrong return type than the
  _opt prefix was wrong, and I coudn't think of a much better name for these
  methods. One possible way to think about them is to read the _opt suffix as
  "optionally".

* Result<T, ()> is often better expressed as Option<T>. This is only applicable
  to the recv_opt() method, but I thought it would be more consistent for
  everything to return Result rather than one method returning an Option.

Despite my two reasons to feel uneasy, I feel much better about the consistency
in return values at this point, and I think the only real open question is if
there's a better suffix for {send,recv}_opt.

Closes #11527
2014-04-12 12:21:58 -07:00
Alex Crichton
f862e1256d doc: Un-ignore lots of guide-ffi tests
Using some strategically-placed `#` markers most of the examples are testable
(and their contents are nontrivial).

Closes #13445
2014-04-12 12:18:45 -07:00
Adrien Tétar
ea344fd18f doc: design changes cleanups
Conflicts:
	src/librustdoc/html/layout.rs
2014-04-12 21:10:26 +02:00
Daniel Fagnan
2d0962ad62 fixed issues
Signed-off-by: Daniel Fagnan <dnfagnan@gmail.com>
2014-04-12 21:07:25 +02:00
Daniel Fagnan
fbdde0e7ba Tweaked the design to be a lot cleaner.
Signed-off-by: Daniel Fagnan <dnfagnan@gmail.com>
2014-04-12 21:07:16 +02:00
Edward Wang
fc043c054f Check bounds when looking up type parameters
A mismatched type with more type parameters than the expected one causes
`typeck` looking up out of the bound of type parameter vector, which
leads to ICE.

Closes #13466
2014-04-12 21:14:24 +08:00
Huon Wilson
31074fdf2e std: update & de-~[] path's tests. 2014-04-12 22:51:18 +10:00
Huon Wilson
1283caa8cb std: migrate path::windows to using StrBuf internally.
Same representation change performed with path::unix.

This also implements BytesContainer for StrBuf & adds an (unsafe) method
for viewing & mutating the raw byte vector of a StrBuf.
2014-04-12 22:51:11 +10:00
Huon Wilson
28e3340a07 std: migrate path::unix to using Vec internally. 2014-04-12 22:50:56 +10:00
Manish Goregaokar
d0aed0995b Update tutorials to use new attribute syntax (#13476) 2014-04-12 09:03:39 +05:30
Kevin Butler
a16eae6ffd libstd: Add unwrap_or and unwrap_or_handle to Result 2014-04-12 03:23:16 +01:00
Kevin Butler
c48a3efb17 librustc: Improve error message for missing feature attributes. 2014-04-12 00:25:32 +01:00
Manish Goregaokar
01d5d51daf Document traits in std::num (#7511) 2014-04-12 04:37:45 +05:30
Keegan McAllister
cee9a83629 Decode non-BMP hex escapes in JSON
Fixes #13064.
2014-04-11 15:54:46 -07:00
Keegan McAllister
58fc85db93 Add tests for Char::encode_utf{8,16} 2014-04-11 15:20:18 -07:00
Keegan McAllister
e011939b1a Implement Char::encode_utf16
And clean up encode_utf8 a bit.
2014-04-11 15:20:15 -07:00
Alex Crichton
7a82d478a3 std: Fix iteration over vectors of 0-size values
Previously, all slices derived from a vector whose values were of size 0 had a
null pointer as the 'data' pointer on the slice. This caused first pointer to be
yielded during iteration to always be the null pointer. Due to the null pointer
optimization, this meant that the first return value was None, instead of
Some(&T).

This commit changes slice construction from a Vec instance to use a base pointer
of 1 if the values have zero size. This means that the iterator will never
return null, and the iteration will proceed appropriately.

Closes #13467
2014-04-11 15:12:56 -07:00
bors
ecc774f788 auto merge of #13395 : Ryman/rust/bytecontainer_impl_container, r=alexcrichton
Also some minor cleanup in Path related to this.
2014-04-11 13:46:45 -07:00
Kevin Butler
9b9ad9b741 Simplify GenericPath::set_extension. 2014-04-11 20:31:46 +01:00
Kevin Butler
d1e20488a5 Parameterize contains_nul for BytesContainer. 2014-04-11 20:27:01 +01:00
Alex Crichton
e6072fa0c4 rustc: Deterministically link upstream C libraries
Previously, upstream C libraries were linked in a nondeterministic fashion
because they were collected through iter_crate_data() which is a nodeterministic
traversal of a hash map. When upstream rlibs had interdependencies among their
native libraries (such as libfoo depending on libc), then the ordering would
occasionally be wrong, causing linkage to fail.

This uses the topologically sorted list of libraries to collect native
libraries, so if a native library depends on libc it just needs to make sure
that the rust crate depends on liblibc.
2014-04-11 12:20:33 -07:00
bors
b7e9306773 auto merge of #13458 : huonw/rust/doc-signatures, r=alexcrichton
Add more type signatures to the docs; tweak a few of them.

Someone reading the docs won't know what the types of various things
are, so this adds them in a few meaningful places to help with
comprehension.

cc #13423.
2014-04-11 12:01:44 -07:00
Alex Crichton
c60d9ad57c mk: Fix rpath on cross compile builds
After removing absolute rpaths, cross compile builds (notably the nightly
builders) broke. This is because the RPATH was pointing at an empty directory
because only the rustc binary is copied over, not all of the target libraries.
This modifies the cross compile logic to fixup the rpath of the stage0
cross-compiled rustc to point to where it came from.
2014-04-11 11:16:10 -07:00
bors
8b6091e8f1 auto merge of #13236 : liigo/rust/rename-benchharness, r=huonw
Closes #12640

based on PR #13030, rebased, and passed all tests.
2014-04-11 10:01:43 -07:00
Eduard Burtescu
9d570ad8c1 rustc: remove the last mentions of @fn. 2014-04-11 18:03:16 +03:00
Eduard Burtescu
f0c0c2ae91 rustc: remove proc -> once || coercions. 2014-04-11 18:03:16 +03:00
Eduard Burtescu
402d946868 rustc: fix fallout from removing ast::Sigil and use ty::TraitStore in ty::ClosureTy. 2014-04-11 18:03:10 +03:00
Eduard Burtescu
9351c01b35 rustdoc: fix fallout from removing ast::Sigil. 2014-04-11 18:01:34 +03:00
Eduard Burtescu
0ac532686f syntax: remove ast::Sigil. 2014-04-11 18:01:34 +03:00
Simon Sapin
b945573e29 liblog doc: Fix apparent search-and-replace errors 2014-04-11 15:28:03 +01:00
Huon Wilson
5b109a1754 Add more type signatures to the docs; tweak a few of them.
Someone reading the docs won't know what the types of various things
are, so this adds them in a few meaningful places to help with
comprehension.

cc #13423.
2014-04-11 23:10:22 +10:00
bors
65abf96fb6 auto merge of #13424 : eddyb/rust/ty-mut-in-store, r=nikomatsakis
Cleans up some remnants of the old mutability system and only allows vector/trait mutability in `VstoreSlice` (`&mut [T]`) and `RegionTraitStore` (`&mut Trait`).
2014-04-11 05:01:38 -07:00
Liigo Zhuang
408f484b66 libtest: rename BenchHarness to Bencher
Closes #12640
2014-04-11 17:31:13 +08:00
bors
1b37afe8a2 auto merge of #13457 : alexcrichton/rust/issue-13420, r=thestinger
On some OSes (such as freebsd), pthread_attr_init allocates memory, so this is
necessary to deallocate that memory.

Closes #13420
2014-04-11 02:21:36 -07:00
bors
9af93ad54d auto merge of #13453 : brson/rust/snappies, r=alexcrichton
This is the first snap based on mingw-w64.
2014-04-11 00:36:37 -07:00
Eduard Burtescu
ee4c770f8b rustc: fix the fallout from moving mutability into VstoreSlice and RegionTraitStore. 2014-04-11 09:01:31 +03:00
bors
9ff08119e3 auto merge of #13451 : cmr/rust/doc-ffi, r=brson
Closes #8748
2014-04-10 22:51:40 -07:00
Alex Crichton
11c9871bcc std: Be sure to call pthread_attr_destroy
On some OSes (such as freebsd), pthread_attr_init allocates memory, so this is
necessary to deallocate that memory.

Closes #13420
2014-04-10 22:38:05 -07:00
Alex Crichton
545d4718c8 std: Make std::comm return types consistent
There are currently a number of return values from the std::comm methods, not
all of which are necessarily completely expressive:

  Sender::try_send(t: T) -> bool
    This method currently doesn't transmit back the data `t` if the send fails
    due to the other end having disconnected. Additionally, this shares the name
    of the synchronous try_send method, but it differs in semantics in that it
    only has one failure case, not two (the buffer can never be full).

  SyncSender::try_send(t: T) -> TrySendResult<T>
    This method accurately conveys all possible information, but it uses a
    custom type to the std::comm module with no convenience methods on it.
    Additionally, if you want to inspect the result you're forced to import
    something from `std::comm`.

  SyncSender::send_opt(t: T) -> Option<T>
    This method uses Some(T) as an "error value" and None as a "success value",
    but almost all other uses of Option<T> have Some/None the other way

  Receiver::try_recv(t: T) -> TryRecvResult<T>
    Similarly to the synchronous try_send, this custom return type is lacking in
    terms of usability (no convenience methods).

With this number of drawbacks in mind, I believed it was time to re-work the
return types of these methods. The new API for the comm module is:

  Sender::send(t: T) -> ()
  Sender::send_opt(t: T) -> Result<(), T>
  SyncSender::send(t: T) -> ()
  SyncSender::send_opt(t: T) -> Result<(), T>
  SyncSender::try_send(t: T) -> Result<(), TrySendError<T>>
  Receiver::recv() -> T
  Receiver::recv_opt() -> Result<T, ()>
  Receiver::try_recv() -> Result<T, TryRecvError>

The notable changes made are:

* Sender::try_send => Sender::send_opt. This renaming brings the semantics in
  line with the SyncSender::send_opt method. An asychronous send only has one
  failure case, unlike the synchronous try_send method which has two failure
  cases (full/disconnected).

* Sender::send_opt returns the data back to the caller if the send is guaranteed
  to fail. This method previously returned `bool`, but then it was unable to
  retrieve the data if the data was guaranteed to fail to send. There is still a
  race such that when `Ok(())` is returned the data could still fail to be
  received, but that's inherent to an asynchronous channel.

* Result is now the basis of all return values. This not only adds lots of
  convenience methods to all return values for free, but it also means that you
  can inspect the return values with no extra imports (Ok/Err are in the
  prelude). Additionally, it's now self documenting when something failed or not
  because the return value has "Err" in the name.

Things I'm a little uneasy about:

* The methods send_opt and recv_opt are not returning options, but rather
  results. I felt more strongly that Option was the wrong return type than the
  _opt prefix was wrong, and I coudn't think of a much better name for these
  methods. One possible way to think about them is to read the _opt suffix as
  "optionally".

* Result<T, ()> is often better expressed as Option<T>. This is only applicable
  to the recv_opt() method, but I thought it would be more consistent for
  everything to return Result rather than one method returning an Option.

Despite my two reasons to feel uneasy, I feel much better about the consistency
in return values at this point, and I think the only real open question is if
there's a better suffix for {send,recv}_opt.

Closes #11527
2014-04-10 21:41:19 -07:00
bors
cea8def620 auto merge of #13440 : huonw/rust/strbuf, r=alexcrichton
libstd: Implement `StrBuf`, a new string buffer type like `Vec`, and port all code over to use it.

Rebased & tests-fixed version of https://github.com/mozilla/rust/pull/13269
2014-04-10 21:01:41 -07:00
Brian Anderson
7ba8cb530a Register snapshots.
This is the first snap based on mingw-w64.
2014-04-10 19:53:10 -07:00
Huon Wilson
def90f43e2 Fix tests. Add Vec<u8> conversion to StrBuf. 2014-04-11 10:55:30 +10:00
Corey Richardson
eabf78c7b9 Document the nullable pointer optimization in the FFI guide
Closes #8748
2014-04-10 20:29:09 -04:00
bors
0156af156d auto merge of #13443 : alexcrichton/rust/rollup, r=alexcrichton
Closes #13441 (debuginfo: Fixes and improvements for #12840, #12886, and #13213)
Closes #13433 (Remove references to @Trait from a compiler error message)
Closes #13430 (Fix outdated lint warning about inner attribute)
Closes #13425 (Remove a pile of (mainly) internal `~[]` uses)
Closes #13419 (Stop using transmute_mut in RefCell)
Closes #13417 (Remove an unnecessary file `src/libnative/io/p`.)
Closes #13409 (Closing assorted resolve bugs)
Closes #13406 (Generalized the pretty-print entry points to support `-o <file>`.)
Closes #13403 (test: Add a test for #7663)
Closes #13402 (rustdoc: Prune the paths that do not appear in the index.)
Closes #13396 (rustc: Remove absolute rpaths)
Closes #13371 (Rename ast::Purity and ast::Impure Function. Closes #7287)
Closes #13350 (collections: replace all ~[T] with Vec<T>.)
2014-04-10 15:31:55 -07:00
Alex Crichton
1f2c18a0af rustc: Don't allow priv use to shadow pub use
Previously, a private use statement would shadow a public use statement, all of
a sudden publicly exporting the privately used item. The correct behavior here
is to only shadow the use for the module in question, but for now it just
reverts the entire name to private so the pub use doesn't have much effect.

The behavior isn't exactly what we want, but this no longer has backwards
compatibility hazards.
2014-04-10 15:22:01 -07:00
Alex Crichton
df533c6e87 rustc: Don't succeed on shadowed nonexistent import
Previously resolve was checking the "import resolution" for whether an import
had succeeded or not, but this was the same structure filled in by a previous
import if a name is shadowed. Instead, this alters resolve to consult the local
resolve state (as opposed to the shared one) to test whether an import succeeded
or not.

Closes #13404
2014-04-10 15:22:00 -07:00
Alex Crichton
83d2c0b8a6 rustc: Disallow importing through use statements
Resolve is currently erroneously allowing imports through private `use`
statements in some circumstances, even across module boundaries. For example,
this code compiles successfully today:

    use std::c_str;
    mod test {
        use c_str::CString;
    }

This should not be allowed because it was explicitly decided that private `use`
statements are purely bringing local names into scope, they are not
participating further in name resolution.

As a consequence of this patch, this code, while valid today, is now invalid:

    mod test {
        use std::c_str;

        unsafe fn foo() {
            ::test::c_str::CString::new(0 as *u8, false);
        }
    }

While plausibly acceptable, I found it to be more consistent if private imports
were only considered candidates to resolve the first component in a path, and no
others.

Closes #12612
2014-04-10 15:22:00 -07:00