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

Super-trait operator doesn't work within trait #18088

Closed
aomader opened this issue Oct 16, 2014 · 3 comments
Closed

Super-trait operator doesn't work within trait #18088

aomader opened this issue Oct 16, 2014 · 3 comments
Labels
A-typesystem Area: The type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@aomader
Copy link

aomader commented Oct 16, 2014

Consider the following simple trait example:

pub trait Indexable<T>: Index<uint, T> {
    fn index2(&self, i: uint) -> &T {
        // Doesn't work:
        // self[i]

        // Does work
        self.index(&i)
    }
}

As you can see by the comments, using the []-operator on self doesn't work directly. Instead, one has to call the index function manually.
It seems like something is broken with operators and super-traits.

$ rustc --version
rustc 0.12.0-nightly (b5ba2f551 2014-10-06 20:27:14 +0000)
@arielb1
Copy link
Contributor

arielb1 commented Oct 16, 2014

Its an autoref problem. The following code:

fn main(){}

pub trait Indexable<T>: Index<uint, T>  {
    fn index2(&self, i: uint) -> &T {
        &(*self)[i]
    }
}

does work.

@steveklabnik steveklabnik added the A-typesystem Area: The type system label Jan 27, 2015
@huonw
Copy link
Member

huonw commented Jan 5, 2016

pub trait Indexable<T>: std::ops::Index<usize, Output = T> {
    fn index2(&self, i: usize) -> &T {
        &self[i]
    }
}
fn main() {}

works fine now, adding needstest.

@huonw huonw added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jan 5, 2016
sophiajt pushed a commit to sophiajt/rust that referenced this issue Sep 28, 2016
testcase about issue-18088

this testcase is associated with issue rust-lang#18088 . you can find that here. rust-lang#18088.
@sanxiyn
Copy link
Member

sanxiyn commented Sep 30, 2016

Fixed by #36783.

@sanxiyn sanxiyn closed this as completed Sep 30, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

5 participants