Skip to content

self types unsound with boxed ifaces #1994

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

Closed
nikomatsakis opened this issue Mar 15, 2012 · 1 comment
Closed

self types unsound with boxed ifaces #1994

nikomatsakis opened this issue Mar 15, 2012 · 1 comment

Comments

@nikomatsakis
Copy link
Contributor

Currently, if a method on an iface mentions the type self, we forbid that method from being called via a boxed iface. But this restriction can be worked around by using generic types:

    iface i { fn foo() -> self<>; }
    fn foo<T:i>(v: T) -> T {
        ret v.foo();
    }
    impl of i for uint {
        fn foo() -> uint { ret self; }
    }
    fn main() {
        let x: i = 3u as i;
        let y = foo(x); // y has type i, but is in fact a uint
    }

A couple of solutions spring to mind, but on IRC we discussed saying that if an iface i includes a self type, then instances of i do not implement i.

@nikomatsakis
Copy link
Contributor Author

A similar problem likely exists with monomorphization and calls to methods with type parameters. The same solution ought to prevent that bug as well.

celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Kobzol pushed a commit to Kobzol/rust that referenced this issue Dec 30, 2024
* Docs for `needs-forced-clang-based-tests` (was `needs-matching-clang`)

* Docs for `aux-codegen-backend`

* Docs for `{{sysroot-base}}` and `{{target-linker}}`
bors pushed a commit to rust-lang-ci/rust that referenced this issue Jan 2, 2025
* Docs for `needs-forced-clang-based-tests` (was `needs-matching-clang`)

* Docs for `aux-codegen-backend`

* Docs for `{{sysroot-base}}` and `{{target-linker}}`
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

No branches or pull requests

2 participants