Skip to content

Commit 76001af

Browse files
committed
Add an Edition on TomlTarget & Target, & wire
1 parent db48c63 commit 76001af

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

src/cargo/core/manifest.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ pub struct Target {
200200
doctest: bool,
201201
harness: bool, // whether to use the test harness (--test)
202202
for_host: bool,
203+
edition: Edition,
203204
}
204205

205206
#[derive(Clone, PartialEq, Eq)]
@@ -280,6 +281,7 @@ compact_debug! {
280281
doctest
281282
harness
282283
for_host
284+
edition
283285
)]
284286
}
285287
}
@@ -507,6 +509,7 @@ impl Target {
507509
doctest: false,
508510
harness: true,
509511
for_host: false,
512+
edition: Edition::Edition2015,
510513
tested: true,
511514
benched: true,
512515
}
@@ -625,6 +628,7 @@ impl Target {
625628
pub fn for_host(&self) -> bool {
626629
self.for_host
627630
}
631+
pub fn edition(&self) -> Edition { self.edition }
628632
pub fn benched(&self) -> bool {
629633
self.benched
630634
}
@@ -746,6 +750,10 @@ impl Target {
746750
self.for_host = for_host;
747751
self
748752
}
753+
pub fn set_edition(&mut self, edition: Edition) -> &mut Target {
754+
self.edition = edition;
755+
self
756+
}
749757
pub fn set_harness(&mut self, harness: bool) -> &mut Target {
750758
self.harness = harness;
751759
self

src/cargo/util/toml/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,7 @@ struct TomlTarget {
13571357
harness: Option<bool>,
13581358
#[serde(rename = "required-features")]
13591359
required_features: Option<Vec<String>>,
1360+
edition: Option<String>,
13601361
}
13611362

13621363
#[derive(Clone)]

src/cargo/util/toml/targets.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use std::fs::{self, DirEntry};
1515
use std::collections::HashSet;
1616

1717
use core::{compiler, Edition, Target};
18-
use util::errors::CargoResult;
18+
use util::errors::{CargoResult, CargoResultExt};
1919
use super::{LibKind, PathValue, StringOrBool, TomlBenchTarget, TomlBinTarget, TomlExampleTarget,
2020
TomlLibTarget, TomlManifest, TomlTarget, TomlTestTarget};
2121

@@ -183,7 +183,7 @@ fn clean_lib(
183183
};
184184

185185
let mut target = Target::lib_target(&lib.name(), crate_types, path);
186-
configure(lib, &mut target);
186+
configure(lib, &mut target)?;
187187
Ok(Some(target))
188188
}
189189

@@ -263,7 +263,7 @@ fn clean_bins(
263263
};
264264

265265
let mut target = Target::bin_target(&bin.name(), path, bin.required_features.clone());
266-
configure(bin, &mut target);
266+
configure(bin, &mut target)?;
267267
result.push(target);
268268
}
269269
return Ok(result);
@@ -324,7 +324,7 @@ fn clean_examples(
324324
path,
325325
toml.required_features.clone(),
326326
);
327-
configure(&toml, &mut target);
327+
configure(&toml, &mut target)?;
328328
result.push(target);
329329
}
330330

@@ -357,7 +357,7 @@ fn clean_tests(
357357
let mut result = Vec::new();
358358
for (path, toml) in targets {
359359
let mut target = Target::test_target(&toml.name(), path, toml.required_features.clone());
360-
configure(&toml, &mut target);
360+
configure(&toml, &mut target)?;
361361
result.push(target);
362362
}
363363
Ok(result)
@@ -410,7 +410,7 @@ fn clean_benches(
410410
let mut result = Vec::new();
411411
for (path, toml) in targets {
412412
let mut target = Target::bench_target(&toml.name(), path, toml.required_features.clone());
413-
configure(&toml, &mut target);
413+
configure(&toml, &mut target)?;
414414
result.push(target);
415415
}
416416

@@ -682,7 +682,7 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
682682
Ok(())
683683
}
684684

685-
fn configure(toml: &TomlTarget, target: &mut Target) {
685+
fn configure(toml: &TomlTarget, target: &mut Target) -> CargoResult<()> {
686686
let t2 = target.clone();
687687
target
688688
.set_tested(toml.test.unwrap_or_else(|| t2.tested()))
@@ -694,7 +694,13 @@ fn configure(toml: &TomlTarget, target: &mut Target) {
694694
(None, None) => t2.for_host(),
695695
(Some(true), _) | (_, Some(true)) => true,
696696
(Some(false), _) | (_, Some(false)) => false,
697+
})
698+
.set_edition(match toml.edition.clone() {
699+
None => t2.edition(),
700+
// TODO: Check the edition feature gate
701+
Some(s) => s.parse().chain_err(|| "failed to parse the `edition` key")?,
697702
});
703+
Ok(())
698704
}
699705

700706
fn target_path(

0 commit comments

Comments
 (0)