@@ -91,6 +91,7 @@ pub struct AutoCfg {
9191 rustc_version : Version ,
9292 target : Option < OsString > ,
9393 no_std : bool ,
94+ edition : Option < String > ,
9495 rustflags : Vec < String > ,
9596 uuid : u64 ,
9697}
@@ -203,6 +204,7 @@ impl AutoCfg {
203204 rustc_version : rustc_version,
204205 target : target,
205206 no_std : false ,
207+ edition : None ,
206208 uuid : new_uuid ( ) ,
207209 } ;
208210
@@ -246,6 +248,36 @@ impl AutoCfg {
246248 self . no_std = no_std;
247249 }
248250
251+ /// Returns the `--edition` string that is currently being passed to `rustc`, if any,
252+ /// as configured by the [`set_edition`][Self::set_edition] method.
253+ pub fn edition ( & self ) -> Option < & str > {
254+ match self . edition {
255+ Some ( ref edition) => Some ( & * * edition) ,
256+ None => None ,
257+ }
258+ }
259+
260+ /// Sets the `--edition` string that will be passed to `rustc`,
261+ /// or `None` to leave the compiler at its default edition.
262+ ///
263+ /// See also [The Rust Edition Guide](https://doc.rust-lang.org/edition-guide/).
264+ ///
265+ /// **Warning:** Setting an unsupported edition will likely cause **all** subsequent probes to
266+ /// fail! As of this writing, the known editions and their minimum Rust versions are:
267+ ///
268+ /// | Edition | Version |
269+ /// | ------- | ---------- |
270+ /// | 2015 | 1.27.0[^1] |
271+ /// | 2018 | 1.31.0 |
272+ /// | 2021 | 1.56.0 |
273+ /// | 2024 | 1.85.0 |
274+ ///
275+ /// [^1]: Prior to 1.27.0, Rust was effectively 2015 Edition by default, but the concept hadn't
276+ /// been established yet, so the explicit `--edition` flag wasn't supported either.
277+ pub fn set_edition ( & mut self , edition : Option < String > ) {
278+ self . edition = edition;
279+ }
280+
249281 /// Tests whether the current `rustc` reports a version greater than
250282 /// or equal to "`major`.`minor`".
251283 pub fn probe_rustc_version ( & self , major : usize , minor : usize ) -> bool {
@@ -282,6 +314,10 @@ impl AutoCfg {
282314 . arg ( & self . out_dir )
283315 . arg ( "--emit=llvm-ir" ) ;
284316
317+ if let Some ( edition) = self . edition . as_ref ( ) {
318+ command. arg ( "--edition" ) . arg ( edition) ;
319+ }
320+
285321 if let Some ( target) = self . target . as_ref ( ) {
286322 command. arg ( "--target" ) . arg ( target) ;
287323 }
0 commit comments