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

librustc: Give trait methods accessible via fewer autoderefs priority #17464

Merged
merged 1 commit into from
Sep 27, 2014

Conversation

pcwalton
Copy link
Contributor

over inherent methods accessible via more autoderefs.

This simplifies the trait matching algorithm. It breaks code like:

impl Foo {
    fn foo(self) {
        // before this change, this will be called
    }
}

impl<'a,'b,'c> Trait for &'a &'b &'c Foo {
    fn foo(self) {
        // after this change, this will be called
    }
}

fn main() {
    let x = &(&(&Foo));
    x.foo();
}

To explicitly indicate that you wish to call the inherent method, perform
explicit dereferences. For example:

fn main() {
    let x = &(&(&Foo));
    (***x).foo();
}

Part of #17282.

[breaking-change]

r? @nikomatsakis

@pcwalton
Copy link
Contributor Author

@nikomatsakis No, that's not an error. Inherent methods win at each level of autoderef. See the logic in search_for_method.

@pcwalton
Copy link
Contributor Author

@bors: retry

over inherent methods accessible via more autoderefs.

This simplifies the trait matching algorithm. It breaks code like:

    impl Foo {
        fn foo(self) {
            // before this change, this will be called
        }
    }

    impl<'a,'b,'c> Trait for &'a &'b &'c Foo {
        fn foo(self) {
            // after this change, this will be called
        }
    }

    fn main() {
        let x = &(&(&Foo));
        x.foo();
    }

To explicitly indicate that you wish to call the inherent method, perform
explicit dereferences. For example:

    fn main() {
        let x = &(&(&Foo));
        (***x).foo();
    }

Part of rust-lang#17282.

[breaking-change]
@pcwalton pcwalton force-pushed the inherent-methods-on-equal-footing branch from e0640b0 to 21df9c8 Compare September 26, 2014 20:03
bors added a commit that referenced this pull request Sep 26, 2014
…g, r=nikomatsakis

over inherent methods accessible via more autoderefs.

This simplifies the trait matching algorithm. It breaks code like:

    impl Foo {
        fn foo(self) {
            // before this change, this will be called
        }
    }

    impl<'a,'b,'c> Trait for &'a &'b &'c Foo {
        fn foo(self) {
            // after this change, this will be called
        }
    }

    fn main() {
        let x = &(&(&Foo));
        x.foo();
    }

To explicitly indicate that you wish to call the inherent method, perform
explicit dereferences. For example:

    fn main() {
        let x = &(&(&Foo));
        (***x).foo();
    }

Part of #17282.

[breaking-change]

r? @nikomatsakis
@bors bors closed this Sep 27, 2014
@bors bors merged commit 21df9c8 into rust-lang:master Sep 27, 2014
lnicola pushed a commit to lnicola/rust that referenced this pull request Jun 23, 2024
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

Successfully merging this pull request may close these issues.

2 participants