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

Allow method overloading on bound generic types #3622

Closed
erickt opened this issue Sep 28, 2012 · 4 comments
Closed

Allow method overloading on bound generic types #3622

erickt opened this issue Sep 28, 2012 · 4 comments

Comments

@erickt
Copy link
Contributor

erickt commented Sep 28, 2012

It'd be nice if we could support method overloading on generic types, but overloading only works on concrete types. I ran into this when I was implementing the new serialization library. Here's a reduced example: https://gist.github.com/3801125. Without generic method overloading, I cannot generically use two different serializers in the same function.

@eholk
Copy link
Contributor

eholk commented Oct 4, 2012

I think this is by design, since it sounds like allowing this would sacrifice coherence.

http://pcwalton.github.com/blog/2012/05/28/coherence/

@nikomatsakis
Copy link
Contributor

I don't think it necessarily violates coherence, but it would violate "no overloading" rules I proposed here:

http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/

I also describe a workaround.

@nikomatsakis
Copy link
Contributor

Admittedly, a very painful one.

@nikomatsakis
Copy link
Contributor

The thing is that what @erickt is really asking for here is not exactly overloading. Instead, the use of overloaded bounds was kind of a workaround for the inability to say something like "a type T that is serializable by any serializer".

Actually, the best answer (at least at the moment) for this specific scenario is to use a trait type. I don't believe the Serializable interface refers to the self type, therefore one could write:

fn print2<
    S1: Serializer,
    S2: Serializer,
    T: Serializable<@Serializer>
>(t: T, s1: @S1, s2: @S2) {
    t.serialize(s1 as @Serializer);
    io::println("");

    t.serialize(s2 as @Serializer);
    io::println("");
}

Here I've rephrased the example in terms of @ rather than & merely because this is closer to being implemented today. You can could do the same thing with &S1, &S2, and &Serializer once we implement that properly.

In any case, I'm going to close, because I don't expect we'll fix this case.

RalfJung pushed a commit to RalfJung/rust that referenced this issue Jun 15, 2024
Implement LLVM x86 SSE4.2 intrinsics

SSE4.2 is arguably the least important SIMD extension for the x86 ISA, but it should still be supported for the sake of completeness.
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

3 participants