Commit Graph

40431 Commits

Author SHA1 Message Date
Alex Crichton
f5b65c5c22 rollup merge of #23573: steveklabnik/doc_associated_types 2015-03-24 14:50:44 -07:00
Alex Crichton
8f6c879d2a rollup merge of #23282: nikomatsakis/fn-trait-inheritance
The primary motivation here is to sidestep #19032 -- for a time, I thought that we should improve coherence or otherwise extend the language, but I now think that any such changes will require more time to bake. In the meantime, inheritance amongst the fn traits is both logically correct *and* a simple solution to that obstacle. This change introduces inheritance and modifies the compiler so that it can properly generate impls for closures and fns.

Things enabled by this PR (but not included in this PR):

1. An impl of `FnMut` for `&mut F` where `F : FnMut` (https://github.com/rust-lang/rust/issues/23015).
2. A better version of `Thunk` I've been calling `FnBox`.

I did not include either of these in the PR because:

1. Adding the impls in 1 currently induces a coherence conflict with the pattern trait. This is interesting and merits some discussion.
2. `FnBox` deserves to be a PR of its own.

The main downside to this design is (a) the need to write impls by hand; (b) the possibility of implementing `FnMut` with different semantics from `Fn`, etc. Point (a) is minor -- in particular, it does not affect normal closure usage -- and could be addressed in the future in many ways (better defaults; convenient macros; specialization; etc). Point (b) is unfortunate but "just a bug" from my POV, and certainly not unique to these traits (c.f. Copy/Clone, PartialEq/Eq, etc). (Until we lift the feature-gate on implementing the Fn traits, in any case, there is room to correct both of these if we find a nice way.)

Note that I believe this change is reversible in the future if we decide on another course of action, due to the feature gate on implementing the `Fn` traits, though I do not (currently) think we should reverse it.

Fixes #18835.

r? @nrc
2015-03-24 14:50:44 -07:00
Erick Tryzelaar
9cabe273d3 syntax: Update #[derive(...)] to work with phantom and associated types
Closes #7671, #19839
2015-03-24 14:43:26 -07:00
Nick Cameron
7e3ee02006 Bug fixes 2015-03-25 10:37:03 +13:00
Felix S. Klock II
1955e05267 Unit tests for Issue 8142, collected into one file. 2015-03-24 22:27:24 +01:00
Felix S. Klock II
5b2e8693e4 Reject specialized Drop impls.
See Issue 8142 for discussion.

This makes it illegal for a Drop impl to be more specialized than the
original item.

So for example, all of the following are now rejected (when they would
have been blindly accepted before):

```rust
struct S<A> { ... };
impl Drop for S<i8> { ... } // error: specialized to concrete type

struct T<'a> { ... };
impl Drop for T<'static> { ... } // error: specialized to concrete region

struct U<A> { ... };
impl<A:Clone> Drop for U<A> { ... } // error: added extra type requirement

struct V<'a,'b>;
impl<'a,'b:a> Drop for V<'a,'b> { ... } // error: added extra region requirement
```

Due to examples like the above, this is a [breaking-change].

(The fix is to either remove the specialization from the `Drop` impl,
or to transcribe the requirements into the struct/enum definition;
examples of both are shown in the PR's fixed to `libstd`.)

----

This is likely to be the last thing blocking the removal of the
`#[unsafe_destructor]` attribute.

Includes two new error codes for the new dropck check.

Update run-pass tests to accommodate new dropck pass.

Update tests and docs to reflect new destructor restriction.

----

Implementation notes:

We identify Drop impl specialization by not being as parametric as the
struct/enum definition via unification.

More specifically:

 1. Attempt unification of a skolemized instance of the struct/enum
    with an instance of the Drop impl's type expression where all of
    the impl's generics (i.e. the free variables of the type
    expression) have been replaced with unification variables.

 2. If unification fails, then reject Drop impl as specialized.

 3. If unification succeeds, check if any of the skolemized
    variables "leaked" into the constraint set for the inference
    context; if so, then reject Drop impl as specialized.

 4. Otherwise, unification succeeded without leaking skolemized
    variables: accept the Drop impl.

We identify whether a Drop impl is injecting new predicates by simply
looking whether the predicate, after an appropriate substitution,
appears on the struct/enum definition.
2015-03-24 22:27:23 +01:00
Felix S. Klock II
290c8de0a6 Added T:Send bound to JoinGuard<T> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
5f57fd591d Added T:Send bound to Queue<T> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
123b5c124e Added T:Send bound to Packet<T> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
018eeb76f0 added T:Send bound to Mutex<T> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
1e71d2e71c Added W: Writer bound to BufferedWriter<W> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
1249e60891 Added T:Send bound to Queue<T> to avoid specialized Drop impl. 2015-03-24 22:27:23 +01:00
Felix S. Klock II
26a79e3c20 Added Write bounds to avoid a specialized Drop impl for BufWriter. 2015-03-24 22:27:22 +01:00
Felix S. Klock II
0adab507bb Added T:Send bound to sync::mpsc::Receiver and sync::mpsc::Sender.
This was necessary to avoid specialized `Drop` impls for the two structs.
2015-03-24 22:27:22 +01:00
Felix S. Klock II
5fa4b4c4af Remove unnecessary bounds from Drop impl for Arc and arc::Weak and
one of the helper method impls.
2015-03-24 22:27:22 +01:00
Erick Tryzelaar
d4701bd4fb test: silence a warning 2015-03-24 14:26:58 -07:00
Ulrik Sverdrup
547a48e193 collections: Update docs for slice since SliceExt was removed
A lot has changed since this doc text was last touched up, and this is
just a minor edit. I remove the trait section entirely since we don't
use extension traits that much anymore, so there are no significant
trait hilights for this module.
2015-03-24 22:23:13 +01:00
Ulrik Sverdrup
00e14f1622 core: Update docs for StrExt demotion in libstd
Main access point of .split() and other similar methods are not using
the StrExt trait anymore, so update the libcore docs to reflect this
(because these docs are visible in libstd API documentation).
2015-03-24 22:21:38 +01:00
Ulrik Sverdrup
227d30414c std: Update docs for removal of ReadExt, WriteExt 2015-03-24 22:20:35 +01:00
Erick Tryzelaar
a17f5563b8 syntax: Allow quotes to insert path 2015-03-24 14:18:39 -07:00
Erick Tryzelaar
4ec07ed29a syntax: Allow where strings to be parsed independent from generics
This allows quasiquoting to insert where clauses.
2015-03-24 14:18:39 -07:00
Erick Tryzelaar
c3f4fba9cc syntax: add {trait_item,impl_item,where_clause}_to_string 2015-03-24 14:18:39 -07:00
Corey Richardson
0e838f749f libcollections: move Vec::push slow path out
Makes Vec::push considerably smaller: 25 instructions, rather than 42, on
x86_64.
2015-03-24 17:12:58 -04:00
Nick Cameron
e7122a5a09 Change lint names to plurals 2015-03-25 10:06:13 +13:00
Nick Cameron
dc206a91c8 Add tests 2015-03-25 10:06:13 +13:00
Nick Cameron
088cd566ea Remove the UnusedCasts lint 2015-03-25 10:06:13 +13:00
Nick Cameron
9374c216f6 Minor refactoring in coercion.rs 2015-03-25 10:06:13 +13: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
Steve Klabnik
406524682b An example for clone 2015-03-24 16:58:08 -04:00
Alex Crichton
4ccf374b4a std: Zero memory when calling read_to_end()
This commit alters the behavior of the `Read::read_to_end()` method to zero all
memory instead of passing an uninitialized buffer to `read`. This change is
motivated by the [discussion on the internals forum][discuss] where the
conclusion has been that the standard library will not expose uninitialized
memory.

[discuss]: http://internals.rust-lang.org/t/uninitialized-memory/1652

Closes #20314
2015-03-24 13:42:19 -07:00
Steve Klabnik
528a5e2bae Add examples for std::ascii
Also tweaked a few things.
2015-03-24 15:47:47 -04:00
bors
ed81038504 Auto merge of #23654 - alexcrichton:rollup, r=alexcrichton 2015-03-24 17:38:09 +00:00
Alex Crichton
d252d0ad54 Test fixes and rebase conflicts, round 4 2015-03-24 10:23:47 -07:00
Steve Klabnik
f2e0810cb8 correct reference wrt shifts
Fixes #23421
2015-03-24 12:58:50 -04:00
Steve Klabnik
0031d57a21 Clean up Any's title line
http://www.reddit.com/r/rust/comments/304q00/type_information_in_rust/cpp43lu
2015-03-24 12:15:49 -04:00
Steve Klabnik
f2996c0c0e Add basic information about associated types 2015-03-24 12:10:01 -04:00
Alex Crichton
a7e204909b Merge remote-tracking branch 'origin/master' into rollup 2015-03-24 08:03:25 -07:00
Steve Klabnik
a34e87f3ab Add Examples for File
This is pretty basic, but it's nice to have something.
2015-03-24 10:52:46 -04:00
Nicholas Mazzuca
a9b31969dc Add the other S_I(RWX)(GRP/OTH) for posix creat 2015-03-24 03:25:48 -07:00
Alex Crichton
c5c3de0cf4 Test fixes and rebase conflicts, round 3 2015-03-23 22:52:21 -07:00
Liam Monahan
37dc801fe6 Improve the wording of the example section description on the ownership page
to make it more clear.
2015-03-23 21:19:54 -04:00
Alex Crichton
253992eb38 rollup merge of #23653: dhuseby/bitrig-stage0-c64d671
@alexcrichton this adds the latest Bitrig snapshot.  Please upload the corresponding snapshot: https://github.com/dhuseby/rust-cross-bitrig/blob/master/snapshots/rust-stage0-2015-03-17-c64d671-bitrig-x86_64-41de2c7a69a1ac648d3fa3b65e96a29bdc122163.tar.bz2
2015-03-23 17:13:39 -07:00
Alex Crichton
1588caca61 rollup merge of #23652: alexcrichton/stabilize-hasher-finish
This commit enables writing a stable implementation of the `Hasher` trait as
well as actually calculating the hash of a vlaue in a stable fashion. The
signature is stabilized as-is.
2015-03-23 17:13:38 -07:00
Alex Crichton
7380b6ffc8 rollup merge of #23645: steveklabnik/gh23642
Fixes #23642
2015-03-23 17:13:38 -07:00
Alex Crichton
6a44f24b9e rollup merge of #23644: mbrubeck/doc-edit
PR #23104 moved `is_null` and `offset` to an inherent impl on the raw pointer type.

I'm not sure whether or how it's possible to link to docs for that impl.

r? @steveklabnik
2015-03-23 17:13:37 -07:00
Alex Crichton
690ee161c6 rollup merge of #23509: aturon/stab-entry
This commit marks as `#[stable]` the `Entry` types for the maps provided
by `std`. The main reason these had been left unstable previously was
uncertainty about an eventual trait design, but several plausible
designs have been proposed that all work fine with the current type definitions.

r? @Gankro
2015-03-23 17:13:27 -07:00
Alex Crichton
29b54387b8 Test fixes and rebase conflicts, round 2 2015-03-23 17:10:19 -07:00
Niko Matsakis
9330bae4bd Fallout from changing fn traits to use inheritance rather than bridge
impls. This is a [breaking-change] (for gated code) in that when you
implement `Fn` (`FnMut`) you must also implement `FnOnce`. This commit
demonstrates how to fix it.
2015-03-23 19:57:30 -04:00
Dave Huseby
3a0c15f3cf adding lastest Bitrig snapshot by hand 2015-03-23 15:58:44 -07:00
Matt Brubeck
3f52d719dc Update docs for ptr module.
PR #23104 moved `is_null` and `offset` to an inherent impl on the raw pointer
type.
2015-03-23 15:57:20 -07:00