Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string: implement From<&String> for String #59825

Merged
merged 1 commit into from May 16, 2019

Conversation

Projects
None yet
@jsgf
Copy link
Contributor

commented Apr 9, 2019

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing &String to an impl Into<String>
parameter frictionless.

Fixes #59827.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

commented Apr 9, 2019

r? @kennytm

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

commented Apr 9, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:1f631d42:start=1554842818052611909,finish=1554842818976404255,duration=923792346
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
$ export GCP_CACHE_BUCKET=rust-lang-ci-cache
$ export AWS_ACCESS_KEY_ID=AKIA46X5W6CZEJZ6XT55
---
[00:04:53]    Compiling rustc-std-workspace-core v1.0.0 (/checkout/src/tools/rustc-std-workspace-core)
[00:04:55]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:04:55]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:04:55]    Compiling rustc-demangle v0.1.10
[00:04:58] error: impl has missing stability attribute
[00:04:58]      |
[00:04:58]      |
[00:04:58] 2182 | / impl From<&String> for String {
[00:04:58] 2183 | |     #[inline]
[00:04:58] 2184 | |     fn from(s: &String) -> String {
[00:04:58] 2185 | |         s.clone()
[00:04:58] 2187 | | }
[00:04:58]      | |_^
[00:04:58] 
[00:04:58] error: aborting due to previous error

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@jsgf jsgf force-pushed the jsgf:from-ref-string branch from fafa735 to 41d2245 Apr 9, 2019

@kennytm kennytm added the needs-fcp label Apr 9, 2019

@@ -2179,6 +2179,14 @@ impl From<&str> for String {
}
}

#[unstable(feature="from_ref_string", issue="59827")]

This comment has been minimized.

Copy link
@kennytm

kennytm Apr 9, 2019

Member

new impls are insta-stable, unfortunately.

This comment has been minimized.

Copy link
@jsgf

jsgf Apr 9, 2019

Author Contributor

Ah, OK. What version should I put then?

This comment has been minimized.

Copy link
@kennytm

kennytm Apr 10, 2019

Member

1.36.0. I don't think this PR could be merged in a day (before the coming release )

This comment has been minimized.

Copy link
@jsgf

jsgf Apr 10, 2019

Author Contributor

.34 would be ambitious yes; I guessed .35, but .36 is fine too.

string: implement From<&String> for String
Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing &String to an `impl Into<String>`
parameter frictionless.

@jsgf jsgf force-pushed the jsgf:from-ref-string branch from 41d2245 to 08b0aca Apr 9, 2019

@Centril Centril added the relnotes label Apr 10, 2019

@WiSaGaN

This comment has been minimized.

Copy link
Contributor

commented Apr 10, 2019

What is so special about String? Compare to things like OsString or even all owned types? Should they all implement From<&T> for T?

@NieDzejkob

This comment has been minimized.

Copy link
Contributor

commented Apr 10, 2019

I'm not familiar with the ffi types, but the special thing about String is that it can Deref to str, which already implements From for String. This makes &string and &string[..] have the same semantics most of the time, but not always.

@WiSaGaN

This comment has been minimized.

Copy link
Contributor

commented Apr 10, 2019

@jsgf

This comment has been minimized.

Copy link
Contributor Author

commented Apr 10, 2019

@WiSaGaN I agree, there's nothing particularly special about String other than it was the case I ran into. It would make equal sense for a lot of types (and if we had specialization I might suggest a blanket default impl<T: Clone> From<&T> for T, but that might be going too far).

@Dylan-DPC

This comment has been minimized.

Copy link
Member

commented Apr 22, 2019

ping from triage @jsgf @kennytm any updates on this?

@jsgf

This comment has been minimized.

Copy link
Contributor Author

commented Apr 22, 2019

@Dylan-DPC I wasn't planning any changes. I'm happy to do similar implementations for Vec and/or OsString if that would unblock it, but it's not clear to me that those missing are blocking objections.

@WiSaGaN

This comment has been minimized.

Copy link
Contributor

commented Apr 23, 2019

I am wondering whether libs team have thought about implementing impl<T: Clone> From<&T> for T before. If we did, and the decision was not to, then what has changed since?

@Centril

This comment has been minimized.

Copy link
Member

commented May 11, 2019

@rust-highfive rust-highfive assigned sfackler and unassigned kennytm May 11, 2019

@sfackler

This comment has been minimized.

Copy link
Member

commented May 11, 2019

I've definitely run into this impl missing, so I'm in favor!

@rfcbot fcp merge

@rfcbot

This comment has been minimized.

Copy link

commented May 11, 2019

Team member @sfackler has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot

This comment has been minimized.

Copy link

commented May 15, 2019

🔔 This is now entering its final comment period, as per the review above. 🔔

@sfackler

This comment has been minimized.

Copy link
Member

commented May 15, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

📌 Commit 08b0aca has been approved by sfackler

@Centril

This comment has been minimized.

Copy link
Member

commented May 15, 2019

@bors rollup

Centril added a commit to Centril/rust that referenced this pull request May 15, 2019

Rollup merge of rust-lang#59825 - jsgf:from-ref-string, r=sfackler
string: implement From<&String> for String

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing `&String` to an `impl Into<String>`
parameter frictionless.

Fixes rust-lang#59827.

bors added a commit that referenced this pull request May 15, 2019

Auto merge of #60859 - Centril:rollup-x7rcz9c, r=Centril
Rollup of 9 pull requests

Successful merges:

 - #59825 (string: implement From<&String> for String)
 - #59923 (Fix convert module's documentation links)
 - #60691 (Include expression to wait for to the span of Await)
 - #60763 (Move token tree related lexer state to a separate struct)
 - #60769 (Update rustc book CLI docs.)
 - #60811 (Bump measureme dependency to 0.3)
 - #60816 (README.md: Mention MSVC 2017+, not 2013(!))
 - #60827 (Use `Symbol` more in lint APIs)
 - #60851 (Move `box` from the stable keyword to unstable keywords list)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request May 15, 2019

Rollup merge of rust-lang#59825 - jsgf:from-ref-string, r=sfackler
string: implement From<&String> for String

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing `&String` to an `impl Into<String>`
parameter frictionless.

Fixes rust-lang#59827.

bors added a commit that referenced this pull request May 15, 2019

Auto merge of #60864 - Centril:rollup-l9jnv2h, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #59825 (string: implement From<&String> for String)
 - #59923 (Fix convert module's documentation links)
 - #60691 (Include expression to wait for to the span of Await)
 - #60763 (Move token tree related lexer state to a separate struct)
 - #60769 (Update rustc book CLI docs.)
 - #60811 (Bump measureme dependency to 0.3)
 - #60816 (README.md: Mention MSVC 2017+, not 2013(!))
 - #60851 (Move `box` from the stable keyword to unstable keywords list)

Failed merges:

r? @ghost

Centril added a commit to Centril/rust that referenced this pull request May 16, 2019

Rollup merge of rust-lang#59825 - jsgf:from-ref-string, r=sfackler
string: implement From<&String> for String

Allow Strings to be created from borrowed Strings. This is mostly
to make things like passing `&String` to an `impl Into<String>`
parameter frictionless.

Fixes rust-lang#59827.

bors added a commit that referenced this pull request May 16, 2019

Auto merge of #60877 - Centril:rollup-j0o5mo5, r=Centril
Rollup of 6 pull requests

Successful merges:

 - #59825 (string: implement From<&String> for String)
 - #59923 (Fix convert module's documentation links)
 - #60691 (Include expression to wait for to the span of Await)
 - #60769 (Update rustc book CLI docs.)
 - #60816 (README.md: Mention MSVC 2017+, not 2013(!))
 - #60851 (Move `box` from the stable keyword to unstable keywords list)

Failed merges:

r? @ghost

@bors bors merged commit 08b0aca into rust-lang:master May 16, 2019

1 check passed

Travis CI - Pull Request Build Passed
Details

@95th 95th referenced this pull request Jun 18, 2019

Merged

Add dyn to areas of core. #2538

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jul 5, 2019

he
Update rust to version 1.36.0
Pkgsrc changes:
 * NetBSD/sparc64 disabling of "packed" removed ("packed" removed upstream)
 * Adapt src_libstd_build.rs patch, update sed'ing of .cargo-checksum.json

Build verified on NetBSD 8.0/amd64.

Upstream changes:

Version 1.36.0 (2019-07-04)
==========================

Language
--------
- [Non-Lexical Lifetimes are now enabled on the 2015 edition.][59114]
- [The order of traits in trait objects no longer affects the semantics of that
  object.][59445] e.g. `dyn Send + fmt::Debug` is now equivalent to
  `dyn fmt::Debug + Send`, where this was previously not the case.

Libraries
---------
- [`HashMap`'s implementation has been replaced with `hashbrown::HashMap` implem
entation.][58623]
- [`TryFromSliceError` now implements `From<Infallible>`.][60318]
- [`mem::needs_drop` is now available as a const fn.][60364]
- [`alloc::Layout::from_size_align_unchecked` is now available as a const fn.][6
0370]
- [`String` now implements `BorrowMut<str>`.][60404]
- [`io::Cursor` now implements `Default`.][60234]
- [Both `NonNull::{dangling, cast}` are now const fns.][60244]
- [The `alloc` crate is now stable.][59675] `alloc` allows you to use a subset
  of `std` (e.g. `Vec`, `Box`, `Arc`) in `#![no_std]` environments if the
  environment has access to heap memory allocation.
- [`String` now implements `From<&String>`.][59825]
- [You can now pass multiple arguments to the `dbg!` macro.][59826] `dbg!` will
  return a tuple of each argument when there is multiple arguments.
- [`Result::{is_err, is_ok}` are now `#[must_use]` and will produce a warning if
  not used.][59648]

Stabilized APIs
---------------
- [`VecDeque::rotate_left`]
- [`VecDeque::rotate_right`]
- [`Iterator::copied`]
- [`io::IoSlice`]
- [`io::IoSliceMut`]
- [`Read::read_vectored`]
- [`Write::write_vectored`]
- [`str::as_mut_ptr`]
- [`mem::MaybeUninit`]
- [`pointer::align_offset`]
- [`future::Future`]
- [`task::Context`]
- [`task::RawWaker`]
- [`task::RawWakerVTable`]
- [`task::Waker`]
- [`task::Poll`]

Cargo
-----
- [Cargo will now produce an error if you attempt to use the name of a required
dependency as a feature.][cargo/6860]
- [You can now pass the `--offline` flag to run cargo without accessing the netw
ork.][cargo/6934]

You can find further change's in [Cargo's 1.36.0 release notes][cargo-1-36-0].

Clippy
------
There have been numerous additions and fixes to clippy, see [Clippy's 1.36.0 rel
ease notes][clippy-1-36-0] for more details.

Misc
----

Compatibility Notes
-------------------
- [`std::arch::x86::_rdtsc` returns `u64` instead of `i64`][stdsimd/559]
- [`std::arch::x86_64::_mm_shuffle_ps` takes an `i32` instead of `u32` for `mask
`][stdsimd/522]
- With the stabilisation of `mem::MaybeUninit`, `mem::uninitialized` use is no
  longer recommended, and will be deprecated in 1.38.0.

[60318]: rust-lang/rust#60318
[60364]: rust-lang/rust#60364
[60370]: rust-lang/rust#60370
[60404]: rust-lang/rust#60404
[60234]: rust-lang/rust#60234
[60244]: rust-lang/rust#60244
[58623]: rust-lang/rust#58623
[59648]: rust-lang/rust#59648
[59675]: rust-lang/rust#59675
[59825]: rust-lang/rust#59825
[59826]: rust-lang/rust#59826
[59445]: rust-lang/rust#59445
[59114]: rust-lang/rust#59114
[cargo/6860]: rust-lang/cargo#6860
[cargo/6934]: rust-lang/cargo#6934
[`VecDeque::rotate_left`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.rotate_left
[`VecDeque::rotate_right`]: https://doc.rust-lang.org/std/collections/struct.VecDeque.html#method.rotate_right
[`Iterator::copied`]: https://doc.rust-lang.org/std/iter/trait.Iterator.html#tymethod.copied
[`io::IoSlice`]: https://doc.rust-lang.org/std/io/struct.IoSlice.html
[`io::IoSliceMut`]: https://doc.rust-lang.org/std/io/struct.IoSliceMut.html
[`Read::read_vectored`]: https://doc.rust-lang.org/std/io/trait.Read.html#method.read_vectored
[`Write::write_vectored`]: https://doc.rust-lang.org/std/io/trait.Write.html#method.write_vectored
[`str::as_mut_ptr`]: https://doc.rust-lang.org/std/primitive.str.html#method.as_mut_ptr
[`mem::MaybeUninit`]: https://doc.rust-lang.org/std/mem/union.MaybeUninit.html
[`pointer::align_offset`]: https://doc.rust-lang.org/std/primitive.pointer.html#method.align_offset
[`future::Future`]: https://doc.rust-lang.org/std/future/trait.Future.html
[`task::Context`]: https://doc.rust-lang.org/beta/std/task/struct.Context.html
[`task::RawWaker`]: https://doc.rust-lang.org/beta/std/task/struct.RawWaker.html
[`task::RawWakerVTable`]: https://doc.rust-lang.org/beta/std/task/struct.RawWakerVTable.html
[`task::Waker`]: https://doc.rust-lang.org/beta/std/task/struct.Waker.html
[`task::Poll`]: https://doc.rust-lang.org/beta/std/task/enum.Poll.html
[clippy-1-36-0]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#rust-136
[cargo-1-36-0]: https://github.com/rust-lang/cargo/blob/master/CHANGELOG.md#cargo-136-2019-07-04
[stdsimd/522]: rust-lang/stdarch#522
[stdsimd/559]: rust-lang/stdarch#559

Erk- added a commit to Erk-/lavalink.rs that referenced this pull request Jul 13, 2019

Fix compilation
This change is made because of a breaking change
in rustc: rust-lang/rust#59825

Signed-off-by: Valdemar Erk <v@erk.io>

@Erk- Erk- referenced this pull request Jul 13, 2019

Open

Fix compilation #1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.