Skip to content
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

Not aware of conditional path attribute #1208

Closed
anowell opened this issue Nov 6, 2016 · 2 comments
Closed

Not aware of conditional path attribute #1208

anowell opened this issue Nov 6, 2016 · 2 comments
Labels

Comments

@anowell
Copy link

anowell commented Nov 6, 2016

#[cfg_attr(feature="with-serde", path = "json-serde.rs")]
#[cfg_attr(feature="with-rustc-serialize", path = "json-rustc-serialize.rs")]
mod json;

results in this error preventing cargo fmt from completing:

error: file not found for module `json`
  --> /home/anowell/proj/algorithmia-rust/src/lib.rs:53:5
   |
53 | mod json;
   |     ^^^^
   |
   = help: name the file either json.rs or json/mod.rs inside the directory "/home/anowell/proj/algorithmia-rust/src"

I am able to work around it with:

#[cfg(feature="with-serde")]
#[path = "json-serde.rs"]
mod json;

#[cfg(feature="with-rustc-serialize")]
#[path = "json-rustc-serialize.rs"]
mod json;
@nrc
Copy link
Member

nrc commented Nov 6, 2016

Although Rustfmt really ought to cope with this, I'd recommend against using this pattern - I'd generally recommend against all uses of the path attribute.

@anowell
Copy link
Author

anowell commented Nov 8, 2016

In general, I also agree with avoiding path and sticking to the default path semantics. But I believe the snippet below is the closest equivalent without using path (where json is not exported outside of the crate, but is accessible everywhere within the crate). And I don't particularly find this easier to read or reason about, so IMO, I went from 3 lines to 6 lines to 10 lines without obvious gains - perhaps "one less concept to understand" (i.e. path) is a gain, but path seems to be the easiest concept to grok in these examples. ¯\_(ツ)_/¯

mod json {
    #[cfg(feature="with-serde")]
    mod json_serde;
    #[cfg(feature="with-serde")]
    pub use json_serde::*;

    #[cfg(feature="with-rustc-serialize")]
    mod json_rustc_serialize;
    #[cfg(feature="with-rustc-serialize")]
    pub use json_rustc_serialize::*;
}

@nrc nrc added the p-low label Nov 2, 2017
christophermaier added a commit to habitat-sh/habitat that referenced this issue May 15, 2019
Looks like `path` attributes are invisible to rustfmt:

- rust-lang/rustfmt#1208
- rust-lang/rustfmt#2407

Ideally, it would be nice to not use the `path` attribute at all, and
we can actually formulate this in a way that doesn't use `path`, but
it seems to involve a lot more repetition. It's not at all clear that
that's a win here, particularly given that we're only going to have
two implementations for a short period of time.

Signed-off-by: Christopher Maier <cmaier@chef.io>
christophermaier added a commit to habitat-sh/habitat that referenced this issue May 17, 2019
Looks like `path` attributes are invisible to rustfmt:

- rust-lang/rustfmt#1208
- rust-lang/rustfmt#2407

Ideally, it would be nice to not use the `path` attribute at all, and
we can actually formulate this in a way that doesn't use `path`, but
it seems to involve a lot more repetition. It's not at all clear that
that's a win here, particularly given that we're only going to have
two implementations for a short period of time.

Signed-off-by: Christopher Maier <cmaier@chef.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants