Skip to content

In-scope traits are leaking beyond imports #10465

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
alexcrichton opened this issue Nov 13, 2013 · 3 comments
Closed

In-scope traits are leaking beyond imports #10465

alexcrichton opened this issue Nov 13, 2013 · 3 comments
Milestone

Comments

@alexcrichton
Copy link
Member

pub mod a {
    pub trait A {
        fn foo(&self);
    }

}
pub mod b {
    use a::A;

    pub struct B;
    impl A for B { fn foo(&self) {} }

    pub mod c {
        use b::B;

        fn foo(b: &B) {
            b.foo(); // trait A is not in scope at this location
        }
    }

}

fn main() {}

That code compiles successfully, but I don't believe that it should. A the commented line, the trait A is not in scope for the module c, so I should get an error that b doesn't have any method named foo in scope.

Nominating, this is a backwards-compatibility issue.

@alexcrichton
Copy link
Member Author

From what I could tell, it appeared that if any of your ancestors imported a trait, then it was automatically in-scope for any descendant. This seems like abstraction leakage which should be plugged.

@nikomatsakis
Copy link
Contributor

Agreed, bogus.

@pnkfelix
Copy link
Member

accepted for P-backcompat-lang.

alexcrichton added a commit that referenced this issue Jan 7, 2014
Turns out the pass in resolve was a little too eager to travel back up the
hierarchy chain when looking for trait candidates.

Closes #10465
alexcrichton added a commit to alexcrichton/rust that referenced this issue Jan 7, 2014
Turns out the pass in resolve was a little too eager to travel back up the
hierarchy chain when looking for trait candidates.

Closes rust-lang#10465
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants