Skip to content
/ rust Public
forked from rust-lang/rust

Commit 20200f6

Browse files
committed
Remove useless smallvec dependency in rustc_lint::non_local_def
1 parent 5c87ca2 commit 20200f6

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4133,7 +4133,6 @@ dependencies = [
41334133
"rustc_target",
41344134
"rustc_trait_selection",
41354135
"rustc_type_ir",
4136-
"smallvec",
41374136
"tracing",
41384137
"unicode-security",
41394138
]

compiler/rustc_lint/Cargo.toml

-1
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

+18-12
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

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

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

127124
let self_ty_has_local_parent = match impl_.self_ty.kind {
128125
TyKind::Path(QPath::Resolved(_, ty_path)) => {
129-
path_has_local_parent(ty_path, cx, &*local_parents)
126+
path_has_local_parent(ty_path, cx, parent, parent_parent)
130127
}
131128
TyKind::TraitObject([principle_poly_trait_ref, ..], _, _) => {
132129
path_has_local_parent(
133130
principle_poly_trait_ref.trait_ref.path,
134131
cx,
135-
&*local_parents,
132+
parent,
133+
parent_parent,
136134
)
137135
}
138136
TyKind::TraitObject([], _, _)
@@ -154,7 +152,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
154152

155153
let of_trait_has_local_parent = impl_
156154
.of_trait
157-
.map(|of_trait| path_has_local_parent(of_trait.path, cx, &*local_parents))
155+
.map(|of_trait| path_has_local_parent(of_trait.path, cx, parent, parent_parent))
158156
.unwrap_or(false);
159157

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

0 commit comments

Comments
 (0)