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

Type parameters on static methods don't work right #4096

Closed
brson opened this issue Dec 2, 2012 · 2 comments
Closed

Type parameters on static methods don't work right #4096

brson opened this issue Dec 2, 2012 · 2 comments
Labels
A-trait-system Area: Trait system

Comments

@brson
Copy link
Contributor

brson commented Dec 2, 2012

This test specifies the type parameters to from_inty but rustc says it didn't.

pub trait Nummy {
    static pure fn from_inty<T>() -> self;
}

impl float: Nummy {
    static pure fn from_inty<T>() -> float { 0.0 }
}

fn main() {
    let _1:float = Nummy::from_inty::<int>(1i);
}
/home/brian/dev/rust/src/test/run-pass/test.rs:10:19: 10:42 error: not enough type parameters provided for this item
/home/brian/dev/rust/src/test/run-pass/test.rs:10     let _1:float = Nummy::from_inty::<int>(1i);
                                                                     ^~~~~~~~~~~~~~~~~~~~~~~
/home/brian/dev/rust/src/test/run-pass/test.rs:10:19: 10:47 error: this function takes 0 parameters but 1 parameter was supplied
/home/brian/dev/rust/src/test/run-pass/test.rs:10     let _1:float = Nummy::from_inty::<int>(1i);
                                                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors
@msullivan
Copy link
Contributor

Static methods have an implicit type parameter for the self type. Calling it with
Nummy::from_inty::<float, int>().

This is, at least, my intended behavior when I implemented them. It isn't clear to me what else would be sensible. This mostly sounds like a documentation problem?

@catamorphism
Copy link
Contributor

Fixed in #8477 -- close this when it lands.

bors added a commit that referenced this issue Aug 14, 2013
r? @msullivan ...e parameters

In this case, it's likely to be that the user forgot the `self` type, so
say so.

Closes #4096
calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants