Skip to content

Commit f9926c6

Browse files
committed
Auto merge of #5989 - alexcrichton:change-default, r=Mark-Simulacrum
Change the default edition for `cargo new` to 2018 As it says on the tin! Some tests were updated to explicitly pass 2015 so they can continue to work on stable, and otherwise `cargo new` should now by default generate a 2018 project.
2 parents 56ee620 + cf8d6a4 commit f9926c6

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

src/cargo/ops/cargo_new.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,16 @@ path = {}
535535
r#"[package]
536536
name = "{}"
537537
version = "0.1.0"
538-
authors = [{}]{}
538+
authors = [{}]
539+
edition = {}
539540
540541
[dependencies]
541542
{}"#,
542543
name,
543544
toml::Value::String(author),
544545
match opts.edition {
545-
Some(edition) => {
546-
let edition = toml::Value::String(edition.to_string());
547-
format!("\nedition = {}", edition)
548-
}
549-
None => String::new(),
546+
Some(edition) => toml::Value::String(edition.to_string()),
547+
None => toml::Value::String("2018".to_string()),
550548
},
551549
cargotoml_path_specifier
552550
).as_bytes(),

tests/testsuite/init.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn cargo_process(s: &str) -> Execs {
1313

1414
#[test]
1515
fn simple_lib() {
16-
cargo_process("init --lib --vcs none")
16+
cargo_process("init --lib --vcs none --edition 2015")
1717
.env("USER", "foo")
1818
.with_stderr("[CREATED] library project")
1919
.run();
@@ -29,7 +29,7 @@ fn simple_lib() {
2929
fn simple_bin() {
3030
let path = paths::root().join("foo");
3131
fs::create_dir(&path).unwrap();
32-
cargo_process("init --bin --vcs none")
32+
cargo_process("init --bin --vcs none --edition 2015")
3333
.env("USER", "foo")
3434
.cwd(&path)
3535
.with_stderr("[CREATED] binary (application) project")

tests/testsuite/new.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn create_empty_gitconfig() {
1414

1515
#[test]
1616
fn simple_lib() {
17-
cargo_process("new --lib foo --vcs none")
17+
cargo_process("new --lib foo --vcs none --edition 2015")
1818
.env("USER", "foo")
1919
.with_stderr("[CREATED] library `foo` project")
2020
.run();
@@ -47,7 +47,7 @@ mod tests {
4747

4848
#[test]
4949
fn simple_bin() {
50-
cargo_process("new --bin foo")
50+
cargo_process("new --bin foo --edition 2015")
5151
.env("USER", "foo")
5252
.with_stderr("[CREATED] binary (application) `foo` project")
5353
.run();
@@ -75,7 +75,7 @@ fn both_lib_and_bin() {
7575

7676
#[test]
7777
fn simple_git() {
78-
cargo_process("new --lib foo").env("USER", "foo").run();
78+
cargo_process("new --lib foo --edition 2015").env("USER", "foo").run();
7979

8080
assert!(paths::root().is_dir());
8181
assert!(paths::root().join("foo/Cargo.toml").is_file());
@@ -474,6 +474,15 @@ fn new_with_edition_2018() {
474474
assert!(manifest.contains("edition = \"2018\""));
475475
}
476476

477+
#[test]
478+
fn new_default_edition() {
479+
cargo_process("new foo")
480+
.env("USER", "foo")
481+
.run();
482+
let manifest = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
483+
assert!(manifest.contains("edition = \"2018\""));
484+
}
485+
477486
#[test]
478487
fn new_with_bad_edition() {
479488
cargo_process("new --edition something_else foo")

0 commit comments

Comments
 (0)