Skip to content

Commit 627363e

Browse files
authored
Reverse dependency between clippy_utils and clippy_config (#13691)
In preparation of #13556, I want to remove the dependency on `clippy_config`, as I don't think that we want to publish that for outside consumers. To do this the 2 dependecies on `clippy_config` had to be removed: 1. The MSRV implementation was in `clippy_config`, but was required in `qualify_min_const`. I think exposing the MSRV infrastructure and the MSRVs we defined might also be helpful for `clippy_utils` users. I don't see why it should not be able to live in `clippy_utils` from a technical point of few. 2. The `create_disallowed_map` function that took in a `clippy_utils::types::DisallowedPath` is moved to the `DisallowedPath` implementation. This also fits there and is only useful for Clippy and not in `clippy_utils` for external consumers. `clippy_config` now depends in `clippy_utils`, so the dependecy just got reversed. But having the `clippy_utils` crate as the base of the dependency tree in Clippy makes sense. changelog: none
2 parents 83f7526 + 5c1811a commit 627363e

File tree

98 files changed

+122
-121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+122
-121
lines changed

book/src/development/adding_lints.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ need to ensure that the MSRV configured for the project is >= the MSRV of the
438438
required Rust feature. If multiple features are required, just use the one with
439439
a lower MSRV.
440440

441-
First, add an MSRV alias for the required feature in [`clippy_config::msrvs`].
441+
First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`].
442442
This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
443443

444444
```rust
@@ -517,7 +517,7 @@ define_Conf! {
517517
}
518518
```
519519

520-
[`clippy_config::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html
520+
[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html
521521

522522
Afterwards update the documentation for the book as described in [Adding configuration to a lint](#adding-configuration-to-a-lint).
523523

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/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::ClippyConfiguration;
2-
use crate::msrvs::Msrv;
32
use crate::types::{
43
DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering,
54
SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind,
65
SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
76
};
7+
use clippy_utils::msrvs::Msrv;
88
use rustc_errors::Applicability;
99
use rustc_session::Session;
1010
use rustc_span::edit_distance::edit_distance;

clippy_config/src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
rustc::untranslatable_diagnostic
1414
)]
1515

16-
extern crate rustc_ast;
17-
extern crate rustc_attr;
18-
#[allow(unused_extern_crates)]
19-
extern crate rustc_driver;
2016
extern crate rustc_errors;
17+
extern crate rustc_hir;
18+
extern crate rustc_middle;
2119
extern crate rustc_session;
2220
extern crate rustc_span;
23-
extern crate smallvec;
2421

2522
mod conf;
2623
mod metadata;
27-
pub mod msrvs;
2824
pub mod types;
2925

3026
pub use conf::{Conf, get_configuration_metadata, lookup_conf_file, sanitize_explanation};

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_dev/src/new_lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
273273
result.push_str(&if enable_msrv {
274274
formatdoc!(
275275
r"
276-
use clippy_config::msrvs::{{self, Msrv}};
276+
use clippy_utils::msrvs::{{self, Msrv}};
277277
use clippy_config::Conf;
278278
{pass_import}
279279
use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
@@ -399,7 +399,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
399399
let _: fmt::Result = writedoc!(
400400
lint_file_contents,
401401
r#"
402-
use clippy_config::msrvs::{{self, Msrv}};
402+
use clippy_utils::msrvs::{{self, Msrv}};
403403
use rustc_lint::{{{context_import}, LintContext}};
404404
405405
use super::{name_upper};

clippy_lints/src/almost_complete_range.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::Conf;
2-
use clippy_config::msrvs::{self, Msrv};
32
use clippy_utils::diagnostics::span_lint_and_then;
3+
use clippy_utils::msrvs::{self, Msrv};
44
use clippy_utils::source::{trim_span, walk_span_to_context};
55
use rustc_ast::ast::{Expr, ExprKind, LitKind, Pat, PatKind, RangeEnd, RangeLimits};
66
use rustc_errors::Applicability;

clippy_lints/src/approx_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_config::Conf;
2-
use clippy_config::msrvs::{self, Msrv};
32
use clippy_utils::diagnostics::span_lint_and_help;
3+
use clippy_utils::msrvs::{self, Msrv};
44
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
55
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/assigning_clones.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_config::Conf;
2-
use clippy_config::msrvs::{self, Msrv};
32
use clippy_utils::diagnostics::span_lint_and_then;
43
use clippy_utils::mir::{PossibleBorrowerMap, enclosing_mir};
4+
use clippy_utils::msrvs::{self, Msrv};
55
use clippy_utils::sugg::Sugg;
66
use clippy_utils::{is_diag_trait_item, is_in_test, last_path_segment, local_is_initialized, path_to_local};
77
use rustc_errors::Applicability;

clippy_lints/src/attrs/deprecated_cfg_attr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{Attribute, DEPRECATED_CFG_ATTR, DEPRECATED_CLIPPY_CFG_ATTR, unnecessary_clippy_cfg};
2-
use clippy_config::msrvs::{self, Msrv};
32
use clippy_utils::diagnostics::span_lint_and_sugg;
3+
use clippy_utils::msrvs::{self, Msrv};
44
use rustc_ast::AttrStyle;
55
use rustc_errors::Applicability;
66
use rustc_lint::EarlyContext;

0 commit comments

Comments
 (0)