Commit Graph

40271 Commits

Author SHA1 Message Date
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
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
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
Aaron Turon
248b2ecd18 Stabilize Entry types
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.
2015-03-23 15:49:15 -07:00
bors
28a0b25f42 Auto merge of #23536 - pnkfelix:arith-oflo-shifts, r=nikomatsakis
overflow-checking for rhs of shift operators

Subtask of #22020 ([RFC 560](https://github.com/rust-lang/rfcs/blob/master/text/0560-integer-overflow.md))
2015-03-23 22:43:39 +00:00
Alex Crichton
3112716f12 rollup merge of #23506: alexcrichton/remove-some-deprecated-things
Conflicts:
	src/test/run-pass/deprecated-no-split-stack.rs
2015-03-23 15:27:06 -07: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
6e0f1d3984 rollup merge of #23484: alexcrichton/marker-trait-stable
This trait has proven quite useful when defining marker traits to avoid the
semi-confusing `PhantomFn` trait and it looks like it will continue to be a
useful tool for defining these traits.
2015-03-23 15:26:24 -07:00
Alex Crichton
04e667a6b1 Test fixes and rebase conflicts, round 1 2015-03-23 15:18:40 -07:00
Alex Crichton
7d07f70ccb rollup merge of #23383: alexcrichton/fs-create-dir-all
Conflicts:
	src/libstd/fs/mod.rs
2015-03-23 15:18: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