about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2015-03-27Rollup merge of #23712 - nikomatsakis:reflect-trait, r=FlaPer87Manish Goregaokar-11/+57
This PR introduces a `Reflect` marker trait which is a supertrait of `Any`. The idea is that `Reflect` is defined for all concrete types, but is not defined for type parameters unless there is a `T:Reflect` bound. This is intended to preserve the parametricity property. This allows the `Any` interface to be stabilized without committing us to unbounded reflection that is not easily detectable by the caller. The implementation of `Reflect` relies on an experimental variant of OIBIT. This variant behaves differently for objects, since it requires that all types exposed as part of the object's *interface* are `Reflect`, but isn't concerned about other types that may be closed over. In other words, you don't have to write `Foo+Reflect` in order for `Foo: Reflect` to hold (where `Foo` is a trait). Given that `Any` is slated to stabilization and hence that we are committed to some form of reflection, the goal of this PR is to leave our options open with respect to parametricity. I see the options for full stabilization as follows (I think an RFC would be an appropriate way to confirm whichever of these three routes we take): 1. We make `Reflect` a lang-item. 2. We stabilize some version of the OIBIT variation I implemented as a general mechanism that may be appropriate for other use cases. 3. We give up on preserving parametricity here and just have `impl<T> Reflect for T` instead. In that case, `Reflect` is a harmless but not especially useful trait going forward. cc @aturon cc @alexcrichton cc @glaebhoerl (this is more-or-less your proposal, as I understood it) cc @reem (this is more-or-less what we discussed on IRC at some point) cc @FlaPer87 (vaguely pertains to OIBIT)
2015-03-26Fix doc tests.Niko Matsakis-0/+1
2015-03-26Implement `Reflect` trait with a variant on the standard OIBITNiko Matsakis-11/+56
semantics that tests the *interface* of trait objects, rather than what they close over.
2015-03-26Register new snapshotsAlex Crichton-358/+0
2015-03-25Auto merge of #23434 - alexcrichton:misc-stab, r=aturonbors-3/+4
Now that we check the stability of fields, the fields of this struct should also be stable.
2015-03-25Rollup merge of #23664 - bluss:std-docs, r=steveklabnikManish Goregaokar-8/+7
Main motivation was to update docs for the removal or "demotion" of certain extension traits. The update to the slice docs was larger, since the text was largely outdated.
2015-03-24Test fixes and rebase conflicts, round 2Alex Crichton-0/+1
2015-03-24rollup merge of #23671: steveklabnik/doc_std_cloneAlex Crichton-0/+8
2015-03-24rollup merge of #23661: steveklabnik/any_docsAlex Crichton-4/+4
http://www.reddit.com/r/rust/comments/304q00/type_information_in_rust/cpp43lu
2015-03-24rollup merge of #23630: nrc/coerce-tidyAlex Crichton-3/+31
See notes on the first commit Closes #18601 r? @nikomatsakis cc @eddyb
2015-03-24rollup merge of #23282: nikomatsakis/fn-trait-inheritanceAlex Crichton-1/+52
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-24core: Update docs for StrExt demotion in libstdUlrik Sverdrup-8/+7
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-25Change lint names to pluralsNick Cameron-20/+20
2015-03-25Add trivial cast lints.Nick Cameron-3/+31
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-24An example for cloneSteve Klabnik-0/+8
2015-03-24Clean up Any's title lineSteve Klabnik-4/+4
http://www.reddit.com/r/rust/comments/304q00/type_information_in_rust/cpp43lu
2015-03-23rollup merge of #23652: alexcrichton/stabilize-hasher-finishAlex Crichton-1/+1
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-23rollup merge of #23644: mbrubeck/doc-editAlex Crichton-6/+3
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-23Update docs for ptr module.Matt Brubeck-6/+3
PR #23104 moved `is_null` and `offset` to an inherent impl on the raw pointer type.
2015-03-23rollup merge of #23503: alexcrichton/fix-ptr-docsAlex Crichton-23/+31
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-23rollup merge of #23484: alexcrichton/marker-trait-stableAlex Crichton-0/+1
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-23rollup merge of #23598: brson/gateAlex Crichton-6/+87
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-23rollup merge of #23633: tomjakubowski/rustdoc-array-primAlex Crichton-0/+2
Previously, impls for `[T; n]` were collected in the same place as impls for `[T]` and `&[T]`. This splits them out into their own primitive page in both core and std.
2015-03-23rollup merge of #23601: nikomatsakis/by-value-indexAlex Crichton-3/+294
This is a [breaking-change]. When indexing a generic map (hashmap, etc) using the `[]` operator, it is now necessary to borrow explicitly, so change `map[key]` to `map[&key]` (consistent with the `get` routine). However, indexing of string-valued maps with constant strings can now be written `map["abc"]`. r? @japaric cc @aturon @Gankro
2015-03-23rollup merge of #23580: nikomatsakis/pattern-and-overflowAlex Crichton-13/+7
2015-03-23rollup merge of #23541: aturon/stab-errorAlex Crichton-5/+10
This small commit stabilizes the `Error` trait as-is, except that `Send` and `Debug` are added as constraints. The `Send` constraint is because most uses of `Error` will be for trait objects, and by default we would like these objects to be transferrable between threads. The `Debug` constraint is to ensure that e.g. `Box<Error>` is `Debug`, and because types that implement `Display` should certainly implement `Debug` in any case. In the near future we expect to add `Any`-like downcasting features to `Error`, but this is waiting on some additional mechanisms (`Reflect`). It will be added before 1.0 via default methods. [breaking-change] r? @alexcrichton Closes #21790
2015-03-23rollup merge of #23538: aturon/conversionAlex Crichton-1/+161
Conflicts: src/librustc_back/rpath.rs
2015-03-23rollup merge of #23269: shepmaster/split-not-double-endedAlex Crichton-30/+124
Closes #23262
2015-03-23rollup merge of #23211: FlaPer87/oibit-send-and-friendsAlex Crichton-0/+4
Fixes #23225 r? @nikomatsakis
2015-03-23Remove auto-deref'ing Pattern impl because it conflicts with otherNiko Matsakis-13/+7
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-23std: Stabilize the `Hasher::finish` methodAlex Crichton-1/+1
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-23Add generic conversion traitsAaron Turon-1/+161
This commit: * Introduces `std::convert`, providing an implementation of RFC 529. * Deprecates the `AsPath`, `AsOsStr`, and `IntoBytes` traits, all in favor of the corresponding generic conversion traits. Consequently, various IO APIs now take `AsRef<Path>` rather than `AsPath`, and so on. Since the types provided by `std` implement both traits, this should cause relatively little breakage. * Deprecates many `from_foo` constructors in favor of `from`. * Changes `PathBuf::new` to take no argument (creating an empty buffer, as per convention). The previous behavior is now available as `PathBuf::from`. * De-stabilizes `IntoCow`. It's not clear whether we need this separate trait. Closes #22751 Closes #14433 [breaking-change]
2015-03-23Add #![feature] attributes to doctestsBrian Anderson-6/+87
2015-03-23rustdoc: Support for "array" primitiveTom Jakubowski-0/+2
Impls on `clean::Type::FixedVector` are now collected in the array primitive page instead of the slice primitive page. Also add a primitive docs for arrays to `std`.
2015-03-23Adjust Index/IndexMut impls. For generic collections, we takeNiko Matsakis-3/+282
references. For collections whose keys are integers, we take both references and by-value.
2015-03-23Compiler and trait changes to make indexing by value.Niko Matsakis-0/+12
2015-03-23Make the `Fn` traits inherit from one another and remove the bridgingNiko Matsakis-1/+52
impls. This requires: 1. modifying trait selection a bit so that when we synthesize impls for fn pointers and closures; 2. adding code to trans so that we can synthesize a `FnMut`/`FnOnce` impl for a `Fn` closure and so forth.
2015-03-23Stabilize the Error traitAaron Turon-5/+10
This small commit stabilizes the `Error` trait as-is, except that `Send` and `Debug` are added as constraints. The `Send` constraint is because most uses of `Error` will be for trait objects, and by default we would like these objects to be transferrable between threads. The `Debug` constraint is to ensure that e.g. `Box<Error>` is `Debug`, and because types that implement `Display` should certainly implement `Debug` in any case. In the near future we expect to add `Any`-like downcasting features to `Error`, but this is waiting on some additional mechanisms (`Reflect`). It will be added before 1.0 via default methods. [breaking-change]
2015-03-21std: Remove deprecated ptr functionsAlex Crichton-23/+31
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-21Auto merge of #23470 - alexcrichton:less-prelude, r=aturonbors-9/+14
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-20std: Remove old_io/old_path from the preludeAlex Crichton-9/+14
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-20Auto merge of #23512 - oli-obk:result_ok_unwrap, r=alexcrichtonbors-2/+2
because then the call to `unwrap()` will not print the error object.
2015-03-20Check trait unsafety for defaulted traitsFlavio Percoco-2/+2
2015-03-20Add default impls for Send/SyncFlavio Percoco-0/+4
2015-03-20don't use Result::ok just to be able to use unwrap/unwrap_orOliver Schneider-2/+2
2015-03-20Auto merge of #23254 - jbcrail:saturating-math-docs, r=steveklabnikbors-0/+20
This was added for #23241.
2015-03-19StrExt::splitn should not require a DoubleEndedSearcherJake Goulding-29/+36
Closes #23262
2015-03-19Introduce rsplitJake Goulding-1/+88
2015-03-19Auto merge of #23507 - jbcrail:fix-comment-spelling, r=alexcrichtonbors-2/+2
I corrected misspelled comments in several crates.
2015-03-19Fix spelling errors in comments.Joseph Crail-2/+2
I corrected misspelled comments in several crates.