Skip to content

Have multiple references to a struct by trait #10945

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

Closed
HeroesGrave opened this issue Dec 13, 2013 · 2 comments
Closed

Have multiple references to a struct by trait #10945

HeroesGrave opened this issue Dec 13, 2013 · 2 comments

Comments

@HeroesGrave
Copy link
Contributor

There was one feature of the @-pointer that has not been fixed since it was removed.

If you wanted to pass a struct around by referring to it as a trait, you could do @SomeTrait.

~-ptrs aren't always suitable for this because you may need more than one reference to the struct underneath the trait.

&-ptrs aren't suitable for this... well, because they aren't. :P

Obviously Rc, which is supposed to be the replacement for '@' doesn't work because you'd need another pointer inside it anyway.

Is there some way that this functionality can be restored?

@huonw
Copy link
Member

huonw commented Dec 13, 2013

Obviously Rc, which is supposed to be the replacement for '@' doesn't work because you'd need another pointer inside it anyway.

Rc<~Trait> is a substitute that should work for many instances of shared ownership trait-objects. (Except for the extra indirection, and some size_of details, this will behave almost exactly like Rc<Trait>.)

In any case, this is something that will hopefully come out of the "dynamically sized types" proposals (or similar; #6308) and/or the smart pointer work (probably both).

(Also, if you really need it, @ and @Trait objects still exist, you can add #[feature(managed_boxes)]; at the top of your crate file (NB. the semicolon is required)... If anyone asks, I didn't tell you this. ;) )

@HeroesGrave
Copy link
Contributor Author

Wait, so Rc<~Trait> lets you have multiple references to an owned pointer?

Thanks for the help.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
[`no_effect`]: Suggest adding `return` if applicable

Closes rust-lang#10941

Unfortunately doesn't catch anything complex as `no_effect` already wouldn't, but I'm fine with that (it catches `ControlFlow` at least :D)

changelog: [`no_effect`]: Suggest adding `return` if statement has same type as function's return type and is the last statement in a block
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

No branches or pull requests

2 participants