Rename the `rust` manifest key to `edition`
authorAlex Crichton <alex@alexcrichton.com>
Thu, 3 May 2018 16:14:25 +0000 (09:14 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 3 May 2018 18:45:04 +0000 (11:45 -0700)
This'll hopefully jive better with the terminology of "edition" throughout the
rest of Rust!

src/cargo/core/features.rs
src/cargo/util/toml/mod.rs
src/doc/src/reference/unstable.md
tests/testsuite/bench.rs
tests/testsuite/doc.rs
tests/testsuite/install.rs
tests/testsuite/package.rs
tests/testsuite/run.rs

index 69a0381f7fd24d104db72ddfc321415d182ae3f3..b83e242ce76bf3b9360c8b189aadd7a7e33adcde 100644 (file)
@@ -49,6 +49,8 @@ use std::env;
 use std::fmt;
 use std::str::FromStr;
 
+use failure::Error;
+
 use util::errors::CargoResult;
 
 /// The edition of the compiler (RFC 2052)
@@ -69,12 +71,15 @@ impl fmt::Display for Edition {
     }
 }
 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)
+            }
         }
     }
 }
index f15d0e2fc5699da1630413fe7f3c9d50123aef29..2d49c1c9150fd1c7b6dfa46560886b01138a129d 100644 (file)
@@ -558,7 +558,7 @@ pub struct TomlProject {
     license_file: Option<String>,
     repository: Option<String>,
     metadata: Option<toml::Value>,
-    rust: Option<String>,
+    edition: Option<String>,
 }
 
 #[derive(Debug, Deserialize, Serialize)]
@@ -719,15 +719,12 @@ impl TomlManifest {
 
         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
         };
index ca004ccce62e7a166fdae9d47c28624cc148123d..6d206b78e2f780de9e1c2a9e9b271281353e35ec 100644 (file)
@@ -181,16 +181,16 @@ cargo +nightly build --out-dir=out -Z unstable-options
 * 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"
 ```
 
 
index 595b47926d0eecff0c1f106a9fcd48d2ec931705..fd133c1892cd6dcaf784cdafaaae8017cd564d07 100644 (file)
@@ -713,7 +713,7 @@ fn bench_autodiscover_2015() {
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "2015"
+            edition = "2015"
 
             [[bench]]
             name = "bench_magic"
index ac9d269d3b1759044fc26be8c741246efe03720c..94e0839d8befa087d303f4e1c4db096f9dc9ac34 100644 (file)
@@ -1496,7 +1496,7 @@ fn doc_edition() {
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "2018"
+            edition = "2018"
         "#,
         )
         .file("src/lib.rs", "")
index d3a18999d96d9a76f6da85b4385785b6ebaa1284..5e6f6f6d3331d640f41fee303b6e855cfc2ad694 100644 (file)
@@ -1038,7 +1038,7 @@ fn installs_from_cwd_with_2018_warnings() {
             name = "foo"
             version = "0.1.0"
             authors = []
-            rust = "2018"
+            edition = "2018"
         "#,
         )
         .file("src/main.rs", "fn main() {}")
index d862beee96dd5df3e507a01a7143aff80edd8c14..0dc91ce207acbc50b90892ff150de003316fe941 100644 (file)
@@ -1110,7 +1110,7 @@ fn test_edition() {
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "2018"
+            edition = "2018"
         "#,
         )
         .file("src/lib.rs", r#" "#)
@@ -1178,7 +1178,7 @@ fn test_edition_malformed() {
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "chicken"
+            edition = "chicken"
         "#,
         )
         .file("src/lib.rs", r#" "#)
@@ -1191,7 +1191,10 @@ fn test_edition_malformed() {
 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
 "
         )),
     );
@@ -1207,7 +1210,7 @@ fn test_edition_nightly() {
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "2015"
+            edition = "2015"
         "#,
         )
         .file("src/lib.rs", r#" "#)
index ac6c6e212d764cc3190d002d758557620abb4bf7..01ccd519686242cf446774c71fcf1066f3aabfb3 100644 (file)
@@ -403,7 +403,7 @@ fn autodiscover_examples_project(rust_edition: &str, autoexamples: Option<bool>)
             name = "foo"
             version = "0.0.1"
             authors = []
-            rust = "{rust_edition}"
+            edition = "{rust_edition}"
             {autoexamples}
 
             [features]