Skip to content

Commit 81483d4

Browse files
committed
Move create_disallowed_map to clippy_config
1 parent 4460db0 commit 81483d4

File tree

8 files changed

+24
-19
lines changed

8 files changed

+24
-19
lines changed

clippy_config/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
name = "clippy_config"
33
version = "0.1.84"
44
edition = "2021"
5+
publish = false
56

67
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
78

89
[dependencies]
10+
clippy_utils = { path = "../clippy_utils" }
911
itertools = "0.12"
1012
serde = { version = "1.0", features = ["derive"] }
1113
toml = "0.7.3"

clippy_config/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
)]
1515

1616
extern crate rustc_errors;
17+
extern crate rustc_hir;
18+
extern crate rustc_middle;
1719
extern crate rustc_session;
1820
extern crate rustc_span;
1921

clippy_config/src/types.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use clippy_utils::def_path_def_ids;
2+
use rustc_hir::def_id::DefIdMap;
3+
use rustc_middle::ty::TyCtxt;
14
use serde::de::{self, Deserializer, Visitor};
25
use serde::{Deserialize, Serialize, ser};
36
use std::collections::HashMap;
@@ -31,6 +34,18 @@ impl DisallowedPath {
3134
}
3235
}
3336

37+
/// Creates a map of disallowed items to the reason they were disallowed.
38+
pub fn create_disallowed_map(
39+
tcx: TyCtxt<'_>,
40+
disallowed: &'static [DisallowedPath],
41+
) -> DefIdMap<(&'static str, Option<&'static str>)> {
42+
disallowed
43+
.iter()
44+
.map(|x| (x.path(), x.path().split("::").collect::<Vec<_>>(), x.reason()))
45+
.flat_map(|(name, path, reason)| def_path_def_ids(tcx, &path).map(move |id| (id, (name, reason))))
46+
.collect()
47+
}
48+
3449
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
3550
pub enum MatchLintBehaviour {
3651
AllTypes,

clippy_lints/src/await_holding_invalid.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_config::Conf;
2+
use clippy_config::types::create_disallowed_map;
23
use clippy_utils::diagnostics::span_lint_and_then;
3-
use clippy_utils::{create_disallowed_map, match_def_path, paths};
4+
use clippy_utils::{match_def_path, paths};
45
use rustc_hir as hir;
56
use rustc_hir::def_id::{DefId, DefIdMap};
67
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/disallowed_macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_utils::create_disallowed_map;
2+
use clippy_config::types::create_disallowed_map;
33
use clippy_utils::diagnostics::{span_lint_and_then, span_lint_hir_and_then};
44
use clippy_utils::macros::macro_backtrace;
55
use rustc_data_structures::fx::FxHashSet;

clippy_lints/src/disallowed_methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_config::Conf;
2-
use clippy_utils::create_disallowed_map;
2+
use clippy_config::types::create_disallowed_map;
33
use clippy_utils::diagnostics::span_lint_and_then;
44
use rustc_hir::def::{CtorKind, DefKind, Res};
55
use rustc_hir::def_id::DefIdMap;

clippy_utils/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
name = "clippy_utils"
33
version = "0.1.84"
44
edition = "2021"
5-
publish = false
65

76
[dependencies]
8-
clippy_config = { path = "../clippy_config" }
97
arrayvec = { version = "0.7", default-features = false }
108
itertools = "0.12"
119
# FIXME(f16_f128): remove when no longer needed for parsing

clippy_utils/src/lib.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,14 @@ use std::hash::BuildHasherDefault;
9191
use std::iter::{once, repeat};
9292
use std::sync::{Mutex, MutexGuard, OnceLock};
9393

94-
use clippy_config::types::DisallowedPath;
9594
use itertools::Itertools;
9695
use rustc_ast::ast::{self, LitKind, RangeLimits};
9796
use rustc_data_structures::fx::FxHashMap;
9897
use rustc_data_structures::packed::Pu128;
9998
use rustc_data_structures::unhash::UnhashMap;
10099
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
101100
use rustc_hir::def::{DefKind, Res};
102-
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LOCAL_CRATE, LocalDefId, LocalModDefId};
101+
use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId};
103102
use rustc_hir::definitions::{DefPath, DefPathData};
104103
use rustc_hir::hir_id::{HirIdMap, HirIdSet};
105104
use rustc_hir::intravisit::{FnKind, Visitor, walk_expr};
@@ -750,18 +749,6 @@ pub fn def_path_def_ids(tcx: TyCtxt<'_>, path: &[&str]) -> impl Iterator<Item =
750749
def_path_res(tcx, path).into_iter().filter_map(|res| res.opt_def_id())
751750
}
752751

753-
/// Creates a map of disallowed items to the reason they were disallowed.
754-
pub fn create_disallowed_map(
755-
tcx: TyCtxt<'_>,
756-
disallowed: &'static [DisallowedPath],
757-
) -> DefIdMap<(&'static str, Option<&'static str>)> {
758-
disallowed
759-
.iter()
760-
.map(|x| (x.path(), x.path().split("::").collect::<Vec<_>>(), x.reason()))
761-
.flat_map(|(name, path, reason)| def_path_def_ids(tcx, &path).map(move |id| (id, (name, reason))))
762-
.collect()
763-
}
764-
765752
/// Convenience function to get the `DefId` of a trait by path.
766753
/// It could be a trait or trait alias.
767754
///

0 commit comments

Comments
 (0)