Skip to content

Can't implement methods for an imported struct type without using global path #11798

Closed
@nham

Description

@nham

This does not work:

use foo::Bar;

fn main() {
    impl Bar {
        fn boop(&self) -> bool {
            true
        }
    }

    let y = Bar {y: 8};
    println!("{}", y.boop());
}

mod foo {
    pub struct Bar {
        y: int,
    }
}

It results in:

module_name_used_type.rs:10:13: 10:16 error: `Bar` does not name a structure
module_name_used_type.rs:10     let y = Bar {y: 8};
                                        ^~~

Changing "impl Bar" to "impl ::foo::Bar" on line 3 does work, however. Is this the intended behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions