@@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
18
18
19
19
use file_lines:: FileLines ;
20
20
use lists:: { ListTactic , SeparatorPlace , SeparatorTactic } ;
21
+ use Summary ;
21
22
22
23
macro_rules! configuration_option_enum{
23
24
( $e: ident: $( $x: ident ) ,+ $( , ) * ) => {
@@ -272,6 +273,23 @@ macro_rules! create_config {
272
273
}
273
274
274
275
impl Config {
276
+ pub fn version_meets_requirement( & self , error_summary: & mut Summary ) -> bool {
277
+ if self . was_set( ) . required_version( ) {
278
+ let version = env!( "CARGO_PKG_VERSION" ) ;
279
+ let required_version = self . required_version( ) ;
280
+ if version != required_version {
281
+ println!(
282
+ "Error: rustfmt version ({}) doesn't match the required version ({})" ,
283
+ version,
284
+ required_version,
285
+ ) ;
286
+ error_summary. add_formatting_error( ) ;
287
+ return false ;
288
+ }
289
+ }
290
+
291
+ true
292
+ }
275
293
276
294
$(
277
295
pub fn $i( & self ) -> $ty {
@@ -622,6 +640,8 @@ create_config! {
622
640
merge_derives: bool , true , "Merge multiple `#[derive(...)]` into a single one" ;
623
641
binop_separator: SeparatorPlace , SeparatorPlace :: Front ,
624
642
"Where to put a binary operator when a binary expression goes multiline." ;
643
+ required_version: String , env!( "CARGO_PKG_VERSION" ) . to_owned( ) ,
644
+ "Require a specific version of rustfmt."
625
645
}
626
646
627
647
#[ cfg( test) ]
0 commit comments