Skip to content

Commit 339797e

Browse files
committed
Eliminate rustc_lint_defs' dependency on rustc_ast.
It currently only depends on two things: - `rustc_ast::AttrId`: this is just a re-export of `rustc_span::AttrId`, so we can import the original instead. - `rustc_ast::AttributeExt`: needed only for the `name` and `id` methods. We can instead pass in the `name` and `id` directly.
1 parent 9454be3 commit 339797e

7 files changed

Lines changed: 15 additions & 11 deletions

File tree

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4184,7 +4184,6 @@ dependencies = [
41844184
name = "rustc_lint_defs"
41854185
version = "0.0.0"
41864186
dependencies = [
4187-
"rustc_ast",
41884187
"rustc_data_structures",
41894188
"rustc_error_messages",
41904189
"rustc_hir_id",

compiler/rustc_lint/src/levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
671671
continue;
672672
}
673673

674-
let (level, lint_id) = match Level::from_attr(attr) {
674+
let (level, lint_id) = match Level::from_attr(attr.name(), || attr.id()) {
675675
None => continue,
676676
// This is the only lint level with a `LintExpectationId` that can be created from
677677
// an attribute.

compiler/rustc_lint_defs/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
rustc_ast = { path = "../rustc_ast" }
98
rustc_data_structures = { path = "../rustc_data_structures" }
109
rustc_error_messages = { path = "../rustc_error_messages" }
1110
rustc_hir_id = { path = "../rustc_hir_id" }

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::borrow::Cow;
22
use std::fmt::Display;
33

4-
use rustc_ast::AttrId;
5-
use rustc_ast::attr::AttributeExt;
64
use rustc_data_structures::fx::FxIndexSet;
75
use rustc_data_structures::stable_hasher::{
86
HashStable, HashStableContext, StableCompare, StableHasher, ToStableHashKey,
@@ -12,7 +10,7 @@ use rustc_hir_id::{HirId, ItemLocalId};
1210
use rustc_macros::{Decodable, Encodable, HashStable};
1311
use rustc_span::def_id::DefPathHash;
1412
pub use rustc_span::edition::Edition;
15-
use rustc_span::{Ident, Symbol, sym};
13+
use rustc_span::{AttrId, Ident, Symbol, sym};
1614
use serde::{Deserialize, Serialize};
1715

1816
pub use self::Level::*;
@@ -238,8 +236,11 @@ impl Level {
238236
}
239237

240238
/// Converts an `Attribute` to a level.
241-
pub fn from_attr(attr: &impl AttributeExt) -> Option<(Self, Option<LintExpectationId>)> {
242-
attr.name().and_then(|name| Self::from_symbol(name, || Some(attr.id())))
239+
pub fn from_attr(
240+
attr_name: Option<Symbol>,
241+
attr_id: impl Fn() -> AttrId,
242+
) -> Option<(Self, Option<LintExpectationId>)> {
243+
attr_name.and_then(|name| Self::from_symbol(name, || Some(attr_id())))
243244
}
244245

245246
/// Converts a `Symbol` to a level.

compiler/rustc_mir_build/src/builder/scope.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12981298
break;
12991299
}
13001300

1301-
if self.tcx.hir_attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
1301+
if self
1302+
.tcx
1303+
.hir_attrs(id)
1304+
.iter()
1305+
.any(|attr| Level::from_attr(attr.name(), || attr.id()).is_some())
1306+
{
13021307
// This is a rare case. It's for a node path that doesn't reach the root due to an
13031308
// intervening lint level attribute. This result doesn't get cached.
13041309
return id;

src/tools/clippy/clippy_lints/src/collapsible_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ impl CollapsibleIf {
238238
},
239239

240240
[attr]
241-
if matches!(Level::from_attr(attr), Some((Level::Expect, _)))
241+
if matches!(Level::from_attr(attr.name(), || attr.id()), Some((Level::Expect, _)))
242242
&& let Some(metas) = attr.meta_item_list()
243243
&& let Some(MetaItemInner::MetaItem(meta_item)) = metas.first()
244244
&& let [tool, lint_name] = meta_item.path.segments.as_slice()

src/tools/clippy/clippy_lints/src/returns/needless_return.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ fn check_final_expr<'tcx>(
181181
match cx.tcx.hir_attrs(expr.hir_id) {
182182
[] => {},
183183
[attr] => {
184-
if matches!(Level::from_attr(attr), Some((Level::Expect, _)))
184+
if matches!(Level::from_attr(attr.name(), || attr.id()), Some((Level::Expect, _)))
185185
&& let metas = attr.meta_item_list()
186186
&& let Some(lst) = metas
187187
&& let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice()

0 commit comments

Comments
 (0)