|
1 | 1 | use crate::ClippyConfiguration; |
2 | 2 | use crate::types::{ |
3 | | - DisallowedPath, DisallowedPathWithoutReplacement, DisallowedProfile, InherentImplLintScope, MacroMatcher, |
4 | | - MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering, SourceItemOrderingCategory, |
| 3 | + DisallowedPath, DisallowedPathWithoutReplacement, InherentImplLintScope, MacroMatcher, MatchLintBehaviour, |
| 4 | + PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering, SourceItemOrderingCategory, |
5 | 5 | SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, |
6 | 6 | SourceItemOrderingTraitAssocItemKinds, SourceItemOrderingWithinModuleItemGroupings, |
7 | 7 | }; |
8 | 8 | use clippy_utils::msrvs::Msrv; |
9 | 9 | use itertools::Itertools; |
10 | | -use rustc_data_structures::fx::FxHashMap; |
11 | 10 | use rustc_errors::Applicability; |
12 | 11 | use rustc_session::Session; |
13 | 12 | use rustc_span::edit_distance::edit_distance; |
@@ -223,74 +222,12 @@ macro_rules! deserialize { |
223 | 222 | }}; |
224 | 223 | } |
225 | 224 |
|
226 | | -macro_rules! parse_conf_value { |
227 | | - ( |
228 | | - $map:expr, |
229 | | - $ty:ty, |
230 | | - $errors:expr, |
231 | | - $file:expr, |
232 | | - $field_span:expr, |
233 | | - profiles @[$($profiles:expr)?], |
234 | | - disallowed @[$($disallowed:expr)?] |
235 | | - ) => { |
236 | | - parse_conf_value_impl!( |
237 | | - $map, |
238 | | - $ty, |
239 | | - $errors, |
240 | | - $file, |
241 | | - $field_span, |
242 | | - ($($profiles)?), |
243 | | - ($($disallowed)?) |
244 | | - ) |
245 | | - }; |
246 | | -} |
247 | | - |
248 | | -macro_rules! parse_conf_value_impl { |
249 | | - ($map:expr, $ty:ty, $errors:expr, $file:expr, $field_span:expr, (), ()) => {{ |
250 | | - let _ = &$field_span; |
251 | | - deserialize!($map, $ty, $errors, $file) |
252 | | - }}; |
253 | | - ($map:expr, $ty:ty, $errors:expr, $file:expr, $field_span:expr, ($profiles:expr), ()) => {{ |
254 | | - let raw_value = $map.next_value::<toml::Value>()?; |
255 | | - let value_span = $field_span.clone(); |
256 | | - let toml::Value::Table(table) = raw_value else { |
257 | | - $errors.push(ConfError::spanned( |
258 | | - $file, |
259 | | - "expected table with named profiles", |
260 | | - None, |
261 | | - value_span.clone(), |
262 | | - )); |
263 | | - continue; |
264 | | - }; |
265 | | - |
266 | | - let map = parse_profiles(table, $file, value_span.clone(), &mut $errors); |
267 | | - |
268 | | - (map, value_span) |
269 | | - }}; |
270 | | - ($map:expr, $ty:ty, $errors:expr, $file:expr, $field_span:expr, (), ($disallowed:expr)) => {{ |
271 | | - let _ = &$field_span; |
272 | | - deserialize!($map, $ty, $errors, $file, $disallowed) |
273 | | - }}; |
274 | | - ( |
275 | | - $map:expr, |
276 | | - $ty:ty, |
277 | | - $errors:expr, |
278 | | - $file:expr, |
279 | | - $field_span:expr, |
280 | | - ($profiles:expr), |
281 | | - ($disallowed:expr) |
282 | | - ) => { |
283 | | - compile_error!("field cannot specify both profiles and disallowed-paths attributes") |
284 | | - }; |
285 | | -} |
286 | | - |
287 | 225 | macro_rules! define_Conf { |
288 | 226 | ($( |
289 | 227 | $(#[doc = $doc:literal])+ |
290 | 228 | $(#[conf_deprecated($dep:literal, $new_conf:ident)])? |
291 | 229 | $(#[default_text = $default_text:expr])? |
292 | 230 | $(#[disallowed_paths_allow_replacements = $replacements_allowed:expr])? |
293 | | - $(#[profiles = $profiles:expr])? |
294 | 231 | $(#[lints($($for_lints:ident),* $(,)?)])? |
295 | 232 | $name:ident: $ty:ty = $default:expr, |
296 | 233 | )*) => { |
@@ -345,20 +282,10 @@ macro_rules! define_Conf { |
345 | 282 |
|
346 | 283 | match field { |
347 | 284 | $(Field::$name => { |
348 | | - let field_span = name.span(); |
349 | 285 | // Is this a deprecated field, i.e., is `$dep` set? If so, push a warning. |
350 | 286 | $(warnings.push(ConfError::spanned(self.0, format!("deprecated field `{}`. {}", name.get_ref(), $dep), None, name.span()));)? |
351 | | - let (value, value_span) = parse_conf_value!( |
352 | | - map, |
353 | | - $ty, |
354 | | - errors, |
355 | | - self.0, |
356 | | - field_span, |
357 | | - // Disallowed-profile table parsing is special-cased to preserve spans for |
358 | | - // diagnostics in disallowed-path entries. |
359 | | - profiles @[$($profiles)?], |
360 | | - disallowed @[$($replacements_allowed)?] |
361 | | - ); |
| 287 | + let (value, value_span) = |
| 288 | + deserialize!(map, $ty, errors, self.0 $(, $replacements_allowed)?); |
362 | 289 | // Was this field set previously? |
363 | 290 | if $name.is_some() { |
364 | 291 | errors.push(ConfError::spanned(self.0, format!("duplicate field `{}`", name.get_ref()), None, name.span())); |
@@ -415,121 +342,6 @@ fn span_from_toml_range(file: &SourceFile, span: Range<usize>) -> Span { |
415 | 342 | ) |
416 | 343 | } |
417 | 344 |
|
418 | | -fn parse_profiles( |
419 | | - table: toml::value::Table, |
420 | | - file: &SourceFile, |
421 | | - value_span: Range<usize>, |
422 | | - errors: &mut Vec<ConfError>, |
423 | | -) -> FxHashMap<String, DisallowedProfile> { |
424 | | - let mut profiles = FxHashMap::default(); |
425 | | - let config_span = span_from_toml_range(file, value_span.clone()); |
426 | | - |
427 | | - for (profile_name, profile_value) in table { |
428 | | - let toml::Value::Table(mut profile_table) = profile_value else { |
429 | | - errors.push(ConfError::spanned( |
430 | | - file, |
431 | | - format!("invalid profile `{profile_name}`: expected table"), |
432 | | - None, |
433 | | - value_span.clone(), |
434 | | - )); |
435 | | - continue; |
436 | | - }; |
437 | | - |
438 | | - let disallowed_methods = match profile_table |
439 | | - .remove("disallowed-methods") |
440 | | - .or_else(|| profile_table.remove("disallowed_methods")) |
441 | | - { |
442 | | - Some(value) => parse_profile_list( |
443 | | - file, |
444 | | - &profile_name, |
445 | | - "disallowed-methods", |
446 | | - value, |
447 | | - value_span.clone(), |
448 | | - config_span, |
449 | | - errors, |
450 | | - ), |
451 | | - None => Vec::new(), |
452 | | - }; |
453 | | - |
454 | | - let disallowed_types = match profile_table |
455 | | - .remove("disallowed-types") |
456 | | - .or_else(|| profile_table.remove("disallowed_types")) |
457 | | - { |
458 | | - Some(value) => parse_profile_list( |
459 | | - file, |
460 | | - &profile_name, |
461 | | - "disallowed-types", |
462 | | - value, |
463 | | - value_span.clone(), |
464 | | - config_span, |
465 | | - errors, |
466 | | - ), |
467 | | - None => Vec::new(), |
468 | | - }; |
469 | | - |
470 | | - if !profile_table.is_empty() { |
471 | | - let keys = profile_table.keys().map(String::as_str).collect::<Vec<_>>().join(", "); |
472 | | - errors.push(ConfError::spanned( |
473 | | - file, |
474 | | - format!("profile `{profile_name}` has unknown keys: {keys}"), |
475 | | - None, |
476 | | - value_span.clone(), |
477 | | - )); |
478 | | - } |
479 | | - |
480 | | - profiles.insert( |
481 | | - profile_name, |
482 | | - DisallowedProfile { |
483 | | - disallowed_methods, |
484 | | - disallowed_types, |
485 | | - }, |
486 | | - ); |
487 | | - } |
488 | | - |
489 | | - profiles |
490 | | -} |
491 | | - |
492 | | -fn parse_profile_list( |
493 | | - file: &SourceFile, |
494 | | - profile_name: &str, |
495 | | - key_name: &str, |
496 | | - value: toml::Value, |
497 | | - value_span: Range<usize>, |
498 | | - config_span: Span, |
499 | | - errors: &mut Vec<ConfError>, |
500 | | -) -> Vec<DisallowedPath> { |
501 | | - let toml::Value::Array(entries) = value else { |
502 | | - errors.push(ConfError::spanned( |
503 | | - file, |
504 | | - format!("profile `{profile_name}`: `{key_name}` must be an array"), |
505 | | - None, |
506 | | - value_span, |
507 | | - )); |
508 | | - return Vec::new(); |
509 | | - }; |
510 | | - |
511 | | - let mut disallowed = Vec::with_capacity(entries.len()); |
512 | | - for entry in entries { |
513 | | - match DisallowedPath::deserialize(entry.clone()) { |
514 | | - Ok(mut path) => { |
515 | | - path.set_span(config_span); |
516 | | - disallowed.push(path); |
517 | | - }, |
518 | | - Err(err) => errors.push(ConfError::spanned( |
519 | | - file, |
520 | | - format!( |
521 | | - "profile `{profile_name}`: {}", |
522 | | - err.to_string().replace('\n', " ").trim() |
523 | | - ), |
524 | | - None, |
525 | | - value_span.clone(), |
526 | | - )), |
527 | | - } |
528 | | - } |
529 | | - |
530 | | - disallowed |
531 | | -} |
532 | | - |
533 | 345 | define_Conf! { |
534 | 346 | /// Which crates to allow absolute paths from |
535 | 347 | #[lints(absolute_paths)] |
@@ -1029,21 +841,6 @@ define_Conf! { |
1029 | 841 | /// The minimum size (in bytes) to consider a type for passing by reference instead of by value. |
1030 | 842 | #[lints(large_types_passed_by_value)] |
1031 | 843 | pass_by_value_size_limit: u64 = 256, |
1032 | | - /// Named profiles of disallowed items (unrelated to Cargo build profiles). |
1033 | | - /// |
1034 | | - /// #### Example |
1035 | | - /// |
1036 | | - /// ```toml |
1037 | | - /// [profiles.persistent] |
1038 | | - /// disallowed-methods = [{ path = "std::env::temp_dir" }] |
1039 | | - /// disallowed-types = [{ path = "std::time::Instant", reason = "use our custom time API" }] |
1040 | | - /// |
1041 | | - /// [profiles.single_threaded] |
1042 | | - /// disallowed-methods = [{ path = "std::thread::spawn" }] |
1043 | | - /// ``` |
1044 | | - #[profiles = true] |
1045 | | - #[lints(disallowed_methods, disallowed_types)] |
1046 | | - profiles: FxHashMap<String, DisallowedProfile> = FxHashMap::default(), |
1047 | 844 | /// Lint "public" fields in a struct that are prefixed with an underscore based on their |
1048 | 845 | /// exported visibility, or whether they are marked as "pub". |
1049 | 846 | #[lints(pub_underscore_fields)] |
|
0 commit comments