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

Change the default edition for cargo new to 2018 #5989

Merged
merged 1 commit into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/cargo/ops/cargo_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,18 +535,16 @@ path = {}
r#"[package]
name = "{}"
version = "0.1.0"
authors = [{}]{}
authors = [{}]
edition = {}

[dependencies]
{}"#,
name,
toml::Value::String(author),
match opts.edition {
Some(edition) => {
let edition = toml::Value::String(edition.to_string());
format!("\nedition = {}", edition)
}
None => String::new(),
Some(edition) => toml::Value::String(edition.to_string()),
None => toml::Value::String("2018".to_string()),
},
cargotoml_path_specifier
).as_bytes(),
Expand Down
4 changes: 2 additions & 2 deletions tests/testsuite/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ fn cargo_process(s: &str) -> Execs {

#[test]
fn simple_lib() {
cargo_process("init --lib --vcs none")
cargo_process("init --lib --vcs none --edition 2015")
.env("USER", "foo")
.with_stderr("[CREATED] library project")
.run();
Expand All @@ -29,7 +29,7 @@ fn simple_lib() {
fn simple_bin() {
let path = paths::root().join("foo");
fs::create_dir(&path).unwrap();
cargo_process("init --bin --vcs none")
cargo_process("init --bin --vcs none --edition 2015")
.env("USER", "foo")
.cwd(&path)
.with_stderr("[CREATED] binary (application) project")
Expand Down
15 changes: 12 additions & 3 deletions tests/testsuite/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn create_empty_gitconfig() {

#[test]
fn simple_lib() {
cargo_process("new --lib foo --vcs none")
cargo_process("new --lib foo --vcs none --edition 2015")
.env("USER", "foo")
.with_stderr("[CREATED] library `foo` project")
.run();
Expand Down Expand Up @@ -47,7 +47,7 @@ mod tests {

#[test]
fn simple_bin() {
cargo_process("new --bin foo")
cargo_process("new --bin foo --edition 2015")
.env("USER", "foo")
.with_stderr("[CREATED] binary (application) `foo` project")
.run();
Expand Down Expand Up @@ -75,7 +75,7 @@ fn both_lib_and_bin() {

#[test]
fn simple_git() {
cargo_process("new --lib foo").env("USER", "foo").run();
cargo_process("new --lib foo --edition 2015").env("USER", "foo").run();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct to assume these are temporary? I imagine in theory at least we'd want to not have this here -- most users shouldn't be passing/working in 2015 edition locally I imagine. Or, at least, we'd want tests for both.

Anyway, not a concern that needs to be resolved in this PR I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes these are temporary until the 2018 edition has hit the stable channel, and then we can change these tests back.


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

#[test]
fn new_default_edition() {
cargo_process("new foo")
.env("USER", "foo")
.run();
let manifest = fs::read_to_string(paths::root().join("foo/Cargo.toml")).unwrap();
assert!(manifest.contains("edition = \"2018\""));
}

#[test]
fn new_with_bad_edition() {
cargo_process("new --edition something_else foo")
Expand Down