Skip to content

bare impls on same-crate different-mod imported types were useful and there is no alternative #749

Closed
@steveklabnik

Description

@steveklabnik

Issue by o11c
Monday Oct 13, 2014 at 22:09 GMT

For earlier discussion, see rust-lang/rust#18016

This issue was labelled with: A-typesystem in the Rust repository


The following code used to work, but there is no longer any way to do this sort of thing.

Moving the impl into the mod can't be done because low-level modules need to remain similar to the C API they are wrapping, for example if they are generated; and unlike C it is not possible to reopen a module after it is closed.

Adding a meaningless trait does not work because trait methods cannot be called unless you import the trait.

Please bring back some way to do this (whispers of every crate being able to silently inject a prelude does not sound like a good idea at all).

pub mod really_a_crate
{
    pub use self::c::Foo;

    pub mod c
    {
        #[allow(non_camel_case_types)]
        #[repr(C)]
        pub enum Foo
        {
            FOO_A,
            FOO_B,
            FOO_C,
        }
    }

    impl c::Foo
    {
        pub fn frob(self)
        {
            println!("Hello, World!");
        }
    }
}

fn main()
{
    let foo: really_a_crate::Foo = really_a_crate::c::FOO_A;
    foo.frob();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions