Commit Graph

35784 Commits

Author SHA1 Message Date
Tshepang Lekhonkhobe
7d55249c91 doc: add missing "by default"
That sentence made it look like there was no option for using 'mut'
2014-12-21 09:32:32 +02:00
bors
ce468e643a auto merge of #19946 : cgaebel/rust/hashmap-drain-iter, r=gankro
It is useful to move all the elements out of a hashmap without deallocating
the underlying buffer. It came up in IRC, and this patch implements it as
`drain`.

r? @Gankro
cc: @frankmcsherry
2014-12-21 07:22:45 +00:00
Barosl Lee
c9010bff6c Fix error message on invalid field names for a struct variant
Fixes #19922.
2014-12-21 10:20:54 +09:00
Jake Goulding
bffd802a3f Fix small typos in std::rand documentation 2014-12-20 17:13:13 -05:00
bors
cc19e3380b auto merge of #19903 : cgaebel/rust/ringbuf-as-slice, r=Gankro
See: https://github.com/rust-lang/rfcs/pull/509

Not sure if this is allowed to land before the RFC. Either way,
it's here for review.

r? @Gankro
cc: @bfops
2014-12-20 20:00:36 +00:00
Tom Jakubowski
fb9b45189e Visit + encode stability for foreign items
Fix #19649
2014-12-20 10:08:16 -08:00
Simon Sapin
e40a81b37b Merge String::push_with_ascii_fast_path into String::push. 2014-12-20 17:36:30 +00:00
Simon Sapin
cc33ce6fd0 Add String::push_with_ascii_fast_path, bench it against String::push
`String::push(&mut self, ch: char)` currently has a single code path
that calls `Char::encode_utf8`.
Perhaps it could be faster for ASCII `char`s, which are represented as
a single byte in UTF-8.

This commit leaves the method unchanged,
adds a copy of it with the fast path,
and adds benchmarks to compare them.

Results show that the fast path very significantly improves the performance
of repeatedly pushing an ASCII `char`,
but does not significantly affect the performance for a non-ASCII `char`
(where the fast path is not taken).

Output of `make check-stage1-collections NO_REBUILD=1 PLEASE_BENCH=1 TESTNAME=string::tests::bench_push`

```
test string::tests::bench_push_char_one_byte                 ... bench:     59552 ns/iter (+/- 2132) = 167 MB/s
test string::tests::bench_push_char_one_byte_with_fast_path  ... bench:      6563 ns/iter (+/- 658) = 1523 MB/s
test string::tests::bench_push_char_two_bytes                ... bench:     71520 ns/iter (+/- 3541) = 279 MB/s
test string::tests::bench_push_char_two_bytes_with_slow_path ... bench:     71452 ns/iter (+/- 4202) = 279 MB/s
test string::tests::bench_push_str                           ... bench:        24 ns/iter (+/- 2)
test string::tests::bench_push_str_one_byte                  ... bench:     38910 ns/iter (+/- 2477) = 257 MB/s
```

A benchmark of pushing a one-byte-long `&str` is added for comparison,
but its performance [has varied a lot lately](
https://github.com/rust-lang/rust/pull/19640#issuecomment-67741561).
(When the input is fixed, `s.push_str("x")` could be used
instead of `s.push('x')`.)
2014-12-20 17:35:59 +00:00
Tom Jakubowski
44f6f52578 metadata: Encode attrs for foreign items.
Related to #19649 and #16289
2014-12-20 09:32:28 -08:00
bors
8a33de89c4 auto merge of #20073 : nikomatsakis/rust/generalized-where-clause-parser, r=nikomatsakis
This is the same branch as #20002 but with the pretty-printing test fixed.
2014-12-20 16:12:37 +00:00
Jake Goulding
b4a065a3a0 Correct typo in doc for StdinReaderGuard 2014-12-20 11:08:51 -05:00
Tobias Bucher
24329d7293 Change Extend and FromIterator functionality of BitvSet
Also fix up some tests from last commit.
2014-12-20 09:10:06 -05:00
Tobias Bucher
e84a383307 Add a new invariant to Bitv
The length of the underlying vector must now be exactly as long as it needs to
be.
2014-12-20 09:10:05 -05:00
Josh Stone
3deb97f5d0 bitv: Fix all() for nbits that are multiples of u32::BITS
The old logic would be ok with *either* 0 or all 1s in the last word,
because it didn't compute a proper mask for the case where nbits is an
exact multiple of u32::BITS.

Add mask_for_bits() to compute this properly, and use it in all().  Add
all/none assertions to most of the tests.  Note in particular, the all-zero
bitv in test_32_elements() was incorrectly all()==true before this patch.
2014-12-20 09:10:04 -05:00
Josh Stone
8f194de95d bitv: correct build failures
- Fix typos on Blocks and MutBlocks.
- Use slice_to_mut() for creating blocks_mut().
- Deref the block parameter in get().
- Access nbits separately from mutating set in pop().
2014-12-20 09:10:03 -05:00
Alexis Beingessner
9c5101542d Conventions and cleanup for Bitv and BitvSet
Part of #18424

This commit changes the semantics of `reserve` and `capacity` for Bitv and BitvSet to match conventions. It also introduces the notion of `reserve_index` and `reserve_index_exact` for collections with maximum-index-based capacity semantics.

Deprecates free function constructors in favour of functions on Bitv itself.

Changes `Bitv::pop` to return an Option rather than panicking.

Deprecates and renames several methods in favour of conventions.

Marks several blessed methods as unstable.

This commit also substantially refactors Bitv and BitvSet's implementations. The new implementation is simpler, cleaner, better documented, and more robust against overflows. It also reduces coupling between Bitv and BitvSet. Tests have been seperated into seperate submodules.

Fixes #16958

[breaking-change]
2014-12-20 09:10:02 -05:00
bors
f8f2c7a953 auto merge of #19900 : alexcrichton/rust/compiler-flags, r=cmr
This commit shuffles around some CLI flags of the compiler to some more stable
locations with some renamings. The changes made were:

* The `-v` flag has been repurposes as the "verbose" flag. The version flag has
  been renamed to `-V`.
* The `-h` screen has been split into two parts. Most top-level options (not
  all) show with `-h`, and the remaining options (generally obscure) can be
  shown with `--help -v` which is a "verbose help screen"
* The `-V` flag (version flag now) has lost its argument as it is now requested
  with `rustc -vV` "verbose version".
* The `--emit` option has had its `ir` and `bc` variants renamed to `llvm-ir`
  and `llvm-bc` to emphasize that they are LLVM's IR/bytecode.
* The `--emit` option has grown a new variant, `dep-info`, which subsumes the
  `--dep-info` CLI argument. The `--dep-info` flag is now deprecated.
* The `--parse-only`, `--no-trans`, `--no-analysis`, and `--pretty` flags have
  moved behind the `-Z` family of flags.
* The `--debuginfo` and `--opt-level` flags were moved behind the top-level `-C`
  flag.
* The `--print-file-name` and `--print-crate-name` flags were moved behind one
  global `--print` flag which now accepts one of `crate-name`, `file-names`, or
  `sysroot`. This global `--print` flag is intended to serve as a mechanism for
  learning various metadata about the compiler itself.
* The top-level `--pretty` flag was moved to a number of `-Z` options.

No warnings are currently enabled to allow tools like Cargo to have time to
migrate to the new flags before spraying warnings to all users.

cc https://github.com/rust-lang/rust/issues/19051
2014-12-20 13:52:27 +00:00
Niko Matsakis
acd31db229 patch up pretty-printing test 2014-12-20 08:41:33 -05:00
Jared Roesch
d87b308b67 Add support for multiple region bounds in where clauses 2014-12-20 03:54:39 -08:00
Jared Roesch
e0cac488ac Add parser support for generalized where clauses
Implement support in the parser for generalized where clauses,
as well as the conversion of ast::WherePredicates to
ty::Predicate in `collect.rs`.
2014-12-20 02:48:17 -08:00
Aaron Turon
92ccc073e1 Stabilize clone
This patch marks `clone` stable, as well as the `Clone` trait, but
leaves `clone_from` unstable. The latter will be decided by the beta.

The patch also marks most manual implementations of `Clone` as stable,
except where the APIs are otherwise deprecated or where there is
uncertainty about providing `Clone`.
2014-12-20 00:37:44 -08:00
Sean McArthur
84b8f318a5 add {:?} fmt syntax 2014-12-20 00:32:07 -08:00
Nick Cameron
31f5ab3f0c Allow Self in impls. 2014-12-20 21:11:36 +13:00
bors
8f51ad2420 auto merge of #19511 : eddyb/rust/no-shadow, r=alexcrichton
r? @erickt
2014-12-20 08:10:23 +00:00
Jarod Liu
a7f1ce37bf use binary literals to better reflect "bitflags" 2014-12-20 16:07:03 +08:00
Aaron Turon
e473e700cc Stabilize cell
This patch finalizes stabilization for the `cell` module, settling on
the current names `Cell`, `RefCell`, `UnsafeCell`, `Ref` and `RefMut`.

While we had considered improving these names, no one was able to
produce a truly compelling alternative.

There is one substantive change here: the `get` method of `UnsafeSell`
is now marked `unsafe`. Merely getting a raw pointer to the contents is
not, by itself, an unsafe operation. (Consider that you can always
safely turn a reference into a raw pointer, and that raw pointer may
then be aliased by subsequent references.)
2014-12-19 23:47:46 -08:00
Aaron Turon
89f75a6e81 Stabilize integer modules
This small patch stabilizes the names of all integer modules (including
`int` and `uint`) and the `MIN` and `MAX` constants. The `BITS` and
`BYTES` constants are left unstable for now.
2014-12-19 22:28:12 -08:00
bors
8443b09e36 auto merge of #19995 : eddyb/rust/split-resolve, r=nikomatsakis
r? @nikomatsakis
2014-12-20 05:52:18 +00:00
Eduard Burtescu
b45d30da34 Fix fallout of removing import_shadowing in tests. 2014-12-20 07:49:37 +02:00
Eduard Burtescu
f95e0c21aa Fix more import_shadowing fallout in collections. 2014-12-20 07:49:37 +02:00
Eduard Burtescu
5193d542f6 Fix the fallout of removing feature(import_shadowing). 2014-12-20 07:49:37 +02:00
Eduard Burtescu
948cc666de rustc_resolve: move export recording into its own module. 2014-12-20 07:28:47 +02:00
Eduard Burtescu
1614d92f51 rustc_resolve: move unused import checking into its own module. 2014-12-20 07:28:47 +02:00
Eduard Burtescu
c54fc980f3 Split resolve from rustc::middle into rustc_resolve. 2014-12-20 07:28:47 +02:00
Eduard Burtescu
a74a050c44 rustc: middle: move some types from resolve to privacy. 2014-12-20 07:28:47 +02:00
Eduard Burtescu
5d1257a760 rustc: middle: move TraitItemKind from resolve to def. 2014-12-20 07:28:46 +02:00
Eduard Burtescu
d9504d4a47 rustc: middle: move Export and ExportMap from resolve to def. 2014-12-20 07:28:46 +02:00
Eduard Burtescu
10a862d4f4 rustc: middle: use cheaper Name in resolve::Export instead of String. 2014-12-20 07:25:42 +02:00
Eduard Burtescu
f0276072a3 rustc: middle: move TraitMap from resolve to ty. 2014-12-20 07:25:41 +02:00
Eduard Burtescu
d8f57c3804 rustc: middle: move DefMap from resolve to def. 2014-12-20 07:25:37 +02:00
Eduard Burtescu
fb1d6f24fc middle: resolve: fix inconsistencies around ExportMap and remove the 2 suffix. 2014-12-20 07:11:03 +02:00
Eduard Burtescu
533822207f rustc: don't allow(non_camel_case_types) in resolve. 2014-12-20 07:11:03 +02:00
Eduard Burtescu
e0d44386d3 rustc: use Ty instead of passing ty::sty around. 2014-12-20 07:04:42 +02:00
Eduard Burtescu
d5267d5845 Remove feature(import_shadowing) from all crates. 2014-12-20 06:37:14 +02:00
Nick Cameron
2e86929a4a Allow use of [_ ; n] syntax for fixed length and repeating arrays.
This does NOT break any existing programs because the `[_, ..n]` syntax is also supported.
2014-12-20 15:23:29 +13:00
bors
1c2df5cc3c auto merge of #19640 : aliblong/rust/power_of_two_reform, r=Gankro
The `is_power_of_two()` method of the `UnsignedInt` trait currently returns `true` for `self == 0`. Zero is not a power of two, assuming an integral exponent `k >= 0`. I've therefore moved this functionality to the new method `is_power_of_two_or_zero()` and reformed `is_power_of_two()` to return false for `self == 0`.

To illustrate the usefulness of the existence of both functions, consider `HashMap`. Its capacity must be zero or a power of two; conversely, it also requires a (non-zero) power of two for key and val alignment.

Also, added a small amount of documentation regarding #18604.
2014-12-20 01:12:19 +00:00
Barosl Lee
314ed2df09 Drop the Match prefix from the MatchSource variants 2014-12-20 09:17:14 +09:00
Barosl Lee
7023bea22c Print a friendly error for the if-let construct without an else block
Fixes #19991.
2014-12-20 09:17:14 +09:00
Barosl Lee
39f249067a Implement Deref for Box
Fixes #18624.
2014-12-20 08:58:33 +09:00
Aaron Liblong
f6328b60da Reform power_of_two methods for perf increase & semantic change to consider 0 not a power of 2.
Vec panics when attempting to reserve capacity > int::MAX (uint::MAX / 2).
2014-12-19 18:21:24 -05:00