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

Rust traits treat (T, &T) and (&T, T) as same type #11384

Closed
uzytkownik opened this issue Jan 7, 2014 · 2 comments · Fixed by #18036
Closed

Rust traits treat (T, &T) and (&T, T) as same type #11384

uzytkownik opened this issue Jan 7, 2014 · 2 comments · Fixed by #18036
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@uzytkownik
Copy link

Rust fails for following code:

trait Common<U> {
    fn common<'r, A>(&'r self, f: |&'r U, &'r U| -> A) -> A;
}

impl<'t, T> Common<T> for (T, &'t T) {
    fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
        f(self.n0_ref(), self.n1_ref().clone())
    }
}

impl<'t, T> Common<T> for (&'t T, T) {
    fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
        f(self.n0_ref().clone(), self.n1_ref())
    }
}

With message:

testtrait.rs:11:1: 15:2 error: conflicting implementations for trait `Common`
testtrait.rs:11 impl<'t, T> Common<T> for (&'t T, T) {
testtrait.rs:12     fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
testtrait.rs:13         f(self.n0_ref().clone(), self.n1_ref())
testtrait.rs:14     }
testtrait.rs:15 }
testtrait.rs:5:1: 9:2 note: note conflicting implementation here
testtrait.rs:5 impl<'t, T> Common<T> for (T, &'t T) {
testtrait.rs:6     fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
testtrait.rs:7         f(self.n0_ref(), self.n1_ref().clone())
testtrait.rs:8     }
testtrait.rs:9 }
testtrait.rs:5:1: 9:2 error: conflicting implementations for trait `Common`
testtrait.rs:5 impl<'t, T> Common<T> for (T, &'t T) {
testtrait.rs:6     fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
testtrait.rs:7         f(self.n0_ref(), self.n1_ref().clone())
testtrait.rs:8     }
testtrait.rs:9 }
testtrait.rs:11:1: 15:2 note: note conflicting implementation here
testtrait.rs:11 impl<'t, T> Common<T> for (&'t T, T) {
testtrait.rs:12     fn common<'r, A>(&'r self, f: |&'r T, &'r T| -> A) -> A {
testtrait.rs:13         f(self.n0_ref().clone(), self.n1_ref())
testtrait.rs:14     }
testtrait.rs:15 }
error: aborting due to 2 previous errors
task 'rustc' failed at 'explicit failure', /var/tmp/portage-ondisk/portage/dev-lang/rust-9999/work/rust-9999/src/libsyntax/diagnostic.rs:74
task '<main>' failed at 'explicit failure', /var/tmp/portage-ondisk/portage/dev-lang/rust-9999/work/rust-9999/src/librustc/lib.rs:440

However the conflict occurs only when there is T and U such that T = &U and U =&T which means that T = &T - i.e. it is a thing borrowed infinitely many times. As such type is not possible the instances are not conflicting and therefore should be allowed.

@japaric
Copy link
Member

japaric commented Oct 14, 2014

I can reproduce the error with this minimal test case:

trait Common {}

impl<'t, T> Common for (T, &'t T) {}

impl<'t, T> Common for (&'t T, T) {}

fn main() {}

on 0.10 and 0.11, but it seems to have been fixed by 0.12, and it also works on:

rustc 0.13.0-dev (7dbd4349c 2014-10-13 10:32:43 +0000)

Should we close this? Maybe add a regression test before closing it?

cc @nikomatsakis Perhaps you know why this wasn't working before?

@sfackler sfackler added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 14, 2014
@nikomatsakis
Copy link
Contributor

I can't say for sure why it was going wrong before... but I'm comfortable closing it if it no longer reproduces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

Successfully merging a pull request may close this issue.

4 participants