Skip to content

Commit cabc5a6

Browse files
authored
Revert "feat: Add profile-specific configuration for disallowed methods and types"
1 parent 3dcef78 commit cabc5a6

17 files changed

Lines changed: 39 additions & 999 deletions

File tree

CHANGELOG.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7609,7 +7609,6 @@ Released 2018-09-13
76097609
[`module-items-ordered-within-groupings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#module-items-ordered-within-groupings
76107610
[`msrv`]: https://doc.rust-lang.org/clippy/lint_configuration.html#msrv
76117611
[`pass-by-value-size-limit`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pass-by-value-size-limit
7612-
[`profiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#profiles
76137612
[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior
76147613
[`recursive-self-in-type-definitions`]: https://doc.rust-lang.org/clippy/lint_configuration.html#recursive-self-in-type-definitions
76157614
[`semicolon-inside-block-ignore-singleline`]: https://doc.rust-lang.org/clippy/lint_configuration.html#semicolon-inside-block-ignore-singleline

book/src/lint_configuration.md

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -986,28 +986,6 @@ The minimum size (in bytes) to consider a type for passing by reference instead
986986
* [`large_types_passed_by_value`](https://rust-lang.github.io/rust-clippy/master/index.html#large_types_passed_by_value)
987987

988988

989-
## `profiles`
990-
Named profiles of disallowed items (unrelated to Cargo build profiles).
991-
992-
#### Example
993-
994-
```toml
995-
[profiles.persistent]
996-
disallowed-methods = [{ path = "std::env::temp_dir" }]
997-
disallowed-types = [{ path = "std::time::Instant", reason = "use our custom time API" }]
998-
999-
[profiles.single_threaded]
1000-
disallowed-methods = [{ path = "std::thread::spawn" }]
1001-
```
1002-
1003-
**Default Value:** `{}`
1004-
1005-
---
1006-
**Affected lints:**
1007-
* [`disallowed_methods`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_methods)
1008-
* [`disallowed_types`](https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types)
1009-
1010-
1011989
## `pub-underscore-fields-behavior`
1012990
Lint "public" fields in a struct that are prefixed with an underscore based on their
1013991
exported visibility, or whether they are marked as "pub".

clippy_config/src/conf.rs

Lines changed: 4 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use crate::ClippyConfiguration;
22
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,
55
SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind,
66
SourceItemOrderingTraitAssocItemKinds, SourceItemOrderingWithinModuleItemGroupings,
77
};
88
use clippy_utils::msrvs::Msrv;
99
use itertools::Itertools;
10-
use rustc_data_structures::fx::FxHashMap;
1110
use rustc_errors::Applicability;
1211
use rustc_session::Session;
1312
use rustc_span::edit_distance::edit_distance;
@@ -223,74 +222,12 @@ macro_rules! deserialize {
223222
}};
224223
}
225224

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-
287225
macro_rules! define_Conf {
288226
($(
289227
$(#[doc = $doc:literal])+
290228
$(#[conf_deprecated($dep:literal, $new_conf:ident)])?
291229
$(#[default_text = $default_text:expr])?
292230
$(#[disallowed_paths_allow_replacements = $replacements_allowed:expr])?
293-
$(#[profiles = $profiles:expr])?
294231
$(#[lints($($for_lints:ident),* $(,)?)])?
295232
$name:ident: $ty:ty = $default:expr,
296233
)*) => {
@@ -345,20 +282,10 @@ macro_rules! define_Conf {
345282

346283
match field {
347284
$(Field::$name => {
348-
let field_span = name.span();
349285
// Is this a deprecated field, i.e., is `$dep` set? If so, push a warning.
350286
$(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)?);
362289
// Was this field set previously?
363290
if $name.is_some() {
364291
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 {
415342
)
416343
}
417344

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-
533345
define_Conf! {
534346
/// Which crates to allow absolute paths from
535347
#[lints(absolute_paths)]
@@ -1029,21 +841,6 @@ define_Conf! {
1029841
/// The minimum size (in bytes) to consider a type for passing by reference instead of by value.
1030842
#[lints(large_types_passed_by_value)]
1031843
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(),
1047844
/// Lint "public" fields in a struct that are prefixed with an underscore based on their
1048845
/// exported visibility, or whether they are marked as "pub".
1049846
#[lints(pub_underscore_fields)]

clippy_config/src/types.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath<R
5757
}
5858
}
5959

60-
#[derive(Debug, Default, Deserialize, Serialize)]
61-
#[serde(deny_unknown_fields, rename_all = "kebab-case")]
62-
pub struct DisallowedProfile {
63-
#[serde(default, alias = "disallowed_methods")]
64-
pub disallowed_methods: Vec<DisallowedPath>,
65-
#[serde(default, alias = "disallowed_types")]
66-
pub disallowed_types: Vec<DisallowedPath>,
67-
}
68-
6960
// `DisallowedPathEnum` is an implementation detail to enable the `Deserialize` implementation just
7061
// above. `DisallowedPathEnum` is not meant to be used outside of this file.
7162
#[derive(Debug, Deserialize, Serialize)]

0 commit comments

Comments
 (0)