path attribute is silently accepted and ignored for inline mod items. #13156

Open
pnkfelix opened this Issue Mar 26, 2014 · 1 comment

Projects

None yet

3 participants

@pnkfelix
Member

Consider the following program p.rs:

#[path="q.rs"] mod q {
    pub fn q_main() { println!("Hello World"); }
}

fn main() { q::q_main() }

I don't know if this is considered a bug or a feature, but we should probably emit a warning when we encounter that useless path attribute attached to q above.

@gkoz
Contributor
gkoz commented Feb 2, 2016

Doesn't seem useless to me. The reference gives this seemingly reasonable example:

The directories and files used for loading external file modules can be influenced with the path attribute.

#[path = "thread_files"]
mod thread {
    // Load the `local_data` module from `thread_files/tls.rs`
    #[path = "tls.rs"]
    mod local_data;
}

Now suppose you're in a build script and want to include src/tls.rs. Is there a better way than

// This module hides some optional stuff
#[cfg(foo_bar)]
#[path = ""]
mod thread {
    #[path = "src/tls.rs"]
    mod local_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment