use std::fmt;
use std::str::FromStr;
+use failure::Error;
+
use util::errors::CargoResult;
/// The edition of the compiler (RFC 2052)
}
}
impl FromStr for Edition {
- type Err = ();
- fn from_str(s: &str) -> Result<Self, ()> {
+ type Err = Error;
+ fn from_str(s: &str) -> Result<Self, Error> {
match s {
"2015" => Ok(Edition::Edition2015),
"2018" => Ok(Edition::Edition2018),
- _ => Err(()),
+ s => {
+ bail!("supported edition values are `2015` or `2018`, but `{}` \
+ is unknown", s)
+ }
}
}
}
license_file: Option<String>,
repository: Option<String>,
metadata: Option<toml::Value>,
- rust: Option<String>,
+ edition: Option<String>,
}
#[derive(Debug, Deserialize, Serialize)]
let pkgid = project.to_package_id(source_id)?;
- let edition = if let Some(ref edition) = project.rust {
+ let edition = if let Some(ref edition) = project.edition {
features
.require(Feature::edition())
.chain_err(|| "editions are unstable")?;
- if let Ok(edition) = edition.parse() {
- edition
- } else {
- bail!("the `rust` key must be one of: `2015`, `2018`")
- }
+ edition.parse()
+ .chain_err(|| "failed to parse the `edition` key")?
} else {
Edition::Edition2015
};
* Tracking Issue: [rust-lang/rust#44581](https://github.com/rust-lang/rust/issues/44581)
* RFC: [#2052](https://github.com/rust-lang/rfcs/blob/master/text/2052-epochs.md)
-You can opt in to a specific Rust Edition for your package with the `rust` key
-in `Cargo.toml`. If you don't specify the edition, it will default to 2015.
-You need to include the appropriate `cargo-features`:
+You can opt in to a specific Rust Edition for your package with the `edition`
+key in `Cargo.toml`. If you don't specify the edition, it will default to
+2015. You need to include the appropriate `cargo-features`:
```toml
cargo-features = ["edition"]
[package]
...
-rust = "2018"
+edition = "2018"
```
name = "foo"
version = "0.0.1"
authors = []
- rust = "2015"
+ edition = "2015"
[[bench]]
name = "bench_magic"
name = "foo"
version = "0.0.1"
authors = []
- rust = "2018"
+ edition = "2018"
"#,
)
.file("src/lib.rs", "")
name = "foo"
version = "0.1.0"
authors = []
- rust = "2018"
+ edition = "2018"
"#,
)
.file("src/main.rs", "fn main() {}")
name = "foo"
version = "0.0.1"
authors = []
- rust = "2018"
+ edition = "2018"
"#,
)
.file("src/lib.rs", r#" "#)
name = "foo"
version = "0.0.1"
authors = []
- rust = "chicken"
+ edition = "chicken"
"#,
)
.file("src/lib.rs", r#" "#)
error: failed to parse manifest at `[..]`
Caused by:
- the `rust` key must be one of: `2015`, `2018`
+ failed to parse the `edition` key
+
+Caused by:
+ supported edition values are `2015` or `2018`, but `chicken` is unknown
"
)),
);
name = "foo"
version = "0.0.1"
authors = []
- rust = "2015"
+ edition = "2015"
"#,
)
.file("src/lib.rs", r#" "#)
name = "foo"
version = "0.0.1"
authors = []
- rust = "{rust_edition}"
+ edition = "{rust_edition}"
{autoexamples}
[features]