@@ -93,19 +93,6 @@ macro_rules! create_config {
93
93
$( pub $i: Option <$ty>) ,+
94
94
}
95
95
96
- impl PartialConfig {
97
- pub fn to_toml( & self ) -> Result <String , String > {
98
- // Non-user-facing options can't be specified in TOML
99
- let mut cloned = self . clone( ) ;
100
- cloned. file_lines = None ;
101
- cloned. verbose = None ;
102
- cloned. width_heuristics = None ;
103
-
104
- :: toml:: to_string( & cloned)
105
- . map_err( |e| format!( "Could not output config: {}" , e) )
106
- }
107
- }
108
-
109
96
// Macro hygiene won't allow us to make `set_$i()` methods on Config
110
97
// for each item, so this struct is used to give the API to set values:
111
98
// `config.set().option(false)`. It's pretty ugly. Consider replacing
@@ -139,23 +126,6 @@ macro_rules! create_config {
139
126
}
140
127
141
128
impl Config {
142
- pub ( crate ) fn version_meets_requirement( & self ) -> bool {
143
- if self . was_set( ) . required_version( ) {
144
- let version = env!( "CARGO_PKG_VERSION" ) ;
145
- let required_version = self . required_version( ) ;
146
- if version != required_version {
147
- println!(
148
- "Error: rustfmt version ({}) doesn't match the required version ({})" ,
149
- version,
150
- required_version,
151
- ) ;
152
- return false ;
153
- }
154
- }
155
-
156
- true
157
- }
158
-
159
129
$(
160
130
pub fn $i( & self ) -> $ty {
161
131
self . $i. 0 . set( true ) ;
@@ -213,37 +183,6 @@ macro_rules! create_config {
213
183
}
214
184
}
215
185
216
- pub ( crate ) fn from_toml( toml: & str , dir: & Path ) -> Result <Config , String > {
217
- let parsed: :: toml:: Value =
218
- toml. parse( ) . map_err( |e| format!( "Could not parse TOML: {}" , e) ) ?;
219
- let mut err: String = String :: new( ) ;
220
- {
221
- let table = parsed
222
- . as_table( )
223
- . ok_or( String :: from( "Parsed config was not table" ) ) ?;
224
- for key in table. keys( ) {
225
- if !Config :: is_valid_name( key) {
226
- let msg = & format!( "Warning: Unknown configuration option `{}`\n " , key) ;
227
- err. push_str( msg)
228
- }
229
- }
230
- }
231
- match parsed. try_into( ) {
232
- Ok ( parsed_config) => {
233
- if !err. is_empty( ) {
234
- eprint!( "{}" , err) ;
235
- }
236
- Ok ( Config :: default ( ) . fill_from_parsed_config( parsed_config, dir) )
237
- }
238
- Err ( e) => {
239
- err. push_str( "Error: Decoding config file failed:\n " ) ;
240
- err. push_str( format!( "{}\n " , e) . as_str( ) ) ;
241
- err. push_str( "Please check your config file." ) ;
242
- Err ( err)
243
- }
244
- }
245
- }
246
-
247
186
pub fn used_options( & self ) -> PartialConfig {
248
187
PartialConfig {
249
188
$(
@@ -287,82 +226,6 @@ macro_rules! create_config {
287
226
}
288
227
}
289
228
290
- /// Constructs a `Config` from the toml file specified at `file_path`.
291
- ///
292
- /// This method only looks at the provided path, for a method that
293
- /// searches parents for a `rustfmt.toml` see `from_resolved_toml_path`.
294
- ///
295
- /// Returns a `Config` if the config could be read and parsed from
296
- /// the file, otherwise errors.
297
- pub ( super ) fn from_toml_path( file_path: & Path ) -> Result <Config , Error > {
298
- let mut file = File :: open( & file_path) ?;
299
- let mut toml = String :: new( ) ;
300
- file. read_to_string( & mut toml) ?;
301
- Config :: from_toml( & toml, file_path. parent( ) . unwrap( ) )
302
- . map_err( |err| Error :: new( ErrorKind :: InvalidData , err) )
303
- }
304
-
305
- /// Resolves the config for input in `dir`.
306
- ///
307
- /// Searches for `rustfmt.toml` beginning with `dir`, and
308
- /// recursively checking parents of `dir` if no config file is found.
309
- /// If no config file exists in `dir` or in any parent, a
310
- /// default `Config` will be returned (and the returned path will be empty).
311
- ///
312
- /// Returns the `Config` to use, and the path of the project file if there was
313
- /// one.
314
- pub ( super ) fn from_resolved_toml_path(
315
- dir: & Path ,
316
- ) -> Result <( Config , Option <PathBuf >) , Error > {
317
- /// Try to find a project file in the given directory and its parents.
318
- /// Returns the path of a the nearest project file if one exists,
319
- /// or `None` if no project file was found.
320
- fn resolve_project_file( dir: & Path ) -> Result <Option <PathBuf >, Error > {
321
- let mut current = if dir. is_relative( ) {
322
- env:: current_dir( ) ?. join( dir)
323
- } else {
324
- dir. to_path_buf( )
325
- } ;
326
-
327
- current = fs:: canonicalize( current) ?;
328
-
329
- loop {
330
- match get_toml_path( & current) {
331
- Ok ( Some ( path) ) => return Ok ( Some ( path) ) ,
332
- Err ( e) => return Err ( e) ,
333
- _ => ( )
334
- }
335
-
336
- // If the current directory has no parent, we're done searching.
337
- if !current. pop( ) {
338
- break ;
339
- }
340
- }
341
-
342
- // If nothing was found, check in the home directory.
343
- if let Some ( home_dir) = dirs:: home_dir( ) {
344
- if let Some ( path) = get_toml_path( & home_dir) ? {
345
- return Ok ( Some ( path) ) ;
346
- }
347
- }
348
-
349
- // If none was found ther either, check in the user's configuration directory.
350
- if let Some ( mut config_dir) = dirs:: config_dir( ) {
351
- config_dir. push( "rustfmt" ) ;
352
- if let Some ( path) = get_toml_path( & config_dir) ? {
353
- return Ok ( Some ( path) ) ;
354
- }
355
- }
356
-
357
- return Ok ( None ) ;
358
- }
359
-
360
- match resolve_project_file( dir) ? {
361
- None => Ok ( ( Config :: default ( ) , None ) ) ,
362
- Some ( path) => Config :: from_toml_path( & path) . map( |config| ( config, Some ( path) ) ) ,
363
- }
364
- }
365
-
366
229
pub fn is_hidden_option( name: & str ) -> bool {
367
230
const HIDE_OPTIONS : [ & str ; 4 ] =
368
231
[ "verbose" , "verbose_diff" , "file_lines" , "width_heuristics" ] ;
0 commit comments