<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/src/libcore/str, branch 1.27.1</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.27.1</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.27.1'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2018-04-22T00:01:29+00:00</updated>
<entry>
<title>Auto merge of #49896 - SimonSapin:inherent, r=alexcrichton</title>
<updated>2018-04-22T00:01:29+00:00</updated>
<author>
<name>bors</name>
<email>bors@rust-lang.org</email>
</author>
<published>2018-04-22T00:01:29+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=d5616e1f18abb46071581d096994a0ff6581e3f9'/>
<id>urn:sha1:d5616e1f18abb46071581d096994a0ff6581e3f9</id>
<content type='text'>
Add inherent methods in libcore for [T], [u8], str, f32, and f64

# Background

Primitive types are defined by the language, they don’t have a type definition like `pub struct Foo { … }` in any crate. So they don’t “belong” to any crate as far as `impl` coherence is concerned, and on principle no crate would be able to define inherent methods for them, without a trait. Since we want these types to have inherent methods anyway, the standard library (with cooperation from the compiler) bends this rule with code like [`#[lang = "u8"] impl u8 { /*…*/ }`](https://github.com/rust-lang/rust/blob/1.25.0/src/libcore/num/mod.rs#L2244-L2245). The `#[lang]` attribute is permanently-unstable and never intended to be used outside of the standard library.

Each lang item can only be defined once. Before this PR there is one impl-coherence-rule-bending lang item per primitive type (plus one for `[u8]`, which overlaps with `[T]`). And so one `impl` block each. These blocks for `str`, `[T]` and `[u8]` are in liballoc rather than libcore because *some* of the methods (like `&lt;[T]&gt;::to_vec(&amp;self) -&gt; Vec&lt;T&gt; where T: Clone`) need a global memory allocator which we don’t want to make a requirement in libcore. Similarly, `impl f32` and `impl f64` are in libstd because some of the methods are based on FFI calls to C’s `libm` and we want, as much as possible, libcore not to require “runtime support”.

In libcore, the methods of `str` and `[T]` that don’t allocate are made available through two **unstable traits** `StrExt` and `SliceExt` (so the traits can’t be *named* by programs on the Stable release channel) that have **stable methods** and are re-exported in the libcore prelude (so that programs on Stable can *call* these methods anyway). Non-allocating `[u8]` methods are not available in libcore: https://github.com/rust-lang/rust/issues/45803. Some `f32` and `f64` methods are in an unstable `core::num::Float` trait with stable methods, but that one is **not in the libcore prelude**. (So as far as Stable programs are concerns it doesn’t exist, and I don’t know what the point was to mark these methods `#[stable]`.)

https://github.com/rust-lang/rust/issues/32110 is the tracking issue for these unstable traits.

# High-level proposal

Since the standard library is already bending the rules, why not bend them *a little more*? By defining a few additional lang items, the compiler can allow the standard library to have *two* `impl` blocks (in different crates) for some primitive types.

The `StrExt` and `SliceExt` traits still exist for now so that we can bootstrap from a previous-version compiler that doesn’t have these lang items yet, but they can be removed in next release cycle. (`Float` is used internally and needs to be public for libcore unit tests, but was already `#[doc(hidden)]`.) I don’t know if https://github.com/rust-lang/rust/issues/32110 should be closed by this PR, or only when the traits are entirely removed after we make a new bootstrap compiler.

# Float methods

Among the methods of the `core::num::Float` trait, three are based on LLVM intrinsics: `abs`, `signum`, and `powi`. PR https://github.com/rust-lang/rust/pull/27823 “Remove dependencies on libm functions from libcore” moved a bunch of `core::num::Float` methods back to libstd, but left these three behind. However they aren’t specifically discussed in the PR thread. The `compiler_builtins` crate defines `__powisf2` and `__powidf2` functions that look like implementations of `powi`, but I couldn’t find a connection with the `llvm.powi.f32` and `llvm.powi.f32` intrinsics by grepping through LLVM’s code.

In discussion starting at https://github.com/rust-lang/rust/issues/32110#issuecomment-370647922 Alex says that we do not want methods in libcore that require “runtime support”, but it’s not clear whether that applies to these `abs`, `signum`, or `powi`. In doubt, I’ve **removed** them for the trait and moved them to inherent methods in libstd for now. We can move them back later (or in this PR) if we decide that’s appropriate.

# Change details

For users on the Stable release channel:

* I believe this PR does not make any breaking change
* Some methods for `[u8]`, `f32`, and `f64` are newly available to `#![no_std]` users (fixes https://github.com/rust-lang/rust/issues/45803)
* There should be no visible change for `std` users in terms of what programs compile or what their behavior is. (Only in compiler error messages, possibly.)

For Nightly users, additionally:

* The unstable `StrExt` and `SliceExt` traits are gone
* Their methods are now inherent methods of `str` and `[T]` (so only code that explicitly named the traits should be affected, not "normal" method calls)
* The `abs`, `signum` and `powi` methods of the `Float` trait are gone
* The `Float` trait’s unstable feature name changed to `float_internals` with no associated tracking issue, to reflect it being a permanently unstable implementation detail rather than a public API on a path to stabilization.
* Its remaining methods are now inherent methods of `f32` and `f64`.

-----

CC @rust-lang/libs for the API changes, @rust-lang/compiler for the new lang items
</content>
</entry>
<entry>
<title>Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)</title>
<updated>2018-04-21T07:47:38+00:00</updated>
<author>
<name>Simon Sapin</name>
<email>simon.sapin@exyr.org</email>
</author>
<published>2018-04-12T06:36:31+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=70fdd1b5c0f6a0673fcf924b3d8880af034bdee0'/>
<id>urn:sha1:70fdd1b5c0f6a0673fcf924b3d8880af034bdee0</id>
<content type='text'>
`Float` still needs to be public for libcore unit tests.
</content>
</entry>
<entry>
<title>Replace StrExt with inherent str methods in libcore</title>
<updated>2018-04-21T07:47:37+00:00</updated>
<author>
<name>Simon Sapin</name>
<email>simon.sapin@exyr.org</email>
</author>
<published>2018-04-07T19:56:02+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=f0705bf033363757a8a2901cd1a7bd76f0fea820'/>
<id>urn:sha1:f0705bf033363757a8a2901cd1a7bd76f0fea820</id>
<content type='text'>
</content>
</entry>
<entry>
<title>smaller PR just to fix #50002</title>
<updated>2018-04-18T01:31:35+00:00</updated>
<author>
<name>Michael Lamparski</name>
<email>diagonaldevice@gmail.com</email>
</author>
<published>2018-04-16T20:34:09+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=b74d6922ff15d9f3bf39d317ccd7141518f4f5ec'/>
<id>urn:sha1:b74d6922ff15d9f3bf39d317ccd7141518f4f5ec</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Remove unwanted auto-linking and update</title>
<updated>2018-04-16T21:37:11+00:00</updated>
<author>
<name>Guillaume Gomez</name>
<email>guillaume1.gomez@gmail.com</email>
</author>
<published>2018-04-15T14:17:18+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=05275dafaaa602fe4a5d275ef724ced39d30465f'/>
<id>urn:sha1:05275dafaaa602fe4a5d275ef724ced39d30465f</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Merge core::unicode::str into core::str</title>
<updated>2018-04-11T22:13:52+00:00</updated>
<author>
<name>Simon Sapin</name>
<email>simon.sapin@exyr.org</email>
</author>
<published>2018-04-05T17:00:48+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=0d9afcd9b9f881545c8b722855f7e39361495d27'/>
<id>urn:sha1:0d9afcd9b9f881545c8b722855f7e39361495d27</id>
<content type='text'>
And the UnicodeStr trait into StrExt
</content>
</entry>
<entry>
<title>Move Utf8Lossy decoder to libcore</title>
<updated>2018-04-11T22:13:43+00:00</updated>
<author>
<name>Simon Sapin</name>
<email>simon.sapin@exyr.org</email>
</author>
<published>2018-04-05T13:55:28+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=f87d4a15a82a76e7510629173c366d084f2c02ca'/>
<id>urn:sha1:f87d4a15a82a76e7510629173c366d084f2c02ca</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Add an example of lossy decoding to str::Utf8Error docs</title>
<updated>2018-03-17T10:17:11+00:00</updated>
<author>
<name>Simon Sapin</name>
<email>simon.sapin@exyr.org</email>
</author>
<published>2018-03-17T09:05:23+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e09dbbc39eeecbf6a8122d86297a1e8701aca26b'/>
<id>urn:sha1:e09dbbc39eeecbf6a8122d86297a1e8701aca26b</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Stabilize `inclusive_range` library feature.</title>
<updated>2018-03-15T08:58:01+00:00</updated>
<author>
<name>kennytm</name>
<email>kennytm@gmail.com</email>
</author>
<published>2018-01-27T19:09:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=b5913f2e7695ad247078619bf4c6a6d3dc4dece5'/>
<id>urn:sha1:b5913f2e7695ad247078619bf4c6a6d3dc4dece5</id>
<content type='text'>
Stabilize std::ops::RangeInclusive and std::ops::RangeInclusiveTo.
</content>
</entry>
<entry>
<title>core: Update stability attributes for FusedIterator</title>
<updated>2018-03-03T13:23:05+00:00</updated>
<author>
<name>Ulrik Sverdrup</name>
<email>bluss@users.noreply.github.com</email>
</author>
<published>2018-03-03T13:15:28+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c7c23fe9482c129855a667909ff58969f6efe1f6'/>
<id>urn:sha1:c7c23fe9482c129855a667909ff58969f6efe1f6</id>
<content type='text'>
</content>
</entry>
</feed>
