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

Add unchecked downcast methods #90851

Merged
merged 4 commits into from
Dec 4, 2021
Merged

Conversation

ibraheemdev
Copy link
Member

impl dyn Any (+ Send + Sync) {
    pub unsafe fn downcast_ref_unchecked<T: Any>(&self) -> &T;
    pub unsafe fn downcast_mut_unchecked<T: Any>(&mut self) -> &mut T;
}

impl<A: Allocator> Box<dyn Any (+ Send + Sync), A> {
    pub unsafe fn downcast_unchecked<T: Any>(&self) -> Box<T, A>;
}

@rust-highfive
Copy link
Collaborator

r? @scottmcm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 13, 2021
@rust-log-analyzer

This comment has been minimized.

@apiraino apiraino added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Nov 18, 2021
@scottmcm
Copy link
Member

This seems plausible, but it looks like there are some failures in the PR build.

@scottmcm scottmcm 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 20, 2021
@ibraheemdev
Copy link
Member Author

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 29, 2021
Copy link
Member

@scottmcm scottmcm left a comment

Choose a reason for hiding this comment

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

Two tiny things to fix (sorry, should have caught them the first time), then r=me.

@@ -1501,21 +1499,48 @@ impl<A: Allocator> Box<dyn Any, A> {
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// ```
#[inline]
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this one was an over-aggressive copy-paste.

Suggested change
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
#[stable(feature = "rust1", since = "1.0.0")]

https://doc.rust-lang.org/1.0.0/std/boxed/struct.Box.html#method.downcast)

@@ -1533,21 +1558,48 @@ impl<A: Allocator> Box<dyn Any + Send, A> {
/// print_if_string(Box::new(my_string));
/// print_if_string(Box::new(0i8));
/// ```
#[inline]
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
Copy link
Member

Choose a reason for hiding this comment

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

Here too

Suggested change
#[stable(feature = "box_send_sync_any_downcast", since = "1.51.0")]
#[stable(feature = "rust1", since = "1.0.0")]

@scottmcm
Copy link
Member

scottmcm commented Dec 3, 2021

Thanks for making the PR!

@bors r+

@bors
Copy link
Contributor

bors commented Dec 3, 2021

📌 Commit 4ec5cdc has been approved by scottmcm

@bors bors 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-review Status: Awaiting review from the assignee but also interested parties. labels Dec 3, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 4, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#90538 (Document how recursion is handled for `ty::Ty`)
 - rust-lang#90851 (Add unchecked downcast methods)
 - rust-lang#91209 (Implement ``@snapshot`` check for htmldocck)
 - rust-lang#91385 (Suggest the `pat_param` specifier before `|` on 2021 edition )
 - rust-lang#91478 (Remove incorrect newline from float cast suggestion)
 - rust-lang#91481 (Use let_else in some more places in rustc_lint)
 - rust-lang#91488 (Fix ICE when `yield`ing in function returning `impl Trait`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0bd4ee7 into rust-lang:master Dec 4, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants