Skip to content

Calling default methods on type parameters that are type parameterized traits does not work #4102

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Comments

@brson
Copy link
Contributor

brson commented Dec 3, 2012

Up-to-date (forward-ported) test case

trait A<T> {
    fn g(x: T) -> T { x }
}

impl A<int> for int { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(j)
}

fn main () {
    fail_unless!(f(0, 2) == 2);
}

Original Report

This assumes #4101 is merged. Fails in trans because substs for the parameterized trait A are not handled correctly.

trait A<T> {
    fn g(x: T) -> T { move x }
}

impl int: A<int> { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(move j)
}

fn main () {
    assert f(0, 2) == 2;
}
@catamorphism
Copy link
Contributor

Reproduced as of eed2ca6

@pnkfelix
Copy link
Member

Reproduced as of c202430

@pnkfelix
Copy link
Member

Not critical for 0.6; de-milestoning

@catamorphism
Copy link
Contributor

Nominating for milestone 5, production-ready

@msullivan
Copy link
Contributor

Fails in typecheck now...

@msullivan
Copy link
Contributor

Oh, wait, that is because implicit self is gone. It still fails in trans.

#[allow(default_methods)];

trait A<T> {
    fn g(&self, x: T) -> T { x }
}

impl A<int> for int { }

fn f<T, V: A<T>>(i: V, j: T) -> T {
    i.g(j)
}

fn main () {
    assert!(f(0, 2) == 2);
}

is an updated version

@msullivan
Copy link
Contributor

Marking that this is part of #2794 for tracking purposes.

@msullivan
Copy link
Contributor

I claimed that I fixed this in an earlier commit, but I found another case that could cause a similar failure. Will be pushing a fix soon.

bors added a commit that referenced this issue Jun 21, 2013
This fixes the large number of problems that prevented cross crate
methods from ever working. It also fixes a couple lingering bugs with
polymorphic default methods and cleans up some of the code paths.

Closes #4102. Closes #4103.

r? nikomatsakis
RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants