Reorder fields in hir::ItemKind variants.
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match the textual order in the source code. The interesting part of the change is in `compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical refactoring.
This commit is contained in:
@@ -164,7 +164,7 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
|
|||||||
fn visit_item(&mut self, i: &'hir Item<'hir>) {
|
fn visit_item(&mut self, i: &'hir Item<'hir>) {
|
||||||
debug_assert_eq!(i.owner_id, self.owner);
|
debug_assert_eq!(i.owner_id, self.owner);
|
||||||
self.with_parent(i.hir_id(), |this| {
|
self.with_parent(i.hir_id(), |this| {
|
||||||
if let ItemKind::Struct(_, struct_def, _) = &i.kind {
|
if let ItemKind::Struct(_, _, struct_def) = &i.kind {
|
||||||
// If this is a tuple or unit-like struct, register the constructor.
|
// If this is a tuple or unit-like struct, register the constructor.
|
||||||
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
if let Some(ctor_hir_id) = struct_def.ctor_hir_id() {
|
||||||
this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
|
this.insert(i.span, ctor_hir_id, Node::Ctor(struct_def));
|
||||||
|
|||||||
@@ -180,7 +180,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
let (ty, body_id) =
|
let (ty, body_id) =
|
||||||
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
|
self.lower_const_item(t, span, e.as_deref(), ImplTraitPosition::StaticTy);
|
||||||
self.lower_define_opaque(hir_id, define_opaque);
|
self.lower_define_opaque(hir_id, define_opaque);
|
||||||
hir::ItemKind::Static(ident, ty, *m, body_id)
|
hir::ItemKind::Static(*m, ident, ty, body_id)
|
||||||
}
|
}
|
||||||
ItemKind::Const(box ast::ConstItem {
|
ItemKind::Const(box ast::ConstItem {
|
||||||
ident,
|
ident,
|
||||||
@@ -200,7 +200,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
self.lower_define_opaque(hir_id, &define_opaque);
|
self.lower_define_opaque(hir_id, &define_opaque);
|
||||||
hir::ItemKind::Const(ident, ty, generics, body_id)
|
hir::ItemKind::Const(ident, generics, ty, body_id)
|
||||||
}
|
}
|
||||||
ItemKind::Fn(box Fn {
|
ItemKind::Fn(box Fn {
|
||||||
sig: FnSig { decl, header, span: fn_sig_span },
|
sig: FnSig { decl, header, span: fn_sig_span },
|
||||||
@@ -304,7 +304,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
),
|
),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
hir::ItemKind::TyAlias(ident, ty, generics)
|
hir::ItemKind::TyAlias(ident, generics, ty)
|
||||||
}
|
}
|
||||||
ItemKind::Enum(ident, generics, enum_definition) => {
|
ItemKind::Enum(ident, generics, enum_definition) => {
|
||||||
let ident = self.lower_ident(*ident);
|
let ident = self.lower_ident(*ident);
|
||||||
@@ -318,7 +318,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
hir::ItemKind::Enum(ident, hir::EnumDef { variants }, generics)
|
hir::ItemKind::Enum(ident, generics, hir::EnumDef { variants })
|
||||||
}
|
}
|
||||||
ItemKind::Struct(ident, generics, struct_def) => {
|
ItemKind::Struct(ident, generics, struct_def) => {
|
||||||
let ident = self.lower_ident(*ident);
|
let ident = self.lower_ident(*ident);
|
||||||
@@ -328,7 +328,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| this.lower_variant_data(hir_id, struct_def),
|
|this| this.lower_variant_data(hir_id, struct_def),
|
||||||
);
|
);
|
||||||
hir::ItemKind::Struct(ident, struct_def, generics)
|
hir::ItemKind::Struct(ident, generics, struct_def)
|
||||||
}
|
}
|
||||||
ItemKind::Union(ident, generics, vdata) => {
|
ItemKind::Union(ident, generics, vdata) => {
|
||||||
let ident = self.lower_ident(*ident);
|
let ident = self.lower_ident(*ident);
|
||||||
@@ -338,7 +338,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
|
|||||||
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
ImplTraitContext::Disallowed(ImplTraitPosition::Generic),
|
||||||
|this| this.lower_variant_data(hir_id, vdata),
|
|this| this.lower_variant_data(hir_id, vdata),
|
||||||
);
|
);
|
||||||
hir::ItemKind::Union(ident, vdata, generics)
|
hir::ItemKind::Union(ident, generics, vdata)
|
||||||
}
|
}
|
||||||
ItemKind::Impl(box Impl {
|
ItemKind::Impl(box Impl {
|
||||||
safety,
|
safety,
|
||||||
|
|||||||
@@ -4106,11 +4106,11 @@ impl<'hir> Item<'hir> {
|
|||||||
|
|
||||||
expect_use, (&'hir UsePath<'hir>, UseKind), ItemKind::Use(p, uk), (p, *uk);
|
expect_use, (&'hir UsePath<'hir>, UseKind), ItemKind::Use(p, uk), (p, *uk);
|
||||||
|
|
||||||
expect_static, (Ident, &'hir Ty<'hir>, Mutability, BodyId),
|
expect_static, (Mutability, Ident, &'hir Ty<'hir>, BodyId),
|
||||||
ItemKind::Static(ident, ty, mutbl, body), (*ident, ty, *mutbl, *body);
|
ItemKind::Static(mutbl, ident, ty, body), (*mutbl, *ident, ty, *body);
|
||||||
|
|
||||||
expect_const, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
|
expect_const, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
|
||||||
ItemKind::Const(ident, ty, generics, body), (*ident, ty, generics, *body);
|
ItemKind::Const(ident, generics, ty, body), (*ident, generics, ty, *body);
|
||||||
|
|
||||||
expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
|
expect_fn, (Ident, &FnSig<'hir>, &'hir Generics<'hir>, BodyId),
|
||||||
ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
|
ItemKind::Fn { ident, sig, generics, body, .. }, (*ident, sig, generics, *body);
|
||||||
@@ -4125,17 +4125,17 @@ impl<'hir> Item<'hir> {
|
|||||||
|
|
||||||
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
|
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm { asm, .. }, asm;
|
||||||
|
|
||||||
expect_ty_alias, (Ident, &'hir Ty<'hir>, &'hir Generics<'hir>),
|
expect_ty_alias, (Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
|
||||||
ItemKind::TyAlias(ident, ty, generics), (*ident, ty, generics);
|
ItemKind::TyAlias(ident, generics, ty), (*ident, generics, ty);
|
||||||
|
|
||||||
expect_enum, (Ident, &EnumDef<'hir>, &'hir Generics<'hir>),
|
expect_enum, (Ident, &'hir Generics<'hir>, &EnumDef<'hir>),
|
||||||
ItemKind::Enum(ident, def, generics), (*ident, def, generics);
|
ItemKind::Enum(ident, generics, def), (*ident, generics, def);
|
||||||
|
|
||||||
expect_struct, (Ident, &VariantData<'hir>, &'hir Generics<'hir>),
|
expect_struct, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
|
||||||
ItemKind::Struct(ident, data, generics), (*ident, data, generics);
|
ItemKind::Struct(ident, generics, data), (*ident, generics, data);
|
||||||
|
|
||||||
expect_union, (Ident, &VariantData<'hir>, &'hir Generics<'hir>),
|
expect_union, (Ident, &'hir Generics<'hir>, &VariantData<'hir>),
|
||||||
ItemKind::Union(ident, data, generics), (*ident, data, generics);
|
ItemKind::Union(ident, generics, data), (*ident, generics, data);
|
||||||
|
|
||||||
expect_trait,
|
expect_trait,
|
||||||
(
|
(
|
||||||
@@ -4278,9 +4278,9 @@ pub enum ItemKind<'hir> {
|
|||||||
Use(&'hir UsePath<'hir>, UseKind),
|
Use(&'hir UsePath<'hir>, UseKind),
|
||||||
|
|
||||||
/// A `static` item.
|
/// A `static` item.
|
||||||
Static(Ident, &'hir Ty<'hir>, Mutability, BodyId),
|
Static(Mutability, Ident, &'hir Ty<'hir>, BodyId),
|
||||||
/// A `const` item.
|
/// A `const` item.
|
||||||
Const(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
|
Const(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>, BodyId),
|
||||||
/// A function declaration.
|
/// A function declaration.
|
||||||
Fn {
|
Fn {
|
||||||
ident: Ident,
|
ident: Ident,
|
||||||
@@ -4309,13 +4309,13 @@ pub enum ItemKind<'hir> {
|
|||||||
fake_body: BodyId,
|
fake_body: BodyId,
|
||||||
},
|
},
|
||||||
/// A type alias, e.g., `type Foo = Bar<u8>`.
|
/// A type alias, e.g., `type Foo = Bar<u8>`.
|
||||||
TyAlias(Ident, &'hir Ty<'hir>, &'hir Generics<'hir>),
|
TyAlias(Ident, &'hir Generics<'hir>, &'hir Ty<'hir>),
|
||||||
/// An enum definition, e.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
/// An enum definition, e.g., `enum Foo<A, B> { C<A>, D<B> }`.
|
||||||
Enum(Ident, EnumDef<'hir>, &'hir Generics<'hir>),
|
Enum(Ident, &'hir Generics<'hir>, EnumDef<'hir>),
|
||||||
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
|
/// A struct definition, e.g., `struct Foo<A> {x: A}`.
|
||||||
Struct(Ident, VariantData<'hir>, &'hir Generics<'hir>),
|
Struct(Ident, &'hir Generics<'hir>, VariantData<'hir>),
|
||||||
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
|
/// A union definition, e.g., `union Foo<A, B> {x: A, y: B}`.
|
||||||
Union(Ident, VariantData<'hir>, &'hir Generics<'hir>),
|
Union(Ident, &'hir Generics<'hir>, VariantData<'hir>),
|
||||||
/// A trait definition.
|
/// A trait definition.
|
||||||
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
Trait(IsAuto, Safety, Ident, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
|
||||||
/// A trait alias.
|
/// A trait alias.
|
||||||
@@ -4352,7 +4352,7 @@ impl ItemKind<'_> {
|
|||||||
match *self {
|
match *self {
|
||||||
ItemKind::ExternCrate(_, ident)
|
ItemKind::ExternCrate(_, ident)
|
||||||
| ItemKind::Use(_, UseKind::Single(ident))
|
| ItemKind::Use(_, UseKind::Single(ident))
|
||||||
| ItemKind::Static(ident, ..)
|
| ItemKind::Static(_, ident, ..)
|
||||||
| ItemKind::Const(ident, ..)
|
| ItemKind::Const(ident, ..)
|
||||||
| ItemKind::Fn { ident, .. }
|
| ItemKind::Fn { ident, .. }
|
||||||
| ItemKind::Macro(ident, ..)
|
| ItemKind::Macro(ident, ..)
|
||||||
@@ -4374,11 +4374,11 @@ impl ItemKind<'_> {
|
|||||||
pub fn generics(&self) -> Option<&Generics<'_>> {
|
pub fn generics(&self) -> Option<&Generics<'_>> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
ItemKind::Fn { generics, .. }
|
ItemKind::Fn { generics, .. }
|
||||||
| ItemKind::TyAlias(_, _, generics)
|
| ItemKind::TyAlias(_, generics, _)
|
||||||
| ItemKind::Const(_, _, generics, _)
|
| ItemKind::Const(_, generics, _, _)
|
||||||
| ItemKind::Enum(_, _, generics)
|
| ItemKind::Enum(_, generics, _)
|
||||||
| ItemKind::Struct(_, _, generics)
|
| ItemKind::Struct(_, generics, _)
|
||||||
| ItemKind::Union(_, _, generics)
|
| ItemKind::Union(_, generics, _)
|
||||||
| ItemKind::Trait(_, _, _, generics, _, _)
|
| ItemKind::Trait(_, _, _, generics, _, _)
|
||||||
| ItemKind::TraitAlias(_, generics, _)
|
| ItemKind::TraitAlias(_, generics, _)
|
||||||
| ItemKind::Impl(Impl { generics, .. }) => generics,
|
| ItemKind::Impl(Impl { generics, .. }) => generics,
|
||||||
@@ -4802,9 +4802,9 @@ impl<'hir> Node<'hir> {
|
|||||||
pub fn ty(self) -> Option<&'hir Ty<'hir>> {
|
pub fn ty(self) -> Option<&'hir Ty<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
Node::Item(it) => match it.kind {
|
Node::Item(it) => match it.kind {
|
||||||
ItemKind::TyAlias(_, ty, _)
|
ItemKind::TyAlias(_, _, ty)
|
||||||
| ItemKind::Static(_, ty, _, _)
|
| ItemKind::Static(_, _, ty, _)
|
||||||
| ItemKind::Const(_, ty, _, _) => Some(ty),
|
| ItemKind::Const(_, _, ty, _) => Some(ty),
|
||||||
ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
|
ItemKind::Impl(impl_item) => Some(&impl_item.self_ty),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
@@ -4824,7 +4824,7 @@ impl<'hir> Node<'hir> {
|
|||||||
|
|
||||||
pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
|
pub fn alias_ty(self) -> Option<&'hir Ty<'hir>> {
|
||||||
match self {
|
match self {
|
||||||
Node::Item(Item { kind: ItemKind::TyAlias(_, ty, _), .. }) => Some(ty),
|
Node::Item(Item { kind: ItemKind::TyAlias(_, _, ty), .. }) => Some(ty),
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -545,15 +545,15 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
|||||||
UseKind::Glob | UseKind::ListStem => {}
|
UseKind::Glob | UseKind::ListStem => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::Static(ident, ref typ, _, body) => {
|
ItemKind::Static(_, ident, ref typ, body) => {
|
||||||
try_visit!(visitor.visit_ident(ident));
|
try_visit!(visitor.visit_ident(ident));
|
||||||
try_visit!(visitor.visit_ty_unambig(typ));
|
try_visit!(visitor.visit_ty_unambig(typ));
|
||||||
try_visit!(visitor.visit_nested_body(body));
|
try_visit!(visitor.visit_nested_body(body));
|
||||||
}
|
}
|
||||||
ItemKind::Const(ident, ref typ, ref generics, body) => {
|
ItemKind::Const(ident, ref generics, ref typ, body) => {
|
||||||
try_visit!(visitor.visit_ident(ident));
|
try_visit!(visitor.visit_ident(ident));
|
||||||
try_visit!(visitor.visit_ty_unambig(typ));
|
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
|
try_visit!(visitor.visit_ty_unambig(typ));
|
||||||
try_visit!(visitor.visit_nested_body(body));
|
try_visit!(visitor.visit_nested_body(body));
|
||||||
}
|
}
|
||||||
ItemKind::Fn { ident, sig, generics, body: body_id, .. } => {
|
ItemKind::Fn { ident, sig, generics, body: body_id, .. } => {
|
||||||
@@ -583,12 +583,12 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
|||||||
// typeck results set correctly.
|
// typeck results set correctly.
|
||||||
try_visit!(visitor.visit_nested_body(fake_body));
|
try_visit!(visitor.visit_nested_body(fake_body));
|
||||||
}
|
}
|
||||||
ItemKind::TyAlias(ident, ref ty, ref generics) => {
|
ItemKind::TyAlias(ident, ref generics, ref ty) => {
|
||||||
try_visit!(visitor.visit_ident(ident));
|
try_visit!(visitor.visit_ident(ident));
|
||||||
try_visit!(visitor.visit_ty_unambig(ty));
|
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
|
try_visit!(visitor.visit_ty_unambig(ty));
|
||||||
}
|
}
|
||||||
ItemKind::Enum(ident, ref enum_definition, ref generics) => {
|
ItemKind::Enum(ident, ref generics, ref enum_definition) => {
|
||||||
try_visit!(visitor.visit_ident(ident));
|
try_visit!(visitor.visit_ident(ident));
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
try_visit!(visitor.visit_enum_def(enum_definition));
|
try_visit!(visitor.visit_enum_def(enum_definition));
|
||||||
@@ -609,8 +609,8 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V::
|
|||||||
try_visit!(visitor.visit_ty_unambig(self_ty));
|
try_visit!(visitor.visit_ty_unambig(self_ty));
|
||||||
walk_list!(visitor, visit_impl_item_ref, *items);
|
walk_list!(visitor, visit_impl_item_ref, *items);
|
||||||
}
|
}
|
||||||
ItemKind::Struct(ident, ref struct_definition, ref generics)
|
ItemKind::Struct(ident, ref generics, ref struct_definition)
|
||||||
| ItemKind::Union(ident, ref struct_definition, ref generics) => {
|
| ItemKind::Union(ident, ref generics, ref struct_definition) => {
|
||||||
try_visit!(visitor.visit_ident(ident));
|
try_visit!(visitor.visit_ident(ident));
|
||||||
try_visit!(visitor.visit_generics(generics));
|
try_visit!(visitor.visit_generics(generics));
|
||||||
try_visit!(visitor.visit_variant_data(struct_definition));
|
try_visit!(visitor.visit_variant_data(struct_definition));
|
||||||
|
|||||||
@@ -297,32 +297,30 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
|
|||||||
hir::ItemKind::Fn { ident, sig, .. } => {
|
hir::ItemKind::Fn { ident, sig, .. } => {
|
||||||
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
|
check_item_fn(tcx, def_id, ident, item.span, sig.decl)
|
||||||
}
|
}
|
||||||
hir::ItemKind::Static(_, ty, ..) => {
|
hir::ItemKind::Static(_, _, ty, _) => {
|
||||||
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
|
check_static_item(tcx, def_id, ty.span, UnsizedHandling::Forbid)
|
||||||
}
|
}
|
||||||
hir::ItemKind::Const(_, ty, ..) => check_const_item(tcx, def_id, ty.span, item.span),
|
hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span),
|
||||||
hir::ItemKind::Struct(_, _, hir_generics) => {
|
hir::ItemKind::Struct(_, generics, _) => {
|
||||||
let res = check_type_defn(tcx, item, false);
|
let res = check_type_defn(tcx, item, false);
|
||||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
check_variances_for_type_defn(tcx, item, generics);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(_, _, hir_generics) => {
|
hir::ItemKind::Union(_, generics, _) => {
|
||||||
let res = check_type_defn(tcx, item, true);
|
let res = check_type_defn(tcx, item, true);
|
||||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
check_variances_for_type_defn(tcx, item, generics);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(_, _, hir_generics) => {
|
hir::ItemKind::Enum(_, generics, _) => {
|
||||||
let res = check_type_defn(tcx, item, true);
|
let res = check_type_defn(tcx, item, true);
|
||||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
check_variances_for_type_defn(tcx, item, generics);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
hir::ItemKind::Trait(..) => check_trait(tcx, item),
|
hir::ItemKind::Trait(..) => check_trait(tcx, item),
|
||||||
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
|
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
|
||||||
// `ForeignItem`s are handled separately.
|
// `ForeignItem`s are handled separately.
|
||||||
hir::ItemKind::ForeignMod { .. } => Ok(()),
|
hir::ItemKind::ForeignMod { .. } => Ok(()),
|
||||||
hir::ItemKind::TyAlias(_, hir_ty, hir_generics)
|
hir::ItemKind::TyAlias(_, generics, hir_ty) if tcx.type_alias_is_lazy(item.owner_id) => {
|
||||||
if tcx.type_alias_is_lazy(item.owner_id) =>
|
|
||||||
{
|
|
||||||
let res = enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
|
let res = enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
|
||||||
let ty = tcx.type_of(def_id).instantiate_identity();
|
let ty = tcx.type_of(def_id).instantiate_identity();
|
||||||
let item_ty =
|
let item_ty =
|
||||||
@@ -335,7 +333,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
|
|||||||
check_where_clauses(wfcx, item.span, def_id);
|
check_where_clauses(wfcx, item.span, def_id);
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
check_variances_for_type_defn(tcx, item, hir_generics);
|
check_variances_for_type_defn(tcx, item, generics);
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
|
|||||||
@@ -248,13 +248,13 @@ fn reject_placeholder_type_signatures_in_item<'tcx>(
|
|||||||
item: &'tcx hir::Item<'tcx>,
|
item: &'tcx hir::Item<'tcx>,
|
||||||
) {
|
) {
|
||||||
let (generics, suggest) = match &item.kind {
|
let (generics, suggest) = match &item.kind {
|
||||||
hir::ItemKind::Union(_, _, generics)
|
hir::ItemKind::Union(_, generics, _)
|
||||||
| hir::ItemKind::Enum(_, _, generics)
|
| hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::TraitAlias(_, generics, _)
|
| hir::ItemKind::TraitAlias(_, generics, _)
|
||||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||||
| hir::ItemKind::Struct(_, _, generics) => (generics, true),
|
| hir::ItemKind::Struct(_, generics, _) => (generics, true),
|
||||||
hir::ItemKind::TyAlias(_, _, generics) => (generics, false),
|
hir::ItemKind::TyAlias(_, generics, _) => (generics, false),
|
||||||
// `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
|
// `static`, `fn` and `const` are handled elsewhere to suggest appropriate type.
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
@@ -470,9 +470,9 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||||||
.tcx
|
.tcx
|
||||||
.hir_expect_item(self.tcx.hir_get_parent_item(self.hir_id()).def_id);
|
.hir_expect_item(self.tcx.hir_get_parent_item(self.hir_id()).def_id);
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
hir::ItemKind::Enum(_, _, generics)
|
hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::Struct(_, _, generics)
|
| hir::ItemKind::Struct(_, generics, _)
|
||||||
| hir::ItemKind::Union(_, _, generics) => {
|
| hir::ItemKind::Union(_, generics, _) => {
|
||||||
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
|
let lt_name = get_new_lifetime_name(self.tcx, poly_trait_ref, generics);
|
||||||
let (lt_sp, sugg) = match generics.params {
|
let (lt_sp, sugg) = match generics.params {
|
||||||
[] => (generics.span, format!("<{lt_name}>")),
|
[] => (generics.span, format!("<{lt_name}>")),
|
||||||
@@ -740,7 +740,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||||||
tcx.at(it.span).explicit_super_predicates_of(def_id);
|
tcx.at(it.span).explicit_super_predicates_of(def_id);
|
||||||
tcx.ensure_ok().predicates_of(def_id);
|
tcx.ensure_ok().predicates_of(def_id);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(_, struct_def, _) | hir::ItemKind::Union(_, struct_def, _) => {
|
hir::ItemKind::Struct(_, _, struct_def) | hir::ItemKind::Union(_, _, struct_def) => {
|
||||||
tcx.ensure_ok().generics_of(def_id);
|
tcx.ensure_ok().generics_of(def_id);
|
||||||
tcx.ensure_ok().type_of(def_id);
|
tcx.ensure_ok().type_of(def_id);
|
||||||
tcx.ensure_ok().predicates_of(def_id);
|
tcx.ensure_ok().predicates_of(def_id);
|
||||||
@@ -762,7 +762,7 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
|
|||||||
tcx.ensure_ok().predicates_of(def_id);
|
tcx.ensure_ok().predicates_of(def_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
hir::ItemKind::Static(_, ty, ..) | hir::ItemKind::Const(_, ty, ..) => {
|
hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _) => {
|
||||||
tcx.ensure_ok().generics_of(def_id);
|
tcx.ensure_ok().generics_of(def_id);
|
||||||
tcx.ensure_ok().type_of(def_id);
|
tcx.ensure_ok().type_of(def_id);
|
||||||
tcx.ensure_ok().predicates_of(def_id);
|
tcx.ensure_ok().predicates_of(def_id);
|
||||||
@@ -1093,7 +1093,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
|||||||
|
|
||||||
let repr = tcx.repr_options_of_def(def_id);
|
let repr = tcx.repr_options_of_def(def_id);
|
||||||
let (kind, variants) = match &item.kind {
|
let (kind, variants) = match &item.kind {
|
||||||
ItemKind::Enum(_, def, _) => {
|
ItemKind::Enum(_, _, def) => {
|
||||||
let mut distance_from_explicit = 0;
|
let mut distance_from_explicit = 0;
|
||||||
let variants = def
|
let variants = def
|
||||||
.variants
|
.variants
|
||||||
@@ -1121,7 +1121,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::AdtDef<'_> {
|
|||||||
|
|
||||||
(AdtKind::Enum, variants)
|
(AdtKind::Enum, variants)
|
||||||
}
|
}
|
||||||
ItemKind::Struct(ident, def, _) | ItemKind::Union(ident, def, _) => {
|
ItemKind::Struct(ident, _, def) | ItemKind::Union(ident, _, def) => {
|
||||||
let adt_kind = match item.kind {
|
let adt_kind = match item.kind {
|
||||||
ItemKind::Struct(..) => AdtKind::Struct,
|
ItemKind::Struct(..) => AdtKind::Struct,
|
||||||
_ => AdtKind::Union,
|
_ => AdtKind::Union,
|
||||||
|
|||||||
@@ -634,11 +634,11 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> {
|
|||||||
// These sorts of items have no lifetime parameters at all.
|
// These sorts of items have no lifetime parameters at all.
|
||||||
intravisit::walk_item(self, item);
|
intravisit::walk_item(self, item);
|
||||||
}
|
}
|
||||||
hir::ItemKind::TyAlias(_, _, generics)
|
hir::ItemKind::TyAlias(_, generics, _)
|
||||||
| hir::ItemKind::Const(_, _, generics, _)
|
| hir::ItemKind::Const(_, generics, _, _)
|
||||||
| hir::ItemKind::Enum(_, _, generics)
|
| hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::Struct(_, _, generics)
|
| hir::ItemKind::Struct(_, generics, _)
|
||||||
| hir::ItemKind::Union(_, _, generics)
|
| hir::ItemKind::Union(_, generics, _)
|
||||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||||
| hir::ItemKind::TraitAlias(_, generics, ..)
|
| hir::ItemKind::TraitAlias(_, generics, ..)
|
||||||
| hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
|
| hir::ItemKind::Impl(&hir::Impl { generics, .. }) => {
|
||||||
|
|||||||
@@ -206,7 +206,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
},
|
},
|
||||||
|
|
||||||
Node::Item(item) => match item.kind {
|
Node::Item(item) => match item.kind {
|
||||||
ItemKind::Static(ident, ty, .., body_id) => {
|
ItemKind::Static(_, ident, ty, body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(
|
infer_placeholder_type(
|
||||||
icx.lowerer(),
|
icx.lowerer(),
|
||||||
@@ -220,7 +220,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
icx.lower_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::Const(ident, ty, _, body_id) => {
|
ItemKind::Const(ident, _, ty, body_id) => {
|
||||||
if ty.is_suggestable_infer_ty() {
|
if ty.is_suggestable_infer_ty() {
|
||||||
infer_placeholder_type(
|
infer_placeholder_type(
|
||||||
icx.lowerer(),
|
icx.lowerer(),
|
||||||
@@ -234,7 +234,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
|
|||||||
icx.lower_ty(ty)
|
icx.lower_ty(ty)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ItemKind::TyAlias(_, self_ty, _) => icx.lower_ty(self_ty),
|
ItemKind::TyAlias(_, _, self_ty) => icx.lower_ty(self_ty),
|
||||||
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
|
ItemKind::Impl(hir::Impl { self_ty, .. }) => match self_ty.find_self_aliases() {
|
||||||
spans if spans.len() > 0 => {
|
spans if spans.len() > 0 => {
|
||||||
let guar = tcx
|
let guar = tcx
|
||||||
@@ -532,5 +532,5 @@ pub(crate) fn type_alias_is_lazy<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) ->
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HasTait.visit_ty_unambig(tcx.hir_expect_item(def_id).expect_ty_alias().1).is_break()
|
HasTait.visit_ty_unambig(tcx.hir_expect_item(def_id).expect_ty_alias().2).is_break()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
|
|
||||||
let generics = match tcx.hir_node_by_def_id(parent_item) {
|
let generics = match tcx.hir_node_by_def_id(parent_item) {
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Struct(_, variant, generics),
|
kind: hir::ItemKind::Struct(_, generics, variant),
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if !variant.fields().iter().any(|field| field.hir_id == parent_hir_id) {
|
if !variant.fields().iter().any(|field| field.hir_id == parent_hir_id) {
|
||||||
@@ -149,7 +149,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
}
|
}
|
||||||
generics
|
generics
|
||||||
}
|
}
|
||||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Enum(_, def, generics), .. }) => {
|
hir::Node::Item(hir::Item { kind: hir::ItemKind::Enum(_, generics, def), .. }) => {
|
||||||
if !def
|
if !def
|
||||||
.variants
|
.variants
|
||||||
.iter()
|
.iter()
|
||||||
@@ -269,7 +269,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
|
|||||||
hir::Node::Field(field) => {
|
hir::Node::Field(field) => {
|
||||||
// Enums can't have unsized fields, fields can only have an unsized tail field.
|
// Enums can't have unsized fields, fields can only have an unsized tail field.
|
||||||
if let hir::Node::Item(hir::Item {
|
if let hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Struct(_, variant, _), ..
|
kind: hir::ItemKind::Struct(_, _, variant), ..
|
||||||
}) = tcx.parent_hir_node(field.hir_id)
|
}) = tcx.parent_hir_node(field.hir_id)
|
||||||
&& variant
|
&& variant
|
||||||
.fields()
|
.fields()
|
||||||
|
|||||||
@@ -145,9 +145,9 @@ fn diagnostic_hir_wf_check<'tcx>(
|
|||||||
ref item => bug!("Unexpected TraitItem {:?}", item),
|
ref item => bug!("Unexpected TraitItem {:?}", item),
|
||||||
},
|
},
|
||||||
hir::Node::Item(item) => match item.kind {
|
hir::Node::Item(item) => match item.kind {
|
||||||
hir::ItemKind::TyAlias(_, ty, _)
|
hir::ItemKind::TyAlias(_, _, ty)
|
||||||
| hir::ItemKind::Static(_, ty, _, _)
|
| hir::ItemKind::Static(_, _, ty, _)
|
||||||
| hir::ItemKind::Const(_, ty, _, _) => vec![ty],
|
| hir::ItemKind::Const(_, _, ty, _) => vec![ty],
|
||||||
hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
|
hir::ItemKind::Impl(impl_) => match &impl_.of_trait {
|
||||||
Some(t) => t
|
Some(t) => t
|
||||||
.path
|
.path
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ impl<'a> State<'a> {
|
|||||||
self.end(ib);
|
self.end(ib);
|
||||||
self.end(cb);
|
self.end(cb);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Static(ident, ty, m, expr) => {
|
hir::ItemKind::Static(m, ident, ty, expr) => {
|
||||||
let (cb, ib) = self.head("static");
|
let (cb, ib) = self.head("static");
|
||||||
if m.is_mut() {
|
if m.is_mut() {
|
||||||
self.word_space("mut");
|
self.word_space("mut");
|
||||||
@@ -609,7 +609,7 @@ impl<'a> State<'a> {
|
|||||||
self.word(";");
|
self.word(";");
|
||||||
self.end(cb);
|
self.end(cb);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Const(ident, ty, generics, expr) => {
|
hir::ItemKind::Const(ident, generics, ty, expr) => {
|
||||||
let (cb, ib) = self.head("const");
|
let (cb, ib) = self.head("const");
|
||||||
self.print_ident(ident);
|
self.print_ident(ident);
|
||||||
self.print_generic_params(generics.params);
|
self.print_generic_params(generics.params);
|
||||||
@@ -660,7 +660,7 @@ impl<'a> State<'a> {
|
|||||||
self.end(cb);
|
self.end(cb);
|
||||||
self.end(ib);
|
self.end(ib);
|
||||||
}
|
}
|
||||||
hir::ItemKind::TyAlias(ident, ty, generics) => {
|
hir::ItemKind::TyAlias(ident, generics, ty) => {
|
||||||
let (cb, ib) = self.head("type");
|
let (cb, ib) = self.head("type");
|
||||||
self.print_ident(ident);
|
self.print_ident(ident);
|
||||||
self.print_generic_params(generics.params);
|
self.print_generic_params(generics.params);
|
||||||
@@ -673,16 +673,16 @@ impl<'a> State<'a> {
|
|||||||
self.word(";");
|
self.word(";");
|
||||||
self.end(cb);
|
self.end(cb);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(ident, ref enum_definition, params) => {
|
hir::ItemKind::Enum(ident, generics, ref enum_def) => {
|
||||||
self.print_enum_def(enum_definition, params, ident.name, item.span);
|
self.print_enum_def(ident.name, generics, enum_def, item.span);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(ident, ref struct_def, generics) => {
|
hir::ItemKind::Struct(ident, generics, ref struct_def) => {
|
||||||
let (cb, ib) = self.head("struct");
|
let (cb, ib) = self.head("struct");
|
||||||
self.print_struct(struct_def, generics, ident.name, item.span, true, cb, ib);
|
self.print_struct(ident.name, generics, struct_def, item.span, true, cb, ib);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(ident, ref struct_def, generics) => {
|
hir::ItemKind::Union(ident, generics, ref struct_def) => {
|
||||||
let (cb, ib) = self.head("union");
|
let (cb, ib) = self.head("union");
|
||||||
self.print_struct(struct_def, generics, ident.name, item.span, true, cb, ib);
|
self.print_struct(ident.name, generics, struct_def, item.span, true, cb, ib);
|
||||||
}
|
}
|
||||||
hir::ItemKind::Impl(&hir::Impl {
|
hir::ItemKind::Impl(&hir::Impl {
|
||||||
constness,
|
constness,
|
||||||
@@ -791,9 +791,9 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
fn print_enum_def(
|
fn print_enum_def(
|
||||||
&mut self,
|
&mut self,
|
||||||
enum_definition: &hir::EnumDef<'_>,
|
|
||||||
generics: &hir::Generics<'_>,
|
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
|
generics: &hir::Generics<'_>,
|
||||||
|
enum_def: &hir::EnumDef<'_>,
|
||||||
span: rustc_span::Span,
|
span: rustc_span::Span,
|
||||||
) {
|
) {
|
||||||
let (cb, ib) = self.head("enum");
|
let (cb, ib) = self.head("enum");
|
||||||
@@ -801,7 +801,7 @@ impl<'a> State<'a> {
|
|||||||
self.print_generic_params(generics.params);
|
self.print_generic_params(generics.params);
|
||||||
self.print_where_clause(generics);
|
self.print_where_clause(generics);
|
||||||
self.space();
|
self.space();
|
||||||
self.print_variants(enum_definition.variants, span, cb, ib);
|
self.print_variants(enum_def.variants, span, cb, ib);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_variants(
|
fn print_variants(
|
||||||
@@ -834,9 +834,9 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
fn print_struct(
|
fn print_struct(
|
||||||
&mut self,
|
&mut self,
|
||||||
struct_def: &hir::VariantData<'_>,
|
|
||||||
generics: &hir::Generics<'_>,
|
|
||||||
name: Symbol,
|
name: Symbol,
|
||||||
|
generics: &hir::Generics<'_>,
|
||||||
|
struct_def: &hir::VariantData<'_>,
|
||||||
span: rustc_span::Span,
|
span: rustc_span::Span,
|
||||||
print_finalizer: bool,
|
print_finalizer: bool,
|
||||||
cb: BoxMarker,
|
cb: BoxMarker,
|
||||||
@@ -886,7 +886,7 @@ impl<'a> State<'a> {
|
|||||||
pub fn print_variant(&mut self, v: &hir::Variant<'_>) {
|
pub fn print_variant(&mut self, v: &hir::Variant<'_>) {
|
||||||
let (cb, ib) = self.head("");
|
let (cb, ib) = self.head("");
|
||||||
let generics = hir::Generics::empty();
|
let generics = hir::Generics::empty();
|
||||||
self.print_struct(&v.data, generics, v.ident.name, v.span, false, cb, ib);
|
self.print_struct(v.ident.name, generics, &v.data, v.span, false, cb, ib);
|
||||||
if let Some(ref d) = v.disr_expr {
|
if let Some(ref d) = v.disr_expr {
|
||||||
self.space();
|
self.space();
|
||||||
self.word_space("=");
|
self.word_space("=");
|
||||||
|
|||||||
@@ -722,8 +722,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
)) => {
|
)) => {
|
||||||
if let Some(hir::Node::Item(hir::Item {
|
if let Some(hir::Node::Item(hir::Item {
|
||||||
kind:
|
kind:
|
||||||
hir::ItemKind::Static(ident, ty, ..)
|
hir::ItemKind::Static(_, ident, ty, _)
|
||||||
| hir::ItemKind::Const(ident, ty, ..),
|
| hir::ItemKind::Const(ident, _, ty, _),
|
||||||
..
|
..
|
||||||
})) = self.tcx.hir_get_if_local(*def_id)
|
})) = self.tcx.hir_get_if_local(*def_id)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -545,22 +545,22 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let (def, ty) = match item.kind {
|
let (def, ty) = match item.kind {
|
||||||
hir::ItemKind::Struct(_, _, ast_generics) => {
|
hir::ItemKind::Struct(_, generics, _) => {
|
||||||
if !ast_generics.params.is_empty() {
|
if !generics.params.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let def = cx.tcx.adt_def(item.owner_id);
|
let def = cx.tcx.adt_def(item.owner_id);
|
||||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||||
}
|
}
|
||||||
hir::ItemKind::Union(_, _, ast_generics) => {
|
hir::ItemKind::Union(_, generics, _) => {
|
||||||
if !ast_generics.params.is_empty() {
|
if !generics.params.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let def = cx.tcx.adt_def(item.owner_id);
|
let def = cx.tcx.adt_def(item.owner_id);
|
||||||
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
(def, Ty::new_adt(cx.tcx, def, ty::List::empty()))
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(_, _, ast_generics) => {
|
hir::ItemKind::Enum(_, generics, _) => {
|
||||||
if !ast_generics.params.is_empty() {
|
if !generics.params.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let def = cx.tcx.adt_def(item.owner_id);
|
let def = cx.tcx.adt_def(item.owner_id);
|
||||||
@@ -1422,7 +1422,7 @@ impl TypeAliasBounds {
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
impl<'tcx> LateLintPass<'tcx> for TypeAliasBounds {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
|
||||||
let hir::ItemKind::TyAlias(_, hir_ty, generics) = item.kind else { return };
|
let hir::ItemKind::TyAlias(_, generics, hir_ty) = item.kind else { return };
|
||||||
|
|
||||||
// There must not be a where clause.
|
// There must not be a where clause.
|
||||||
if generics.predicates.is_empty() {
|
if generics.predicates.is_empty() {
|
||||||
@@ -2125,9 +2125,9 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
|
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
|
||||||
|
|
||||||
let def_id = item.owner_id.def_id;
|
let def_id = item.owner_id.def_id;
|
||||||
if let hir::ItemKind::Struct(_, _, hir_generics)
|
if let hir::ItemKind::Struct(_, generics, _)
|
||||||
| hir::ItemKind::Enum(_, _, hir_generics)
|
| hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::Union(_, _, hir_generics) = item.kind
|
| hir::ItemKind::Union(_, generics, _) = item.kind
|
||||||
{
|
{
|
||||||
let inferred_outlives = cx.tcx.inferred_outlives_of(def_id);
|
let inferred_outlives = cx.tcx.inferred_outlives_of(def_id);
|
||||||
if inferred_outlives.is_empty() {
|
if inferred_outlives.is_empty() {
|
||||||
@@ -2135,7 +2135,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let ty_generics = cx.tcx.generics_of(def_id);
|
let ty_generics = cx.tcx.generics_of(def_id);
|
||||||
let num_where_predicates = hir_generics
|
let num_where_predicates = generics
|
||||||
.predicates
|
.predicates
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|predicate| predicate.kind.in_where_clause())
|
.filter(|predicate| predicate.kind.in_where_clause())
|
||||||
@@ -2145,7 +2145,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
let mut lint_spans = Vec::new();
|
let mut lint_spans = Vec::new();
|
||||||
let mut where_lint_spans = Vec::new();
|
let mut where_lint_spans = Vec::new();
|
||||||
let mut dropped_where_predicate_count = 0;
|
let mut dropped_where_predicate_count = 0;
|
||||||
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
|
for (i, where_predicate) in generics.predicates.iter().enumerate() {
|
||||||
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
let (relevant_lifetimes, bounds, predicate_span, in_where_clause) =
|
||||||
match where_predicate.kind {
|
match where_predicate.kind {
|
||||||
hir::WherePredicateKind::RegionPredicate(predicate) => {
|
hir::WherePredicateKind::RegionPredicate(predicate) => {
|
||||||
@@ -2228,7 +2228,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
} else if i + 1 < num_where_predicates {
|
} else if i + 1 < num_where_predicates {
|
||||||
// If all the bounds on a predicate were inferable and there are
|
// If all the bounds on a predicate were inferable and there are
|
||||||
// further predicates, we want to eat the trailing comma.
|
// further predicates, we want to eat the trailing comma.
|
||||||
let next_predicate_span = hir_generics.predicates[i + 1].span;
|
let next_predicate_span = generics.predicates[i + 1].span;
|
||||||
if next_predicate_span.from_expansion() {
|
if next_predicate_span.from_expansion() {
|
||||||
where_lint_spans.push(predicate_span);
|
where_lint_spans.push(predicate_span);
|
||||||
} else {
|
} else {
|
||||||
@@ -2237,7 +2237,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Eat the optional trailing comma after the last predicate.
|
// Eat the optional trailing comma after the last predicate.
|
||||||
let where_span = hir_generics.where_clause_span;
|
let where_span = generics.where_clause_span;
|
||||||
if where_span.from_expansion() {
|
if where_span.from_expansion() {
|
||||||
where_lint_spans.push(predicate_span);
|
where_lint_spans.push(predicate_span);
|
||||||
} else {
|
} else {
|
||||||
@@ -2255,18 +2255,18 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
|
|||||||
|
|
||||||
// If all predicates in where clause are inferable, drop the entire clause
|
// If all predicates in where clause are inferable, drop the entire clause
|
||||||
// (including the `where`)
|
// (including the `where`)
|
||||||
if hir_generics.has_where_clause_predicates
|
if generics.has_where_clause_predicates
|
||||||
&& dropped_where_predicate_count == num_where_predicates
|
&& dropped_where_predicate_count == num_where_predicates
|
||||||
{
|
{
|
||||||
let where_span = hir_generics.where_clause_span;
|
let where_span = generics.where_clause_span;
|
||||||
// Extend the where clause back to the closing `>` of the
|
// Extend the where clause back to the closing `>` of the
|
||||||
// generics, except for tuple struct, which have the `where`
|
// generics, except for tuple struct, which have the `where`
|
||||||
// after the fields of the struct.
|
// after the fields of the struct.
|
||||||
let full_where_span =
|
let full_where_span =
|
||||||
if let hir::ItemKind::Struct(_, hir::VariantData::Tuple(..), _) = item.kind {
|
if let hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(..)) = item.kind {
|
||||||
where_span
|
where_span
|
||||||
} else {
|
} else {
|
||||||
hir_generics.span.shrink_to_hi().to(where_span)
|
generics.span.shrink_to_hi().to(where_span)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Due to macro expansions, the `full_where_span` might not actually contain all
|
// Due to macro expansions, the `full_where_span` might not actually contain all
|
||||||
|
|||||||
@@ -95,8 +95,8 @@ impl<'tcx> LateLintPass<'tcx> for DefaultCouldBeDerived {
|
|||||||
kind:
|
kind:
|
||||||
hir::ItemKind::Struct(
|
hir::ItemKind::Struct(
|
||||||
_,
|
_,
|
||||||
hir::VariantData::Struct { fields, recovered: _ },
|
|
||||||
_generics,
|
_generics,
|
||||||
|
hir::VariantData::Struct { fields, recovered: _ },
|
||||||
),
|
),
|
||||||
..
|
..
|
||||||
})) => fields.iter().map(|f| (f.ident.name, f)).collect::<FxHashMap<_, _>>(),
|
})) => fields.iter().map(|f| (f.ident.name, f)).collect::<FxHashMap<_, _>>(),
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions {
|
|||||||
&& parent_opt_item_name != Some(kw::Underscore)
|
&& parent_opt_item_name != Some(kw::Underscore)
|
||||||
&& let Some(parent) = parent.as_local()
|
&& let Some(parent) = parent.as_local()
|
||||||
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
|
&& let Node::Item(item) = cx.tcx.hir_node_by_def_id(parent)
|
||||||
&& let ItemKind::Const(ident, ty, _, _) = item.kind
|
&& let ItemKind::Const(ident, _, ty, _) = item.kind
|
||||||
&& let TyKind::Tup(&[]) = ty.kind
|
&& let TyKind::Tup(&[]) = ty.kind
|
||||||
{
|
{
|
||||||
Some(ident.span)
|
Some(ident.span)
|
||||||
|
|||||||
@@ -513,7 +513,7 @@ impl<'tcx> LateLintPass<'tcx> for NonUpperCaseGlobals {
|
|||||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||||
let attrs = cx.tcx.hir_attrs(it.hir_id());
|
let attrs = cx.tcx.hir_attrs(it.hir_id());
|
||||||
match it.kind {
|
match it.kind {
|
||||||
hir::ItemKind::Static(ident, ..)
|
hir::ItemKind::Static(_, ident, ..)
|
||||||
if !ast::attr::contains_name(attrs, sym::no_mangle) =>
|
if !ast::attr::contains_name(attrs, sym::no_mangle) =>
|
||||||
{
|
{
|
||||||
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &ident);
|
NonUpperCaseGlobals::check_upper_case(cx, "static variable", &ident);
|
||||||
|
|||||||
@@ -1710,7 +1710,7 @@ impl ImproperCTypesDefinitions {
|
|||||||
&& cx.tcx.sess.target.os == "aix"
|
&& cx.tcx.sess.target.os == "aix"
|
||||||
&& !adt_def.all_fields().next().is_none()
|
&& !adt_def.all_fields().next().is_none()
|
||||||
{
|
{
|
||||||
let struct_variant_data = item.expect_struct().1;
|
let struct_variant_data = item.expect_struct().2;
|
||||||
for field_def in struct_variant_data.fields().iter().skip(1) {
|
for field_def in struct_variant_data.fields().iter().skip(1) {
|
||||||
// Struct fields (after the first field) are checked for the
|
// Struct fields (after the first field) are checked for the
|
||||||
// power alignment rule, as fields after the first are likely
|
// power alignment rule, as fields after the first are likely
|
||||||
@@ -1735,9 +1735,9 @@ impl ImproperCTypesDefinitions {
|
|||||||
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
|
impl<'tcx> LateLintPass<'tcx> for ImproperCTypesDefinitions {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Static(_, ty, ..)
|
hir::ItemKind::Static(_, _, ty, _)
|
||||||
| hir::ItemKind::Const(_, ty, ..)
|
| hir::ItemKind::Const(_, _, ty, _)
|
||||||
| hir::ItemKind::TyAlias(_, ty, ..) => {
|
| hir::ItemKind::TyAlias(_, _, ty) => {
|
||||||
self.check_ty_maybe_containing_foreign_fnptr(
|
self.check_ty_maybe_containing_foreign_fnptr(
|
||||||
cx,
|
cx,
|
||||||
ty,
|
ty,
|
||||||
@@ -1804,7 +1804,7 @@ declare_lint_pass!(VariantSizeDifferences => [VARIANT_SIZE_DIFFERENCES]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
impl<'tcx> LateLintPass<'tcx> for VariantSizeDifferences {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) {
|
||||||
if let hir::ItemKind::Enum(_, ref enum_definition, _) = it.kind {
|
if let hir::ItemKind::Enum(_, _, ref enum_definition) = it.kind {
|
||||||
let t = cx.tcx.type_of(it.owner_id).instantiate_identity();
|
let t = cx.tcx.type_of(it.owner_id).instantiate_identity();
|
||||||
let ty = cx.tcx.erase_regions(t);
|
let ty = cx.tcx.erase_regions(t);
|
||||||
let Ok(layout) = cx.layout_of(ty) else { return };
|
let Ok(layout) = cx.layout_of(ty) else { return };
|
||||||
|
|||||||
@@ -920,7 +920,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}) => until_within(*outer_span, generics.where_clause_span),
|
}) => until_within(*outer_span, generics.where_clause_span),
|
||||||
// Constants and Statics.
|
// Constants and Statics.
|
||||||
Node::Item(Item {
|
Node::Item(Item {
|
||||||
kind: ItemKind::Const(_, ty, ..) | ItemKind::Static(_, ty, ..),
|
kind: ItemKind::Const(_, _, ty, _) | ItemKind::Static(_, _, ty, _),
|
||||||
span: outer_span,
|
span: outer_span,
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -558,7 +558,7 @@ fn construct_const<'a, 'tcx>(
|
|||||||
// Figure out what primary body this item has.
|
// Figure out what primary body this item has.
|
||||||
let (span, const_ty_span) = match tcx.hir_node(hir_id) {
|
let (span, const_ty_span) = match tcx.hir_node(hir_id) {
|
||||||
Node::Item(hir::Item {
|
Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Static(_, ty, _, _) | hir::ItemKind::Const(_, ty, _, _),
|
kind: hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _),
|
||||||
span,
|
span,
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -802,7 +802,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
match target {
|
match target {
|
||||||
Target::Struct => {
|
Target::Struct => {
|
||||||
if let Some(ItemLike::Item(hir::Item {
|
if let Some(ItemLike::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Struct { fields, .. }, _),
|
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Struct { fields, .. }),
|
||||||
..
|
..
|
||||||
})) = item
|
})) = item
|
||||||
&& !fields.is_empty()
|
&& !fields.is_empty()
|
||||||
@@ -1130,12 +1130,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Enum(_, _, generics) | ItemKind::Struct(_, _, generics)
|
ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _)
|
||||||
if generics.params.len() != 0 => {}
|
if generics.params.len() != 0 => {}
|
||||||
ItemKind::Trait(_, _, _, generics, _, items)
|
ItemKind::Trait(_, _, _, generics, _, items)
|
||||||
if generics.params.len() != 0
|
if generics.params.len() != 0
|
||||||
|| items.iter().any(|item| matches!(item.kind, AssocItemKind::Type)) => {}
|
|| items.iter().any(|item| matches!(item.kind, AssocItemKind::Type)) => {}
|
||||||
ItemKind::TyAlias(_, _, generics) if generics.params.len() != 0 => {}
|
ItemKind::TyAlias(_, generics, _) if generics.params.len() != 0 => {}
|
||||||
_ => {
|
_ => {
|
||||||
self.dcx().emit_err(errors::DocSearchUnboxInvalid { span: meta.span() });
|
self.dcx().emit_err(errors::DocSearchUnboxInvalid { span: meta.span() });
|
||||||
}
|
}
|
||||||
@@ -2792,7 +2792,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_c_like_enum(item: &Item<'_>) -> bool {
|
fn is_c_like_enum(item: &Item<'_>) -> bool {
|
||||||
if let ItemKind::Enum(_, ref def, _) = item.kind {
|
if let ItemKind::Enum(_, _, ref def) = item.kind {
|
||||||
for variant in def.variants {
|
for variant in def.variants {
|
||||||
match variant.data {
|
match variant.data {
|
||||||
hir::VariantData::Unit(..) => { /* continue */ }
|
hir::VariantData::Unit(..) => { /* continue */ }
|
||||||
|
|||||||
@@ -749,7 +749,7 @@ fn check_item<'tcx>(
|
|||||||
match tcx.def_kind(id.owner_id) {
|
match tcx.def_kind(id.owner_id) {
|
||||||
DefKind::Enum => {
|
DefKind::Enum => {
|
||||||
let item = tcx.hir_item(id);
|
let item = tcx.hir_item(id);
|
||||||
if let hir::ItemKind::Enum(_, ref enum_def, _) = item.kind {
|
if let hir::ItemKind::Enum(_, _, ref enum_def) = item.kind {
|
||||||
if let Some(comes_from_allow) = allow_dead_code {
|
if let Some(comes_from_allow) = allow_dead_code {
|
||||||
worklist.extend(
|
worklist.extend(
|
||||||
enum_def.variants.iter().map(|variant| (variant.def_id, comes_from_allow)),
|
enum_def.variants.iter().map(|variant| (variant.def_id, comes_from_allow)),
|
||||||
@@ -804,7 +804,7 @@ fn check_item<'tcx>(
|
|||||||
}
|
}
|
||||||
DefKind::Struct => {
|
DefKind::Struct => {
|
||||||
let item = tcx.hir_item(id);
|
let item = tcx.hir_item(id);
|
||||||
if let hir::ItemKind::Struct(_, ref variant_data, _) = item.kind
|
if let hir::ItemKind::Struct(_, _, ref variant_data) = item.kind
|
||||||
&& let Some(ctor_def_id) = variant_data.ctor_def_id()
|
&& let Some(ctor_def_id) = variant_data.ctor_def_id()
|
||||||
{
|
{
|
||||||
struct_constructors.insert(ctor_def_id, item.owner_id.def_id);
|
struct_constructors.insert(ctor_def_id, item.owner_id.def_id);
|
||||||
@@ -1061,7 +1061,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
|||||||
let tuple_fields = if let Some(parent_id) = parent_item
|
let tuple_fields = if let Some(parent_id) = parent_item
|
||||||
&& let node = tcx.hir_node_by_def_id(parent_id)
|
&& let node = tcx.hir_node_by_def_id(parent_id)
|
||||||
&& let hir::Node::Item(hir::Item {
|
&& let hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Tuple(fields, _, _), _),
|
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(fields, _, _)),
|
||||||
..
|
..
|
||||||
}) = node
|
}) = node
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -430,7 +430,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
|
|||||||
kind = AnnotationKind::DeprecationProhibited;
|
kind = AnnotationKind::DeprecationProhibited;
|
||||||
const_stab_inherit = InheritConstStability::Yes;
|
const_stab_inherit = InheritConstStability::Yes;
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(_, ref sd, _) => {
|
hir::ItemKind::Struct(_, _, ref sd) => {
|
||||||
if let Some(ctor_def_id) = sd.ctor_def_id() {
|
if let Some(ctor_def_id) = sd.ctor_def_id() {
|
||||||
self.annotate(
|
self.annotate(
|
||||||
ctor_def_id,
|
ctor_def_id,
|
||||||
|
|||||||
@@ -599,8 +599,8 @@ impl<'tcx> EmbargoVisitor<'tcx> {
|
|||||||
DefKind::Struct | DefKind::Union => {
|
DefKind::Struct | DefKind::Union => {
|
||||||
// While structs and unions have type privacy, their fields do not.
|
// While structs and unions have type privacy, their fields do not.
|
||||||
let item = self.tcx.hir_expect_item(def_id);
|
let item = self.tcx.hir_expect_item(def_id);
|
||||||
if let hir::ItemKind::Struct(_, ref struct_def, _)
|
if let hir::ItemKind::Struct(_, _, ref struct_def)
|
||||||
| hir::ItemKind::Union(_, ref struct_def, _) = item.kind
|
| hir::ItemKind::Union(_, _, ref struct_def) = item.kind
|
||||||
{
|
{
|
||||||
for field in struct_def.fields() {
|
for field in struct_def.fields() {
|
||||||
let field_vis = self.tcx.local_visibility(field.def_id);
|
let field_vis = self.tcx.local_visibility(field.def_id);
|
||||||
@@ -725,7 +725,7 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Enum(_, ref def, _) => {
|
hir::ItemKind::Enum(_, _, ref def) => {
|
||||||
if let Some(item_ev) = item_ev {
|
if let Some(item_ev) = item_ev {
|
||||||
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
||||||
}
|
}
|
||||||
@@ -763,8 +763,8 @@ impl<'tcx> Visitor<'tcx> for EmbargoVisitor<'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(_, ref struct_def, _)
|
hir::ItemKind::Struct(_, _, ref struct_def)
|
||||||
| hir::ItemKind::Union(_, ref struct_def, _) => {
|
| hir::ItemKind::Union(_, _, ref struct_def) => {
|
||||||
if let Some(item_ev) = item_ev {
|
if let Some(item_ev) = item_ev {
|
||||||
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
self.reach(item.owner_id.def_id, item_ev).generics().predicates();
|
||||||
for field in struct_def.fields() {
|
for field in struct_def.fields() {
|
||||||
@@ -868,7 +868,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TestReachabilityVisitor<'a, 'tcx> {
|
|||||||
self.effective_visibility_diagnostic(item.owner_id.def_id);
|
self.effective_visibility_diagnostic(item.owner_id.def_id);
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
hir::ItemKind::Enum(_, ref def, _) => {
|
hir::ItemKind::Enum(_, _, ref def) => {
|
||||||
for variant in def.variants.iter() {
|
for variant in def.variants.iter() {
|
||||||
self.effective_visibility_diagnostic(variant.def_id);
|
self.effective_visibility_diagnostic(variant.def_id);
|
||||||
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
if let Some(ctor_def_id) = variant.data.ctor_def_id() {
|
||||||
@@ -879,7 +879,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TestReachabilityVisitor<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir::ItemKind::Struct(_, ref def, _) | hir::ItemKind::Union(_, ref def, _) => {
|
hir::ItemKind::Struct(_, _, ref def) | hir::ItemKind::Union(_, _, ref def) => {
|
||||||
if let Some(ctor_def_id) = def.ctor_def_id() {
|
if let Some(ctor_def_id) = def.ctor_def_id() {
|
||||||
self.effective_visibility_diagnostic(ctor_def_id);
|
self.effective_visibility_diagnostic(ctor_def_id);
|
||||||
}
|
}
|
||||||
@@ -1651,7 +1651,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
DefKind::Enum => {
|
DefKind::Enum => {
|
||||||
let item = tcx.hir_item(id);
|
let item = tcx.hir_item(id);
|
||||||
if let hir::ItemKind::Enum(_, ref def, _) = item.kind {
|
if let hir::ItemKind::Enum(_, _, ref def) = item.kind {
|
||||||
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
||||||
|
|
||||||
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
||||||
@@ -1689,8 +1689,8 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
|||||||
// Subitems of structs and unions have their own publicity.
|
// Subitems of structs and unions have their own publicity.
|
||||||
DefKind::Struct | DefKind::Union => {
|
DefKind::Struct | DefKind::Union => {
|
||||||
let item = tcx.hir_item(id);
|
let item = tcx.hir_item(id);
|
||||||
if let hir::ItemKind::Struct(_, ref struct_def, _)
|
if let hir::ItemKind::Struct(_, _, ref struct_def)
|
||||||
| hir::ItemKind::Union(_, ref struct_def, _) = item.kind
|
| hir::ItemKind::Union(_, _, ref struct_def) = item.kind
|
||||||
{
|
{
|
||||||
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
self.check_unnameable(item.owner_id.def_id, effective_vis);
|
||||||
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
self.check(item.owner_id.def_id, item_visibility, effective_vis)
|
||||||
|
|||||||
@@ -2026,7 +2026,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
LetVisitor { span }.visit_body(body).break_value()
|
LetVisitor { span }.visit_body(body).break_value()
|
||||||
}
|
}
|
||||||
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, ty, _, _), .. }) => {
|
hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(_, _, ty, _), .. }) => {
|
||||||
Some(&ty.peel_refs().kind)
|
Some(&ty.peel_refs().kind)
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
@@ -351,14 +351,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
kind:
|
kind:
|
||||||
hir::ItemKind::Struct(_, _, generics)
|
hir::ItemKind::Struct(_, generics, _)
|
||||||
| hir::ItemKind::Enum(_, _, generics)
|
| hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::Union(_, _, generics)
|
| hir::ItemKind::Union(_, generics, _)
|
||||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||||
| hir::ItemKind::Fn { generics, .. }
|
| hir::ItemKind::Fn { generics, .. }
|
||||||
| hir::ItemKind::TyAlias(_, _, generics)
|
| hir::ItemKind::TyAlias(_, generics, _)
|
||||||
| hir::ItemKind::Const(_, _, generics, _)
|
| hir::ItemKind::Const(_, generics, _, _)
|
||||||
| hir::ItemKind::TraitAlias(_, generics, _),
|
| hir::ItemKind::TraitAlias(_, generics, _),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
@@ -411,14 +411,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
hir::Node::Item(hir::Item {
|
hir::Node::Item(hir::Item {
|
||||||
kind:
|
kind:
|
||||||
hir::ItemKind::Struct(_, _, generics)
|
hir::ItemKind::Struct(_, generics, _)
|
||||||
| hir::ItemKind::Enum(_, _, generics)
|
| hir::ItemKind::Enum(_, generics, _)
|
||||||
| hir::ItemKind::Union(_, _, generics)
|
| hir::ItemKind::Union(_, generics, _)
|
||||||
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
| hir::ItemKind::Trait(_, _, _, generics, ..)
|
||||||
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
| hir::ItemKind::Impl(hir::Impl { generics, .. })
|
||||||
| hir::ItemKind::Fn { generics, .. }
|
| hir::ItemKind::Fn { generics, .. }
|
||||||
| hir::ItemKind::TyAlias(_, _, generics)
|
| hir::ItemKind::TyAlias(_, generics, _)
|
||||||
| hir::ItemKind::Const(_, _, generics, _)
|
| hir::ItemKind::Const(_, generics, _, _)
|
||||||
| hir::ItemKind::TraitAlias(_, generics, _),
|
| hir::ItemKind::TraitAlias(_, generics, _),
|
||||||
..
|
..
|
||||||
}) if !param_ty => {
|
}) if !param_ty => {
|
||||||
|
|||||||
@@ -1750,7 +1750,7 @@ fn maybe_expand_private_type_alias<'tcx>(
|
|||||||
} else {
|
} else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
let hir::ItemKind::TyAlias(_, ty, generics) = alias else { return None };
|
let hir::ItemKind::TyAlias(_, generics, ty) = alias else { return None };
|
||||||
|
|
||||||
let final_seg = &path.segments.last().expect("segments were empty");
|
let final_seg = &path.segments.last().expect("segments were empty");
|
||||||
let mut args = DefIdMap::default();
|
let mut args = DefIdMap::default();
|
||||||
@@ -2804,21 +2804,21 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||||||
let mut name = get_name(cx, item, renamed).unwrap();
|
let mut name = get_name(cx, item, renamed).unwrap();
|
||||||
|
|
||||||
let kind = match item.kind {
|
let kind = match item.kind {
|
||||||
ItemKind::Static(_, ty, mutability, body_id) => StaticItem(Static {
|
ItemKind::Static(mutability, _, ty, body_id) => StaticItem(Static {
|
||||||
type_: Box::new(clean_ty(ty, cx)),
|
type_: Box::new(clean_ty(ty, cx)),
|
||||||
mutability,
|
mutability,
|
||||||
expr: Some(body_id),
|
expr: Some(body_id),
|
||||||
}),
|
}),
|
||||||
ItemKind::Const(_, ty, generics, body_id) => ConstantItem(Box::new(Constant {
|
ItemKind::Const(_, generics, ty, body_id) => ConstantItem(Box::new(Constant {
|
||||||
generics: clean_generics(generics, cx),
|
generics: clean_generics(generics, cx),
|
||||||
type_: clean_ty(ty, cx),
|
type_: clean_ty(ty, cx),
|
||||||
kind: ConstantKind::Local { body: body_id, def_id },
|
kind: ConstantKind::Local { body: body_id, def_id },
|
||||||
})),
|
})),
|
||||||
ItemKind::TyAlias(_, hir_ty, generics) => {
|
ItemKind::TyAlias(_, generics, ty) => {
|
||||||
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
|
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
|
||||||
let rustdoc_ty = clean_ty(hir_ty, cx);
|
let rustdoc_ty = clean_ty(ty, cx);
|
||||||
let type_ =
|
let type_ =
|
||||||
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, hir_ty)), cx, None, None);
|
clean_middle_ty(ty::Binder::dummy(lower_ty(cx.tcx, ty)), cx, None, None);
|
||||||
let generics = clean_generics(generics, cx);
|
let generics = clean_generics(generics, cx);
|
||||||
if let Some(count) = cx.current_type_aliases.get_mut(&def_id) {
|
if let Some(count) = cx.current_type_aliases.get_mut(&def_id) {
|
||||||
*count -= 1;
|
*count -= 1;
|
||||||
@@ -2847,7 +2847,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||||||
));
|
));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
ItemKind::Enum(_, def, generics) => EnumItem(Enum {
|
ItemKind::Enum(_, generics, def) => EnumItem(Enum {
|
||||||
variants: def.variants.iter().map(|v| clean_variant(v, cx)).collect(),
|
variants: def.variants.iter().map(|v| clean_variant(v, cx)).collect(),
|
||||||
generics: clean_generics(generics, cx),
|
generics: clean_generics(generics, cx),
|
||||||
}),
|
}),
|
||||||
@@ -2855,11 +2855,11 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||||||
generics: clean_generics(generics, cx),
|
generics: clean_generics(generics, cx),
|
||||||
bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
|
bounds: bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect(),
|
||||||
}),
|
}),
|
||||||
ItemKind::Union(_, variant_data, generics) => UnionItem(Union {
|
ItemKind::Union(_, generics, variant_data) => UnionItem(Union {
|
||||||
generics: clean_generics(generics, cx),
|
generics: clean_generics(generics, cx),
|
||||||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
||||||
}),
|
}),
|
||||||
ItemKind::Struct(_, variant_data, generics) => StructItem(Struct {
|
ItemKind::Struct(_, generics, variant_data) => StructItem(Struct {
|
||||||
ctor_kind: variant_data.ctor_kind(),
|
ctor_kind: variant_data.ctor_kind(),
|
||||||
generics: clean_generics(generics, cx),
|
generics: clean_generics(generics, cx),
|
||||||
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ impl DocVisitor<'_> for CoverageCalculator<'_, '_> {
|
|||||||
data: hir::VariantData::Tuple(_, _, _),
|
data: hir::VariantData::Tuple(_, _, _),
|
||||||
..
|
..
|
||||||
}) | hir::Node::Item(hir::Item {
|
}) | hir::Node::Item(hir::Item {
|
||||||
kind: hir::ItemKind::Struct(_, hir::VariantData::Tuple(_, _, _), _),
|
kind: hir::ItemKind::Struct(_, _, hir::VariantData::Tuple(_, _, _)),
|
||||||
..
|
..
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match &item.kind {
|
match &item.kind {
|
||||||
ItemKind::Enum(_, enum_def, _generics) if self.enable_ordering_for_enum => {
|
ItemKind::Enum(_, _generics, enum_def) if self.enable_ordering_for_enum => {
|
||||||
let mut cur_v: Option<&Variant<'_>> = None;
|
let mut cur_v: Option<&Variant<'_>> = None;
|
||||||
for variant in enum_def.variants {
|
for variant in enum_def.variants {
|
||||||
if variant.span.in_external_macro(cx.sess().source_map()) {
|
if variant.span.in_external_macro(cx.sess().source_map()) {
|
||||||
@@ -288,7 +288,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
|
|||||||
cur_v = Some(variant);
|
cur_v = Some(variant);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _generics) if self.enable_ordering_for_struct => {
|
ItemKind::Struct(_, _generics, VariantData::Struct { fields, .. }) if self.enable_ordering_for_struct => {
|
||||||
let mut cur_f: Option<&FieldDef<'_>> = None;
|
let mut cur_f: Option<&FieldDef<'_>> = None;
|
||||||
for field in *fields {
|
for field in *fields {
|
||||||
if field.span.in_external_macro(cx.sess().source_map()) {
|
if field.span.in_external_macro(cx.sess().source_map()) {
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ impl_lint_pass!(EmptyWithBrackets => [EMPTY_STRUCTS_WITH_BRACKETS, EMPTY_ENUM_VA
|
|||||||
|
|
||||||
impl LateLintPass<'_> for EmptyWithBrackets {
|
impl LateLintPass<'_> for EmptyWithBrackets {
|
||||||
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) {
|
||||||
if let ItemKind::Struct(ident, var_data, _) = &item.kind
|
if let ItemKind::Struct(ident, _, var_data) = &item.kind
|
||||||
&& !item.span.from_expansion()
|
&& !item.span.from_expansion()
|
||||||
&& has_brackets(var_data)
|
&& has_brackets(var_data)
|
||||||
&& let span_after_ident = item.span.with_lo(ident.span.hi())
|
&& let span_after_ident = item.span.with_lo(ident.span.hi())
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ impl<'tcx> LateLintPass<'tcx> for UnportableVariant {
|
|||||||
if cx.tcx.data_layout.pointer_size.bits() != 64 {
|
if cx.tcx.data_layout.pointer_size.bits() != 64 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if let ItemKind::Enum(_, def, _) = &item.kind {
|
if let ItemKind::Enum(_, _, def) = &item.kind {
|
||||||
for var in def.variants {
|
for var in def.variants {
|
||||||
if let Some(anon_const) = &var.disr_expr {
|
if let Some(anon_const) = &var.disr_expr {
|
||||||
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);
|
let def_id = cx.tcx.hir_body_owner_def_id(anon_const.body);
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ fn check_fn_decl(cx: &LateContext<'_>, decl: &FnDecl<'_>, sp: Span, max: u64) {
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
|
impl<'tcx> LateLintPass<'tcx> for ExcessiveBools {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) {
|
||||||
if let ItemKind::Struct(_, variant_data, _) = &item.kind
|
if let ItemKind::Struct(_, _, variant_data) = &item.kind
|
||||||
&& variant_data.fields().len() as u64 > self.max_struct_bools
|
&& variant_data.fields().len() as u64 > self.max_struct_bools
|
||||||
&& has_n_bools(
|
&& has_n_bools(
|
||||||
variant_data.fields().iter().map(|field| field.ty),
|
variant_data.fields().iter().map(|field| field.ty),
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ impl LateLintPass<'_> for ExhaustiveItems {
|
|||||||
"exported enums should not be exhaustive",
|
"exported enums should not be exhaustive",
|
||||||
[].as_slice(),
|
[].as_slice(),
|
||||||
),
|
),
|
||||||
ItemKind::Struct(_, v, ..) => (
|
ItemKind::Struct(_, _, v) => (
|
||||||
EXHAUSTIVE_STRUCTS,
|
EXHAUSTIVE_STRUCTS,
|
||||||
"exported structs should not be exhaustive",
|
"exported structs should not be exhaustive",
|
||||||
v.fields(),
|
v.fields(),
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ fn check_result_large_err<'tcx>(cx: &LateContext<'tcx>, err_ty: Ty<'tcx>, hir_ty
|
|||||||
.did()
|
.did()
|
||||||
.as_local()
|
.as_local()
|
||||||
&& let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id)
|
&& let hir::Node::Item(item) = cx.tcx.hir_node_by_def_id(local_def_id)
|
||||||
&& let hir::ItemKind::Enum(_, ref def, _) = item.kind
|
&& let hir::ItemKind::Enum(_, _, ref def) = item.kind
|
||||||
{
|
{
|
||||||
let variants_size = AdtVariantInfo::new(cx, *adt, subst);
|
let variants_size = AdtVariantInfo::new(cx, *adt, subst);
|
||||||
if let Some((first_variant, variants)) = variants_size.split_first()
|
if let Some((first_variant, variants)) = variants_size.split_first()
|
||||||
|
|||||||
@@ -535,10 +535,10 @@ impl LateLintPass<'_> for ItemNameRepetitions {
|
|||||||
|
|
||||||
if span_is_local(item.span) {
|
if span_is_local(item.span) {
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Enum(_, def, _) => {
|
ItemKind::Enum(_, _, def) => {
|
||||||
self.check_variants(cx, item, &def);
|
self.check_variants(cx, item, &def);
|
||||||
},
|
},
|
||||||
ItemKind::Struct(_, VariantData::Struct { fields, .. }, _) => {
|
ItemKind::Struct(_, _, VariantData::Struct { fields, .. }) => {
|
||||||
self.check_fields(cx, item, fields);
|
self.check_fields(cx, item, fields);
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ impl_lint_pass!(LargeConstArrays => [LARGE_CONST_ARRAYS]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
|
impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
if let ItemKind::Const(ident, _, generics, _) = &item.kind
|
if let ItemKind::Const(ident, generics, _, _) = &item.kind
|
||||||
// Since static items may not have generics, skip generic const items.
|
// Since static items may not have generics, skip generic const items.
|
||||||
// FIXME(generic_const_items): I don't think checking `generics.hwcp` suffices as it
|
// FIXME(generic_const_items): I don't think checking `generics.hwcp` suffices as it
|
||||||
// doesn't account for empty where-clauses that only consist of keyword `where` IINM.
|
// doesn't account for empty where-clauses that only consist of keyword `where` IINM.
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ impl_lint_pass!(LargeEnumVariant => [LARGE_ENUM_VARIANT]);
|
|||||||
|
|
||||||
impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
impl<'tcx> LateLintPass<'tcx> for LargeEnumVariant {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
|
||||||
if let ItemKind::Enum(ident, ref def, _) = item.kind
|
if let ItemKind::Enum(ident, _, ref def) = item.kind
|
||||||
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity()
|
||||||
&& let ty::Adt(adt, subst) = ty.kind()
|
&& let ty::Adt(adt, subst) = ty.kind()
|
||||||
&& adt.variants().len() > 1
|
&& adt.variants().len() > 1
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
|
|||||||
}
|
}
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Enum(_, def, _) if def.variants.len() > 1 => {
|
ItemKind::Enum(_, _, def) if def.variants.len() > 1 => {
|
||||||
let iter = def.variants.iter().filter_map(|v| {
|
let iter = def.variants.iter().filter_map(|v| {
|
||||||
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
|
(matches!(v.data, VariantData::Unit(_, _)) && is_doc_hidden(cx.tcx.hir_attrs(v.hir_id)))
|
||||||
.then_some((v.def_id, v.span))
|
.then_some((v.def_id, v.span))
|
||||||
@@ -98,7 +98,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualNonExhaustive {
|
|||||||
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
|
self.potential_enums.push((item.owner_id.def_id, id, item.span, span));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
ItemKind::Struct(_, variant_data, _) => {
|
ItemKind::Struct(_, _, variant_data) => {
|
||||||
let fields = variant_data.fields();
|
let fields = variant_data.fields();
|
||||||
let private_fields = fields
|
let private_fields = fields
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
@@ -225,7 +225,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug {
|
|||||||
&& let typeck_results = cx.tcx.typeck_body(*body_id)
|
&& let typeck_results = cx.tcx.typeck_body(*body_id)
|
||||||
&& should_lint(cx, typeck_results, block)
|
&& should_lint(cx, typeck_results, block)
|
||||||
// we intentionally only lint structs, see lint description
|
// we intentionally only lint structs, see lint description
|
||||||
&& let ItemKind::Struct(_, data, _) = &self_item.kind
|
&& let ItemKind::Struct(_, _, data) = &self_item.kind
|
||||||
{
|
{
|
||||||
check_struct(cx, typeck_results, block, self_ty, item, data);
|
check_struct(cx, typeck_results, block, self_ty, item, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ struct LazyInfo {
|
|||||||
impl LazyInfo {
|
impl LazyInfo {
|
||||||
fn from_item(cx: &LateContext<'_>, item: &Item<'_>) -> Option<Self> {
|
fn from_item(cx: &LateContext<'_>, item: &Item<'_>) -> Option<Self> {
|
||||||
// Check if item is a `once_cell:sync::Lazy` static.
|
// Check if item is a `once_cell:sync::Lazy` static.
|
||||||
if let ItemKind::Static(_, ty, _, body_id) = item.kind
|
if let ItemKind::Static(_, _, ty, body_id) = item.kind
|
||||||
&& let Some(path_def_id) = path_def_id(cx, ty)
|
&& let Some(path_def_id) = path_def_id(cx, ty)
|
||||||
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
|
&& let hir::TyKind::Path(hir::QPath::Resolved(_, path)) = ty.kind
|
||||||
&& paths::ONCE_CELL_SYNC_LAZY.matches(cx, path_def_id)
|
&& paths::ONCE_CELL_SYNC_LAZY.matches(cx, path_def_id)
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ impl PubUnderscoreFields {
|
|||||||
impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
|
impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
|
||||||
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) {
|
||||||
// This lint only pertains to structs.
|
// This lint only pertains to structs.
|
||||||
let ItemKind::Struct(_, variant_data, _) = &item.kind else {
|
let ItemKind::Struct(_, _, variant_data) = &item.kind else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for TrailingEmptyArray {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
|
fn is_struct_with_trailing_zero_sized_array<'tcx>(cx: &LateContext<'tcx>, item: &Item<'tcx>) -> bool {
|
||||||
if let ItemKind::Struct(_, data, _) = &item.kind
|
if let ItemKind::Struct(_, _, data) = &item.kind
|
||||||
&& let Some(last_field) = data.fields().last()
|
&& let Some(last_field) = data.fields().last()
|
||||||
&& let field_ty = cx.tcx.normalize_erasing_regions(
|
&& let field_ty = cx.tcx.normalize_erasing_regions(
|
||||||
cx.typing_env(),
|
cx.typing_env(),
|
||||||
|
|||||||
@@ -447,7 +447,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
|
|||||||
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
let is_exported = cx.effective_visibilities.is_exported(item.owner_id.def_id);
|
||||||
|
|
||||||
match item.kind {
|
match item.kind {
|
||||||
ItemKind::Static(_, ty, _, _) | ItemKind::Const(_, ty, _, _) => self.check_ty(
|
ItemKind::Static(_, _, ty, _) | ItemKind::Const(_, _, ty, _) => self.check_ty(
|
||||||
cx,
|
cx,
|
||||||
ty,
|
ty,
|
||||||
CheckTyContext {
|
CheckTyContext {
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ impl LateLintPass<'_> for UpperCaseAcronyms {
|
|||||||
ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, ident, ..) => {
|
ItemKind::TyAlias(ident, ..) | ItemKind::Struct(ident, ..) | ItemKind::Trait(_, _, ident, ..) => {
|
||||||
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
||||||
},
|
},
|
||||||
ItemKind::Enum(ident, ref enumdef, _) => {
|
ItemKind::Enum(ident, _, ref enumdef) => {
|
||||||
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
check_ident(cx, &ident, it.hir_id(), self.upper_case_acronyms_aggressive);
|
||||||
// check enum variants separately because again we only want to lint on private enums and
|
// check enum variants separately because again we only want to lint on private enums and
|
||||||
// the fn check_variant does not know about the vis of the enum of its variants
|
// the fn check_variant does not know about the vis of the enum of its variants
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
|
|||||||
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
|
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
|
||||||
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
|
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
|
||||||
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),
|
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),
|
||||||
ItemKind::Struct(_, VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")),
|
ItemKind::Struct(_, _, VariantData::Struct { .. }) => (Pat::Str("struct"), Pat::Str("}")),
|
||||||
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
|
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),
|
||||||
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
|
ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")),
|
||||||
ItemKind::Trait(_, Safety::Unsafe, ..)
|
ItemKind::Trait(_, Safety::Unsafe, ..)
|
||||||
|
|||||||
@@ -2362,7 +2362,7 @@ fn with_test_item_names(tcx: TyCtxt<'_>, module: LocalModDefId, f: impl FnOnce(&
|
|||||||
for id in tcx.hir_module_free_items(module) {
|
for id in tcx.hir_module_free_items(module) {
|
||||||
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
|
if matches!(tcx.def_kind(id.owner_id), DefKind::Const)
|
||||||
&& let item = tcx.hir_item(id)
|
&& let item = tcx.hir_item(id)
|
||||||
&& let ItemKind::Const(ident, ty, _generics, _body) = item.kind
|
&& let ItemKind::Const(ident, _generics, ty, _body) = item.kind
|
||||||
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
|
&& let TyKind::Path(QPath::Resolved(_, path)) = ty.kind
|
||||||
// We could also check for the type name `test::TestDescAndFn`
|
// We could also check for the type name `test::TestDescAndFn`
|
||||||
&& let Res::Def(DefKind::Struct, _) = path.res
|
&& let Res::Def(DefKind::Struct, _) = path.res
|
||||||
|
|||||||
Reference in New Issue
Block a user