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

The Place trait should be unsafe. #1391

Closed
Stebalien opened this issue Dec 3, 2015 · 4 comments
Closed

The Place trait should be unsafe. #1391

Stebalien opened this issue Dec 3, 2015 · 4 comments
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.

Comments

@Stebalien
Copy link
Contributor

Rust will blindly write into whatever pointer is returned by Place::pointer() so the trait itself should be unsafe to implement.

pub unsafe trait Place<Data> where Data: ?Sized {
    fn pointer(&mut self) -> *mut Data;
}
@nagisa
Copy link
Member

nagisa commented Dec 3, 2015

Alternatively it could return a mutable reference. Any reason it doesn’t, @pnkfelix?

@Stebalien
Copy link
Contributor Author

Because the returned pointer won't have been initialized (and references should always point to initialized data). We'd need &uninit.

@oli-obk
Copy link
Contributor

oli-obk commented Dec 4, 2015

another alternative is to return a wrapper type with a lifetime parameter that only has an unsafe constructor (and internally contains the pointer). This type could then offer a safe interface to write into.

@Stebalien
Copy link
Contributor Author

Closed in favor of an amendment: #1401

@Centril Centril added the T-libs-api Relevant to the library API team, which will review and decide on the RFC. label Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-libs-api Relevant to the library API team, which will review and decide on the RFC.
Projects
None yet
Development

No branches or pull requests

4 participants