Skip to content

🎨 zb: Remove unsafe type casting code#1439

Open
sander-machado wants to merge 2 commits into
z-galaxy:mainfrom
barcoopensource:remove-unsafe-upcasting-code
Open

🎨 zb: Remove unsafe type casting code#1439
sander-machado wants to merge 2 commits into
z-galaxy:mainfrom
barcoopensource:remove-unsafe-upcasting-code

Conversation

@sander-machado

Copy link
Copy Markdown

Rustc 1.86 stabilizes a new features called trait_upcasting. As quoted from the rust docs "Enable upcasts from dyn Trait1 to dyn Trait2 if Trait1 is a subtrait of Trait2". Which is exactly what this unsafe code was doing. I added the new syntax and increased the compiler version to 1.86 to enable this feature and remove these unsafe blocks. There were also multiple places where this check was called without any reason as it's checked at construction (and would just panic either way).

Related to: rust-lang/rust#65991

@sander-machado sander-machado marked this pull request as ready for review July 20, 2025 23:05
@zeenix

zeenix commented Jul 20, 2025

Copy link
Copy Markdown
Contributor

Cool. I'll look at it in more detail later but in the meantime, please split the commit to keep commits atomic. Here, I see at least 3 logical changes: removal of unneeded checks (which I'm not too sure about), bumping of MSRV and removal of unsafe code.

@zeenix

zeenix commented Aug 14, 2025

Copy link
Copy Markdown
Contributor

@sander-machado ping?

@zeenix

zeenix commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

@sander-machado I think Rust 1.86 is not too new anymore. Let's bump the MSRV as part of this PR? You'll want to rebase though.

@sander-machado

Copy link
Copy Markdown
Author

@sander-machado I think Rust 1.86 is not too new anymore. Let's bump the MSRV as part of this PR? You'll want to rebase though.

Great I'll update my PR once that is done!

@zeenix

zeenix commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

@sander-machado I think Rust 1.86 is not too new anymore. Let's bump the MSRV as part of this PR? You'll want to rebase though.

Great I'll update my PR once that is done!

I meant, you bump the MSRV as part of this PR but it's about to happen with another PR that's about to be merged: #1620. Please rebase on that.

@sander-machado sander-machado force-pushed the remove-unsafe-upcasting-code branch 2 times, most recently from d643b8f to 638e74f Compare December 19, 2025 18:14
@sander-machado

Copy link
Copy Markdown
Author

@sander-machado I think Rust 1.86 is not too new anymore. Let's bump the MSRV as part of this PR? You'll want to rebase though.

Great I'll update my PR once that is done!

I meant, you bump the MSRV as part of this PR but it's about to happen with another PR that's about to be merged: #1620. Please rebase on that.

Yeah I was referring to that one (had to bump it 1 more anyway), as that's a coworker who made it. But yeah that's not obvious for you ofcourse haha. I have updated my commits to hopefully be atomic and tried to use to correct emojis. Btw I noticed that if you click the name of the emoji you copy the emoji string which almost made me use that instead before I noticed maybe that's why you keep getting people use the string?

@codspeed-hq

codspeed-hq Bot commented Dec 20, 2025

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 22 untouched benchmarks


Comparing barcoopensource:remove-unsafe-upcasting-code (dc5194c) with main (1a36b7c)

Open in CodSpeed

@zeenix zeenix left a comment

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.

LGTM apart from one thing and the usual nitpicks on commit messages: 😄

  • They're missing the zb: prefix.
  • second one could be shorter to be close to the guideline, something likeReplace unsafe downcast API w/ std's.
  • A description would be nice, even if a short one. For the second commit, you could use the same description as the PR's since this is the main commit.
  • typo: build ins -> built-ins. However this becomes irrelevant if you change the title.

Comment thread zbus/src/object_server/mod.rs Outdated
Rustc 1.86 stabilizes a new feature called trait_upcasting. As quoted from the rust docs "Enable upcasts from dyn Trait1 to dyn Trait2 if Trait1 is a subtrait of Trait2". Which is exactly what this unsafe code was doing. Added the new syntax to enable this feature and remove these unsafe blocks. There were also multiple places where this check was called without any reason as it's checked at construction (and would just panic either way).

Related to: rust-lang/rust#65991
These downcasts are already validated at construction time and would just panic either way, so they serve no purpose.
@sander-machado sander-machado force-pushed the remove-unsafe-upcasting-code branch from 6f2e8f4 to dc5194c Compare May 29, 2026 16:00

@zeenix zeenix left a comment

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.

The changes look good to me, but please use 🦺 as the emoji prefix and ensure that lines in description of git commit message < 75 chars (as per our and git conventions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants