Skip to content

Commit f921410

Browse files
committed
Fix clippy
1 parent b08576b commit f921410

15 files changed

+47
-47
lines changed

src/tools/clippy/clippy_lints/src/doc.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use rustc_parse::maybe_new_parser_from_source_str;
2121
use rustc_parse::parser::ForceCollect;
2222
use rustc_session::parse::ParseSess;
2323
use rustc_session::{declare_tool_lint, impl_lint_pass};
24+
use rustc_span::def_id::LocalDefId;
2425
use rustc_span::edition::Edition;
2526
use rustc_span::source_map::{BytePos, FilePathMapping, MultiSpan, SourceMap, Span};
2627
use rustc_span::{sym, FileName, Pos};
@@ -231,7 +232,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
231232
fpu.visit_expr(&body.value);
232233
lint_for_missing_headers(
233234
cx,
234-
item.hir_id(),
235+
item.def_id,
235236
item.span,
236237
sig,
237238
headers,
@@ -258,7 +259,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
258259
let headers = check_attrs(cx, &self.valid_idents, attrs);
259260
if let hir::TraitItemKind::Fn(ref sig, ..) = item.kind {
260261
if !in_external_macro(cx.tcx.sess, item.span) {
261-
lint_for_missing_headers(cx, item.hir_id(), item.span, sig, headers, None, None);
262+
lint_for_missing_headers(cx, item.def_id, item.span, sig, headers, None, None);
262263
}
263264
}
264265
}
@@ -279,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
279280
fpu.visit_expr(&body.value);
280281
lint_for_missing_headers(
281282
cx,
282-
item.hir_id(),
283+
item.def_id,
283284
item.span,
284285
sig,
285286
headers,
@@ -292,14 +293,14 @@ impl<'tcx> LateLintPass<'tcx> for DocMarkdown {
292293

293294
fn lint_for_missing_headers<'tcx>(
294295
cx: &LateContext<'tcx>,
295-
hir_id: hir::HirId,
296+
def_id: LocalDefId,
296297
span: impl Into<MultiSpan> + Copy,
297298
sig: &hir::FnSig<'_>,
298299
headers: DocHeaders,
299300
body_id: Option<hir::BodyId>,
300301
panic_span: Option<Span>,
301302
) {
302-
if !cx.access_levels.is_exported(hir_id) {
303+
if !cx.access_levels.is_exported(def_id) {
303304
return; // Private functions do not require doc comments
304305
}
305306
if !headers.safety && sig.header.unsafety == hir::Unsafety::Unsafe {
@@ -321,6 +322,7 @@ fn lint_for_missing_headers<'tcx>(
321322
);
322323
}
323324
if !headers.errors {
325+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
324326
if is_type_diagnostic_item(cx, return_ty(cx, hir_id), sym::result_type) {
325327
span_lint(
326328
cx,

src/tools/clippy/clippy_lints/src/enum_variants.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl LateLintPass<'_> for EnumVariantNames {
297297
}
298298
}
299299
if let ItemKind::Enum(ref def, _) = item.kind {
300-
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.hir_id())) {
300+
if !(self.avoid_breaking_exported_api && cx.access_levels.is_exported(item.def_id)) {
301301
check_variant(cx, self.threshold, def, &item_name, item_name_chars, item.span);
302302
}
303303
}

src/tools/clippy/clippy_lints/src/exhaustive_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
7171
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
7272
if_chain! {
7373
if let ItemKind::Enum(..) | ItemKind::Struct(..) = item.kind;
74-
if cx.access_levels.is_exported(item.hir_id());
74+
if cx.access_levels.is_exported(item.def_id);
7575
let attrs = cx.tcx.hir().attrs(item.hir_id());
7676
if !attrs.iter().any(|a| a.has_name(sym::non_exhaustive));
7777
then {

src/tools/clippy/clippy_lints/src/functions/must_use.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast::ast::Attribute;
22
use rustc_errors::Applicability;
3-
use rustc_hir::def_id::DefIdSet;
3+
use rustc_hir::def_id::{DefIdSet, LocalDefId};
44
use rustc_hir::{self as hir, def::Res, intravisit, QPath};
55
use rustc_lint::{LateContext, LintContext};
66
use rustc_middle::{
@@ -22,7 +22,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2222
let attrs = cx.tcx.hir().attrs(item.hir_id());
2323
let attr = must_use_attr(attrs);
2424
if let hir::ItemKind::Fn(ref sig, ref _generics, ref body_id) = item.kind {
25-
let is_public = cx.access_levels.is_exported(item.hir_id());
25+
let is_public = cx.access_levels.is_exported(item.def_id);
2626
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2727
if let Some(attr) = attr {
2828
check_needless_must_use(cx, sig.decl, item.hir_id(), item.span, fn_header_span, attr);
@@ -33,7 +33,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
3333
sig.decl,
3434
cx.tcx.hir().body(*body_id),
3535
item.span,
36-
item.hir_id(),
36+
item.def_id,
3737
item.span.with_hi(sig.decl.output.span().hi()),
3838
"this function could have a `#[must_use]` attribute",
3939
);
@@ -43,7 +43,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
4343

4444
pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
4545
if let hir::ImplItemKind::Fn(ref sig, ref body_id) = item.kind {
46-
let is_public = cx.access_levels.is_exported(item.hir_id());
46+
let is_public = cx.access_levels.is_exported(item.def_id);
4747
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4848
let attrs = cx.tcx.hir().attrs(item.hir_id());
4949
let attr = must_use_attr(attrs);
@@ -55,7 +55,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
5555
sig.decl,
5656
cx.tcx.hir().body(*body_id),
5757
item.span,
58-
item.hir_id(),
58+
item.def_id,
5959
item.span.with_hi(sig.decl.output.span().hi()),
6060
"this method could have a `#[must_use]` attribute",
6161
);
@@ -65,7 +65,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
6565

6666
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
6767
if let hir::TraitItemKind::Fn(ref sig, ref eid) = item.kind {
68-
let is_public = cx.access_levels.is_exported(item.hir_id());
68+
let is_public = cx.access_levels.is_exported(item.def_id);
6969
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
7070

7171
let attrs = cx.tcx.hir().attrs(item.hir_id());
@@ -80,7 +80,7 @@ pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitIte
8080
sig.decl,
8181
body,
8282
item.span,
83-
item.hir_id(),
83+
item.def_id,
8484
item.span.with_hi(sig.decl.output.span().hi()),
8585
"this method could have a `#[must_use]` attribute",
8686
);
@@ -132,7 +132,7 @@ fn check_must_use_candidate<'tcx>(
132132
decl: &'tcx hir::FnDecl<'_>,
133133
body: &'tcx hir::Body<'_>,
134134
item_span: Span,
135-
item_id: hir::HirId,
135+
item_id: LocalDefId,
136136
fn_span: Span,
137137
msg: &str,
138138
) {
@@ -141,7 +141,7 @@ fn check_must_use_candidate<'tcx>(
141141
|| in_external_macro(cx.sess(), item_span)
142142
|| returns_unit(decl)
143143
|| !cx.access_levels.is_exported(item_id)
144-
|| is_must_use_ty(cx, return_ty(cx, item_id))
144+
|| is_must_use_ty(cx, return_ty(cx, cx.tcx.hir().local_def_id_to_hir_id(item_id)))
145145
{
146146
return;
147147
}

src/tools/clippy/clippy_lints/src/functions/not_unsafe_ptr_arg_deref.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use rustc_hir::{self as hir, intravisit, HirIdSet};
22
use rustc_lint::LateContext;
33
use rustc_middle::{hir::map::Map, ty};
4+
use rustc_span::def_id::LocalDefId;
45

56
use clippy_utils::diagnostics::span_lint;
67
use clippy_utils::ty::type_is_unsafe_function;
@@ -21,13 +22,13 @@ pub(super) fn check_fn(
2122
intravisit::FnKind::Closure => return,
2223
};
2324

24-
check_raw_ptr(cx, unsafety, decl, body, hir_id);
25+
check_raw_ptr(cx, unsafety, decl, body, cx.tcx.hir().local_def_id(hir_id));
2526
}
2627

2728
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
2829
if let hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(eid)) = item.kind {
2930
let body = cx.tcx.hir().body(eid);
30-
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.hir_id());
31+
check_raw_ptr(cx, sig.header.unsafety, sig.decl, body, item.def_id);
3132
}
3233
}
3334

@@ -36,10 +37,10 @@ fn check_raw_ptr(
3637
unsafety: hir::Unsafety,
3738
decl: &'tcx hir::FnDecl<'tcx>,
3839
body: &'tcx hir::Body<'tcx>,
39-
hir_id: hir::HirId,
40+
def_id: LocalDefId,
4041
) {
4142
let expr = &body.value;
42-
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(hir_id) {
43+
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(def_id) {
4344
let raw_ptrs = iter_input_pats(decl, body)
4445
.zip(decl.inputs.iter())
4546
.filter_map(|(arg, ty)| raw_ptr_arg(arg, ty))

src/tools/clippy/clippy_lints/src/functions/result_unit_err.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::RESULT_UNIT_ERR;
1515

1616
pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
1717
if let hir::ItemKind::Fn(ref sig, ref _generics, _) = item.kind {
18-
let is_public = cx.access_levels.is_exported(item.hir_id());
18+
let is_public = cx.access_levels.is_exported(item.def_id);
1919
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
2020
if is_public {
2121
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);
@@ -25,7 +25,7 @@ pub(super) fn check_item(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2525

2626
pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<'_>) {
2727
if let hir::ImplItemKind::Fn(ref sig, _) = item.kind {
28-
let is_public = cx.access_levels.is_exported(item.hir_id());
28+
let is_public = cx.access_levels.is_exported(item.def_id);
2929
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
3030
if is_public && trait_ref_of_method(cx, item.hir_id()).is_none() {
3131
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);
@@ -35,7 +35,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'tcx>, item: &'tcx hir::ImplItem<
3535

3636
pub(super) fn check_trait_item(cx: &LateContext<'tcx>, item: &'tcx hir::TraitItem<'_>) {
3737
if let hir::TraitItemKind::Fn(ref sig, _) = item.kind {
38-
let is_public = cx.access_levels.is_exported(item.hir_id());
38+
let is_public = cx.access_levels.is_exported(item.def_id);
3939
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
4040
if is_public {
4141
check_result_unit_err(cx, sig.decl, item.span, fn_header_span);

src/tools/clippy/clippy_lints/src/implicit_hasher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for ImplicitHasher {
114114
}
115115
}
116116

117-
if !cx.access_levels.is_exported(item.hir_id()) {
117+
if !cx.access_levels.is_exported(item.def_id) {
118118
return;
119119
}
120120

src/tools/clippy/clippy_lints/src/len_zero.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
131131
if item.ident.name == sym::len;
132132
if let ImplItemKind::Fn(sig, _) = &item.kind;
133133
if sig.decl.implicit_self.has_implicit_self();
134-
if cx.access_levels.is_exported(item.hir_id());
134+
if cx.access_levels.is_exported(item.def_id);
135135
if matches!(sig.decl.output, FnRetTy::Return(_));
136136
if let Some(imp) = get_parent_as_impl(cx.tcx, item.hir_id());
137137
if imp.of_trait.is_none();
@@ -207,7 +207,7 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, trait_items
207207
}
208208
}
209209

210-
if cx.access_levels.is_exported(visited_trait.hir_id())
210+
if cx.access_levels.is_exported(visited_trait.def_id)
211211
&& trait_items.iter().any(|i| is_named_self(cx, i, sym::len))
212212
{
213213
let mut current_and_super_traits = DefIdSet::default();
@@ -331,11 +331,7 @@ fn check_for_is_empty(
331331
None,
332332
None,
333333
),
334-
Some(is_empty)
335-
if !cx
336-
.access_levels
337-
.is_exported(cx.tcx.hir().local_def_id_to_hir_id(is_empty.def_id.expect_local())) =>
338-
{
334+
Some(is_empty) if !cx.access_levels.is_exported(is_empty.def_id.expect_local()) => {
339335
(
340336
format!(
341337
"{} `{}` has a public `len` method, but a private `is_empty` method",

src/tools/clippy/clippy_lints/src/methods/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
19031903

19041904
then {
19051905
// if this impl block implements a trait, lint in trait definition instead
1906-
if !implements_trait && cx.access_levels.is_exported(impl_item.hir_id()) {
1906+
if !implements_trait && cx.access_levels.is_exported(impl_item.def_id) {
19071907
// check missing trait implementations
19081908
for method_config in &TRAIT_METHODS {
19091909
if name == method_config.method_name &&
@@ -1935,7 +1935,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
19351935

19361936
if sig.decl.implicit_self.has_implicit_self()
19371937
&& !(self.avoid_breaking_exported_api
1938-
&& cx.access_levels.is_exported(impl_item.hir_id()))
1938+
&& cx.access_levels.is_exported(impl_item.def_id))
19391939
{
19401940
wrong_self_convention::check(
19411941
cx,

src/tools/clippy/clippy_lints/src/missing_inline.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
8787
return;
8888
}
8989

90-
if !cx.access_levels.is_exported(it.hir_id()) {
90+
if !cx.access_levels.is_exported(it.def_id) {
9191
return;
9292
}
9393
match it.kind {
@@ -140,7 +140,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
140140
}
141141

142142
// If the item being implemented is not exported, then we don't need #[inline]
143-
if !cx.access_levels.is_exported(impl_item.hir_id()) {
143+
if !cx.access_levels.is_exported(impl_item.def_id) {
144144
return;
145145
}
146146

@@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
155155
};
156156

157157
if let Some(trait_def_id) = trait_def_id {
158-
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.hir_id()) {
158+
if trait_def_id.is_local() && !cx.access_levels.is_exported(impl_item.def_id) {
159159
// If a trait is being implemented for an item, and the
160160
// trait is not exported, we don't need #[inline]
161161
return;

src/tools/clippy/clippy_lints/src/new_without_default.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'tcx> LateLintPass<'tcx> for NewWithoutDefault {
9999
if_chain! {
100100
if sig.decl.inputs.is_empty();
101101
if name == sym::new;
102-
if cx.access_levels.is_reachable(id);
102+
if cx.access_levels.is_reachable(impl_item.def_id);
103103
let self_def_id = cx.tcx.hir().local_def_id(cx.tcx.hir().get_parent_item(id));
104104
let self_ty = cx.tcx.type_of(self_def_id);
105105
if TyS::same_type(self_ty, return_ty(cx, id));

src/tools/clippy/clippy_lints/src/pass_by_ref_or_value.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_hir::{BindingAnnotation, Body, FnDecl, HirId, Impl, ItemKind, MutTy, M
1414
use rustc_lint::{LateContext, LateLintPass};
1515
use rustc_middle::ty;
1616
use rustc_session::{declare_tool_lint, impl_lint_pass};
17+
use rustc_span::def_id::LocalDefId;
1718
use rustc_span::{sym, Span};
1819
use rustc_target::abi::LayoutOf;
1920
use rustc_target::spec::abi::Abi;
@@ -134,13 +135,12 @@ impl<'tcx> PassByRefOrValue {
134135
}
135136
}
136137

137-
fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, hir_id: HirId, decl: &FnDecl<'_>, span: Option<Span>) {
138-
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) {
138+
fn check_poly_fn(&mut self, cx: &LateContext<'tcx>, def_id: LocalDefId, decl: &FnDecl<'_>, span: Option<Span>) {
139+
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
139140
return;
140141
}
141-
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
142142

143-
let fn_sig = cx.tcx.fn_sig(fn_def_id);
143+
let fn_sig = cx.tcx.fn_sig(def_id);
144144
let fn_sig = cx.tcx.erase_late_bound_regions(fn_sig);
145145

146146
let fn_body = cx.enclosing_body.map(|id| cx.tcx.hir().body(id));
@@ -231,7 +231,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
231231
}
232232

233233
if let hir::TraitItemKind::Fn(method_sig, _) = &item.kind {
234-
self.check_poly_fn(cx, item.hir_id(), &*method_sig.decl, None);
234+
self.check_poly_fn(cx, item.def_id, &*method_sig.decl, None);
235235
}
236236
}
237237

@@ -278,6 +278,6 @@ impl<'tcx> LateLintPass<'tcx> for PassByRefOrValue {
278278
}
279279
}
280280

281-
self.check_poly_fn(cx, hir_id, decl, Some(span));
281+
self.check_poly_fn(cx, cx.tcx.hir().local_def_id(hir_id), decl, Some(span));
282282
}
283283
}

src/tools/clippy/clippy_lints/src/redundant_pub_crate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl_lint_pass!(RedundantPubCrate => [REDUNDANT_PUB_CRATE]);
4141
impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
4242
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
4343
if let VisibilityKind::Crate { .. } = item.vis.node {
44-
if !cx.access_levels.is_exported(item.hir_id()) {
44+
if !cx.access_levels.is_exported(item.def_id) {
4545
if let Some(false) = self.is_exported.last() {
4646
let span = item.span.with_hi(item.ident.span.hi());
4747
let descr = cx.tcx.def_kind(item.def_id).descr(item.def_id.to_def_id());
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantPubCrate {
6464
}
6565

6666
if let ItemKind::Mod { .. } = item.kind {
67-
self.is_exported.push(cx.access_levels.is_exported(item.hir_id()));
67+
self.is_exported.push(cx.access_levels.is_exported(item.def_id));
6868
}
6969
}
7070

src/tools/clippy/clippy_lints/src/unnecessary_wraps.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
8181
// Abort if public function/method or closure.
8282
match fn_kind {
8383
FnKind::ItemFn(..) | FnKind::Method(..) => {
84-
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(hir_id) {
84+
let def_id = cx.tcx.hir().local_def_id(hir_id);
85+
if self.avoid_breaking_exported_api && cx.access_levels.is_exported(def_id) {
8586
return;
8687
}
8788
},

src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
104104
fn check_item(&mut self, cx: &LateContext<'_>, it: &Item<'_>) {
105105
// do not lint public items or in macros
106106
if in_external_macro(cx.sess(), it.span)
107-
|| (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.hir_id()))
107+
|| (self.avoid_breaking_exported_api && cx.access_levels.is_exported(it.def_id))
108108
{
109109
return;
110110
}

0 commit comments

Comments
 (0)