@@ -18,6 +18,7 @@ use std::path::{Path, PathBuf};
1818
1919use file_lines:: FileLines ;
2020use lists:: { ListTactic , SeparatorPlace , SeparatorTactic } ;
21+ use Summary ;
2122
2223macro_rules! configuration_option_enum{
2324 ( $e: ident: $( $x: ident ) ,+ $( , ) * ) => {
@@ -272,6 +273,23 @@ macro_rules! create_config {
272273 }
273274
274275 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+ }
275293
276294 $(
277295 pub fn $i( & self ) -> $ty {
@@ -622,6 +640,8 @@ create_config! {
622640 merge_derives: bool , true , "Merge multiple `#[derive(...)]` into a single one" ;
623641 binop_separator: SeparatorPlace , SeparatorPlace :: Front ,
624642 "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."
625645}
626646
627647#[ cfg( test) ]
0 commit comments