Skip to content

Commit 5ed654e

Browse files
authored
Merge pull request #717 from integer32llc/edition-2021
Add support for Rust 2021
2 parents acdf3c7 + b8b5baf commit 5ed654e

File tree

20 files changed

+442
-379
lines changed

20 files changed

+442
-379
lines changed

compiler/base/Cargo.toml

Lines changed: 68 additions & 67 deletions
Large diffs are not rendered by default.

compiler/base/crate-information.json

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

compiler/base/modify-cargo-toml/Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/base/modify-cargo-toml/src/main.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ fn main() {
2020
let mut cargo_toml: Value = toml::from_str(&input)
2121
.unwrap_or_else(|e| panic!("Cannot parse {} as TOML: {}", input_filename.display(), e));
2222

23+
if env::var_os("PLAYGROUND_FEATURE_EDITION2021").is_some() {
24+
cargo_toml = set_feature_edition2021(cargo_toml);
25+
}
26+
2327
if let Ok(edition) = env::var("PLAYGROUND_EDITION") {
2428
cargo_toml = set_edition(cargo_toml, &edition);
2529
}
@@ -62,6 +66,22 @@ fn ensure_string_in_vec(values: &mut Vec<String>, val: &str) {
6266
}
6367
}
6468

69+
fn set_feature_edition2021(cargo_toml: Value) -> Value {
70+
#[derive(Debug, Serialize, Deserialize)]
71+
#[serde(rename_all = "kebab-case")]
72+
struct CargoToml {
73+
#[serde(default)]
74+
cargo_features: Vec<String>,
75+
#[serde(flatten)]
76+
other: Other,
77+
}
78+
79+
modify(cargo_toml, |mut cargo_toml: CargoToml| {
80+
ensure_string_in_vec(&mut cargo_toml.cargo_features, "edition2021");
81+
cargo_toml
82+
})
83+
}
84+
6585
fn set_edition(cargo_toml: Value, edition: &str) -> Value {
6686
#[derive(Debug, Serialize, Deserialize)]
6787
#[serde(rename_all = "kebab-case")]

tests/Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ GEM
2020
addressable (~> 2.7)
2121
mini_mime (1.1.0)
2222
mini_portile2 (2.5.1)
23-
nokogiri (1.11.3)
23+
nokogiri (1.11.4)
2424
mini_portile2 (~> 2.5.0)
2525
racc (~> 1.4)
2626
public_suffix (4.0.6)

tests/spec/features/editions_spec.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,45 @@
77

88
before do
99
visit '/'
10-
editor.set(rust_2018_code)
10+
editor.set(rust_edition_code)
1111
end
1212

13-
scenario "using the 2015 channel" do
14-
in_advanced_options_menu { choose '2015' }
13+
scenario "using the 2015 edition" do
14+
in_advanced_options_menu { select '2015' }
1515
click_on("Run")
1616

1717
within(:output, :stderr) do
18-
expect(page).to have_content 'unused variable: `async`'
19-
expect(page).to_not have_content 'expected identifier, found keyword `async`'
18+
expect(page).to have_content 'cannot find struct, variant or union type `async` in this scope'
2019
end
2120
end
2221

23-
scenario "using the 2018 channel" do
24-
in_advanced_options_menu { choose '2018' }
22+
scenario "using the 2018 edition" do
23+
in_advanced_options_menu { select '2018' }
2524
click_on("Run")
2625

2726
within(:output, :stderr) do
28-
expect(page).to have_content 'expected identifier, found keyword `async`'
29-
expect(page).to_not have_content 'unused variable: `async`'
27+
expect(page).to have_content "thread 'main' panicked at 'Box<Any>'"
28+
end
29+
end
30+
31+
scenario "using the 2021 edition" do
32+
in_advanced_options_menu { select '2021' }
33+
click_on("Run")
34+
35+
within(:output, :stderr) do
36+
expect(page).to have_content 'format argument must be a string literal', wait: 10
3037
end
3138
end
3239

3340
def editor
3441
Editor.new(page)
3542
end
3643

37-
def rust_2018_code
44+
def rust_edition_code
3845
<<~EOF
46+
#![allow(non_fmt_panic)]
3947
fn main() {
40-
let async = 42;
48+
panic!(async {})
4149
}
4250
EOF
4351
end

tests/spec/features/sharing_with_others_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
in_channel_menu { click_on("Nightly") }
1616
in_mode_menu { click_on("Release") }
17-
in_advanced_options_menu { choose("2018") }
17+
in_advanced_options_menu { select("2018") }
1818

1919
within(:header) { click_on 'Share' }
2020

tests/spec/features/url_parameters_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
RSpec::Matchers.define :have_edition do |expected|
2727
match do |actual|
2828
in_advanced_options_menu do
29-
expect(page).to have_checked_field(expected, visible: false)
29+
expect(page).to have_select(selected: expected)
3030
end
3131
end
3232
end

0 commit comments

Comments
 (0)