Skip to content

Commit d0796bf

Browse files
committed
Basic support for Rust 2021
1 parent 13ddc3d commit d0796bf

File tree

5 files changed

+29
-0
lines changed

5 files changed

+29
-0
lines changed

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")]

ui/frontend/AdvancedOptionsMenu.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const AdvancedOptionsMenu: React.SFC = () => {
2929
>
3030
<option value={Edition.Rust2015}>2015</option>
3131
<option value={Edition.Rust2018}>2018</option>
32+
<option value={Edition.Rust2021}>2021</option>
3233
</SelectConfig>
3334

3435
<EitherConfig

ui/frontend/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export enum Mode {
9696
export enum Edition {
9797
Rust2015 = '2015',
9898
Rust2018 = '2018',
99+
Rust2021 = '2021',
99100
}
100101

101102
export enum Backtrace {

ui/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,6 +1480,7 @@ fn parse_edition(s: &str) -> Result<Option<sandbox::Edition>> {
14801480
"" => None,
14811481
"2015" => Some(sandbox::Edition::Rust2015),
14821482
"2018" => Some(sandbox::Edition::Rust2018),
1483+
"2021" => Some(sandbox::Edition::Rust2021),
14831484
value => InvalidEdition { value }.fail()?,
14841485
})
14851486
}

ui/src/sandbox.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,7 @@ pub enum Mode {
681681
pub enum Edition {
682682
Rust2015,
683683
Rust2018,
684+
Rust2021, // TODO - add parallel tests for 2021
684685
}
685686

686687
impl Edition {
@@ -690,6 +691,7 @@ impl Edition {
690691
match *self {
691692
Rust2015 => "2015",
692693
Rust2018 => "2018",
694+
Rust2021 => "2021",
693695
}
694696
}
695697
}
@@ -751,6 +753,10 @@ impl DockerCommandExt for Command {
751753

752754
fn apply_edition(&mut self, req: impl EditionRequest) {
753755
if let Some(edition) = req.edition() {
756+
if edition == Edition::Rust2021 {
757+
self.args(&["--env", &format!("PLAYGROUND_FEATURE_EDITION2021=true")]);
758+
}
759+
754760
self.args(&["--env", &format!("PLAYGROUND_EDITION={}", edition.cargo_ident())]);
755761
}
756762
}

0 commit comments

Comments
 (0)