Skip to content

use statement fails silently if it would shadow an existing name #10884

Closed
@HildarTheDorf

Description

@HildarTheDorf

If a use statement would shadow an existing name, it does nothing, not even emit a warning. While the rule on not importing if it would shadow seems to be "working as intended", it might be helpful to issue a warning (or error).

use module::module;
use mod1::mod2;
use light::ShadowMe;

// Test for shadowing it's own module name.
mod module {
    struct module;

    impl module {
        pub fn new() -> module {
            module
        }
    }
}

// Test for shadowing another module
mod mod1 {
    struct mod2;

    impl mod2 {
        pub fn new() -> mod2 {
            mod2
        }
    }
}

mod mod2 {
    struct somethingtomakethismoduleworthwhile;
}

// Test for shadowing a struct name
struct ShadowMe;

impl ShadowMe {
    fn DoNothing(&self) {}
}

mod light {
    pub struct ShadowMe;
}

fn main()
{
    // Fails.
    //let test1fail = module::new();

    // Succeeds.
    let test1pass = module::module::new();

    // Fails
    //let test2fail = mod2::new();

    // Succeeds.
    let test2pass = mod1::mod2::new();

    // Succeeds, test3 is of type ::ShadowMe, not light::ShadowMe
    let test3 = ShadowMe;
    test3.DoNothing();
}

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