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

Implement <Rc<Any>>::downcast #44273

Merged
merged 2 commits into from
Sep 17, 2017
Merged

Implement <Rc<Any>>::downcast #44273

merged 2 commits into from
Sep 17, 2017

Conversation

bluss
Copy link
Member

@bluss bluss commented Sep 2, 2017

  • Implement <Rc<Any>>::downcast::<T>
    • New unstable method. Works just like Box<Any>, but for Rc.
    • Any has two cases for its methods: Any and Any + Send; Rc is never Send, so that case is skipped for Rc.
    • Motivation for being a method with self is to match Box and there is no user-supplied type; the inner type is Any and downcast does not conflict with any method of Any.
  • Arc was skipped because Any itself has no downcast for the case that makes most sense: Any + Send + Sync

@rust-highfive
Copy link
Collaborator

r? @sfackler

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

@bluss
Copy link
Member Author

bluss commented Sep 2, 2017

I'll probably revise this -- the pointer math in from_raw does not optimize out as it should

@kennytm
Copy link
Member

kennytm commented Sep 2, 2017

Arc is skipped because Any itself has no downcast for the case that makes most sense: Any + Send + Sync

Why we don't implement downcast for Any + Send + Sync? Other than it isn't terribly necessary.

Implement downcast the like it exists for Box.

The implementation avoids using into_raw/from_raw, because the pointer
arithmetic which should cancel does not seem to optimize out at the
moment.

Since Rc<T> is never Send, only Rc<Any> and not Rc<Any + Send>
implements downcast.
@bluss bluss changed the title Implement <Rc<Any>>::downcast and generalize Rc::into_raw Implement <Rc<Any>>::downcast Sep 3, 2017
@bluss
Copy link
Member Author

bluss commented Sep 3, 2017

I pushed a new version with a more direct implementation, because the pointer arithmetic of using into_raw/from_raw did not optimize out. (playground demo for that)

@bluss
Copy link
Member Author

bluss commented Sep 3, 2017

@kennytm I'm not sure, there are only four combinations of Any and Send, Sync, so it's simple to cover them all, but a bit confusing in the API doc.

@sfackler sfackler added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Sep 3, 2017
@sfackler
Copy link
Member

sfackler commented Sep 3, 2017

This seems reasonable to me.

@rfcbot fcp merge

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Sep 4, 2017
@rfcbot
Copy link

rfcbot commented Sep 4, 2017

Team member @sfackler 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.

@arielb1 arielb1 added the S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). label Sep 5, 2017
@rfcbot
Copy link

rfcbot commented Sep 13, 2017

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

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Sep 13, 2017
@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 14, 2017

📌 Commit 758a0ce has been approved by alexcrichton

@alexcrichton alexcrichton 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 Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Sep 14, 2017
@alexcrichton
Copy link
Member

@bors: rollup

@alexcrichton
Copy link
Member

@bors: r-

oh actually, @bluss mind filing a tracking issue for this and updating the PR with that number?

@bluss
Copy link
Member Author

bluss commented Sep 15, 2017

Sure, updated with tracking issue #44608

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Sep 15, 2017

📌 Commit 3a39d95 has been approved by alexcrichton

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 16, 2017
Implement <Rc<Any>>::downcast

* Implement `<Rc<Any>>::downcast::<T>`
  * New unstable method. Works just like Box\<Any\>, but for Rc.
  * Any has two cases for its methods: Any and Any + Send; Rc is never Send, so that case is skipped for Rc.
  * Motivation for being a method with self is to match Box and there is no user-supplied type; the inner type is Any and downcast does not conflict with any method of Any.
* Arc was skipped because Any itself has no downcast for the case that makes most sense: Any + Send + Sync
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Sep 16, 2017
Implement <Rc<Any>>::downcast

* Implement `<Rc<Any>>::downcast::<T>`
  * New unstable method. Works just like Box\<Any\>, but for Rc.
  * Any has two cases for its methods: Any and Any + Send; Rc is never Send, so that case is skipped for Rc.
  * Motivation for being a method with self is to match Box and there is no user-supplied type; the inner type is Any and downcast does not conflict with any method of Any.
* Arc was skipped because Any itself has no downcast for the case that makes most sense: Any + Send + Sync
alexcrichton added a commit to alexcrichton/rust that referenced this pull request Sep 17, 2017
Implement <Rc<Any>>::downcast

* Implement `<Rc<Any>>::downcast::<T>`
  * New unstable method. Works just like Box\<Any\>, but for Rc.
  * Any has two cases for its methods: Any and Any + Send; Rc is never Send, so that case is skipped for Rc.
  * Motivation for being a method with self is to match Box and there is no user-supplied type; the inner type is Any and downcast does not conflict with any method of Any.
* Arc was skipped because Any itself has no downcast for the case that makes most sense: Any + Send + Sync
bors added a commit that referenced this pull request Sep 17, 2017
@bors bors merged commit 3a39d95 into rust-lang:master Sep 17, 2017
@bluss bluss deleted the rc-downcast branch March 17, 2018 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants