about summary refs log tree commit diff
path: root/src/libcore/str
AgeCommit message (Collapse)AuthorLines
2015-03-26Register new snapshotsAlex Crichton-88/+0
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 #23630: nrc/coerce-tidyAlex Crichton-1/+1
See notes on the first commit Closes #18601 r? @nikomatsakis cc @eddyb
2015-03-24rollup merge of #23282: nikomatsakis/fn-trait-inheritanceAlex Crichton-1/+28
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-25Add trivial cast lints.Nick Cameron-1/+1
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-23rollup merge of #23601: nikomatsakis/by-value-indexAlex Crichton-0/+78
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 #23538: aturon/conversionAlex Crichton-0/+4
Conflicts: src/librustc_back/rpath.rs
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-23Add generic conversion traitsAaron Turon-0/+4
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-23Adjust Index/IndexMut impls. For generic collections, we takeNiko Matsakis-0/+78
references. For collections whose keys are integers, we take both references and by-value.
2015-03-23Make the `Fn` traits inherit from one another and remove the bridgingNiko Matsakis-1/+28
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-19StrExt::splitn should not require a DoubleEndedSearcherJake Goulding-29/+36
Closes #23262
2015-03-19Introduce rsplitJake Goulding-1/+88
2015-03-19Fix spelling errors in comments.Joseph Crail-2/+2
I corrected misspelled comments in several crates.
2015-03-18Register new snapshotsAlex Crichton-2/+0
2015-03-17std: Tweak some unstable features of `str`Alex Crichton-4/+7
This commit clarifies some of the unstable features in the `str` module by moving them out of the blanket `core` and `collections` features. The following methods were moved to the `str_char` feature which generally encompasses decoding specific characters from a `str` and dealing with the result. It is unclear if any of these methods need to be stabilized for 1.0 and the most conservative route for now is to continue providing them but to leave them as unstable under a more specific name. * `is_char_boundary` * `char_at` * `char_range_at` * `char_at_reverse` * `char_range_at_reverse` * `slice_shift_char` The following methods were moved into the generic `unicode` feature as they are specifically enabled by the `unicode` crate itself. * `nfd_chars` * `nfkd_chars` * `nfc_chars` * `graphemes` * `grapheme_indices` * `width`
2015-03-17Rollup merge of #23329 - jbcrail:rm-syntax-highlight, r=sanxiynManish Goregaokar-3/+3
As suggested by @steveklabnik in #23254, I removed the redundant Rust syntax highlighting from the documentation.
2015-03-16impl<T> *const T, impl<T> *mut TJorge Aparicio-0/+1
2015-03-13Remove explicit syntax highlight from docs.Joseph Crail-3/+3
2015-03-11Example -> ExamplesSteve Klabnik-2/+2
This brings comments in line with https://github.com/rust-lang/rfcs/blob/master/text/0505-api-comment-conventions.md#using-markdown
2015-03-11Auto merge of #23251 - tbu-:pr_rm_core_str_checked_add, r=alexcrichtonbors-1/+4
2015-03-10Auto merge of #23249 - tbu-:pr_rm_core_str_macros, r=alexcrichtonbors-41/+40
2015-03-10Remove unneeded `saturating_add`Tobias Bucher-1/+4
2015-03-10Remove unneeded macro witcheryTobias Bucher-41/+40
2015-03-05Remove integer suffixes where the types in compiled code are identical.Eduard Burtescu-4/+4
2015-03-03Auto merge of #22532 - pnkfelix:arith-overflow, r=pnkfelix,eddybbors-4/+5
Rebase and follow-through on work done by @cmr and @aatch. Implements most of rust-lang/rfcs#560. Errors encountered from the checks during building were fixed. The checks for division, remainder and bit-shifting have not been implemented yet. See also PR #20795 cc @Aatch ; cc @nikomatsakis
2015-03-03Rollup merge of #22989 - laijs:fix_FromStr_bool_comment, r=alexcrichtonManish Goregaokar-2/+13
Fix the return type in the comments. An old commit 082bfde41217 (\"Fallout of std::str stabilization\") removed the example of FromStr::from_str(), this commit adds it back. But the example of StrExt::parse() is still kept with an additinal note. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2015-03-03Add `core::num::wrapping` and fix overflow errors.James Miller-4/+5
Many of the core rust libraries have places that rely on integer wrapping behaviour. These places have been altered to use the wrapping_* methods: * core::hash::sip - A number of macros * core::str - The `maximal_suffix` method in `TwoWaySearcher` * rustc::util::nodemap - Implementation of FnvHash * rustc_back::sha2 - A number of macros and other places * rand::isaac - Isaac64Rng, changed to use the Wrapping helper type Some places had "benign" underflow. This is when underflow or overflow occurs, but the unspecified value is not used due to other conditions. * collections::bit::Bitv - underflow when `self.nbits` is zero. * collections::hash::{map,table} - Underflow when searching an empty table. Did cause undefined behaviour in this case due to an out-of-bounds ptr::offset based on the underflowed index. However the resulting pointers would never be read from. * syntax::ext::deriving::encodable - Underflow when calculating the index of the last field in a variant with no fields. These cases were altered to avoid the underflow, often by moving the underflowing operation to a place where underflow could not happen. There was one case that relied on the fact that unsigned arithmetic and two's complement arithmetic are identical with wrapping semantics. This was changed to use the wrapping_* methods. Finally, the calculation of variant discriminants could overflow if the preceeding discriminant was `U64_MAX`. The logic in `rustc::middle::ty` for this was altered to avoid the overflow completely, while the remaining places were changed to use wrapping methods. This is because `rustc::middle::ty::enum_variants` now throws an error when the calculated discriminant value overflows a `u64`. This behaviour can be triggered by the following code: ``` enum Foo { A = U64_MAX, B } ``` This commit also implements the remaining integer operators for Wrapped<T>.
2015-03-03str: fix comments for FromStr for boolLai Jiangshan-2/+13
Fix the return type in the comments. An old commit 082bfde41217 ("Fallout of std::str stabilization") removed the example of FromStr::from_str(), this commit adds it back. But the example of StrExt::parse() is still kept with an additinal note. Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2015-03-02Enable recursion for visit_ty in lint visitorIvan Petkov-0/+2
* The lint visitor's visit_ty method did not recurse, and had a reference to the now closed #10894 * The newly enabled recursion has only affected the `deprectated` lint which now detects uses of deprecated items in trait impls and function return types * Renamed some references to `CowString` and `CowVec` to `Cow<str>` and `Cow<[T]>`, respectively, which appear outside of the crate which defines them * Replaced a few instances of `InvariantType<T>` with `PhantomData<Cell<T>>` * Disabled the `deprecated` lint in several places that reference/implement traits on deprecated items which will get cleaned up in the future * Disabled the `exceeding_bitshifts` lint for compile-fail/huge-array-simple test so it doesn't shadow the expected error on 32bit systems * Unfortunately, this means that if a library declares `#![deny(deprecated)]` and marks anything as deprecated, it will have to disable the lint for any uses of said item, e.g. any impl the now deprecated item For any library that denies deprecated items but has deprecated items of its own, this is a [breaking-change]
2015-02-27Add some missing stability attributes on struct fields.Huon Wilson-0/+1
2015-02-20Addressed PR commentsMarvin Löbel-56/+197
2015-02-20Fix tidy and rebase falloutMarvin Löbel-15/+27
Added a few bugfixes and additional testcases
2015-02-20Added a Pattern impl that delegates to the dereference of a type.Marvin Löbel-22/+89
This allows to match with a `&String` or `&&str`, for example.
2015-02-20Refactored code into Searcher traits with naive implementationsMarvin Löbel-372/+451
Made the family of Split iterators use the Pattern API Renamed the Matcher traits into Searcher
2015-02-20Made match_indices use the generic pattern APIMarvin Löbel-29/+34
2015-02-20Made str::MatchIndices a private implementantion detailMarvin Löbel-10/+24
2015-02-20Added string pattern traits and basic implementantionsMarvin Löbel-126/+282
2015-02-18Replace all uses of `&foo[]` with `&foo[..]` en masse.Niko Matsakis-1/+1
2015-02-15Audit integer types in libunicode, libcore/(char, str) and libstd/asciiVadim Petrochenkov-77/+79
2015-02-11rustc: Fix a number of stability lint holesAlex Crichton-3/+3
There are a number of holes that the stability lint did not previously cover, including: * Types * Bounds on type parameters on functions and impls * Where clauses * Imports * Patterns (structs and enums) These holes have all been fixed by overriding the `visit_path` function on the AST visitor instead of a few specialized cases. This change also necessitated a few stability changes: * The `collections::fmt` module is now stable (it was already supposed to be). * The `thread_local::imp::Key` type is now stable (it was already supposed to be). * The `std::rt::{begin_unwind, begin_unwind_fmt}` functions are now stable. These are required via the `panic!` macro. * The `std::old_io::stdio::{println, println_args}` functions are now stable. These are required by the `print!` and `println!` macros. * The `ops::{FnOnce, FnMut, Fn}` traits are now `#[stable]`. This is required to make bounds with these traits stable. Note that manual implementations of these traits are still gated by default, this stability only allows bounds such as `F: FnOnce()`. Additionally, the compiler now has special logic to ignore its own generated `__test` module for the `--test` harness in terms of stability. Closes #8962 Closes #16360 Closes #20327 [breaking-change]
2015-02-06Rollup merge of #21925 - sfackler:allow-missing-copy, r=alexcrichtonManish Goregaokar-1/+0
This was particularly helpful in the time just after OIBIT's implementation to make sure things that were supposed to be Copy continued to be, but it's now creates a lot of noise for types that intentionally don't want to be Copy. r? @alexcrichton
2015-02-04remove all kind annotations from closuresJorge Aparicio-4/+4
2015-02-03Switch missing_copy_implementations to default-allowSteven Fackler-1/+0
This was particularly helpful in the time just after OIBIT's implementation to make sure things that were supposed to be Copy continued to be, but it's now creates a lot of noise for types that intentionally don't want to be Copy.
2015-02-02rollup merge of #21842: alexcrichton/issue-21839Alex Crichton-2/+2
Now that associated types are fully implemented the iterator adaptors only need type parameters which are associated with actual storage. All other type parameters can either be derived from these (e.g. they are an associated type) or can be bare on the `impl` block itself. This is a breaking change due to the removal of type parameters on these iterator adaptors, but code can fairly easily migrate by just deleting the relevant type parameters for each adaptor. Other behavior should not be affected. Closes #21839 [breaking-change]
2015-02-02register snapshotsJorge Aparicio-10/+0
2015-02-01std: Remove extra type params on iter adaptorsAlex Crichton-2/+2
Now that associated types are fully implemented the iterator adaptors only need type parameters which are associated with actual storage. All other type parameters can either be derived from these (e.g. they are an associated type) or can be bare on the `impl` block itself. This is a breaking change due to the removal of type parameters on these iterator adaptors, but code can fairly easily migrate by just deleting the relevant type parameters for each adaptor. Other behavior should not be affected. Closes #21839 [breaking-change]