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

Functions should be able to initialize their arguments #793

Closed
eholk opened this issue Aug 1, 2011 · 4 comments
Closed

Functions should be able to initialize their arguments #793

eholk opened this issue Aug 1, 2011 · 4 comments
Labels
A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@eholk
Copy link
Contributor

eholk commented Aug 1, 2011

This came up in the course of writing comms as a library. I want to be able to write this:

fn recv_into(v : &T) {
    rustrt::port_recv(unsafe::reinterpret_cast(ptr::addr_of(v)),
                      **raw_port);
}

fn recv() -> T {
    let x : T;
    self.recv_into(x);
    ret x;
}

recv_into has the form it does because it calls into the runtime library, which needs a pointer to the place where the data should go. Ideally, we won't always want to initialize this, and in fact in some cases we may not be able to (for example, a tag type is exported from a module, but not its constructor).

What would be nice is some time of typestate annotation that says a parameter may not be initialized (or perhaps even stronger, is not initialized), and then declare as a postcondition that its argument is initialized.

I'm not sure what ramifications this might have as far as safety and typestate analysis, but this pattern is relatively common in a lot of systems code I've seen.

@ghost ghost assigned catamorphism Aug 1, 2011
@graydon
Copy link
Contributor

graydon commented Feb 15, 2012

See also #1487. This will take some work but it seems useful in a few places.

@eholk
Copy link
Contributor Author

eholk commented Jul 17, 2012

Now that typestate is gone, is this issue still relevant?

It seems like it might be related to moving out of closures.

@catamorphism
Copy link
Contributor

It's still relevant -- liveness analysis does the same analysis that typestate did before.

@catamorphism
Copy link
Contributor

No activity for a long time; it seems like people aren't crying out for this feature. Rust has changed enough since this was filed that I suspect there's a way to address it now, though I don't know offhand.

Closing.

pdietl pushed a commit to pdietl/rust that referenced this issue Apr 23, 2020
UB definition: mention size_of_val for determining a reference's span
ZuseZ4 pushed a commit to EnzymeAD/rust that referenced this issue Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants