Commit Graph

38342 Commits

Author SHA1 Message Date
Alex Crichton
74f7e06939 rollup merge of #21899: nikomatsakis/closure-unify-anyhow
This *almost* completes the job for #16440. The idea is that even if we do not know whether some closure type `C` implements `Fn` or `FnMut` (etc), we still know its argument and return types. So if we see an obligation `C : Fn(_0)`, we can unify `_0` with those argument types while still considering the obligation ambiguous and unsatisfied. This helps to make a lot of progress with type inference even before closure kind inference is done.

As part of this PR, the explicit `:` syntax is removed from the AST and completely ignored. We still infer the closure kind based on the expected type if that is available. There are several reasons for this. First, deciding the closure kind earlier is always better, as it allows us to make more progress. Second, this retains a (admittedly obscure) way for users to manually specify the closure kind, which is useful for writing tests if nothing else. Finally, there are still some cases where inference can fail, so it may be useful to have this manual override. (The expectation is that we will eventually revisit an explicit syntax for specifying the closure kind, but it will not be `:` and may be some sort of generalization of the `||` syntax to handle other traits as well.)

This commit does not *quite* fix #16640 because a snapshot is still needed to enable the obsolete syntax errors for explicit `&mut:` and friends.

r? @eddyb as he reviewed the prior patch in this direction
2015-02-03 20:11:20 -08:00
Alex Crichton
1d921f557d rollup merge of #21897: dotdash/rposition
The extra check caused by the expect() call can, in general, not be
optimized away, because the length of the iterator is unknown at compile
time, causing a noticable slow-down. Since the check only triggers if
the element isn't actually found in the iterator, i.e. it isn't
guaranteed to trigger for ill-behaved ExactSizeIterators, it seems
reasonable to switch to an implementation that doesn't need the check
and just always returns None if the value isn't found.

Benchmark:
````rust
let v: Vec<u8> = (0..1024*65).map(|_| 0).collect();
b.iter(|| {
    v.as_slice().iter().rposition(|&c| c == 1)
});
````

Before:
````
test rposition  ... bench:     49939 ns/iter (+/- 23)
````

After:
````
test rposition  ... bench:     33306 ns/iter (+/- 68)
````
2015-02-03 20:11:20 -08:00
Alex Crichton
61b2f3a4f0 rollup merge of #21893: vhbit/ios-build-fix 2015-02-03 20:11:19 -08:00
P1start
cfe18fb836 Fix Unicode name mangling
`{` and `}` aren’t valid characters on ARM.

This also fixes a small bug where `)` (**r**ight **p**arenthesis) and `*`
(**r**aw **p**ointer) would both mangle to `$RP$`, making `)` show up as `*` in
backtraces.
2015-02-04 15:32:59 +13:00
Andrea Canciani
8f7c2d518d Replace be with become
As per rust-lang/rfcs#601, replace `be` with `become` as reserved
keyword for tail call optimization.
2015-02-04 01:25:24 +01:00
Alex Crichton
5a35ad7100 rollup merge of #21882: Gankro/vec_entry
Building over night, posting for review now. Presumably not much should need change.

I consider this necessary to move forward with a proper stabilization of the API.

r? @huonw
2015-02-03 15:35:57 -08:00
Alex Crichton
087e8479b9 rollup merge of #21870: alexcrichton/missing-stability
* Display::fmt is stable
* Debug::fmt is stable
* FromIterator::from_iter is stable
* Peekable::peek is stable
2015-02-03 15:35:55 -08:00
Alex Crichton
b53695b47a rollup merge of #21835: alexcrichton/iov2
This commit is an implementation of [RFC 576][rfc] which adds back the `std::io`
module to the standard library. No functionality in `std::old_io` has been
deprecated just yet, and the new `std::io` module is behind the same `io`
feature gate.

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

A good bit of functionality was copied over from `std::old_io`, but many tweaks
were required for the new method signatures. Behavior such as precisely when
buffered objects call to the underlying object may have been tweaked slightly in
the transition. All implementations were audited to use composition wherever
possible. For example the custom `pos` and `cap` cursors in `BufReader` were
removed in favor of just using `Cursor<Vec<u8>>`.

A few liberties were taken during this implementation which were not explicitly
spelled out in the RFC:

* The old `LineBufferedWriter` is now named `LineWriter`
* The internal representation of `Error` now favors OS error codes (a
  0-allocation path) and contains a `Box` for extra semantic data.
* The io prelude currently reexports `Seek` as `NewSeek` to prevent conflicts
  with the real prelude reexport of `old_io::Seek`
* The `chars` method was moved from `BufReadExt` to `ReadExt`.
* The `chars` iterator returns a custom error with a variant that explains that
  the data was not valid UTF-8.
2015-02-03 15:35:54 -08:00
Alex Crichton
8550bf74c1 rollup merge of #21759: aturon/new-path
This PR implements [path reform](https://github.com/rust-lang/rfcs/pull/474), and motivation and details for the change can be found there.

For convenience, the old path API is being kept as `old_path` for the time being. Updating after this PR is just a matter of changing imports to `old_path` (which is likely not needed, since the prelude entries still export the old path API).

This initial PR does not include additional normalization or platform-specific path extensions. These will be done in follow up commits or PRs.

[breaking-change]

Closes #20034
Closes #12056
Closes #11594
Closes #14028
Closes #14049
Closes #10035
2015-02-03 15:35:53 -08:00
Aaron Turon
45ddf50ceb Add new path module
Implements [RFC 474](https://github.com/rust-lang/rfcs/pull/474); see
that RFC for details/motivation for this change.

This initial commit does not include additional normalization or
platform-specific path extensions. These will be done in follow up
commits or PRs.
2015-02-03 14:52:03 -08: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
Aaron Turon
3e39f0bc0e Rename std::path to std::old_path
As part of [RFC 474](https://github.com/rust-lang/rfcs/pull/474), this
commit renames `std::path` to `std::old_path`, leaving the existing path
API in place to ease migration to the new one. Updating should be as
simple as adjusting imports, and the prelude still maps to the old path
APIs for now.

[breaking-change]
2015-02-03 14:34:42 -08:00
Manish Goregaokar
a5ddacf001 More test fixes 2015-02-04 03:46:36 +05:30
Manish Goregaokar
2258f906ab Don't check stability for tests 2015-02-04 03:21:10 +05:30
Manish Goregaokar
f5e5bdb197 Fix test 2015-02-04 03:20:12 +05:30
Manish Goregaokar
d02d4c3c9b Add staged_api and unmarked_api features to reference.md 2015-02-04 02:30:31 +05:30
Manish Goregaokar
b64572cefe Add unmarked_api feature (fixes #21884) 2015-02-04 02:30:31 +05:30
Manish Goregaokar
4aa661ab36 Add test for missing stability checker 2015-02-04 02:30:31 +05:30
Manish Goregaokar
c6aaea6725 Fix some missing stability attrs 2015-02-04 02:30:31 +05:30
Manish Goregaokar
6ec5a0f62b Error when #![staged_api] crates are missing stability markers 2015-02-04 02:30:27 +05:30
Alex Crichton
5cf9905e25 std: Add io module again
This commit is an implementation of [RFC 576][rfc] which adds back the `std::io`
module to the standard library. No functionality in `std::old_io` has been
deprecated just yet, and the new `std::io` module is behind the same `io`
feature gate.

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

A good bit of functionality was copied over from `std::old_io`, but many tweaks
were required for the new method signatures. Behavior such as precisely when
buffered objects call to the underlying object may have been tweaked slightly in
the transition. All implementations were audited to use composition wherever
possible. For example the custom `pos` and `cap` cursors in `BufReader` were
removed in favor of just using `Cursor<Vec<u8>>`.

A few liberties were taken during this implementation which were not explicitly
spelled out in the RFC:

* The old `LineBufferedWriter` is now named `LineWriter`
* The internal representation of `Error` now favors OS error codes (a
  0-allocation path) and contains a `Box` for extra semantic data.
* The io prelude currently reexports `Seek` as `NewSeek` to prevent conflicts
  with the real prelude reexport of `old_io::Seek`
* The `chars` method was moved from `BufReadExt` to `ReadExt`.
* The `chars` iterator returns a custom error with a variant that explains that
  the data was not valid UTF-8.
2015-02-03 12:51:12 -08:00
Alex Crichton
d30f225b49 std: Remove iter::ByRef and generalize impls
This removes the `ByRef` iterator adaptor to stay in line with the changes to
`std::io`. The `by_ref` method instead just returns `&mut Self`.

This also removes the implementation of `Iterator for &mut Iterator` and instead
generalizes it to `Iterator for &mut I` where `I: Iterator + ?Sized`. The
`Box<I>` implementations were also updated.

This is a breaking change due to the removal of the `std::iter::ByRef` type. All
mentions of `ByRef<'a, T>` should be replaced with `&mut T` to migrate forward.

[breaking-change]
2015-02-03 12:41:23 -08:00
Manish Goregaokar
0b9e227a16 Move stability pass after privacy pass 2015-02-04 00:32:37 +05:30
Niko Matsakis
8ddcb06b1d Update for new snapshot after rebasing. 2015-02-03 13:14:36 -05:00
Niko Matsakis
68ad6949d4 Correct one case where the inference was detecting a looser result than the
explicit annotation, leading to "extra `mut` declaration" lint errors.
2015-02-03 13:14:29 -05:00
Niko Matsakis
0431134119 Remove the explicit closure kind syntax from the parser and AST;
upgrade the inference based on expected type so that it is able to
infer the fn kind in isolation even if the full signature is not
available (and we could perhaps do better still in some cases, such as
extracting just the types of the arguments but not the return value).
2015-02-03 11:56:16 -05:00
Niko Matsakis
47f18659ff Update compile-fail tests to use the expected type to force the
closure kind, thereby detecting what happens if there are
mismatches. Simply removing the `:` annotations caused most of these
tests to pass or produce other errors, because the inference would
convert the closure into a more appropriate kind. (The ability to
override the inference by using the expected type is an important
backdoor partly for this reason.)
2015-02-03 11:55:46 -05:00
Niko Matsakis
498595a3dc Teach project to unify the return type even if a precise match is not
possible.  There is some amount of duplication as a result (similar to
select) -- I am not happy about this but not sure how to fix it
without deeper rewrites.
2015-02-03 11:55:45 -05:00
Niko Matsakis
c9e1c445db Allow closure arguments types to unify even if we can't fully resolve
a trait obligation. Partial fix for #16440 -- closure return types are
not handled yet.
2015-02-03 11:55:45 -05:00
Björn Steinbrink
9a17f62947 Optimize rposition
The extra check caused by the expect() call can, in general, not be
optimized away, because the length of the iterator is unknown at compile
time, causing a noticable slow-down. Since the check only triggers if
the element isn't actually found in the iterator, i.e. it isn't
guaranteed to trigger for ill-behaved ExactSizeIterators, it seems
reasonable to switch to an implementation that doesn't need the check
and just always returns None if the value isn't found.

Benchmark:
````rust
let v: Vec<u8> = (0..1024*65).map(|_| 0).collect();
b.iter(|| {
    v.as_slice().iter().rposition(|&c| c == 1)
});
````

Before:
````
test rposition  ... bench:     49939 ns/iter (+/- 23)
````

After:
````
test rposition  ... bench:     33306 ns/iter (+/- 68)
````
2015-02-03 16:54:06 +01:00
bors
3b2ed14906 Auto merge of #21877 - dotdash:less_auto_deref, r=alexcrichton 2015-02-03 14:56:32 +00:00
Alexis
88449a8f79 add naivest entry API to VecMap 2015-02-03 09:36:07 -05:00
Valerii Hiora
3449751ff7 iOS: fixed build 2015-02-03 15:31:31 +02:00
bors
3d072a193b Auto merge of #21675 - huonw:less-false-positives, r=nikomatsakis
That is, when offering suggestions for unresolved method calls, avoid
suggesting traits for which implementing the trait for the receiver type
either makes little sense (e.g. type errors, or sugared unboxed
closures), or violates coherence.

The latter is approximated by ensuring that at least one of `{receiver
type, trait}` is local. This isn't precisely correct due to
multidispatch, but the error messages one encounters in such situation
are useless more often than not; it is better to be conservative and
miss some cases, than have overly many false positives (e.g. writing
`some_slice.map(|x| ...)` uselessly suggested that one should implement
`IteratorExt` for `&[T]`, while the correct fix is to call `.iter()`).

Closes #21420.
2015-02-03 12:49:21 +00:00
James Miller
40b6e34240 Rc: Add assumptions that the pointer is non-null
Since the snapshot compiler is still using an older LLVM version, omit
the call in stage0, because compile times explode otherwise.
2015-02-03 13:36:36 +01:00
P1start
d244f09911 Compute widths properly when displaying spans in error messages
Closes #8706.
2015-02-04 00:56:51 +13:00
Huon Wilson
e81ae40770 Try to only suggest implementable traits for method calls.
That is, when offering suggestions for unresolved method calls, avoid
suggesting traits for which implementing the trait for the receiver type
either makes little sense (e.g. type errors, or sugared unboxed
closures), or violates coherence.

The latter is approximated by ensuring that at least one of `{receiver
type, trait}` is local. This isn't precisely correct due to
multidispatch, but the error messages one encounters in such situation
are useless more often than not; it is better to be conservative and
miss some cases, than have overly many false positives (e.g. writing
`some_slice.map(|x| ...)` uselessly suggested that one should implement
`IteratorExt` for `&[T]`, while the correct fix is to call `.iter()`).

Closes #21420.
2015-02-03 22:33:54 +11:00
bors
cfc91090e9 Auto merge of #21745 - chris-morgan:add-missing-unstable-attributes, r=huonw
I’d kind of like to be able to use HashState in AnyMap, which I can’t do without a stability attribute on it. While I was at it I looked around and found a few more missing.
2015-02-03 10:40:33 +00:00
bors
336c8d2e9c Auto merge of #21613 - alfie:suffix-small, r=alexcrichton 2015-02-03 07:59:04 +00:00
Björn Steinbrink
1a56a1a515 Emit !nonnull metadata for loads of region and unique pointers
These pointers are never null, let's tell LLVM about it.
2015-02-03 08:55:04 +01:00
Richo Healey
73d5d89567 lint: Warn about no-mangled statics that are not exported 2015-02-02 23:11:24 -08:00
Richo Healey
51ed1ecefd lint: Deny #[no_mangle] const items
This renames the PrivateNoMangleFns lint to allow both to happen in a
single pass, since they do roughly the same work.
2015-02-02 23:11:23 -08:00
Alex Crichton
b2297fd710 std: Add some missing stability attributes
* Display::fmt is stable
* Debug::fmt is stable
* FromIterator::from_iter is stable
* Peekable::peek is stable
2015-02-02 22:45:37 -08:00
bors
7858cb432d Auto merge of #21872 - alexcrichton:rollup, r=alexcrichton 2015-02-03 03:44:05 +00:00
Alex Crichton
9ece22ee00 Test fixes and rebase conflicts 2015-02-02 18:50:23 -08:00
Björn Steinbrink
a3d2d35fcb Avoid extra ref/deref cycles when converting &T to *T 2015-02-03 01:22:09 +01:00
Alfie John
8f4844d58b More deprecating of i/u suffixes 2015-02-02 23:37:01 +00:00
Simonas Kazlauskas
ababf73e78 Remove is postfix in Reference → Numbers 2015-02-02 23:15:16 +02:00
Alex Crichton
fea07cfd3f rollup merge of #21869: dotdash/bogus_match
The inner match will always result in `true`, so we can as well replace
it with just that.
2015-02-02 11:01:29 -08:00
Alex Crichton
cd47cf906b rollup merge of #21865: steveklabnik/gh21501
Fixes #21501

r? @huonw
2015-02-02 11:01:26 -08:00