Commit Graph

5281 Commits

Author SHA1 Message Date
Alex Crichton 0d8f5fa618 core: Move Option::expect to libstd from libcore
See #14008 for more details
2014-05-07 08:17:32 -07:00
Alex Crichton f62c121eb0 core: Inherit the cell module 2014-05-07 08:16:14 -07:00
Alex Crichton d4b5d82a33 core: Add unwrap()/unwrap_err() methods to Result
These implementations must live in libstd right now because the fmt module has
not been migrated yet. This will occur in a later PR.

Just to be clear, there are new extension traits, but they are not necessary
once the std::fmt module has migrated to libcore, which is a planned migration
in the future.
2014-05-07 08:16:14 -07:00
Alex Crichton a156534a96 core: Inherit the result module
The unwrap()/unwrap_err() methods are temporarily removed, and will be added
back in the next commit.
2014-05-07 08:16:14 -07:00
Alex Crichton e4271cae54 core: Add a limited implementation of failure
This adds an small of failure to libcore, hamstrung by the fact that std::fmt
hasn't been migrated yet. A few asserts were re-worked to not use std::fmt
features, but these asserts can go back to their original form once std::fmt has
migrated.

The current failure implementation is to just have some symbols exposed by
std::rt::unwind that are linked against by libcore. This is an explicit circular
dependency, unfortunately. This will be officially supported in the future
through compiler support with much nicer failure messages. Additionally, there
are two depended-upon symbols today, but in the future there will only be one
(once std::fmt has migrated).
2014-05-07 08:16:14 -07:00
Alex Crichton c67ebf1ef3 std: Remove a glob to get std to compile 2014-05-07 08:16:14 -07:00
Alex Crichton 9bae6ec828 core: Inherit possible string functionality
This moves as much allocation as possible from teh std::str module into
core::str. This includes essentially all non-allocating functionality, mostly
iterators and slicing and such.

This primarily splits the Str trait into only having the as_slice() method,
adding a new StrAllocating trait to std::str which contains the relevant new
allocation methods. This is a breaking change if any of the methods of "trait
Str" were overriden. The old functionality can be restored by implementing both
the Str and StrAllocating traits.

[breaking-change]
2014-05-07 08:16:14 -07:00
Alex Crichton 544d909401 core: Inherit necessary unicode functionality
The unicode module remains private, but the normalization iterators require an
allocation, so some functionality needs to remain in libstd
2014-05-07 08:15:58 -07:00
Alex Crichton 91ede1f09a core: Inherit non-allocating slice functionality
This commit adds a new trait, MutableVectorAllocating, which represents
functions on vectors which can allocate.

This is another extension trait to slices which should be removed once a lang
item exists for the ~ allocation.
2014-05-07 08:15:58 -07:00
Alex Crichton be0a11729e core: Inherit the specific numeric modules
This implements all traits inside of core::num for all the primitive types,
removing all the functionality from libstd. The std modules reexport all of the
necessary items from the core modules.
2014-05-07 08:15:58 -07:00
Alex Crichton 0c30293886 core: Inherit what's possible from the num module
This strips out all string-related functionality from the num module. The
inherited functionality is all that will be implemented in libcore (for now).
Primarily, libcore will not implement the Float trait or any string-related
functionality.

It may be possible to migrate string parsing functionality into libcore in the
future, but for now it will remain in libstd.

All functionality in core::num is reexported in std::num.
2014-05-07 08:15:58 -07:00
Alex Crichton c5229e5d2e core: Inhert ~/@/& cmp traits, remove old modules
This commit removes the std::{managed, reference} modules. The modules serve
essentially no purpose, and the only free function removed was `managed::ptr_eq`
which can be achieved by comparing references.

[breaking-change]
2014-05-07 08:15:58 -07:00
Alex Crichton 5592a8f5db core: Inherit the cmp module
This removes the TotalOrd and TotalEq implementation macros, they will be added
later to the numeric modules (where the other comparison implementations live).
2014-05-07 08:15:19 -07:00
Alex Crichton b024ba544c core: Inherit the iter module 2014-05-07 08:14:56 -07:00
Alex Crichton 06fcb6b1c8 core: Inherit the option module 2014-05-07 08:14:56 -07:00
Alex Crichton 6636215a44 core: Inherit the bool module 2014-05-07 08:14:56 -07:00
Alex Crichton 92095d125a core: Inherit the tuple module 2014-05-07 08:14:54 -07:00
Alex Crichton 54b81997f3 core: Inherit the clone module 2014-05-07 08:13:56 -07:00
Alex Crichton e7eed5f670 core: Inherit the unit module 2014-05-07 08:13:56 -07:00
Alex Crichton dfd967f239 core: Inherit the default module 2014-05-07 08:13:56 -07:00
Alex Crichton 17cb238ee8 core: Inherit the raw module 2014-05-07 08:13:56 -07:00
Alex Crichton 8ed728babb core: Inherit the any module 2014-05-07 08:13:56 -07:00
Alex Crichton 85a8e6b80a core: Inherit the finally module 2014-05-07 08:13:24 -07:00
Alex Crichton 7192452545 core: Inherit the char module 2014-05-07 08:13:24 -07:00
Alex Crichton d9708539af core: Inherit the container module 2014-05-07 08:13:24 -07:00
Alex Crichton 2ad98fbb27 core: Inherit the ty module 2014-05-07 08:13:24 -07:00
Alex Crichton ead6e16a60 core: Inherit the ops module 2014-05-07 08:13:06 -07:00
Alex Crichton ec8a805b6d core: Inherit the kinds module 2014-05-07 08:13:06 -07:00
Alex Crichton 28624661c3 core: Inherit the cast module 2014-05-07 08:13:06 -07:00
Alex Crichton 645b157564 core: Inherit the ptr module 2014-05-07 08:13:06 -07:00
Alex Crichton dca8a0d6e4 core: Inherit the mem module 2014-05-07 08:12:48 -07:00
Alex Crichton 5b75e44fb0 core: Inherit the intrinsics module 2014-05-07 08:12:48 -07:00
bors ef6daf9935 auto merge of #13958 : pcwalton/rust/detilde, r=pcwalton
for `~str`/`~[]`.

Note that `~self` still remains, since I forgot to add support for
`Box<self>` before the snapshot.

r? @brson or @alexcrichton or whoever
2014-05-07 05:16:48 -07:00
bors 4a5d39001b auto merge of #13914 : alexcrichton/rust/pile-o-rustdoc-fixes, r=brson
Lots of assorted things here and there, all the details are in the commits.

Closes #11712
2014-05-07 03:21:47 -07:00
Patrick Walton 090040bf40 librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except
for `~str`/`~[]`.

Note that `~self` still remains, since I forgot to add support for
`Box<self>` before the snapshot.

How to update your code:

* Instead of `~EXPR`, you should write `box EXPR`.

* Instead of `~TYPE`, you should write `Box<Type>`.

* Instead of `~PATTERN`, you should write `box PATTERN`.

[breaking-change]
2014-05-06 23:12:54 -07:00
bors 2dcbad5bc4 auto merge of #13754 : alexcrichton/rust/net-experimental, r=brson
The underlying I/O objects implement a good deal of various options here and
there for tuning network sockets and how they perform. Most of this is a relic
of "whatever libuv provides", but these options are genuinely useful.

It is unclear at this time whether these options should be well supported or
not, or whether they have correct names or not. For now, I believe it's better
to expose the functionality than to not, but all new methods are added with
an #[experimental] annotation.
2014-05-06 22:01:43 -07:00
bors cf6857b9e9 auto merge of #13897 : aturon/rust/issue-6085, r=bjz
The `std::bitflags::bitflags!` macro did not provide support for
adding attributes to the generates structure, due to limitations in
the parser for macros. This patch works around the parser limitations
by requiring a `flags` keyword in the `bitflags!` invocations:

    bitflags!(
        #[deriving(Hash)]
        #[doc="Three flags"]
        flags Flags: u32 {
            FlagA       = 0x00000001,
            FlagB       = 0x00000010,
            FlagC       = 0x00000100
        }
    )

The intent of `std::bitflags` is to allow building type-safe wrappers
around C-style flags APIs. But in addition to construction these flags
from the Rust side, we need a way to convert them from the C
side. This patch adds a `from_bits` function, which is unsafe since
the bits in question may not represent a valid combination of flags.

Finally, this patch changes `std::io::FilePermissions` from an exposed
`u32` representation to a typesafe representation (that only allows valid
flag combinations) using the `std::bitflags`.

Closes #6085.
2014-05-06 12:41:55 -07:00
bors bd3fb81e5e auto merge of #13934 : huonw/rust/transmute-mut, r=alexcrichton
Turning a `&T` into an `&mut T` is undefined behaviour, and needs to be
done very very carefully. Providing a convenience function for exactly
this task is a bad idea, just tempting people into doing the wrong
thing.

(The right thing is to use types like `Cell`, `RefCell` or `Unsafe`.)

cc https://github.com/mozilla/rust/issues/13933
2014-05-05 16:51:30 -07:00
bors 7583544fb5 auto merge of #13912 : seanmonstar/rust/logrecord, r=alexcrichton
The logging macros now create a LogRecord, and pass that to the Logger. This will allow custom loggers to change the formatting, and possible filter on more properties of the log record.

DefaultLogger's formatting was taken from Python's default formatting:
`LEVEL:from: message`

Also included: fmt::Arguments now implement Show, so they can be used to
extend format strings.

@alexcrichton r?
2014-05-05 15:26:31 -07:00
Aaron Turon 8d1d7d9b5f Change std::io::FilePermission to a typesafe representation
This patch changes `std::io::FilePermissions` from an exposed `u32`
representation to a typesafe representation (that only allows valid
flag combinations) using the `std::bitflags`, thus ensuring a greater
degree of safety on the Rust side.

Despite the change to the type, most code should continue to work
as-is, sincde the new type provides bit operations in the style of C
flags. To get at the underlying integer representation, use the `bits`
method; to (unsafely) convert to `FilePermissions`, use
`FilePermissions::from_bits`.

Closes #6085.

[breaking-change]
2014-05-05 15:24:36 -07:00
Aaron Turon c00d8fd9a0 Add (unsafe) coercion from bits to std::bitflags
The intent of `std::bitflags` is to allow building type-safe wrappers
around C-style flags APIs. But in addition to construction these flags
from the Rust side, we need a way to convert them from the C
side. This patch adds a `from_bits` function, which is unsafe since
the bits in question may not represent a valid combination of flags.
2014-05-05 15:24:36 -07:00
Aaron Turon b733df0fc7 Allow attributes in std::bitflags::bitflags!
The `std::bitflags::bitflags!` macro did not provide support for
adding attributes to the generated structure or flags, due to
limitations in the parser for macros. This patch works around the
parser limitations by requiring a `flags` keyword in the overall
`bitflags!` invocation, and a `static` keyword for each flag:

    bitflags!(
        #[deriving(Hash)]
        #[doc="Three flags"]
        flags Flags: u32 {
            #[doc="The first flag"]
            static FlagA       = 0x00000001,
            static FlagB       = 0x00000010,
            static FlagC       = 0x00000100
        }
    )
2014-05-05 15:24:36 -07:00
Sean McArthur ceb29314a7 log: Logger receiveis a LogRecord
The logging macros now create a LogRecord, and pass that to the
Logger, instead of passing a `level` and `args`. The new signature is:

    trait Logger {
        fn log(&mut self, record: &LogRecord);
    }

The LogRecord includes additional values that may be useful to custom
loggers, and also allows for further expansion if not values are found
useful.

DefaultLogger's formatting was taken from Python's default formatting:
`LEVEL:from: message`

Also included: fmt::Arguments now implement Show, so they can be used to
extend format strings.

[breaking-change]
2014-05-05 11:18:53 -07:00
Huon Wilson edd9bad4ee std::comm: use Unsafe to avoid U.B. & -> &mut transmutes. 2014-05-05 18:20:41 +10:00
Huon Wilson 781ac3e777 std: deprecate cast::transmute_mut.
Turning a `&T` into an `&mut T` carries a large risk of undefined
behaviour, and needs to be done very very carefully. Providing a
convenience function for exactly this task is a bad idea, just tempting
people into doing the wrong thing.

The right thing is to use types like `Cell`, `RefCell` or `Unsafe`.

For memory safety, Rust has that guarantee that `&mut` pointers do not
alias with any other pointer, that is, if you have a `&mut T` then that
is the only usable pointer to that `T`. This allows Rust to assume that
writes through a `&mut T` do not affect the values of any other `&` or
`&mut` references. `&` pointers have no guarantees about aliasing or
not, so it's entirely possible for the same pointer to be passed into
both arguments of a function like

    fn foo(x: &int, y: &int) { ... }

Converting either of `x` or `y` to a `&mut` pointer and modifying it
would affect the other value: invalid behaviour.

(Similarly, it's undefined behaviour to modify the value of an immutable
local, like `let x = 1;`.)

At a low-level, the *only* safe way to obtain an `&mut` out of a `&` is
using the `Unsafe` type (there are higher level wrappers around it, like
`Cell`, `RefCell`, `Mutex` etc.). The `Unsafe` type is registered with
the compiler so that it can reason a little about these `&` to `&mut`
casts, but it is still up to the user to ensure that the `&mut`s
obtained out of an `Unsafe` never alias.

(Note that *any* conversion from `&` to `&mut` can be invalid, including
a plain `transmute`, or casting `&T` -> `*T` -> `*mut T` -> `&mut T`.)

[breaking-change]
2014-05-05 18:20:41 +10:00
Alex Crichton 877f09bf96 Register new snapshots 2014-05-04 22:35:21 -07:00
bors 1b5bbbf877 auto merge of #13865 : alexcrichton/rust/issue-13861, r=brson
Previously, windows was using the CREATE_NEW flag which fails if the file
previously existed, which differed from the unix semantics. This alters the
opening to use the OPEN_ALWAYS flag to mirror the unix semantics.

Closes #13861
2014-05-04 18:36:43 -07:00
Alex Crichton 9306e840f5 rustdoc: Migrate from sundown to hoedown
This primary fix brought on by this upgrade is the proper matching of the ```
and ~~~ doc blocks. This also moves hoedown to a git submodule rather than a
bundled repository.

Additionally, hoedown is stricter about code blocks, so this ended up fixing a
lot of invalid code blocks (ending with " ```" instead of "```", or ending with
"~~~~" instead of "~~~").

Closes #12776
2014-05-03 17:36:20 -07:00
bors 0c691df8ac auto merge of #13773 : brson/rust/boxxy, r=alexcrichton
`box` is the way you allocate in future-rust.
2014-05-03 10:56:57 -07:00
bors bca9647cd3 auto merge of #13904 : pcwalton/rust/box, r=alexcrichton
r? @alexcrichton

RFC#14 

Issue #13885.
2014-05-03 09:31:49 -07:00