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

Support crate package renaming #1331

Closed
mjbshaw opened this issue Jul 3, 2018 · 2 comments
Closed

Support crate package renaming #1331

mjbshaw opened this issue Jul 3, 2018 · 2 comments

Comments

@mjbshaw
Copy link

mjbshaw commented Jul 3, 2018

Crates can now be renamed in the dependencies section. Attempting to do this with the current version of serde fails. Example:

Cargo.toml:

cargo-features = ["rename-dependency"]

[package]
name = "demo"
version = "0.1.0"

[dependencies]
sd = { git = "https://github.com/serde-rs/serde", package = "serde_derive" }
sj = { git = "https://github.com/serde-rs/json", package = "serde_json" }

src/main.rs:

#[macro_use]
extern crate sd;
extern crate sj;

#[derive(Serialize, Deserialize, Debug)]
struct Point {
    x: i32,
    y: i32,
}

fn main() {
    let point = Point { x: 1, y: 2 };

    // Convert the Point to a JSON string.
    let serialized = sj::to_string(&point).unwrap();

    // Prints serialized = {"x":1,"y":2}
    println!("serialized = {}", serialized);

    // Convert the JSON string back to a Point.
    let deserialized: Point = sj::from_str(&serialized).unwrap();

    // Prints deserialized = Point { x: 1, y: 2 }
    println!("deserialized = {:?}", deserialized);
}

Output of cargo run:

   Compiling demo v0.1.0 (file:///private/tmp/demo)
error[E0463]: can't find crate for `_serde`
 --> src/main.rs:5:21
  |
5 | #[derive(Serialize, Deserialize, Debug)]
  |                     ^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
error: Could not compile `demo`.

To learn more, run the command again with --verbose.

I imagine supporting this will require new features to be added to Rust's procedural macros.

Cargo and Rust versions:

$ cargo --version
cargo 1.28.0-nightly (e2348c2db 2018-06-07)
$ rustc --version
rustc 1.28.0-nightly (e3bf634e0 2018-06-28)
@dtolnay
Copy link
Member

dtolnay commented Jul 3, 2018

Currently serde_derive requires that you list serde in Cargo.toml as well (see https://serde.rs/derive.html) which is missing in yours. So the failure you see is from there being no serde in Cargo.toml, not directly because of the serde_derive or serde_json rename.

In the case that serde really needs to be renamed, I would prefer to track this under #953. Thanks!

@dtolnay dtolnay closed this as completed Jul 3, 2018
@mjbshaw
Copy link
Author

mjbshaw commented Jul 4, 2018

Thanks! Sorry I overlooked #953.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants