Skip to content

Commit 8501e52

Browse files
committed
Remove useless smallvec dependency in rustc_lint::non_local_def
1 parent cc482fb commit 8501e52

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4097,7 +4097,6 @@ dependencies = [
40974097
"rustc_target",
40984098
"rustc_trait_selection",
40994099
"rustc_type_ir",
4100-
"smallvec",
41014100
"tracing",
41024101
"unicode-security",
41034102
]

compiler/rustc_lint/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ rustc_span = { path = "../rustc_span" }
2323
rustc_target = { path = "../rustc_target" }
2424
rustc_trait_selection = { path = "../rustc_trait_selection" }
2525
rustc_type_ir = { path = "../rustc_type_ir" }
26-
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2726
tracing = "0.1"
2827
unicode-security = "0.1.0"
2928
# tidy-alphabetical-end

compiler/rustc_lint/src/non_local_def.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use rustc_hir::{def::DefKind, Body, Item, ItemKind, Node, Path, QPath, TyKind};
22
use rustc_span::def_id::{DefId, LOCAL_CRATE};
33
use rustc_span::{sym, symbol::kw, ExpnKind, MacroKind};
44

5-
use smallvec::{smallvec, SmallVec};
6-
75
use crate::lints::{NonLocalDefinitionsCargoUpdateNote, NonLocalDefinitionsDiag};
86
use crate::{LateContext, LateLintPass, LintContext};
97

@@ -113,25 +111,25 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
113111
// is using local items and so we don't lint on it.
114112

115113
// We also ignore anon-const in item by including the anon-const
116-
// parent as well; and since it's quite uncommon, we use smallvec
117-
// to avoid unnecessary heap allocations.
118-
let local_parents: SmallVec<[DefId; 1]> = if parent_def_kind == DefKind::Const
114+
// parent as well.
115+
let parent_parent = if parent_def_kind == DefKind::Const
119116
&& parent_opt_item_name == Some(kw::Underscore)
120117
{
121-
smallvec![parent, cx.tcx.parent(parent)]
118+
Some(cx.tcx.parent(parent))
122119
} else {
123-
smallvec![parent]
120+
None
124121
};
125122

126123
let self_ty_has_local_parent = match impl_.self_ty.kind {
127124
TyKind::Path(QPath::Resolved(_, ty_path)) => {
128-
path_has_local_parent(ty_path, cx, &*local_parents)
125+
path_has_local_parent(ty_path, cx, parent, parent_parent)
129126
}
130127
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
131128
path_has_local_parent(
132129
principle_poly_trait_ref.trait_ref.path,
133130
cx,
134-
&*local_parents,
131+
parent,
132+
parent_parent,
135133
)
136134
}
137135
TyKind::TraitObject([], _, _)
@@ -153,7 +151,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
153151

154152
let of_trait_has_local_parent = impl_
155153
.of_trait
156-
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
154+
.map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent))
157155
.unwrap_or(false);
158156

159157
// If none of them have a local parent (LOGICAL NOR) this means that
@@ -217,6 +215,14 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
217215
/// std::convert::PartialEq<Foo<Bar>>
218216
/// ^^^^^^^^^^^^^^^^^^^^^^^
219217
/// ```
220-
fn path_has_local_parent(path: &Path<'_>, cx: &LateContext<'_>, local_parents: &[DefId]) -> bool {
221-
path.res.opt_def_id().is_some_and(|did| local_parents.contains(&cx.tcx.parent(did)))
218+
fn path_has_local_parent(
219+
path: &Path<'_>,
220+
cx: &LateContext<'_>,
221+
impl_parent: DefId,
222+
impl_parent_parent: Option<DefId>,
223+
) -> bool {
224+
path.res.opt_def_id().is_some_and(|did| {
225+
let res_parent = cx.tcx.parent(did);
226+
res_parent == impl_parent || Some(res_parent) == impl_parent_parent
227+
})
222228
}

0 commit comments

Comments
 (0)