Commit Graph

28910 Commits

Author SHA1 Message Date
Tom Lee
611c2ae4f1 Try to parse TcpStream::connect 'host' parameter as an IP.
Fall back to get_host_addresses to try a DNS lookup if we can't
parse it as an IP address.
2014-05-12 21:41:48 -07:00
Tom Lee
a57889a580 Easier interface for TCP ::connect and ::bind.
Prior to this commit, TcpStream::connect and TcpListener::bind took a
single SocketAddr argument. This worked well enough, but the API felt a
little too "low level" for most simple use cases.

A great example is connecting to rust-lang.org on port 80. Rust users would
need to:

  1. resolve the IP address of rust-lang.org using
     io::net::addrinfo::get_host_addresses.

  2. check for errors

  3. if all went well, use the returned IP address and the port number
     to construct a SocketAddr

  4. pass this SocketAddr to TcpStream::connect.

I'm modifying the type signature of TcpStream::connect and
TcpListener::bind so that the API is a little easier to use.

TcpStream::connect now accepts two arguments: a string describing the
host/IP of the host we wish to connect to, and a u16 representing the
remote port number.

Similarly, TcpListener::bind has been modified to take two arguments:
a string describing the local interface address (e.g. "0.0.0.0" or
"127.0.0.1") and a u16 port number.

Here's how to port your Rust code to use the new TcpStream::connect API:

  // old ::connect API
  let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080};
  let stream = TcpStream::connect(addr).unwrap()

  // new ::connect API (minimal change)
  let addr = SocketAddr{ip: Ipv4Addr{127, 0, 0, 1}, port: 8080};
  let stream = TcpStream::connect(addr.ip.to_str(), addr.port()).unwrap()

  // new ::connect API (more compact)
  let stream = TcpStream::connect("127.0.0.1", 8080).unwrap()

  // new ::connect API (hostname)
  let stream = TcpStream::connect("rust-lang.org", 80)

Similarly, for TcpListener::bind:

  // old ::bind API
  let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080};
  let mut acceptor = TcpListener::bind(addr).listen();

  // new ::bind API (minimal change)
  let addr = SocketAddr{ip: Ipv4Addr{0, 0, 0, 0}, port: 8080};
  let mut acceptor = TcpListener::bind(addr.ip.to_str(), addr.port()).listen()

  // new ::bind API (more compact)
  let mut acceptor = TcpListener::bind("0.0.0.0", 8080).listen()

[breaking-change]
2014-05-12 21:41:48 -07:00
Cameron Zwarich
45b4ef4633 Remove a workaround for deriving(Clone) on unit structs. 2014-05-12 21:29:31 -07:00
Corey Richardson
2886938169 num: rename Cmplx to Complex
Cmplx is a uselessly short name. Change it to be more clear.

[breaking-change]
2014-05-12 21:27:40 -07:00
Alex Crichton
5001a66665 Test fixes from rollup
Closes #14163 (Fix typos in rustc manpage)
Closes #14161 (Add the patch number to version strings. Closes #13289)
Closes #14156 (rustdoc: Fix hiding implementations of traits)
Closes #14152 (add shebang to scripts that have execute bit set)
Closes #14150 (libcore: remove fails from slice.rs and remove duplicated length checking)
Closes #14147 (Make ProcessOutput Eq, TotalEq, Clone)
Closes #14142 (doc: updates rust manual (loop to continue))
Closes #14141 (doc: Update the linkage documentation)
Closes #14139 (Remove an unnecessary .move_iter().collect())
Closes #14136 (Two minor fixes in parser.rs)
Closes #14130 (Fixed typo in comments of driver.rs)
Closes #14128 (Add `stat` method to `std::io::fs::File` to stat without a Path.)
Closes #14114 (rustdoc: List macros in the sidebar)
Closes #14113 (shootout-nbody improvement)
Closes #14112 (Improved example code in Option)
Closes #14104 (Remove reference to MutexArc)
Closes #14087 (emacs: highlight `macro_name!` in macro invocations using [] delimiters)
2014-05-12 20:17:36 -07:00
bors
1ee5e7f185 auto merge of #13820 : klutzy/rust/urandom, r=alexcrichton
This patch adds document which explains when to use `OSRng` in
cryptographic context, and explains why we use `/dev/urandom` instead
of `/dev/random`.
2014-05-12 20:17:13 -07:00
Huon Wilson
13491dbadb emacs: highlight macro_name! in macro invocations using [] delimiters 2014-05-12 19:52:29 -07:00
Derek Chiang (Enchi Jiang)
5518071019 Remove reference to MutexArc 2014-05-12 19:52:29 -07:00
Adolfo Ochagavía
85e34b2396 Improved example code in Option 2014-05-12 19:52:29 -07:00
Guillaume Pinot
437338ab65 shootout-nbody improvement
- factorize operation
- factorize loop (and gain a level of indentation)
- ~5% faster

Thanks to @Ryman for the propositions :)
2014-05-12 19:52:29 -07:00
Seo Sanghyeon
48beab1205 rustdoc: List macros in the sidebar 2014-05-12 19:52:29 -07:00
Yuri Kunde Schlesner
8c55fcd1f2 Add stat method to std::io::fs::File to stat without a Path.
The `FileStat` struct contained a `path` field, which was filled by the
`stat` and `lstat` function. Since this field isn't in fact returned by
the operating system (it was copied from the paths passed to the
functions) it was removed, as in the `fstat` case we aren't working with
a `Path`, but directly with a fd.

If your code used the `path` field of `FileStat` you will now have to
manually store the path passed to `stat` along with the returned struct.

[breaking-change]
2014-05-12 19:52:29 -07:00
Adolfo Ochagavía
f096516d2b Fixed typo in comments of driver.rs 2014-05-12 19:52:29 -07:00
Paul Stansifer
cdd5893347 Cleanup some ugly variable names, now that we have let-hygiene. 2014-05-12 19:52:29 -07:00
Paul Stansifer
0aae5574ea Add some long-overdue documentation on the INTERPOLATED helper macros. 2014-05-12 19:52:29 -07:00
Simon Sapin
16351731ac Remove an unnecessary .move_iter().collect() 2014-05-12 19:52:29 -07:00
Alex Crichton
e798b97ce9 doc: Update the linkage documentation
After allowing mixing rlibs and dylibs in #13892, the documentation was not
updated accordingly to reflect this new capability.
2014-05-12 19:52:29 -07:00
Piotr Jawniak
06ea9893d5 doc: updates rust manual (loop to continue)
Keyword for continue expressions was changed from loop to continue, but the
manual was not updated.
2014-05-12 19:52:29 -07:00
Yehuda Katz
31de69d0dd Make ProcessOutput Eq, TotalEq, Clone 2014-05-12 19:52:29 -07:00
Kevin Butler
826aeea007 libcore: remove fails from slice.rs and remove duplicated length checking
core::slice::raw::{shift_ptr,pop_ptr} now returns Option<*T> rather than
*T. They no longer fail on empty slices.

[breaking-change]
2014-05-12 19:52:29 -07:00
David Creswick
0a707140cb add shebang to scripts that have execute bit set 2014-05-12 19:52:29 -07:00
Alex Crichton
e44a84e7cd rustdoc: Fix hiding implementations of traits
This bug was introduced when rustdoc gained the ability to hyperlink across
crates in pub use statements.

Closes #14125
2014-05-12 19:52:29 -07:00
Brian Anderson
c1da4f875f Add the patch number to version strings. Closes #13289 2014-05-12 19:52:29 -07:00
Alexandre Gagnon
3e9f66fc9f Fix typos in rustc manpage 2014-05-12 19:52:28 -07:00
bors
07d63228ea auto merge of #14157 : pcwalton/rust/detildestr-rustdoc, r=pcwalton
r? @brson
2014-05-12 18:37:13 -07:00
Patrick Walton
9ba91e1243 librustdoc: Remove all ~str usage from librustdoc. 2014-05-12 17:57:26 -07:00
Niko Matsakis
7d6f1aa2ac Factor out foldable better to reduce code duplication. There is now a "double
dispatch" pattern that lets you easily write new folders and then apply them to
various structures, reusing the "folding" effort.
2014-05-12 17:46:26 -04:00
Patrick Walton
6559a3675e librustc: Remove all uses of ~str from librustc. 2014-05-12 11:28:57 -07:00
bors
e8053b9a7f auto merge of #13932 : MrAlert/rust/win-compat, r=brson
This addresses #12842 by offering fallback implementations for functions that aren't available.

In this case, as Windows XP simply doesn't support symbolic links at all, the fallbacks simply return an error code indicating that the function hasn't been implemented. This should allow programs written in Rust to run under XP while still offering full support for symbolic links under newer versions of Windows with the same binary, but due to LLVM using stderror_s(), which isn't available in msvcrt.dll in XP, rustc itself will not.

The fallback implementation is as follows:

Calling the function instead calls to a mutable function pointer. This in and of itself would not constitute a performance hit because DLL calls are implemented in a similar manner (see Import Address Table). The function pointer initially points to a thunk which tries to get the address of the associated function and write it back to the function pointer. If it fails to find the function, it instead writes the address to a fallback. As this operation is idempotent, reading and writing the pointer simply needs to be atomic. Subsequent calls to the function should be as fast as any other DLL call, as the pointer will then point directly to either the correct function or a fallback.
2014-05-12 09:12:04 -07:00
bors
edae0bdabf auto merge of #13922 : Rufflewind/rust/patch-1, r=pnkfelix
Since rust-top-item-beg-re hasn't been defined yet, using defvar instead of
setq is more appropriate here (and also silences compilation warnings).
2014-05-12 03:36:53 -07:00
bors
0550b79f73 auto merge of #14127 : thestinger/rust/snapshot, r=huonw 2014-05-12 00:31:52 -07:00
Daniel Micay
8b912bc56b register snapshots 2014-05-12 02:52:32 -04:00
bors
e031ba1028 auto merge of #14096 : nick29581/rust/driver, r=brson
The goal of this refactoring is to make the rustc driver code easier to understand and use. Since this is as close to an API as we have, I think it is important that it is nice. On getting stuck in, I found that there wasn't as much to change as I'd hoped to make the stage... functions easier to use by tools (which is a good thing :-) ).

This patch only moves code around - mostly just moving code to different files, but a few extracted method refactorings too. To summarise the changes: I added driver::config which handles everything about configuring the compiler. driver::session now just defines and builds session objects. I moved driver code from librustc/lib.rs to librustc/driver/mod.rs so all the code is one place. I extracted methods to make emulating the compiler without being the compiler a little easier. Within the driver directory, I moved code around to more logically fit in the modules.
2014-05-11 21:31:48 -07:00
bors
72fc4a5eb7 auto merge of #14119 : thestinger/rust/heap, r=cmr 2014-05-11 17:51:41 -07:00
Daniel Micay
f1735cefcf make sure jemalloc valgrind support is enabled
This requires pointing it at the valgrind headers we carry in-tree.
2014-05-11 20:05:22 -04:00
bors
b40c3e9d3d auto merge of #14110 : SSheldon/rust/strbuf_mutable, r=alexcrichton
Despite implementing the Container trait, StrBuf did not implement the Mutable trait and had no clear method; this request implements the clear method of the Mutable trait for StrBuf.

Testing done: added a test and ran `make check` without any failures.
2014-05-11 16:21:44 -07:00
Daniel Micay
69b321c84b heap: replace exchange_free with deallocate
The `std::rt::heap` API is Rust's global allocator, so there's no need
to have this as a separate API.
2014-05-11 18:41:45 -04:00
bors
f483aa3a91 auto merge of #14102 : moonglum/rust/slice-clarification-in-readme, r=kballard
There are no arrays in Rust, they are slices. Especially in the tutorial beginners should not be confused with wrong terminology. It helps to know the right names for things when you want to find something in the documentation.

@erickt explained that today to me and it helped me a lot when getting started 😉 Maybe we should also explain what a slice and what a vector is in the tutorial. If you like that, I will try to do that and attach that to the pull request 😉
2014-05-11 14:51:46 -07:00
Daniel Micay
32988db2bd heap: add a way to print allocator statistics 2014-05-11 17:41:36 -04:00
Daniel Micay
f3de28a920 mark rust_malloc/rust_free as unsafe
Support for this was added by 08237cad8d.
2014-05-11 17:41:36 -04:00
Alex Crichton
034f218061 mk: Bundle jemalloc with make dist
The dist tarball doesn't depend on git, so all git submodules must be included
inside of it.
2014-05-11 17:41:36 -04:00
bors
20356e4cc3 auto merge of #14108 : thestinger/rust/jemalloc, r=huonw 2014-05-11 11:21:44 -07:00
Daniel Micay
420708f389 sync::deque: port to the new allocator API 2014-05-11 13:54:53 -04:00
Daniel Micay
7da24ea1a9 hashmap: port to the new allocator API 2014-05-11 13:30:19 -04:00
bors
c690bda159 auto merge of #14101 : alexcrichton/rust/issue-14095, r=kballard
When the values in html::item_type were updated, the JS definitions were
accidentally not updated as well.

Closes #14095
2014-05-11 09:51:43 -07:00
bors
032510bae2 auto merge of #14103 : alan-andrade/rust/manual-smallfix, r=alexcrichton
Hi,

I believe the word "managed" doesn't make sense here anymore. It's just a box.
2014-05-11 08:01:43 -07:00
bors
2877a4e989 auto merge of #14090 : TeXitoi/rust/shootout-nbody-improvement, r=alexcrichton
- minimize bound check
- factorise operations
- use x, y, z instead of [f64, ..3]
- ~1.15 faster
2014-05-11 04:41:43 -07:00
Steven Sheldon
a40b971aaf Implement Mutable trait for StrBuf. 2014-05-11 03:49:09 -07:00
bors
fb569fd398 auto merge of #14069 : alexcrichton/rust/cast-module, r=brson
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.

* transmute - This function was moved to `mem`, but it is now marked as
              #[unstable]. This is due to planned changes to the `transmute`
              function and how it can be invoked (see the #[unstable] comment).
              For more information, see RFC 5 and #12898

* transmute_copy - This function was moved to `mem`, with clarification that is
                   is not an error to invoke it with T/U that are different
                   sizes, but rather that it is strongly discouraged. This
                   function is now #[stable]

* forget - This function was moved to `mem` and marked #[stable]

* bump_box_refcount - This function was removed due to the deprecation of
                      managed boxes as well as its questionable utility.

* transmute_mut - This function was previously deprecated, and removed as part
                  of this commit.

* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
                         can be achieved with an `as` in safe code, so it was
                         removed.

* transmute_lifetime - This function was removed because it is likely a strong
                       indication that code is incorrect in the first place.

* transmute_mut_lifetime - This function was removed for the same reasons as
                           `transmute_lifetime`

* copy_lifetime - This function was moved to `mem`, but it is marked
                  `#[unstable]` now due to the likelihood of being removed in
                  the future if it is found to not be very useful.

* copy_mut_lifetime - This function was also moved to `mem`, but had the same
                      treatment as `copy_lifetime`.

* copy_lifetime_vec - This function was removed because it is not used today,
                      and its existence is not necessary with DST
                      (copy_lifetime will suffice).

In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.

    transmute - #[unstable]
    transmute_copy - #[stable]
    forget - #[stable]
    copy_lifetime - #[unstable]
    copy_mut_lifetime - #[unstable]
2014-05-11 02:26:43 -07:00
Alex Crichton
f94d671bfa core: Remove the cast module
This commit revisits the `cast` module in libcore and libstd, and scrutinizes
all functions inside of it. The result was to remove the `cast` module entirely,
folding all functionality into the `mem` module. Specifically, this is the fate
of each function in the `cast` module.

* transmute - This function was moved to `mem`, but it is now marked as
              #[unstable]. This is due to planned changes to the `transmute`
              function and how it can be invoked (see the #[unstable] comment).
              For more information, see RFC 5 and #12898

* transmute_copy - This function was moved to `mem`, with clarification that is
                   is not an error to invoke it with T/U that are different
                   sizes, but rather that it is strongly discouraged. This
                   function is now #[stable]

* forget - This function was moved to `mem` and marked #[stable]

* bump_box_refcount - This function was removed due to the deprecation of
                      managed boxes as well as its questionable utility.

* transmute_mut - This function was previously deprecated, and removed as part
                  of this commit.

* transmute_mut_unsafe - This function doesn't serve much of a purpose when it
                         can be achieved with an `as` in safe code, so it was
                         removed.

* transmute_lifetime - This function was removed because it is likely a strong
                       indication that code is incorrect in the first place.

* transmute_mut_lifetime - This function was removed for the same reasons as
                           `transmute_lifetime`

* copy_lifetime - This function was moved to `mem`, but it is marked
                  `#[unstable]` now due to the likelihood of being removed in
                  the future if it is found to not be very useful.

* copy_mut_lifetime - This function was also moved to `mem`, but had the same
                      treatment as `copy_lifetime`.

* copy_lifetime_vec - This function was removed because it is not used today,
                      and its existence is not necessary with DST
                      (copy_lifetime will suffice).

In summary, the cast module was stripped down to these functions, and then the
functions were moved to the `mem` module.

    transmute - #[unstable]
    transmute_copy - #[stable]
    forget - #[stable]
    copy_lifetime - #[unstable]
    copy_mut_lifetime - #[unstable]

[breaking-change]
2014-05-11 01:13:02 -07:00