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

Fully seal ToSocketAddrs #2891

Closed
seanmonstar opened this issue Sep 28, 2020 · 1 comment · Fixed by #2892
Closed

Fully seal ToSocketAddrs #2891

seanmonstar opened this issue Sep 28, 2020 · 1 comment · Fixed by #2892
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net
Milestone

Comments

@seanmonstar
Copy link
Member

Currently the ToSocketAddrs trait is meant only for bounds, and all methods are supposed to be implementation details. This is done by putting them methods on "private" super trait. However, due to the way bounds on generics works, these methods are accidentally available to users.

fn bound<T: ToSocketAddrs>(t: T) {
    // But legal here, since T: ToSocketAddrs leaks the super trait methods
    t.to_socket_addrs();
}

fn main() {
    // Uncomment to see error
    //"127.0.0.1:0".to_socket_addrs();
    bound("127.0.0.1:0");
}

The solution is to define a private Internal argument type that must also be passed, so a user will see a compilation error when trying to call t.to_socket_addrs(), since they didn't call t.to_socket_addrs(Internal), and can't!

@seanmonstar seanmonstar added A-tokio Area: The main tokio crate M-net Module: tokio/net P-high labels Sep 28, 2020
@seanmonstar seanmonstar added this to the v0.3 milestone Sep 28, 2020
@taiki-e
Copy link
Member

taiki-e commented Sep 28, 2020

Probably FromStream has the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-bug Category: This is a bug. M-net Module: tokio/net
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants