Skip to content

Implement Rc/Arc conversions for string-like types - #45990

Merged
bors merged 1 commit into
rust-lang:masterfrom
murarth:rc-from-strs
Nov 26, 2017
Merged

Implement Rc/Arc conversions for string-like types#45990
bors merged 1 commit into
rust-lang:masterfrom
murarth:rc-from-strs

Conversation

@murarth

Copy link
Copy Markdown
Contributor

Provides the following conversion implementations:

  • From<{CString,&CStr}> for {Arc,Rc}<CStr>
  • From<{OsString,&OsStr}> for {Arc,Rc}<OsStr>
  • From<{PathBuf,&Path}> for {Arc,Rc}<Path>

Closes#45008

@kennytmkennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs-api [DEPRECATED; DO NOT USE] relnotes Marks issues that should be documented in the release notes of the next release. labels Nov 14, 2017
Comment threadsrc/libstd/ffi/c_str.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we do this via Arc::into_raw + x as *const CStr + Arc::from_raw instead of transmute?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I've now replaced each instance of transmute.

@murarth

Copy link
Copy Markdown
ContributorAuthor

Tests passed. r? @kennytm

@kennytm

Copy link
Copy Markdown
Member

r? @BurntSushi

Comment threadsrc/libstd/ffi/c_str.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this safe? What guarantees that &'a CStr outlives the resulting Arc<CStr>?

@CentrilCentrilNov 15, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would &'a CStr need to outlive Arc<CStr>? Arc::from does a new heap allocation and copies over all the contents of s.
The unsafe block just does Arc<[u8]> -> Arc<CStr>. This is safe since the invariants of CStr are maintained.

@BurntSushiBurntSushiNov 15, 2017

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see. I didn't realize there was a copy here. In hindsight, the Arc<[u8]> type should have told me that. And of course this impl: https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-From<&'a [T]>

@BurntSushiBurntSushi added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 15, 2017
@Centril

Copy link
Copy Markdown
Contributor

This is continuation of RFC 1845, shared_from_slice, which motivates this PR =)

@BurntSushi

Copy link
Copy Markdown
Member

This seems reasonable to me!

@rfcbot merge

@kennytmkennytm added S-waiting-on-team and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 15, 2017
@kennytm

Copy link
Copy Markdown
Member

@BurntSushi The correct command is @rfcbot fcp merge...

@BurntSushi

Copy link
Copy Markdown
Member

Let's try it again...

@rfcbot fcp merge

@rfcbot

rfcbot commented Nov 15, 2017

Copy link
Copy Markdown

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

No concerns currently listed.

Once these reviewers reach consensus, 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.

@rfcbotrfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 15, 2017
@kennytm

Copy link
Copy Markdown
Member

Ping @Kimundi, ticky boxes for you!

@rfcbotrfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Nov 22, 2017
@rfcbot

Copy link
Copy Markdown

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

@rfcbotrfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Nov 22, 2017
@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+

@bors

bors commented Nov 25, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 3c1d59f has been approved by alexcrichton

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-team labels Nov 25, 2017
@bors

bors commented Nov 25, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 3c1d59f61817c4470ebbaa17c925633c71cb1fd3 with merge b199f97bdde51ed7ad4c16799c3ef05a354428e1...

@bors

bors commented Nov 25, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-appveyor

@kennytm

Copy link
Copy Markdown
Member
Could not compile stage0-libstd on all Windows, missing imports.
error[E0433]: failed to resolve. Use of undeclared type or module `Arc`
--> src\libstd\sys\windows\os_str.rs:162:18
|
162 | unsafe { Arc::from_raw(Arc::into_raw(arc) as *const Slice) }
| ^^^ Use of undeclared type or module `Arc`
error[E0433]: failed to resolve. Use of undeclared type or module `Arc`
--> src\libstd\sys\windows\os_str.rs:162:32
|
162 | unsafe { Arc::from_raw(Arc::into_raw(arc) as *const Slice) }
| ^^^ Use of undeclared type or module `Arc`
error[E0412]: cannot find type `Arc` in this scope
--> src\libstd\sys\windows\os_str.rs:121:31
|
121 | pub fn into_arc(&self) -> Arc<Slice> {
| ^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
14 | use alloc::arc::Arc;
|
error[E0412]: cannot find type `Arc` in this scope
--> src\libstd\sys\windows\os_str.rs:160:31
|
160 | pub fn into_arc(&self) -> Arc<Slice> {
| ^^^ not found in this scope
|
help: possible candidate is found in another module, you can import it into scope
|
14 | use alloc::arc::Arc;
|
error: aborting due to 4 previous errors
error: Could not compile `std`.

@kennytmkennytm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 25, 2017
@murarth

Copy link
Copy Markdown
ContributorAuthor

@kennytm: Fixed. re-r+?

@kennytm

Copy link
Copy Markdown
Member

@bors r=alexcrichton

@bors

bors commented Nov 25, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 85e6421 has been approved by alexcrichton

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 25, 2017
kennytm added a commit to kennytm/rust that referenced this pull request Nov 25, 2017
Implement `Rc`/`Arc` conversions for string-like types
Provides the following conversion implementations:
* `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>`
* `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>`
* `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
Closesrust-lang#45008
@kennytmkennytm mentioned this pull request Nov 25, 2017
@bors

bors commented Nov 26, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 85e6421 with merge 5600b272ddaffa84cdbbdf4872a89a2680d72ccf...

@bors

bors commented Nov 26, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-travis

Provides the following conversion implementations:
* `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>`
* `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>`
* `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
@murarth

Copy link
Copy Markdown
ContributorAuthor

Psh. The wasm stuff merged and added a new OsString implementation. It's a straight copy of the Unix implementation, so I copied over the changes.

@kennytm

Copy link
Copy Markdown
Member

@bors r=alexcrichton

@bors

bors commented Nov 26, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 1bbc776 has been approved by alexcrichton

@bors

bors commented Nov 26, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 1bbc776 with merge d4dc289...

bors added a commit that referenced this pull request Nov 26, 2017
Implement `Rc`/`Arc` conversions for string-like types
Provides the following conversion implementations:
* `From<`{`CString`,`&CStr`}`>` for {`Arc`,`Rc`}`<CStr>`
* `From<`{`OsString`,`&OsStr`}`>` for {`Arc`,`Rc`}`<OsStr>`
* `From<`{`PathBuf`,`&Path`}`>` for {`Arc`,`Rc`}`<Path>`
Closes#45008
@bors

bors commented Nov 26, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing d4dc289 to master...

@bors
bors merged commit 1bbc776 into rust-lang:masterNov 26, 2017
@murarth
murarth deleted the rc-from-strs branch November 26, 2017 17:13
lo48576 pushed a commit to lo48576/opaque_typedef that referenced this pull request Dec 2, 2017
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Jan 4, 2018
Correct a few stability attributes
* The extra impls for `ManuallyDrop` were added in rust-lang#44310 which was only stabilised in 1.22.0.
* The impls for `SliceIndex` were stabilised in rust-lang#43373 but as `RangeInclusive` and `RangeToInclusive` are still unstable the impls should remain unstable.
* The `From` impls for atomic integers were added in rust-lang#45610 but most atomic integers are still unstable.
* The `shared_from_slice2` impls were added in rust-lang#45990 but they won't be stable until 1.24.0.
* The `Mutex` and `RwLock` impls were added in rust-lang#46082 but won't be stable until 1.24.0.
kennytm added a commit to kennytm/rust that referenced this pull request Jan 4, 2018
Correct a few stability attributes
* The extra impls for `ManuallyDrop` were added in rust-lang#44310 which was only stabilised in 1.22.0.
* The impls for `SliceIndex` were stabilised in rust-lang#43373 but as `RangeInclusive` and `RangeToInclusive` are still unstable the impls should remain unstable.
* The `From` impls for atomic integers were added in rust-lang#45610 but most atomic integers are still unstable.
* The `shared_from_slice2` impls were added in rust-lang#45990 but they won't be stable until 1.24.0.
* The `Mutex` and `RwLock` impls were added in rust-lang#46082 but won't be stable until 1.24.0.
kennytm added a commit to kennytm/rust that referenced this pull request Jan 5, 2018
Correct a few stability attributes
* The extra impls for `ManuallyDrop` were added in rust-lang#44310 which was only stabilised in 1.22.0.
* The impls for `SliceIndex` were stabilised in rust-lang#43373 but as `RangeInclusive` and `RangeToInclusive` are still unstable the impls should remain unstable.
* The `From` impls for atomic integers were added in rust-lang#45610 but most atomic integers are still unstable.
* The `shared_from_slice2` impls were added in rust-lang#45990 but they won't be stable until 1.24.0.
* The `Mutex` and `RwLock` impls were added in rust-lang#46082 but won't be stable until 1.24.0.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-libs-api[DEPRECATED; DO NOT USE]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@murarth@kennytm@Centril@BurntSushi@rfcbot@alexcrichton@bors