Skip to content

Commit d1d0fee

Browse files
authored
Rustup (#14445)
r? @ghost changelog: none
2 parents f2feb0f + a086879 commit d1d0fee

File tree

101 files changed

+380
-453
lines changed

Some content is hidden

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

101 files changed

+380
-453
lines changed

clippy_lints/src/arbitrary_source_item_ordering.rs

+35-60
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use clippy_config::types::{
66
};
77
use clippy_utils::diagnostics::span_lint_and_note;
88
use rustc_hir::{
9-
AssocItemKind, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind, UseKind,
10-
Variant, VariantData,
9+
AssocItemKind, FieldDef, HirId, ImplItemRef, IsAuto, Item, ItemKind, Mod, QPath, TraitItemRef, TyKind, Variant,
10+
VariantData,
1111
};
1212
use rustc_lint::{LateContext, LateLintPass, LintContext};
1313
use rustc_session::impl_lint_pass;
@@ -202,11 +202,7 @@ impl ArbitrarySourceItemOrdering {
202202
}
203203

204204
/// Produces a linting warning for incorrectly ordered item members.
205-
fn lint_member_name<T: LintContext>(
206-
cx: &T,
207-
ident: &rustc_span::symbol::Ident,
208-
before_ident: &rustc_span::symbol::Ident,
209-
) {
205+
fn lint_member_name<T: LintContext>(cx: &T, ident: &rustc_span::Ident, before_ident: &rustc_span::Ident) {
210206
span_lint_and_note(
211207
cx,
212208
ARBITRARY_SOURCE_ITEM_ORDERING,
@@ -218,21 +214,18 @@ impl ArbitrarySourceItemOrdering {
218214
}
219215

220216
fn lint_member_item<T: LintContext>(cx: &T, item: &Item<'_>, before_item: &Item<'_>, msg: &'static str) {
221-
let span = if item.ident.as_str().is_empty() {
222-
&item.span
217+
let span = if let Some(ident) = item.kind.ident() {
218+
ident.span
223219
} else {
224-
&item.ident.span
220+
item.span
225221
};
226222

227-
let (before_span, note) = if before_item.ident.as_str().is_empty() {
228-
(
229-
&before_item.span,
230-
"should be placed before the following item".to_owned(),
231-
)
223+
let (before_span, note) = if let Some(ident) = before_item.kind.ident() {
224+
(ident.span, format!("should be placed before `{}`", ident.as_str(),))
232225
} else {
233226
(
234-
&before_item.ident.span,
235-
format!("should be placed before `{}`", before_item.ident.as_str(),),
227+
before_item.span,
228+
"should be placed before the following item".to_owned(),
236229
)
237230
};
238231

@@ -241,7 +234,7 @@ impl ArbitrarySourceItemOrdering {
241234
return;
242235
}
243236

244-
span_lint_and_note(cx, ARBITRARY_SOURCE_ITEM_ORDERING, *span, msg, Some(*before_span), note);
237+
span_lint_and_note(cx, ARBITRARY_SOURCE_ITEM_ORDERING, span, msg, Some(before_span), note);
245238
}
246239

247240
/// Produces a linting warning for incorrectly ordered trait items.
@@ -263,7 +256,7 @@ impl ArbitrarySourceItemOrdering {
263256
impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
264257
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
265258
match &item.kind {
266-
ItemKind::Enum(enum_def, _generics) if self.enable_ordering_for_enum => {
259+
ItemKind::Enum(_, enum_def, _generics) if self.enable_ordering_for_enum => {
267260
let mut cur_v: Option<&Variant<'_>> = None;
268261
for variant in enum_def.variants {
269262
if variant.span.in_external_macro(cx.sess().source_map()) {
@@ -278,7 +271,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
278271
cur_v = Some(variant);
279272
}
280273
},
281-
ItemKind::Struct(VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
274+
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
282275
let mut cur_f: Option<&FieldDef<'_>> = None;
283276
for field in *fields {
284277
if field.span.in_external_macro(cx.sess().source_map()) {
@@ -293,7 +286,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
293286
cur_f = Some(field);
294287
}
295288
},
296-
ItemKind::Trait(is_auto, _safety, _generics, _generic_bounds, item_ref)
289+
ItemKind::Trait(is_auto, _safety, _ident, _generics, _generic_bounds, item_ref)
297290
if self.enable_ordering_for_trait && *is_auto == IsAuto::No =>
298291
{
299292
let mut cur_t: Option<&TraitItemRef> = None;
@@ -370,50 +363,24 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
370363
continue;
371364
}
372365

373-
// The following exceptions (skipping with `continue;`) may not be
374-
// complete, edge cases have not been explored further than what
375-
// appears in the existing code base.
376-
if item.ident.name == rustc_span::symbol::kw::Empty {
377-
if let ItemKind::Impl(_) = item.kind {
378-
// Sorting trait impls for unnamed types makes no sense.
379-
if get_item_name(item).is_empty() {
380-
continue;
381-
}
382-
} else if let ItemKind::ForeignMod { .. } = item.kind {
383-
continue;
384-
} else if let ItemKind::GlobalAsm { .. } = item.kind {
385-
continue;
386-
} else if let ItemKind::Use(path, use_kind) = item.kind {
387-
if path.segments.is_empty() {
388-
// Use statements that contain braces get caught here.
389-
// They will still be linted internally.
390-
continue;
391-
} else if path.segments.len() >= 2
392-
&& (path.segments[0].ident.name == rustc_span::sym::std
393-
|| path.segments[0].ident.name == rustc_span::sym::core)
394-
&& path.segments[1].ident.name == rustc_span::sym::prelude
395-
{
396-
// Filters the autogenerated prelude use statement.
397-
// e.g. `use std::prelude::rustc_2021`
398-
} else if use_kind == UseKind::Glob {
399-
// Filters glob kinds of uses.
400-
// e.g. `use std::sync::*`
401-
} else {
402-
// This can be used for debugging.
403-
// println!("Unknown autogenerated use statement: {:?}", item);
404-
}
405-
continue;
406-
}
407-
}
366+
let ident = if let Some(ident) = item.kind.ident() {
367+
ident
368+
} else if let ItemKind::Impl(_) = item.kind
369+
&& !get_item_name(item).is_empty()
370+
{
371+
rustc_span::Ident::empty() // FIXME: a bit strange, is there a better way to do it?
372+
} else {
373+
continue;
374+
};
408375

409-
if item.ident.name.as_str().starts_with('_') {
376+
if ident.name.as_str().starts_with('_') {
410377
// Filters out unnamed macro-like impls for various derives,
411378
// e.g. serde::Serialize or num_derive::FromPrimitive.
412379
continue;
413380
}
414381

415-
if item.ident.name == rustc_span::sym::std && item.span.is_dummy() {
416-
if let ItemKind::ExternCrate(None) = item.kind {
382+
if ident.name == rustc_span::sym::std && item.span.is_dummy() {
383+
if let ItemKind::ExternCrate(None, _) = item.kind {
417384
// Filters the auto-included Rust standard library.
418385
continue;
419386
}
@@ -559,6 +526,14 @@ fn get_item_name(item: &Item<'_>) -> String {
559526
String::new()
560527
}
561528
},
562-
_ => item.ident.name.as_str().to_owned(),
529+
// FIXME: `Ident::empty` for anonymous items is a bit strange, is there
530+
// a better way to do it?
531+
_ => item
532+
.kind
533+
.ident()
534+
.unwrap_or(rustc_span::Ident::empty())
535+
.name
536+
.as_str()
537+
.to_owned(),
563538
}
564539
}

clippy_lints/src/attrs/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ mod utils;
1616
use clippy_config::Conf;
1717
use clippy_utils::msrvs::{self, Msrv, MsrvStack};
1818
use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind};
19-
use rustc_hir::{ImplItem, Item, TraitItem};
19+
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
2020
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
2121
use rustc_session::impl_lint_pass;
2222
use rustc_span::sym;
@@ -465,22 +465,24 @@ impl Attributes {
465465

466466
impl<'tcx> LateLintPass<'tcx> for Attributes {
467467
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
468-
let attrs = cx.tcx.hir().attrs(item.hir_id());
469-
if is_relevant_item(cx, item) {
470-
inline_always::check(cx, item.span, item.ident.name, attrs);
468+
let attrs = cx.tcx.hir_attrs(item.hir_id());
469+
if let ItemKind::Fn { ident, .. } = item.kind
470+
&& is_relevant_item(cx, item)
471+
{
472+
inline_always::check(cx, item.span, ident.name, attrs);
471473
}
472474
repr_attributes::check(cx, item.span, attrs, self.msrv);
473475
}
474476

475477
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx ImplItem<'_>) {
476478
if is_relevant_impl(cx, item) {
477-
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
479+
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
478480
}
479481
}
480482

481483
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
482484
if is_relevant_trait(cx, item) {
483-
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir().attrs(item.hir_id()));
485+
inline_always::check(cx, item.span, item.ident.name, cx.tcx.hir_attrs(item.hir_id()));
484486
}
485487
}
486488
}

clippy_lints/src/attrs/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
2424
if let ItemKind::Fn { body: eid, .. } = item.kind {
2525
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir_body(eid).value)
2626
} else {
27-
true
27+
false
2828
}
2929
}
3030

clippy_lints/src/default_union_representation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn is_zst<'tcx>(cx: &LateContext<'tcx>, field: &FieldDef, args: ty::GenericArgsR
9797
}
9898

9999
fn has_c_repr_attr(cx: &LateContext<'_>, hir_id: HirId) -> bool {
100-
let attrs = cx.tcx.hir().attrs(hir_id);
100+
let attrs = cx.tcx.hir_attrs(hir_id);
101101

102102
find_attr!(attrs, AttributeKind::Repr(r) if r.iter().any(|(x, _)| *x == ReprAttr::ReprC))
103103
}

clippy_lints/src/derivable_impls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
197197
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
198198
&& let Body { value: func_expr, .. } = cx.tcx.hir_body(*b)
199199
&& let &ty::Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()
200-
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
200+
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
201201
&& !attrs.iter().any(|attr| attr.doc_str().is_some())
202-
&& cx.tcx.hir().attrs(impl_item_hir).is_empty()
202+
&& cx.tcx.hir_attrs(impl_item_hir).is_empty()
203203
{
204204
if adt_def.is_struct() {
205205
check_struct(cx, item, self_ty, func_expr, adt_def, args, cx.tcx.typeck_body(*b));

clippy_lints/src/derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ fn check_unsafe_derive_deserialize<'tcx>(
384384
.tcx
385385
.inherent_impls(def.did())
386386
.iter()
387-
.map(|imp_did| cx.tcx.hir().expect_item(imp_did.expect_local()))
387+
.map(|imp_did| cx.tcx.hir_expect_item(imp_did.expect_local()))
388388
.any(|imp| has_unsafe(cx, imp))
389389
{
390390
span_lint_hir_and_then(

clippy_lints/src/disallowed_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl_lint_pass!(DisallowedTypes => [DISALLOWED_TYPES]);
9999

100100
impl<'tcx> LateLintPass<'tcx> for DisallowedTypes {
101101
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
102-
if let ItemKind::Use(path, UseKind::Single) = &item.kind {
102+
if let ItemKind::Use(path, UseKind::Single(_)) = &item.kind {
103103
for res in &path.res {
104104
self.check_res_emit(cx, res, item.span);
105105
}

clippy_lints/src/doc/missing_headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn check(
2525
&& cx
2626
.tcx
2727
.hir_parent_iter(owner_id.into())
28-
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir().attrs(id)))
28+
.any(|(id, _node)| is_doc_hidden(cx.tcx.hir_attrs(id)))
2929
{
3030
return;
3131
}

clippy_lints/src/enum_clike.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
3838
if cx.tcx.data_layout.pointer_size.bits() != 64 {
3939
return;
4040
}
41-
if let ItemKind::Enum(def, _) = &item.kind {
41+
if let ItemKind::Enum(_, def, _) = &item.kind {
4242
for var in def.variants {
4343
if let Some(anon_const) = &var.disr_expr {
4444
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);

clippy_lints/src/error_impl_error.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ declare_lint_pass!(ErrorImplError => [ERROR_IMPL_ERROR]);
3737
impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
3838
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
3939
match item.kind {
40-
ItemKind::TyAlias(..)
41-
if item.ident.name == sym::Error
40+
ItemKind::TyAlias(ident, ..)
41+
if ident.name == sym::Error
4242
&& is_visible_outside_module(cx, item.owner_id.def_id)
4343
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
4444
&& let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error)
@@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError {
4747
span_lint(
4848
cx,
4949
ERROR_IMPL_ERROR,
50-
item.ident.span,
50+
ident.span,
5151
"exported type alias named `Error` that implements `Error`",
5252
);
5353
},

clippy_lints/src/escape.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
9191
}
9292

9393
// find `self` ty for this trait if relevant
94-
if let ItemKind::Trait(_, _, _, _, items) = item.kind {
94+
if let ItemKind::Trait(_, _, _, _, _, items) = item.kind {
9595
for trait_item in items {
9696
if trait_item.id.owner_id.def_id == fn_def_id {
9797
// be sure we have `self` parameter in this function
@@ -150,6 +150,8 @@ impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
150150
}
151151
}
152152

153+
fn use_cloned(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
154+
153155
fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
154156
if cmt.place.projections.is_empty() {
155157
if let PlaceBase::Local(lid) = cmt.place.base {
@@ -160,26 +162,23 @@ impl<'tcx> Delegate<'tcx> for EscapeDelegate<'_, 'tcx> {
160162
}
161163

162164
fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) {
163-
if cmt.place.projections.is_empty() {
164-
let map = &self.cx.tcx.hir();
165-
if is_argument(self.cx.tcx, cmt.hir_id) {
166-
// Skip closure arguments
167-
let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id);
168-
if let Node::Expr(..) = self.cx.tcx.parent_hir_node(parent_id) {
169-
return;
170-
}
165+
if cmt.place.projections.is_empty() && is_argument(self.cx.tcx, cmt.hir_id) {
166+
// Skip closure arguments
167+
let parent_id = self.cx.tcx.parent_hir_id(cmt.hir_id);
168+
if let Node::Expr(..) = self.cx.tcx.parent_hir_node(parent_id) {
169+
return;
170+
}
171171

172-
// skip if there is a `self` parameter binding to a type
173-
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
174-
if let Some(trait_self_ty) = self.trait_self_ty {
175-
if map.name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
176-
return;
177-
}
172+
// skip if there is a `self` parameter binding to a type
173+
// that contains `Self` (i.e.: `self: Box<Self>`), see #4804
174+
if let Some(trait_self_ty) = self.trait_self_ty {
175+
if self.cx.tcx.hir_name(cmt.hir_id) == kw::SelfLower && cmt.place.ty().contains(trait_self_ty) {
176+
return;
178177
}
178+
}
179179

180-
if is_non_trait_box(cmt.place.ty()) && !self.is_large_box(cmt.place.ty()) {
181-
self.set.insert(cmt.hir_id);
182-
}
180+
if is_non_trait_box(cmt.place.ty()) && !self.is_large_box(cmt.place.ty()) {
181+
self.set.insert(cmt.hir_id);
183182
}
184183
}
185184
}

clippy_lints/src/excessive_bools.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn check_fn_decl(cx: &LateContext<'_>, decl: &FnDecl<'_>, sp: Span, max: u64) {
127127

128128
impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
129129
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
130-
if let ItemKind::Struct(variant_data, _) = &item.kind
130+
if let ItemKind::Struct(_, variant_data, _) = &item.kind
131131
&& variant_data.fields().len() as u64 > self.max_struct_bools
132132
&& has_n_bools(
133133
variant_data.fields().iter().map(|field| field.ty),

clippy_lints/src/exhaustive_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ impl LateLintPass<'_> for ExhaustiveItems {
7676
"exported enums should not be exhaustive",
7777
[].as_slice(),
7878
),
79-
ItemKind::Struct(v, ..) => (
79+
ItemKind::Struct(_, v, ..) => (
8080
EXHAUSTIVE_STRUCTS,
8181
"exported structs should not be exhaustive",
8282
v.fields(),
8383
),
8484
_ => return,
8585
};
8686
if cx.effective_visibilities.is_exported(item.owner_id.def_id)
87-
&& let attrs = cx.tcx.hir().attrs(item.hir_id())
87+
&& let attrs = cx.tcx.hir_attrs(item.hir_id())
8888
&& !attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
8989
&& fields.iter().all(|f| cx.tcx.visibility(f.def_id).is_public())
9090
{

clippy_lints/src/format_impl.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,8 @@ impl FormatImplExpr<'_, '_> {
209209
// Handle dereference of &self -> self that is equivalent (i.e. via *self in fmt() impl)
210210
// Since the argument to fmt is itself a reference: &self
211211
let reference = peel_ref_operators(self.cx, arg);
212-
let map = self.cx.tcx.hir();
213212
// Is the reference self?
214-
if path_to_local(reference).map(|x| map.name(x)) == Some(kw::SelfLower) {
213+
if path_to_local(reference).map(|x| self.cx.tcx.hir_name(x)) == Some(kw::SelfLower) {
215214
let FormatTraitNames { name, .. } = self.format_trait_impl;
216215
span_lint(
217216
self.cx,

clippy_lints/src/four_forward_slashes.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for FourForwardSlashes {
4343
let sm = cx.sess().source_map();
4444
let mut span = cx
4545
.tcx
46-
.hir()
47-
.attrs(item.hir_id())
46+
.hir_attrs(item.hir_id())
4847
.iter()
4948
.filter(|i| i.is_doc_comment())
5049
.fold(item.span.shrink_to_lo(), |span, attr| span.to(attr.span()));

0 commit comments

Comments
 (0)