Skip to content

Commit 0bf39bf

Browse files
committed
DisallowedPath -> ConfPath; REPLACEMENTS_ALLOWED -> REPLACEABLE
1 parent e6b63d1 commit 0bf39bf

File tree

8 files changed

+69
-71
lines changed

8 files changed

+69
-71
lines changed

clippy_config/src/conf.rs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::ClippyConfiguration;
22
use crate::types::{
3-
DisallowedPath, DisallowedPathWithoutReplacement, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour,
4-
Rename, SourceItemOrdering, SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings,
3+
ConfPath, ConfPathWithoutReplacement, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename,
4+
SourceItemOrdering, SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings,
55
SourceItemOrderingModuleItemKind, SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
66
SourceItemOrderingWithinModuleItemGroupings,
77
};
@@ -190,17 +190,16 @@ macro_rules! deserialize {
190190
(value, value_span)
191191
}};
192192

193-
($map:expr, $ty:ty, $errors:expr, $file:expr, $replacements_allowed:expr) => {{
193+
($map:expr, $ty:ty, $errors:expr, $file:expr, $replaceable:expr) => {{
194194
let array = $map.next_value::<Vec<toml::Spanned<toml::Value>>>()?;
195-
let mut disallowed_paths_span = Range {
195+
let mut conf_paths_span = Range {
196196
start: usize::MAX,
197197
end: usize::MIN,
198198
};
199-
let mut disallowed_paths = Vec::new();
199+
let mut conf_paths = Vec::new();
200200
for raw_value in array {
201201
let value_span = raw_value.span();
202-
let mut disallowed_path = match DisallowedPath::<$replacements_allowed>::deserialize(raw_value.into_inner())
203-
{
202+
let mut conf_path = match ConfPath::<$replaceable>::deserialize(raw_value.into_inner()) {
204203
Err(e) => {
205204
$errors.push(ConfError::spanned(
206205
$file,
@@ -210,13 +209,13 @@ macro_rules! deserialize {
210209
));
211210
continue;
212211
},
213-
Ok(disallowed_path) => disallowed_path,
212+
Ok(conf_path) => conf_path,
214213
};
215-
disallowed_paths_span = union(&disallowed_paths_span, &value_span);
216-
disallowed_path.set_span(span_from_toml_range($file, value_span));
217-
disallowed_paths.push(disallowed_path);
214+
conf_paths_span = union(&conf_paths_span, &value_span);
215+
conf_path.set_span(span_from_toml_range($file, value_span));
216+
conf_paths.push(conf_path);
218217
}
219-
(disallowed_paths, disallowed_paths_span)
218+
(conf_paths, conf_paths_span)
220219
}};
221220
}
222221

@@ -225,7 +224,7 @@ macro_rules! define_Conf {
225224
$(#[doc = $doc:literal])+
226225
$(#[conf_deprecated($dep:literal, $new_conf:ident)])?
227226
$(#[default_text = $default_text:expr])?
228-
$(#[disallowed_paths_allow_replacements = $replacements_allowed:expr])?
227+
$(#[conf_paths_allow_replacements = $replaceable:expr])?
229228
$(#[lints($($for_lints:ident),* $(,)?)])?
230229
$name:ident: $ty:ty = $default:expr,
231230
)*) => {
@@ -283,7 +282,7 @@ macro_rules! define_Conf {
283282
// Is this a deprecated field, i.e., is `$dep` set? If so, push a warning.
284283
$(warnings.push(ConfError::spanned(self.0, format!("deprecated field `{}`. {}", name.get_ref(), $dep), None, name.span()));)?
285284
let (value, value_span) =
286-
deserialize!(map, $ty, errors, self.0 $(, $replacements_allowed)?);
285+
deserialize!(map, $ty, errors, self.0 $(, $replaceable)?);
287286
// Was this field set previously?
288287
if $name.is_some() {
289288
errors.push(ConfError::spanned(self.0, format!("duplicate field `{}`", name.get_ref()), None, name.span()));
@@ -529,9 +528,9 @@ define_Conf! {
529528
)]
530529
avoid_breaking_exported_api: bool = true,
531530
/// The list of types which may not be held across an await point.
532-
#[disallowed_paths_allow_replacements = false]
531+
#[conf_paths_allow_replacements = false]
533532
#[lints(await_holding_invalid_type)]
534-
await_holding_invalid_types: Vec<DisallowedPathWithoutReplacement> = Vec::new(),
533+
await_holding_invalid_types: Vec<ConfPathWithoutReplacement> = Vec::new(),
535534
/// DEPRECATED LINT: BLACKLISTED_NAME.
536535
///
537536
/// Use the Disallowed Names lint instead
@@ -582,9 +581,9 @@ define_Conf! {
582581
/// - `replacement` (optional): suggested alternative macro
583582
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
584583
/// if the path doesn't exist, instead of emitting an error
585-
#[disallowed_paths_allow_replacements = true]
584+
#[conf_paths_allow_replacements = true]
586585
#[lints(disallowed_macros)]
587-
disallowed_macros: Vec<DisallowedPath> = Vec::new(),
586+
disallowed_macros: Vec<ConfPath> = Vec::new(),
588587
/// The list of disallowed methods, written as fully qualified paths.
589588
///
590589
/// **Fields:**
@@ -593,9 +592,9 @@ define_Conf! {
593592
/// - `replacement` (optional): suggested alternative method
594593
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
595594
/// if the path doesn't exist, instead of emitting an error
596-
#[disallowed_paths_allow_replacements = true]
595+
#[conf_paths_allow_replacements = true]
597596
#[lints(disallowed_methods)]
598-
disallowed_methods: Vec<DisallowedPath> = Vec::new(),
597+
disallowed_methods: Vec<ConfPath> = Vec::new(),
599598
/// The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
600599
/// `".."` can be used as part of the list to indicate that the configured values should be appended to the
601600
/// default configuration of Clippy. By default, any configuration will replace the default value.
@@ -609,9 +608,9 @@ define_Conf! {
609608
/// - `replacement` (optional): suggested alternative type
610609
/// - `allow-invalid` (optional, `false` by default): when set to `true`, it will ignore this entry
611610
/// if the path doesn't exist, instead of emitting an error
612-
#[disallowed_paths_allow_replacements = true]
611+
#[conf_paths_allow_replacements = true]
613612
#[lints(disallowed_types)]
614-
disallowed_types: Vec<DisallowedPath> = Vec::new(),
613+
disallowed_types: Vec<ConfPath> = Vec::new(),
615614
/// The list of words this lint should not consider as identifiers needing ticks. The value
616615
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
617616
/// default configuration of Clippy. By default, any configuration will replace the default value. For example:

clippy_config/src/types.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ pub struct Rename {
1818
pub rename: String,
1919
}
2020

21-
pub type DisallowedPathWithoutReplacement = DisallowedPath<false>;
21+
pub type ConfPathWithoutReplacement = ConfPath<false>;
2222

2323
#[derive(Debug, Serialize)]
24-
pub struct DisallowedPath<const REPLACEMENT_ALLOWED: bool = true> {
24+
pub struct ConfPath<const REPLACEABLE: bool = true> {
2525
path: String,
2626
reason: Option<String>,
2727
replacement: Option<String>,
@@ -31,20 +31,20 @@ pub struct DisallowedPath<const REPLACEMENT_ALLOWED: bool = true> {
3131
/// This could be useful when conditional compilation is used, or when a clippy.toml file is
3232
/// shared among multiple projects.
3333
allow_invalid: bool,
34-
/// The span of the `DisallowedPath`.
34+
/// The span of the `ConfPath`.
3535
///
3636
/// Used for diagnostics.
3737
#[serde(skip_serializing)]
3838
span: Span,
3939
}
4040

41-
impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath<REPLACEMENT_ALLOWED> {
41+
impl<'de, const REPLACEABLE: bool> Deserialize<'de> for ConfPath<REPLACEABLE> {
4242
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
4343
where
4444
D: Deserializer<'de>,
4545
{
46-
let enum_ = DisallowedPathEnum::deserialize(deserializer)?;
47-
if !REPLACEMENT_ALLOWED && enum_.replacement().is_some() {
46+
let enum_ = ConfPathEnum::deserialize(deserializer)?;
47+
if !REPLACEABLE && enum_.replacement().is_some() {
4848
return Err(de::Error::custom("replacement not allowed for this configuration"));
4949
}
5050
Ok(Self {
@@ -57,11 +57,11 @@ impl<'de, const REPLACEMENT_ALLOWED: bool> Deserialize<'de> for DisallowedPath<R
5757
}
5858
}
5959

60-
// `DisallowedPathEnum` is an implementation detail to enable the `Deserialize` implementation just
61-
// above. `DisallowedPathEnum` is not meant to be used outside of this file.
60+
// `ConfPathEnum` is an implementation detail to enable the `Deserialize` implementation just above.
61+
// `ConfPathEnum` is not meant to be used outside of this file.
6262
#[derive(Debug, Deserialize, Serialize)]
6363
#[serde(untagged, deny_unknown_fields)]
64-
enum DisallowedPathEnum {
64+
enum ConfPathEnum {
6565
Simple(String),
6666
WithReason {
6767
path: String,
@@ -72,7 +72,7 @@ enum DisallowedPathEnum {
7272
},
7373
}
7474

75-
impl<const REPLACEMENT_ALLOWED: bool> DisallowedPath<REPLACEMENT_ALLOWED> {
75+
impl<const REPLACEABLE: bool> ConfPath<REPLACEABLE> {
7676
pub fn path(&self) -> &str {
7777
&self.path
7878
}
@@ -101,7 +101,7 @@ impl<const REPLACEMENT_ALLOWED: bool> DisallowedPath<REPLACEMENT_ALLOWED> {
101101
}
102102
}
103103

104-
impl DisallowedPathEnum {
104+
impl ConfPathEnum {
105105
pub fn path(&self) -> &str {
106106
let (Self::Simple(path) | Self::WithReason { path, .. }) = self;
107107

@@ -132,22 +132,21 @@ impl DisallowedPathEnum {
132132

133133
/// Creates a map of disallowed items to the reason they were disallowed.
134134
#[allow(clippy::type_complexity)]
135-
pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
135+
pub fn create_conf_path_map<const REPLACEABLE: bool>(
136136
tcx: TyCtxt<'_>,
137-
disallowed_paths: &'static [DisallowedPath<REPLACEMENT_ALLOWED>],
137+
conf_paths: &'static [ConfPath<REPLACEABLE>],
138138
ns: PathNS,
139139
def_kind_predicate: impl Fn(DefKind) -> bool,
140140
predicate_description: &str,
141141
allow_prim_tys: bool,
142142
) -> (
143-
DefIdMap<(&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)>,
144-
FxHashMap<PrimTy, (&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)>,
143+
DefIdMap<(&'static str, &'static ConfPath<REPLACEABLE>)>,
144+
FxHashMap<PrimTy, (&'static str, &'static ConfPath<REPLACEABLE>)>,
145145
) {
146-
let mut def_ids: DefIdMap<(&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)> = DefIdMap::default();
147-
let mut prim_tys: FxHashMap<PrimTy, (&'static str, &'static DisallowedPath<REPLACEMENT_ALLOWED>)> =
148-
FxHashMap::default();
149-
for disallowed_path in disallowed_paths {
150-
let path = disallowed_path.path();
146+
let mut def_ids: DefIdMap<(&'static str, &ConfPath<REPLACEABLE>)> = DefIdMap::default();
147+
let mut prim_tys: FxHashMap<PrimTy, (&'static str, &ConfPath<REPLACEABLE>)> = FxHashMap::default();
148+
for conf_path in conf_paths {
149+
let path = conf_path.path();
151150
let sym_path: Vec<Symbol> = path.split("::").map(Symbol::intern).collect();
152151
let mut resolutions = lookup_path(tcx, ns, &sym_path);
153152
resolutions.retain(|&def_id| def_kind_predicate(tcx.def_kind(def_id)));
@@ -162,7 +161,7 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
162161

163162
if resolutions.is_empty()
164163
&& prim_ty.is_none()
165-
&& !disallowed_path.allow_invalid
164+
&& !conf_path.allow_invalid
166165
// Don't warn about unloaded crates:
167166
// https://github.com/rust-lang/rust-clippy/pull/14397#issuecomment-2848328221
168167
&& (sym_path.len() < 2 || !find_crates(tcx, sym_path[0]).is_empty())
@@ -179,16 +178,16 @@ pub fn create_disallowed_map<const REPLACEMENT_ALLOWED: bool>(
179178
};
180179
tcx.sess
181180
.dcx()
182-
.struct_span_warn(disallowed_path.span(), message)
181+
.struct_span_warn(conf_path.span(), message)
183182
.with_help("add `allow-invalid = true` to the entry to suppress this warning")
184183
.emit();
185184
}
186185

187186
for def_id in resolutions {
188-
def_ids.insert(def_id, (path, disallowed_path));
187+
def_ids.insert(def_id, (path, conf_path));
189188
}
190189
if let Some(ty) = prim_ty {
191-
prim_tys.insert(ty, (path, disallowed_path));
190+
prim_tys.insert(ty, (path, conf_path));
192191
}
193192
}
194193

clippy_lints/src/await_holding_invalid.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_config::types::{DisallowedPathWithoutReplacement, create_disallowed_map};
2+
use clippy_config::types::{ConfPathWithoutReplacement, create_conf_path_map};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::paths::{self, PathNS};
55
use rustc_hir as hir;
@@ -174,12 +174,12 @@ declare_clippy_lint! {
174174
impl_lint_pass!(AwaitHolding => [AWAIT_HOLDING_LOCK, AWAIT_HOLDING_REFCELL_REF, AWAIT_HOLDING_INVALID_TYPE]);
175175

176176
pub struct AwaitHolding {
177-
def_ids: DefIdMap<(&'static str, &'static DisallowedPathWithoutReplacement)>,
177+
def_ids: DefIdMap<(&'static str, &'static ConfPathWithoutReplacement)>,
178178
}
179179

180180
impl AwaitHolding {
181181
pub(crate) fn new(tcx: TyCtxt<'_>, conf: &'static Conf) -> Self {
182-
let (def_ids, _) = create_disallowed_map(
182+
let (def_ids, _) = create_conf_path_map(
183183
tcx,
184184
&conf.await_holding_invalid_types,
185185
PathNS::Type,
@@ -252,8 +252,8 @@ impl AwaitHolding {
252252
);
253253
},
254254
);
255-
} else if let Some(&(path, disallowed_path)) = self.def_ids.get(&adt.did()) {
256-
emit_invalid_type(cx, ty_cause.source_info.span, path, disallowed_path);
255+
} else if let Some(&(path, conf_path)) = self.def_ids.get(&adt.did()) {
256+
emit_invalid_type(cx, ty_cause.source_info.span, path, conf_path);
257257
}
258258
}
259259
}
@@ -264,14 +264,14 @@ fn emit_invalid_type(
264264
cx: &LateContext<'_>,
265265
span: Span,
266266
path: &'static str,
267-
disallowed_path: &'static DisallowedPathWithoutReplacement,
267+
conf_path: &'static ConfPathWithoutReplacement,
268268
) {
269269
span_lint_and_then(
270270
cx,
271271
AWAIT_HOLDING_INVALID_TYPE,
272272
span,
273273
format!("holding a disallowed type across an await point `{path}`"),
274-
disallowed_path.diag_amendment(span),
274+
conf_path.diag_amendment(span),
275275
);
276276
}
277277

clippy_lints/src/disallowed_macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_config::types::{DisallowedPath, create_disallowed_map};
2+
use clippy_config::types::{ConfPath, create_conf_path_map};
33
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
44
use clippy_utils::macros::macro_backtrace;
55
use clippy_utils::paths::PathNS;
@@ -63,7 +63,7 @@ declare_clippy_lint! {
6363
}
6464

6565
pub struct DisallowedMacros {
66-
disallowed: DefIdMap<(&'static str, &'static DisallowedPath)>,
66+
disallowed: DefIdMap<(&'static str, &'static ConfPath)>,
6767
seen: FxHashSet<ExpnId>,
6868
// Track the most recently seen node that can have a `derive` attribute.
6969
// Needed to use the correct lint level.
@@ -76,7 +76,7 @@ pub struct DisallowedMacros {
7676

7777
impl DisallowedMacros {
7878
pub fn new(tcx: TyCtxt<'_>, conf: &'static Conf, early_macro_cache: AttrStorage) -> Self {
79-
let (disallowed, _) = create_disallowed_map(
79+
let (disallowed, _) = create_conf_path_map(
8080
tcx,
8181
&conf.disallowed_macros,
8282
PathNS::Macro,
@@ -102,9 +102,9 @@ impl DisallowedMacros {
102102
return;
103103
}
104104

105-
if let Some(&(path, disallowed_path)) = self.disallowed.get(&mac.def_id) {
105+
if let Some(&(path, conf_path)) = self.disallowed.get(&mac.def_id) {
106106
let msg = format!("use of a disallowed macro `{path}`");
107-
let add_note = disallowed_path.diag_amendment(mac.span);
107+
let add_note = conf_path.diag_amendment(mac.span);
108108
if matches!(mac.kind, MacroKind::Derive)
109109
&& let Some(derive_src) = derive_src
110110
{

clippy_lints/src/disallowed_methods.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_config::types::{DisallowedPath, create_disallowed_map};
2+
use clippy_config::types::{ConfPath, create_conf_path_map};
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use clippy_utils::paths::PathNS;
55
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -62,12 +62,12 @@ declare_clippy_lint! {
6262
}
6363

6464
pub struct DisallowedMethods {
65-
disallowed: DefIdMap<(&'static str, &'static DisallowedPath)>,
65+
disallowed: DefIdMap<(&'static str, &'static ConfPath)>,
6666
}
6767

6868
impl DisallowedMethods {
6969
pub fn new(tcx: TyCtxt<'_>, conf: &'static Conf) -> Self {
70-
let (disallowed, _) = create_disallowed_map(
70+
let (disallowed, _) = create_conf_path_map(
7171
tcx,
7272
&conf.disallowed_methods,
7373
PathNS::Value,
@@ -95,13 +95,13 @@ impl<'tcx> LateLintPass<'tcx> for DisallowedMethods {
9595
},
9696
_ => return,
9797
};
98-
if let Some(&(path, disallowed_path)) = self.disallowed.get(&id) {
98+
if let Some(&(path, conf_path)) = self.disallowed.get(&id) {
9999
span_lint_and_then(
100100
cx,
101101
DISALLOWED_METHODS,
102102
span,
103103
format!("use of a disallowed method `{path}`"),
104-
disallowed_path.diag_amendment(span),
104+
conf_path.diag_amendment(span),
105105
);
106106
}
107107
}

0 commit comments

Comments
 (0)