Commit Graph

420 Commits

Author SHA1 Message Date
bors
a54a809219 Auto merge of #25359 - thepowersgang:result-expect-2, r=alexcrichton
As it says in the title. I've added an `expect` method to `Result` that allows printing both an error message (e.g. what operation was attempted), and the error value. This is separate from the `unwrap` and `ok().expect("message")` behaviours.
2015-06-15 05:11:53 +00:00
John Hodge
0937c10f3c libcore/Result - RFC#1119 Add an 'expect' method to Result 2015-06-15 12:00:16 +08:00
Joshua Landau
ca7418b846 Removed many pointless calls to *iter() and iter_mut() 2015-06-10 21:14:03 +01:00
Simon Sapin
6369dcbad8 Move collectionstest::char into coretest::char 2015-06-09 13:08:29 +02:00
Simon Sapin
c6a8d5e733 Fix coretest::char::test_to_uppercase for complex mapping 2015-06-09 13:08:22 +02:00
bors
a0f028da07 Auto merge of #25817 - XMPPwocky:once_cleanedup, r=alexcrichton
Closes #24443.
2015-05-30 01:12:35 +00:00
Nathaniel Theis
103e79d26a Implement RFC 771: std::iter::once 2015-05-29 12:02:13 -07:00
Niko Matsakis
2c5e784d6f add const_fn features 2015-05-29 09:42:54 -04:00
Simon Sapin
d0afa6ede3 Add map and filter_map associated functions to std::cell::Ref and RefMut
See design discussion in https://github.com/rust-lang/rust/pull/25747
2015-05-29 08:39:07 +02:00
Simon Sapin
c516eee503 Move std::cell::clone_ref to a clone associated function on std::cell::Ref
... and generalize the bounds on the value type.
2015-05-28 23:01:36 +02:00
Eduard Burtescu
377b0900ae Use const fn to abstract away the contents of UnsafeCell & friends. 2015-05-27 11:19:03 +03:00
Steven Fackler
e161d5cf73 Stabilize debug builders for 1.2.0 2015-05-19 21:57:39 -07:00
Nick Cameron
5d4cce6cec Rebasing 2015-05-13 14:35:53 +12:00
bors
67ba6dcf68 Auto merge of #24612 - lifthrasiir:flt2dec, r=pnkfelix
This is a direct port of my prior work on the float formatting. The detailed description is available [here](https://github.com/lifthrasiir/rust-strconv#flt2dec). In brief,

* This adds a new hidden module `core::num::flt2dec` for testing from `libcoretest`. Why is it in `core::num` instead of `core::fmt`? Because I envision that the table used by `flt2dec` is directly applicable to `dec2flt` (cf. #24557) as well, which exceeds the realm of "formatting".
* This contains both Dragon4 algorithm (exact, complete but slow) and Grisu3 algorithm (exact, fast but incomplete).
* The code is accompanied with a large amount of self-tests and some exhaustive tests. In particular, `libcoretest` gets a new dependency on `librand`. For the external interface it relies on the existing test suite.
* It is known that, in the best case, the entire formatting code has about 30 KBs of binary overhead (judged from strconv experiments). Not too bad but there might be a potential room for improvements.

This is rather large code. I did my best to comment and annotate the code, but you have been warned.

For the maximal availability the original code was licensed in CC0, but I've also dual-licensed it in MIT/Apache as well so there should be no licensing concern.

This is [breaking-change] as it changes the float output slightly (and it also affects the casing of `inf` and `nan`). I hope this is not a big deal though :)

Fixes #7030, #18038 and #24556. Also related to #6220 and #20870.

## Known Issues

- [x] I've yet to finish `make check-stage1`. It does pass main test suites including `run-pass` but there might be some unknown edges on the doctests.
- [ ] Figure out how this PR affects rustc.
- [ ] Determine which internal routine is mapped to the formatting specifier. Depending on the decision, some internal routine can be safely removed (for instance, currently `to_shortest_str` is unused).
2015-05-09 14:56:56 +00:00
Kang Seonghoon
3d34e177dd core: use banker's rounding for the exact mode in flt2dec.
For the shortest mode the IEEE 754 decoder already provides
an exact rounding range accounting for banker's rounding,
but it was not the case for the exact mode. This commit alters
the exact mode algorithm for Dragon so that any number ending at
`...x5000...` with even `x` and infinite zeroes will round to
`...x` instead of `...(x+1)` as it was. Grisu is not affected
by this change because this halfway case always results in
the failure for Grisu.
2015-05-06 21:11:14 +09:00
Kang Seonghoon
a641b05fda core: updated for the master changes.
The master no longer has `std::num::Float`, so a generic `ldexp` is
not readily available. `DecodableFloat::ldexpi` works around this.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
97ea7c14ba core: fixed a slight bug.
The bug involves the incorrect logic for `core::num::flt2dec::decoder`.
This makes some numbers in the form of 2^n missing one final digits,
which breaks the bijectivity criterion. The regression tests have been
added, and f32 exhaustive test is rerun to get the updated result.
2015-05-06 14:22:26 +09:00
Kang Seonghoon
8a195f0754 core: fixed typos and revised comments in flt2dec. 2015-05-06 14:22:20 +09:00
Kang Seonghoon
f9bfda0a6f core: tweaked flt2dec to match the casing of the older formatting code. 2015-05-06 14:21:48 +09:00
Kang Seonghoon
c82da7a54b core: added core::num::flt2dec for floating-point formatting.
This is a fork of the flt2dec portion of rust-strconv [1] with
a necessary relicensing (the original code was licensed CC0-1.0).
Each module is accompanied with large unit tests, integrated
in this commit as coretest::num::flt2dec. This module is added
in order to replace the existing core::fmt::float method.

The forked revision of rust-strconv is from 2015-04-20, with a commit ID
9adf6d3571c6764a6f240a740c823024f70dc1c7.

[1] https://github.com/lifthrasiir/rust-strconv/
2015-05-06 14:19:37 +09:00
Steven Allen
3fcbc31489 Optimize iterator adapters.
Specifically, make count, nth, and last call the corresponding methods
on the underlying iterator where possible. This way, if the underlying
iterator has an optimized count, nth, or last implementations (e.g.
slice::Iter), these methods will propagate these optimizations.

Additionally, change Skip::next to take advantage of a potentially
optimized nth method on the underlying iterator.
2015-05-05 14:17:23 -04:00
bors
1a60dc4fc4 Auto merge of #24737 - P1start:dst-cell, r=alexcrichton
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to be simplified to `Rc<RefCell<Trait>>`.
2015-05-03 17:22:09 +00:00
bors
f6574c5b04 Auto merge of #25006 - alexcrichton:unstable-indexing, r=aturon
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791

[breaking-change]
2015-05-01 22:54:09 +00:00
P1start
57d8289754 Make UnsafeCell, RefCell, Mutex, and RwLock accept DSTs
This + DST coercions (#24619) would allow code like `Rc<RefCell<Box<Trait>>>` to
be simplified to `Rc<RefCell<Trait>>`.
2015-05-02 10:03:35 +12:00
Alex Crichton
b1976f1f6e std: Remove index notation on slice iterators
These implementations were intended to be unstable, but currently the stability
attributes cannot handle a stable trait with an unstable `impl` block. This
commit also audits the rest of the standard library for explicitly-`#[unstable]`
impl blocks. No others were removed but some annotations were changed to
`#[stable]` as they're defacto stable anyway.

One particularly interesting `impl` marked `#[stable]` as part of this commit
is the `Add<&[T]>` impl for `Vec<T>`, which uses `push_all` and implicitly
clones all elements of the vector provided.

Closes #24791
2015-05-01 10:40:46 -07:00
bors
613109db1b Auto merge of #24720 - critiqjo:stepby-sizehint, r=alexcrichton
`Iterator::size_hint` can be easily implemented for `StepBy`.
#23708
2015-05-01 16:42:19 +00:00
critiqjo
2a8fc9b02c iterator: Add StepBy::size_hint method
Fixes `Step::steps_between` implementations by integer types
to correctly handle `by != 1`.
2015-05-01 14:10:08 +05:30
Tamir Duberstein
f7947bc936 Unstub some tests 2015-04-28 21:23:28 -07:00
Tamir Duberstein
8073af7399 Tests need not be public 2015-04-28 21:22:58 -07:00
Tamir Duberstein
cd5abe7635 Remove unused variable 2015-04-28 21:22:06 -07:00
bors
c48b499ea3 Auto merge of #24888 - tamird:snapshot, r=alexcrichton
r? @alexcrichton cc @brson
2015-04-29 02:16:01 +00:00
Tamir Duberstein
69abc12b00 Register new snapshots 2015-04-28 17:23:45 -07:00
bors
c4b23aec4c Auto merge of #24865 - bluss:range-size, r=alexcrichton
core: Fix size_hint for signed integer `Range<T>` iterators

There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-29 00:15:22 +00:00
bors
97d4e76c20 Auto merge of #24701 - Stebalien:slice, r=alexcrichton
Instead of using the O(n) defaults, define O(1) shortcuts. I also copied (and slightly modified) the relevant tests from the iter tests into the slice tests just in case someone comes along and changes them in the future.

Partially implements  #24214.
2015-04-27 22:46:48 +00:00
Ulrik Sverdrup
95be21df47 core: Fix size_hint for signed integer Range<T> iterators
There was an overflow bug in .size_hint() for signed iterators, which
produced an hilariously incorrect size or an overflow panic.

Incorrect size is a serious bug since the iterators are marked
ExactSizeIterator. (And leads to abort() on (-1i8..127).collect() when
the collection tries to preallocate too much).

All signed range iterators were affected.

> (-1i8..127).size_hint()
(18446744073709551488, Some(18446744073709551488))

Bug found using quickcheck.

Fixes #24851
2015-04-27 21:14:43 +02:00
Johannes Oertel
07cc7d9960 Change name of unit test sub-module to "tests".
Changes the style guidelines regarding unit tests to recommend using a
sub-module named "tests" instead of "test" for unit tests as "test"
might clash with imports of libtest.
2015-04-24 23:06:41 +02:00
Steven Allen
de8c79a535 Implement O(1) slice::Iter methods.
Instead of using the O(n) defaults, define O(1) shortcuts.
2015-04-22 17:17:24 -04:00
Alex Crichton
a568a7f9f2 std: Bring back f32::from_str_radix as an unstable API
This API was exercised in a few tests and mirrors the `from_str_radix`
functionality of the integer types.
2015-04-21 15:23:54 -07:00
Piotr Czarnecki
13bc8afa4b Model lexer: Fix remaining issues 2015-04-21 12:02:12 +02:00
kwantam
29d1252e4d deprecate Unicode functions that will be moved to crates.io
This patch
1. renames libunicode to librustc_unicode,
2. deprecates several pieces of libunicode (see below), and
3. removes references to deprecated functions from
   librustc_driver and libsyntax. This may change pretty-printed
   output from these modules in cases involving wide or combining
   characters used in filenames, identifiers, etc.

The following functions are marked deprecated:

1. char.width() and str.width():
   --> use unicode-width crate

2. str.graphemes() and str.grapheme_indices():
   --> use unicode-segmentation crate

3. str.nfd_chars(), str.nfkd_chars(), str.nfc_chars(), str.nfkc_chars(),
   char.compose(), char.decompose_canonical(), char.decompose_compatible(),
   char.canonical_combining_class():
   --> use unicode-normalization crate
2015-04-16 17:03:05 -04:00
Alex Crichton
700e627cf7 test: Fixup many library unit tests 2015-04-14 10:14:19 -07:00
Ben Ashford
faef52a847 Fix for #23150 2015-04-10 13:19:14 +01:00
bors
e4f9ddb878 Auto merge of #24180 - huonw:optimise-max-etc, r=alexcrichton
The main change in this patch is removing the use of `Option` inside the
inner loops of those functions to avoid comparisons where one branch
will only trigger on the first pass through the loop.

The included benchmarks go from:

    test bench_max    ... bench:       372 ns/iter (+/- 118)
    test bench_max_by ... bench:       428 ns/iter (+/- 33)
    test bench_max_by2 ... bench:      7128 ns/iter (+/- 326)

to:

    test bench_max    ... bench:       317 ns/iter (+/- 64)
    test bench_max_by ... bench:       356 ns/iter (+/- 270)
    test bench_max_by2 ... bench:      1387 ns/iter (+/- 183)

Problem noticed in http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
2015-04-10 07:54:18 +00:00
Huon Wilson
c2258d6d04 Optimise Iterator::{max, max_by, min, min_by}.
The main change in this patch is removing the use of `Option` inside the
inner loops of those functions to avoid comparisons where one branch
will only trigger on the first pass through the loop.

The included benchmarks go from:

    test bench_max    ... bench:       372 ns/iter (+/- 118)
    test bench_max_by ... bench:       428 ns/iter (+/- 33)
    test bench_max_by2 ... bench:      7128 ns/iter (+/- 326)

to:

    test bench_max    ... bench:       317 ns/iter (+/- 64)
    test bench_max_by ... bench:       356 ns/iter (+/- 270)
    test bench_max_by2 ... bench:      1387 ns/iter (+/- 183)

Problem noticed in http://www.reddit.com/r/rust/comments/31syce/using_iterators_to_find_the_index_of_the_min_or/
2015-04-10 14:42:17 +10:00
bors
dd6c4a8f15 Auto merge of #23293 - tbu-:pr_additive_multiplicative, r=alexcrichton
Previously it could not be implemented for types outside `libcore/iter.rs` due
to coherence issues.
2015-04-08 00:42:10 +00:00
Tobias Bucher
97f24a8596 Make sum and product inherent methods on Iterator
In addition to being nicer, this also allows you to use `sum` and `product` for
iterators yielding custom types aside from the standard integers.

Due to removing the `AdditiveIterator` and `MultiplicativeIterator` trait, this
is a breaking change.

[breaking-change]
2015-04-08 00:26:35 +02:00
bors
b2e65ee6e4 Auto merge of #23952 - Kimundi:more_string_pattern, r=alexcrichton
This adds the missing methods and turns `str::pattern` in a user facing module, as per RFC.

This also contains some big internal refactorings:
- string iterator pairs are implemented with a central macro to reduce redundancy 
- Moved all tests from `coretest::str` into `collectionstest::str` and left a note to prevent the two sets of tests drifting apart further.

See https://github.com/rust-lang/rust/issues/22477
2015-04-07 00:57:08 +00:00
Marvin Löbel
c29559d28a Moved coretest::str tests into collectiontest::str 2015-04-05 18:52:58 +02:00
Marvin Löbel
c04f22a667 Refactored core::str::pattern to become a user-facing module and hide away
CharEq.
2015-04-05 18:52:57 +02:00
bors
fc98b19cf7 Auto merge of #23832 - petrochenkov:usize, r=aturon
These constants are small and can fit even in `u8`, but semantically they have type `usize` because they denote sizes and are almost always used in `usize` context. The change of their type to `u32` during the integer audit led only to the large amount of `as usize` noise (see the second commit, which removes this noise).

This is a minor [breaking-change] to an unstable interface.

r? @aturon
2015-04-03 04:29:52 +00:00
Alex Crichton
9edbf42a34 rollup merge of #23945: pnkfelix/gate-u-negate
Feature-gate  unsigned unary negate.

Discussed in weekly meeting here: https://github.com/rust-lang/meeting-minutes/blob/master/weekly-meetings/2015-03-31.md#feature-gate--expr

and also in the internals thread here: http://internals.rust-lang.org/t/forbid-unsigned-integer/752
2015-04-01 18:36:21 -07:00
Alex Crichton
f86318d63c Test fixes and rebase conflicts, round 2
Conflicts:
	src/libcore/num/mod.rs
2015-04-02 02:07:51 +02:00
Alex Crichton
e98dce3e00 std: Changing the meaning of the count to splitn
This commit is an implementation of [RFC 979][rfc] which changes the meaning of
the count parameter to the `splitn` function on strings and slices. The
parameter now means the number of items that are returned from the iterator, not
the number of splits that are made.

[rfc]: https://github.com/rust-lang/rfcs/pull/979

Closes #23911
[breaking-change]
2015-04-01 13:29:42 -07:00
Alex Crichton
4f643d79fc rollup merge of #23863: pnkfelix/arith-oflo-const-eval
const_eval : add overflow-checking for {`+`, `-`, `*`, `/`, `<<`, `>>`}.

One tricky detail here: There is some duplication of labor between `rustc::middle::const_eval` and `rustc_trans::trans::consts`. It might be good to explore ways to try to factor out the common structure to the two passes (by abstracting over the particular value-representation used in the compile-time interpreter).

----

Update: Rebased atop #23841

Fix #22531

Fix #23030

Fix #23221

Fix #23235
2015-03-31 18:06:35 -07:00
Felix S. Klock II
8d54ea3ec9 Fallout from changes for overflow-checking during constant evaluation. 2015-04-01 02:56:07 +02:00
Alex Crichton
3422be3666 rollup merge of #23288: alexcrichton/issue-19470
This is a deprecated attribute that is slated for removal, and it also affects
all implementors of the trait. This commit removes the attribute and fixes up
implementors accordingly. The primary implementation which was lost was the
ability to compare `&[T]` and `Vec<T>` (in that order).

This change also modifies the `assert_eq!` macro to not consider both directions
of equality, only the one given in the left/right forms to the macro. This
modification is motivated due to the fact that `&[T] == Vec<T>` no longer
compiles, causing hundreds of errors in unit tests in the standard library (and
likely throughout the community as well).

Closes #19470
[breaking-change]
2015-03-31 15:59:35 -07:00
Alex Crichton
d4a2c94180 std: Clean out #[deprecated] APIs
This commit cleans out a large amount of deprecated APIs from the standard
library and some of the facade crates as well, updating all users in the
compiler and in tests as it goes along.
2015-03-31 15:49:57 -07:00
Alex Crichton
5cf126ae2f std: Remove #[old_orphan_check] from PartialEq
This is a deprecated attribute that is slated for removal, and it also affects
all implementors of the trait. This commit removes the attribute and fixes up
implementors accordingly. The primary implementation which was lost was the
ability to compare `&[T]` and `Vec<T>` (in that order).

This change also modifies the `assert_eq!` macro to not consider both directions
of equality, only the one given in the left/right forms to the macro. This
modification is motivated due to the fact that `&[T] == Vec<T>` no longer
compiles, causing hundreds of errors in unit tests in the standard library (and
likely throughout the community as well).

cc #19470
[breaking-change]
2015-03-31 13:39:14 -07:00
Alex Crichton
acd48a2b3e std: Standardize (input, output) param orderings
This functions swaps the order of arguments to a few functions that previously
took (output, input) parameters, but now take (input, output) parameters (in
that order).

The affected functions are:

* ptr::copy
* ptr::copy_nonoverlapping
* slice::bytes::copy_memory
* intrinsics::copy
* intrinsics::copy_nonoverlapping

Closes #22890
[breaking-change]
2015-03-30 14:08:40 -07:00
Vadim Petrochenkov
883adc6763 Fix the fallout 2015-03-30 12:19:11 +03:00
Steven Fackler
4037f2a368 Update debug helpers and add list builder
The collections debug helpers no longer prefix output with the
collection name, in line with the current conventions for Debug
implementations. Implementations that want to preserve the current
behavior can simply add a `try!(write!(fmt, "TypeName "));` at the
beginning of the `fmt` method.

[breaking-change]
2015-03-28 10:33:51 -07:00
Alex Crichton
990202cd0e rollup merge of #23794: brson/slicegate
Conflicts:
	src/test/run-pass/issue-13027.rs
2015-03-27 16:09:52 -07:00
Brian Anderson
1639e51f6e Feature gate *all* slice patterns. #23121
Until some backwards-compatibility hazards are fixed in #23121,
these need to be unstable.

[breaking-change]
2015-03-27 12:50:49 -07:00
Alex Crichton
01560112b8 Test fixes and rebase conflicts, round 1 2015-03-27 11:29:36 -07:00
Alex Crichton
43bfaa4a33 Mass rename uint/int to usize/isize
Now that support has been removed, all lingering use cases are renamed.
2015-03-26 12:10:22 -07:00
Nick Cameron
95602a759d Add trivial cast lints.
This permits all coercions to be performed in casts, but adds lints to warn in those cases.

Part of this patch moves cast checking to a later stage of type checking. We acquire obligations to check casts as part of type checking where we previously checked them. Once we have type checked a function or module, then we check any cast obligations which have been acquired. That means we have more type information available to check casts (this was crucial to making coercions work properly in place of some casts), but it means that casts cannot feed input into type inference.

[breaking change]

* Adds two new lints for trivial casts and trivial numeric casts, these are warn by default, but can cause errors if you build with warnings as errors. Previously, trivial numeric casts and casts to trait objects were allowed.
* The unused casts lint has gone.
* Interactions between casting and type inference have changed in subtle ways. Two ways this might manifest are:
- You may need to 'direct' casts more with extra type information, for example, in some cases where `foo as _ as T` succeeded, you may now need to specify the type for `_`
- Casts do not influence inference of integer types. E.g., the following used to type check:

```
let x = 42;
let y = &x as *const u32;
```

Because the cast would inform inference that `x` must have type `u32`. This no longer applies and the compiler will fallback to `i32` for `x` and thus there will be a type error in the cast. The solution is to add more type information:

```
let x: u32 = 42;
let y = &x as *const u32;
```
2015-03-25 10:03:57 +13:00
Alex Crichton
aea822626f rollup merge of #23503: alexcrichton/fix-ptr-docs
The method with which backwards compatibility was retained ended up leading to
documentation that rustdoc didn't handle well and largely ended up confusing.
2015-03-23 15:26:24 -07:00
Alex Crichton
c608084ff5 rollup merge of #23598: brson/gate
Conflicts:
	src/compiletest/compiletest.rs
	src/libcollections/lib.rs
	src/librustc_back/lib.rs
	src/libserialize/lib.rs
	src/libstd/lib.rs
	src/libtest/lib.rs
	src/test/run-make/rustdoc-default-impl/foo.rs
	src/test/run-pass/env-home-dir.rs
2015-03-23 15:13:15 -07:00
Niko Matsakis
76ead08108 Remove auto-deref'ing Pattern impl because it conflicts with other
possible blanket impls and also triggers internal overflow. Add some
special cases for common uses (&&str, &String) for now; bounds-targeting
deref coercions are probably the right longer term answer.
2015-03-23 18:05:20 -04:00
Brian Anderson
df290f127e Require feature attributes, and add them where necessary 2015-03-23 14:40:26 -07:00
Alex Crichton
e24fe5b8cf std: Remove deprecated ptr functions
The method with which backwards compatibility was retained ended up leading to
documentation that rustdoc didn't handle well and largely ended up confusing.
2015-03-21 10:16:01 -07:00
Alex Crichton
212e03181e std: Remove old_io/old_path from the prelude
This commit removes the reexports of `old_io` traits as well as `old_path` types
and traits from the prelude. This functionality is now all deprecated and needs
to be removed to make way for other functionality like `Seek` in the `std::io`
module (currently reexported as `NewSeek` in the io prelude).

Closes #23377
Closes #23378
2015-03-20 20:07:19 -07:00
Manish Goregaokar
fad4c380e8 Rollup merge of #23385 - tamird:cleanup-whitespace, r=alexcrichton
r? @alexcrichton

Conflicts:
	src/test/run-pass/test-fn-signature-verification-for-explicit-return-type.rs
2015-03-17 15:21:22 +05:30
Tamir Duberstein
d51047ded0 Strip all leading/trailing newlines 2015-03-15 09:08:21 -07:00
Aaron Turon
1d5983aded Deprecate range, range_step, count, distributions
This commit deprecates the `count`, `range` and `range_step` functions
in `iter`, in favor of range notation. To recover all existing
functionality, a new `step_by` adapter is provided directly on `ops::Range`
and `ops::RangeFrom`.

[breaking-change]
2015-03-13 14:45:13 -07:00
bors
49f7550a25 Auto merge of #23162 - sfackler:debug-builders, r=alexcrichton
I've made some minor changes from the implementation attached to the RFC to try to minimize codegen. The methods now take `&Debug` trait objects rather than being parameterized and there are inlined stub methods that call to non-inlined methods to do the work.

r? @alexcrichton 

cc @huonw for the `derive(Debug)` changes.
2015-03-12 07:30:44 +00:00
Steven Fackler
905a611b94 Switch to a specific feature 2015-03-11 12:58:01 -07:00
bors
cfea8ec416 Auto merge of #23126 - alexcrichton:char-third-pass, r=aturon
This commit performs another pass over the `std::char` module for stabilization.
Some minor cleanup is performed such as migrating documentation from libcore to
libunicode (where the `std`-facing trait resides) as well as a slight
reorganiation in libunicode itself. Otherwise, the stability modifications made
are:

* `char::from_digit` is now stable
* `CharExt::is_digit` is now stable
* `CharExt::to_digit` is now stable
* `CharExt::to_{lower,upper}case` are now stable after being modified to return
  an iterator over characters. While the implementation today has not changed
  this should allow us to implement the full set of case conversions in unicode
  where some characters can map to multiple when doing an upper or lower case
  mapping.
* `StrExt::to_{lower,upper}case` was added as unstable for a convenience of not
  having to worry about characters expanding to more characters when you just
  want the whole string to get into upper or lower case.

This is a breaking change due to the change in the signatures of the
`CharExt::to_{upper,lower}case` methods. Code can be updated to use functions
like `flat_map` or `collect` to handle the difference.

[breaking-change]

Closes #20333
2015-03-10 22:45:10 +00:00
Alex Crichton
0f6a0b58f9 std: Stabilize more of the char module
This commit performs another pass over the `std::char` module for stabilization.
Some minor cleanup is performed such as migrating documentation from libcore to
libunicode (where the `std`-facing trait resides) as well as a slight
reorganiation in libunicode itself. Otherwise, the stability modifications made
are:

* `char::from_digit` is now stable
* `CharExt::is_digit` is now stable
* `CharExt::to_digit` is now stable
* `CharExt::to_{lower,upper}case` are now stable after being modified to return
  an iterator over characters. While the implementation today has not changed
  this should allow us to implement the full set of case conversions in unicode
  where some characters can map to multiple when doing an upper or lower case
  mapping.
* `StrExt::to_{lower,upper}case` was added as unstable for a convenience of not
  having to worry about characters expanding to more characters when you just
  want the whole string to get into upper or lower case.

This is a breaking change due to the change in the signatures of the
`CharExt::to_{upper,lower}case` methods. Code can be updated to use functions
like `flat_map` or `collect` to handle the difference.

[breaking-change]
2015-03-10 15:08:31 -07:00
Steven Fackler
bd6ed22fdf Switch derive(Debug) to use the debug builders 2015-03-09 23:24:34 -07:00
Steven Fackler
e3656bd81b Implement RFC 640 2015-03-09 23:24:34 -07:00
Steven Fackler
e2605b42c7 Rename #[should_fail] to #[should_panic] 2015-03-09 10:14:21 -07:00
Manish Goregaokar
2fcdd824ef Rollup merge of #23056 - awlnx:master, r=nrc 2015-03-06 22:22:33 +05:30
awlnx
951ef9d1f1 fix for new attributes failing. issue #22964 2015-03-05 11:53:51 -05:00
Eduard Burtescu
e64670888a Remove integer suffixes where the types in compiled code are identical. 2015-03-05 12:38:33 +05:30
bors
bdf6e4fcf5 Auto merge of #22920 - tshepang:remove-some-warnings, r=huonw 2015-03-04 12:16:51 +00:00
Felix S. Klock II
0d5bcb14ad Switched to Box::new in many places.
Many of the modifications putting in `Box::new` calls also include a
pointer to Issue 22405, which tracks going back to `box <expr>` if
possible in the future.

(Still tried to use `Box<_>` where it sufficed; thus some tests still
have `box_syntax` enabled, as they use a mix of `box` and `Box::new`.)

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03 21:05:55 +01:00
Felix S. Klock II
270f0eef73 Add : Box<_> or ::Box<_> type annotations to various places.
This is the kind of change that one is expected to need to make to
accommodate overloaded-`box`.

----

Note that this is not *all* of the changes necessary to accommodate
Issue 22181.  It is merely the subset of those cases where there was
already a let-binding in place that made it easy to add the necesasry
type ascription.

(For unnamed intermediate `Box` values, one must go down a different
route; `Box::new` is the option that maximizes portability, but has
potential inefficiency depending on whether the call is inlined.)

----

There is one place worth note, `run-pass/coerce-match.rs`, where I
used an ugly form of `Box<_>` type ascription where I would have
preferred to use `Box::new` to accommodate overloaded-`box`.  I
deliberately did not use `Box::new` here, because that is already done
in coerce-match-calls.rs.

----

Precursor for overloaded-`box` and placement-`in`; see Issue 22181.
2015-03-03 20:29:01 +01:00
bors
14f0942a49 Auto merge of #22532 - pnkfelix:arith-overflow, r=pnkfelix,eddyb
Rebase and follow-through on work done by @cmr and @aatch.

Implements most of rust-lang/rfcs#560. Errors encountered from the checks during building were fixed.

The checks for division, remainder and bit-shifting have not been implemented yet.

See also PR #20795

cc @Aatch ; cc @nikomatsakis
2015-03-03 14:18:03 +00:00
Felix S. Klock II
c8db89aa82 Accommodate arith-overflow in core::num, std::num, coretest::num.
* `core::num`: adjust `UnsignedInt::is_power_of_two`,
   `UnsignedInt::next_power_of_two`, `Int::pow`.

   In particular for `Int::pow`: (1.) do not panic when `base`
   overflows if `acc` never observes the overflowed `base`, and (2.)
   if `acc` does observe the overflowed `base`, make sure we only
   panic if we would have otherwise (e.g. during a computation of
   `base * base`).

 * also in `core::num`: avoid underflow during computation of `uint::MAX`.

 * `std::num`: adjust tests `uint::test_uint_from_str_overflow`,
   `uint::test_uint_to_str_overflow`, `strconv`

 * `coretest::num`: adjust `test::test_int_from_str_overflow`.
2015-03-03 12:10:57 +01:00
Florian Zeitz
f35f973cb7 Use consts instead of statics where appropriate
This changes the type of some public constants/statics in libunicode.
Notably some `&'static &'static [(char, char)]` have changed
to `&'static [(char, char)]`. The regexp crate seems to be the
sole user of these, yet this is technically a [breaking-change]
2015-03-02 17:11:51 +01:00
Manish Goregaokar
fb19cd7fb7 Rollup merge of #22504 - GuillaumeGomez:audit-integer-libcore, r=Manishearth
Part of #22240.
2015-03-02 03:53:41 +05:30
Guillaume Gomez
df126589b9 Remove int/uint from libstd/lib.rs 2015-03-01 13:03:44 +01:00
Tshepang Lekhonkhobe
55ce45e7b5 remove some compiler warnings 2015-03-01 09:35:57 +02:00
Guillaume Gomez
1c4fb909ff Make Int::pow() take exp as u32 instead usize 2015-03-01 01:58:55 +01:00
Manish Goregaokar
cf29aa5300 Rollup merge of #22835 - tshepang:remove-some-warnings, r=jakub- 2015-02-27 22:07:04 +05:30
Manish Goregaokar
ce5f1b3216 Rollup merge of #22817 - jmesmon:result-or-type, r=huonw
Changes .or() so that it can return a Result with a different E type
than the one it is called on.

Essentially:

    fn or(self, res: Result<T, E>) -> Result<T, E>

becomes

    fn or<F>(self, res: Result<T, F>) -> Result<T, F>

This brings `or` in line with the existing `and` & `or_else`

This is a
[breaking-change]
Due to some code needing additional type annotations.
2015-02-27 22:07:03 +05:30
Tshepang Lekhonkhobe
8b2ff472cf remove some compiler warnings 2015-02-26 07:21:26 +02:00
Cody P Schafer
07dc8d67c9 Result::or : avoid over-specializing the type
Changes .or() so that it can return a Result with a different E type
than the one it is called on.

Essentially:

    fn or(self, res: Result<T, E>) -> Result<T, E>

becomes

    fn or<F>(self, res: Result<T, F>) -> Result<T, F>

This brings `or` in line with the existing `and` and `or_else` member
types.

This is a
[breaking-change]
Due to some code needing additional type annotations.
2015-02-25 17:38:28 -05:00
Manish Goregaokar
ad73cb0e18 Rollup merge of #22747 - krdln:fix-parsing-minus, r=alexcrichton
Makes Rust less amusing by fixing [#22745](https://github.com/rust-lang/rust/issues/22745)
2015-02-25 03:20:58 +05:30
Vadim Petrochenkov
2807a1ce02 Use arrays instead of vectors in tests 2015-02-24 21:15:45 +03:00
Michał Krasnoborski
a9f6f4b73e Add missing fn 2015-02-24 08:24:42 +01:00
Michał Krasnoborski
948a17ed1d Stop parsing "-" as integer, fixes #22745 2015-02-24 06:04:49 +01:00
bors
67eb38ee4c Auto merge of #22466 - Kimundi:str_pattern_ai_safe, r=aturon
This is not a complete implementation of the RFC:

- only existing methods got updated, no new ones added
- doc comments are not extensive enough yet
- optimizations got lost and need to be reimplemented

See https://github.com/rust-lang/rfcs/pull/528

Technically a

[breaking-change]
2015-02-22 22:45:46 +00:00
Alexis
97aa34046f try to reduce bajillion warnings 2015-02-20 19:55:00 -05:00
Marvin Löbel
a641996796 Fix tidy and rebase fallout
Added a few bugfixes and additional testcases
2015-02-20 00:58:07 +01:00
Marvin Löbel
c1de0a0f9e Added a Pattern impl that delegates to the dereference of a type.
This allows to match with a `&String` or `&&str`, for example.
2015-02-20 00:58:06 +01:00
Marvin Löbel
f9ef8cd555 Refactored code into Searcher traits with naive implementations
Made the family of Split iterators use the Pattern API

Renamed the Matcher traits into Searcher
2015-02-20 00:57:38 +01:00
Marvin Löbel
54f0bead81 Added string pattern traits and basic implementantions 2015-02-20 00:32:59 +01:00
Marvin Löbel
d68eb3d248 Added benchmarks for string pattern matching functions 2015-02-20 00:32:59 +01:00
Alex Crichton
1506b34e0c rollup merge of #22286: nikomatsakis/variance-4b
Conflicts:
	src/librustc/middle/infer/combine.rs
	src/librustc_typeck/check/wf.rs
2015-02-18 15:52:01 -08:00
Alex Crichton
231eeaa35b rollup merge of #22502: nikomatsakis/deprecate-bracket-bracket
Conflicts:
	src/libcollections/slice.rs
	src/libcollections/str.rs
	src/librustc/middle/lang_items.rs
	src/librustc_back/rpath.rs
	src/librustc_typeck/check/regionck.rs
	src/libstd/ffi/os_str.rs
	src/libsyntax/diagnostic.rs
	src/libsyntax/parse/parser.rs
	src/libsyntax/util/interner.rs
	src/test/run-pass/regions-refcell.rs
2015-02-18 15:48:40 -08:00
Alex Crichton
365bd9a9e3 Round 1 fixes and rebase conflicts 2015-02-18 15:27:42 -08:00
Niko Matsakis
9ea84aeed4 Replace all uses of &foo[] with &foo[..] en masse. 2015-02-18 17:36:03 -05:00
Alex Crichton
5250a82f79 rollup merge of #22497: nikomatsakis/suffixes
Conflicts:
	src/librustc_trans/trans/tvec.rs
2015-02-18 14:35:01 -08:00
Alex Crichton
9774b7e64b rollup merge of #22480: alexcrichton/hashv3
This commit is an implementation of [RFC 823][rfc] which is another pass over
the `std::hash` module for stabilization. The contents of the module were not
entirely marked stable, but some portions which remained quite similar to the
previous incarnation are now marked `#[stable]`. Specifically:

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0823-hash-simplification.md

* `std::hash` is now stable (the name)
* `Hash` is now stable
* `Hash::hash` is now stable
* `Hasher` is now stable
* `SipHasher` is now stable
* `SipHasher::new` and `new_with_keys` are now stable
* `Hasher for SipHasher` is now stable
* Many `Hash` implementations are now stable

All other portions of the `hash` module remain `#[unstable]` as they are less
commonly used and were recently redesigned.

This commit is a breaking change due to the modifications to the `std::hash` API
and more details can be found on the [RFC][rfc].

Closes #22467
[breaking-change]
2015-02-18 14:32:03 -08:00
Alex Crichton
c07ec507e2 rollup merge of #22287: Ryman/purge_carthographers
This overlaps with #22276 (I left make check running overnight) but covers a number of additional cases and has a few rewrites where the clones are not even necessary.

This also implements `RandomAccessIterator` for `iter::Cloned`

cc @steveklabnik, you may want to glance at this before #22281 gets the bors treatment
2015-02-18 14:31:55 -08:00
Alex Crichton
f83e23ad7c std: Stabilize the hash module
This commit is an implementation of [RFC 823][rfc] which is another pass over
the `std::hash` module for stabilization. The contents of the module were not
entirely marked stable, but some portions which remained quite similar to the
previous incarnation are now marked `#[stable]`. Specifically:

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/0823-hash-simplification.md

* `std::hash` is now stable (the name)
* `Hash` is now stable
* `Hash::hash` is now stable
* `Hasher` is now stable
* `SipHasher` is now stable
* `SipHasher::new` and `new_with_keys` are now stable
* `Hasher for SipHasher` is now stable
* Many `Hash` implementations are now stable

All other portions of the `hash` module remain `#[unstable]` as they are less
commonly used and were recently redesigned.

This commit is a breaking change due to the modifications to the `std::hash` API
and more details can be found on the [RFC][rfc].

Closes #22467
[breaking-change]
2015-02-18 08:26:20 -08:00
Niko Matsakis
872ce47955 Fallout: tests. As tests frequently elide things, lots of changes
here.  Some of this may have been poorly rebased, though I tried to be
careful and preserve the spirit of the test.
2015-02-18 10:25:28 -05:00
Niko Matsakis
801bc48939 Rewrite Unique<T> so that it is covariant in T, implies NonZero and ownership,
and also follows the API of `NonZero` a bit more closely. More to do
here I think (including perhaps a new name).
2015-02-18 10:25:12 -05:00
Niko Matsakis
01615b04c6 Convert required suffixes into a use of as. 2015-02-18 09:09:13 -05:00
Kevin Butler
061206b9c7 Remove usage of .map(|&foo| foo) 2015-02-18 00:57:35 +00:00
Kevin Butler
2f586b9687 Opt for .cloned() over .map(|x| x.clone()) etc. 2015-02-18 00:56:07 +00:00
Aaron Turon
d0de2b46e9 Fallout from stabilization 2015-02-17 15:14:17 -08:00
Manish Goregaokar
f0f8be2a2e Fix rollup (remove slicing_syntax) 2015-02-15 19:26:39 +05:30
bors
cca1cf613b Auto merge of #21895 - alfie:libcoretest, r=pnkfelix 2015-02-12 14:58:13 +00:00
Felix S. Klock II
f90c3864b6 Add core::marker::PhantomData.
Port `core::ptr::Unique` to have `PhantomData`. Add `PhantomData` to
`TypedArena` and `Vec` as well.

As a drive-by, switch `ptr::Unique` from a tuple-struct to a struct
with fields.
2015-02-11 13:51:09 +01:00
Alfie John
bffbcb5729 Deprecating i/u suffixes in libcoretest 2015-02-10 22:56:31 +00:00
Alex Crichton
ba7b79008b rollup merge of #22142: Kimundi/unsized_unique
This is to allow for use cases like sending a raw pointer slice across thread boundaries.
2015-02-10 08:43:16 -08:00
Marvin Löbel
792dc8d067 Made the ptr::Unique type accept unsized types, to allow for use cases
like sending a raw pointer slice across thread boundaries.
2015-02-10 14:37:44 +01:00
Ulrik Sverdrup
4f61e16032 Fix std::ops::Range size_hint and ExactSizeIterator impls
When self.start > self.end, these iterators simply return None,
so we adjust the size_hint to just return zero in this case.

Certain optimizations can be implemented in and outside libstd if we
know we can trust the size_hint for all inputs to for example
Range<usize>.

This corrects the ExactSizeIterator implementations, which IMO were
unsound and incorrect previously, since they allowed a range like (2..1)
to return a size_hint of -1us in when debug assertions are turned off.
2015-02-08 00:17:04 +01:00
Jorge Aparicio
17bc7d8d5b cleanup: replace as[_mut]_slice() calls with deref coercions 2015-02-05 13:45:01 -05:00
Jorge Aparicio
571cc7f8e9 remove all kind annotations from closures 2015-02-04 20:06:08 -05:00
bors
c3e1f77291 Auto merge of #21892 - huonw:deprecate-rand, r=alexcrichton
Use [`rand`](https://crates.io/crates/rand) and [`derive_rand`](https://crates.io/crates/derive_rand) from crates.io.

[breaking-change]
2015-02-04 08:47:27 +00:00
Huon Wilson
df1ac7aa63 Deprecate in-tree rand, std::rand and #[derive(Rand)].
Use the crates.io crate `rand` (version 0.1 should be a drop in
replacement for `std::rand`) and `rand_macros` (`#[derive_Rand]` should
be a drop-in replacement).

[breaking-change]
2015-02-04 09:39:40 +11:00
Alex Crichton
87eb67f4f0 rollup merge of #21854: alexcrichton/try-borrow
The existence of these two functions is at odds with our current [error
conventions][conventions] which recommend that panicking and `Result`-like
variants should not be provided together.

[conventions]: https://github.com/rust-lang/rfcs/blob/master/text/0236-error-conventions.md#do-not-provide-both-result-and-fail-variants

This commit adds a new `borrow_state` function returning a `BorrowState` enum to
`RefCell` which serves as a replacemnt for the `try_borrow` and `try_borrow_mut`
functions.
2015-02-02 11:01:23 -08:00
Jorge Aparicio
d5d7e6565a for x in xs.iter() -> for x in &xs 2015-02-02 13:40:18 -05:00
Alex Crichton
deed093a38 std: Deprecate RefCell::{try_borrow, try_borrow_mut}
The existence of these two functions is at odds with our current [error
conventions][conventions] which recommend that panicking and `Result`-like
variants should not be provided together.

[conventions]: https://github.com/rust-lang/rfcs/blob/master/text/0236-error-conventions.md#do-not-provide-both-result-and-fail-variants

This commit adds a new `borrow_state` function returning a `BorrowState` enum to
`RefCell` which serves as a replacemnt for the `try_borrow` and `try_borrow_mut`
functions.
2015-02-01 18:58:14 -08:00
Tobias Bucher
b4a43f3864 Kill more isizes 2015-01-31 17:40:40 +01:00
Alex Crichton
3a2530d611 Test fixes and rebase conflicts
Also some tidying up of a bunch of crate attributes
2015-01-30 14:53:34 -08:00
Alex Crichton
188d7c0bc3 rollup merge of #21631: tbu-/isize_police
Conflicts:
	src/libcoretest/iter.rs
2015-01-30 13:27:02 -08:00
Alex Crichton
ac1a03d742 rollup merge of #21718: alexcrichton/stabilize-from-str
This commits adds an associated type to the `FromStr` trait representing an
error payload for parses which do not succeed. The previous return value,
`Option<Self>` did not allow for this form of payload. After the associated type
was added, the following attributes were applied:

* `FromStr` is now stable
* `FromStr::Err` is now stable
* `FromStr::from_str` is now stable
* `StrExt::parse` is now stable
* `FromStr for bool` is now stable
* `FromStr for $float` is now stable
* `FromStr for $integral` is now stable
* Errors returned from stable `FromStr` implementations are stable
* Errors implement `Display` and `Error` (both impl blocks being `#[stable]`)

Closes #15138
2015-01-30 12:03:20 -08:00
Alex Crichton
0cdde6e5e0 std: Stabilize FromStr and parse
This commits adds an associated type to the `FromStr` trait representing an
error payload for parses which do not succeed. The previous return value,
`Option<Self>` did not allow for this form of payload. After the associated type
was added, the following attributes were applied:

* `FromStr` is now stable
* `FromStr::Err` is now stable
* `FromStr::from_str` is now stable
* `StrExt::parse` is now stable
* `FromStr for bool` is now stable
* `FromStr for $float` is now stable
* `FromStr for $integral` is now stable
* Errors returned from stable `FromStr` implementations are stable
* Errors implement `Display` and `Error` (both impl blocks being `#[stable]`)

Closes #15138
2015-01-30 08:52:44 -08:00
Jorge Aparicio
ed82b5a70e remove Copy impls from iterators 2015-01-30 10:37:44 -05:00
Tobias Bucher
7f64fe4e27 Remove all i suffixes 2015-01-30 04:38:54 +01:00
Nick Cameron
023d49e347 Change from core::ops::RangeFull to std::ops 2015-01-30 12:01:08 +13:00
Jorge Aparicio
788181d405 s/Show/Debug/g 2015-01-29 07:49:02 -05:00
Jorge Aparicio
efc97a51ff convert remaining range(a, b) to a..b 2015-01-29 07:49:01 -05:00
Jorge Aparicio
7d661af9c8 for x in range(a, b) -> for x in a..b
sed -i 's/in range(\([^,]*\), *\([^()]*\))/in \1\.\.\2/g' **/*.rs
2015-01-29 07:47:37 -05:00
Jorge Aparicio
c300d681bd range(a, b).foo() -> (a..b).foo()
sed -i 's/ range(\([^,]*\), *\([^()]*\))\./ (\1\.\.\2)\./g' **/*.rs
2015-01-29 07:46:44 -05:00