box a bunch of large types

This commit is contained in:
Oli Scherer 2023-03-29 12:34:05 +00:00
parent ec74653652
commit 4bebdd7104
16 changed files with 83 additions and 79 deletions

View File

@ -2917,11 +2917,11 @@ pub enum ItemKind {
/// A static item (`static`). /// A static item (`static`).
/// ///
/// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`. /// E.g., `static FOO: i32 = 42;` or `static FOO: &'static str = "bar";`.
Static(Static), Static(Box<Static>),
/// A constant item (`const`). /// A constant item (`const`).
/// ///
/// E.g., `const FOO: i32 = 42;`. /// E.g., `const FOO: i32 = 42;`.
Const(ConstItem), Const(Box<ConstItem>),
/// A function declaration (`fn`). /// A function declaration (`fn`).
/// ///
/// E.g., `fn foo(bar: usize) -> usize { .. }`. /// E.g., `fn foo(bar: usize) -> usize { .. }`.
@ -3037,7 +3037,7 @@ pub type AssocItem = Item<AssocItemKind>;
pub enum AssocItemKind { pub enum AssocItemKind {
/// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`. /// An associated constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
/// If `def` is parsed, then the constant is provided, and otherwise required. /// If `def` is parsed, then the constant is provided, and otherwise required.
Const(ConstItem), Const(Box<ConstItem>),
/// An associated function. /// An associated function.
Fn(Box<Fn>), Fn(Box<Fn>),
/// An associated type. /// An associated type.
@ -3049,7 +3049,7 @@ pub enum AssocItemKind {
impl AssocItemKind { impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness { pub fn defaultness(&self) -> Defaultness {
match *self { match *self {
Self::Const(ConstItem { defaultness, .. }) Self::Const(box ConstItem { defaultness, .. })
| Self::Fn(box Fn { defaultness, .. }) | Self::Fn(box Fn { defaultness, .. })
| Self::Type(box TyAlias { defaultness, .. }) => defaultness, | Self::Type(box TyAlias { defaultness, .. }) => defaultness,
Self::MacCall(..) => Defaultness::Final, Self::MacCall(..) => Defaultness::Final,
@ -3099,7 +3099,7 @@ impl From<ForeignItemKind> for ItemKind {
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind { fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
match foreign_item_kind { match foreign_item_kind {
ForeignItemKind::Static(a, b, c) => { ForeignItemKind::Static(a, b, c) => {
ItemKind::Static(Static { ty: a, mutability: b, expr: c }) ItemKind::Static(Static { ty: a, mutability: b, expr: c }.into())
} }
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind), ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind), ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
@ -3113,7 +3113,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> { fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
Ok(match item_kind { Ok(match item_kind {
ItemKind::Static(Static { ty: a, mutability: b, expr: c }) => { ItemKind::Static(box Static { ty: a, mutability: b, expr: c }) => {
ForeignItemKind::Static(a, b, c) ForeignItemKind::Static(a, b, c)
} }
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind), ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
@ -3132,8 +3132,8 @@ mod size_asserts {
use super::*; use super::*;
use rustc_data_structures::static_assert_size; use rustc_data_structures::static_assert_size;
// tidy-alphabetical-start // tidy-alphabetical-start
static_assert_size!(AssocItem, 104); static_assert_size!(AssocItem, 88);
static_assert_size!(AssocItemKind, 32); static_assert_size!(AssocItemKind, 16);
static_assert_size!(Attribute, 32); static_assert_size!(Attribute, 32);
static_assert_size!(Block, 32); static_assert_size!(Block, 32);
static_assert_size!(Expr, 72); static_assert_size!(Expr, 72);

View File

@ -1030,7 +1030,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
match kind { match kind {
ItemKind::ExternCrate(_orig_name) => {} ItemKind::ExternCrate(_orig_name) => {}
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree), ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
ItemKind::Static(Static { ty, mutability: _, expr }) => { ItemKind::Static(box Static { ty, mutability: _, expr }) => {
vis.visit_ty(ty); vis.visit_ty(ty);
visit_opt(expr, |expr| vis.visit_expr(expr)); visit_opt(expr, |expr| vis.visit_expr(expr));
} }

View File

@ -305,8 +305,8 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
match &item.kind { match &item.kind {
ItemKind::ExternCrate(_) => {} ItemKind::ExternCrate(_) => {}
ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false), ItemKind::Use(use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
ItemKind::Static(Static { ty, mutability: _, expr }) ItemKind::Static(box Static { ty, mutability: _, expr })
| ItemKind::Const(ConstItem { ty, expr, .. }) => { | ItemKind::Const(box ConstItem { ty, expr, .. }) => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }
@ -675,7 +675,7 @@ pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem,
visitor.visit_ident(ident); visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs); walk_list!(visitor, visit_attribute, attrs);
match kind { match kind {
AssocItemKind::Const(ConstItem { ty, expr, .. }) => { AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
visitor.visit_ty(ty); visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr); walk_list!(visitor, visit_expr, expr);
} }

View File

@ -229,11 +229,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs) self.lower_use_tree(use_tree, &prefix, id, vis_span, ident, attrs)
} }
ItemKind::Static(ast::Static { ty: t, mutability: m, expr: e }) => { ItemKind::Static(box ast::Static { ty: t, mutability: m, expr: e }) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref()); let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
hir::ItemKind::Static(ty, *m, body_id) hir::ItemKind::Static(ty, *m, body_id)
} }
ItemKind::Const(ast::ConstItem { ty, expr, .. }) => { ItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref()); let (ty, body_id) = self.lower_const_item(ty, span, expr.as_deref());
hir::ItemKind::Const(ty, body_id) hir::ItemKind::Const(ty, body_id)
} }
@ -708,7 +708,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let trait_item_def_id = hir_id.expect_owner(); let trait_item_def_id = hir_id.expect_owner();
let (generics, kind, has_default) = match &i.kind { let (generics, kind, has_default) = match &i.kind {
AssocItemKind::Const(ConstItem { ty, expr, .. }) => { AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
let ty = let ty =
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy)); self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
let body = expr.as_ref().map(|x| self.lower_const_body(i.span, Some(x))); let body = expr.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
@ -809,7 +809,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_attrs(hir_id, &i.attrs); self.lower_attrs(hir_id, &i.attrs);
let (generics, kind) = match &i.kind { let (generics, kind) = match &i.kind {
AssocItemKind::Const(ConstItem { ty, expr, .. }) => { AssocItemKind::Const(box ConstItem { ty, expr, .. }) => {
let ty = let ty =
self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy)); self.lower_ty(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
( (

View File

@ -983,14 +983,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.err_handler().emit_err(errors::FieldlessUnion { span: item.span }); self.err_handler().emit_err(errors::FieldlessUnion { span: item.span });
} }
} }
ItemKind::Const(ConstItem { defaultness, expr: None, .. }) => { ItemKind::Const(box ConstItem { defaultness, expr: None, .. }) => {
self.check_defaultness(item.span, *defaultness); self.check_defaultness(item.span, *defaultness);
self.session.emit_err(errors::ConstWithoutBody { self.session.emit_err(errors::ConstWithoutBody {
span: item.span, span: item.span,
replace_span: self.ending_semi_or_hi(item.span), replace_span: self.ending_semi_or_hi(item.span),
}); });
} }
ItemKind::Static(Static { expr: None, .. }) => { ItemKind::Static(box Static { expr: None, .. }) => {
self.session.emit_err(errors::StaticWithoutBody { self.session.emit_err(errors::StaticWithoutBody {
span: item.span, span: item.span,
replace_span: self.ending_semi_or_hi(item.span), replace_span: self.ending_semi_or_hi(item.span),
@ -1259,7 +1259,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
if ctxt == AssocCtxt::Impl { if ctxt == AssocCtxt::Impl {
match &item.kind { match &item.kind {
AssocItemKind::Const(ConstItem { expr: None, .. }) => { AssocItemKind::Const(box ConstItem { expr: None, .. }) => {
self.session.emit_err(errors::AssocConstWithoutBody { self.session.emit_err(errors::AssocConstWithoutBody {
span: item.span, span: item.span,
replace_span: self.ending_semi_or_hi(item.span), replace_span: self.ending_semi_or_hi(item.span),

View File

@ -157,7 +157,7 @@ impl<'a> State<'a> {
self.print_use_tree(tree); self.print_use_tree(tree);
self.word(";"); self.word(";");
} }
ast::ItemKind::Static(Static { ty, mutability: mutbl, expr: body }) => { ast::ItemKind::Static(box Static { ty, mutability: mutbl, expr: body }) => {
let def = ast::Defaultness::Final; let def = ast::Defaultness::Final;
self.print_item_const( self.print_item_const(
item.ident, item.ident,
@ -168,7 +168,7 @@ impl<'a> State<'a> {
def, def,
); );
} }
ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr }) => { ast::ItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
self.print_item_const( self.print_item_const(
item.ident, item.ident,
None, None,
@ -515,7 +515,7 @@ impl<'a> State<'a> {
ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => { ast::AssocItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs); self.print_fn_full(sig, ident, generics, vis, *defaultness, body.as_deref(), attrs);
} }
ast::AssocItemKind::Const(ast::ConstItem { defaultness, ty, expr }) => { ast::AssocItemKind::Const(box ast::ConstItem { defaultness, ty, expr }) => {
self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness); self.print_item_const(ident, None, ty, expr.as_deref(), vis, *defaultness);
} }
ast::AssocItemKind::Type(box ast::TyAlias { ast::AssocItemKind::Type(box ast::TyAlias {

View File

@ -25,12 +25,12 @@ pub fn expand(
// FIXME - if we get deref patterns, use them to reduce duplication here // FIXME - if we get deref patterns, use them to reduce duplication here
let (item, is_stmt, ty_span) = let (item, is_stmt, ty_span) =
if let Annotatable::Item(item) = &item if let Annotatable::Item(item) = &item
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind && let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
{ {
(item, false, ecx.with_def_site_ctxt(ty.span)) (item, false, ecx.with_def_site_ctxt(ty.span))
} else if let Annotatable::Stmt(stmt) = &item } else if let Annotatable::Stmt(stmt) = &item
&& let StmtKind::Item(item) = &stmt.kind && let StmtKind::Item(item) = &stmt.kind
&& let ItemKind::Static(ast::Static { ty, ..}) = &item.kind && let ItemKind::Static(box ast::Static { ty, ..}) = &item.kind
{ {
(item, true, ecx.with_def_site_ctxt(ty.span)) (item, true, ecx.with_def_site_ctxt(ty.span))
} else { } else {

View File

@ -254,25 +254,27 @@ pub fn expand_test_or_bench(
let location_info = get_location_info(cx, &item); let location_info = get_location_info(cx, &item);
let mut test_const = cx.item( let mut test_const =
sp, cx.item(
Ident::new(item.ident.name, sp), sp,
thin_vec![ Ident::new(item.ident.name, sp),
// #[cfg(test)] thin_vec![
cx.attr_nested_word(sym::cfg, sym::test, attr_sp), // #[cfg(test)]
// #[rustc_test_marker = "test_case_sort_key"] cx.attr_nested_word(sym::cfg, sym::test, attr_sp),
cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp), // #[rustc_test_marker = "test_case_sort_key"]
], cx.attr_name_value_str(sym::rustc_test_marker, test_path_symbol, attr_sp),
// const $ident: test::TestDescAndFn = ],
ast::ItemKind::Const(ast::ConstItem { // const $ident: test::TestDescAndFn =
defaultness: ast::Defaultness::Final, ast::ItemKind::Const(
ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))), ast::ConstItem {
// test::TestDescAndFn { defaultness: ast::Defaultness::Final,
expr: Some( ty: cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
cx.expr_struct( // test::TestDescAndFn {
sp, expr: Some(
test_path("TestDescAndFn"), cx.expr_struct(
thin_vec![ sp,
test_path("TestDescAndFn"),
thin_vec![
// desc: test::TestDesc { // desc: test::TestDesc {
field( field(
"desc", "desc",
@ -359,10 +361,12 @@ pub fn expand_test_or_bench(
// testfn: test::StaticTestFn(...) | test::StaticBenchFn(...) // testfn: test::StaticTestFn(...) | test::StaticBenchFn(...)
field("testfn", test_fn), // } field("testfn", test_fn), // }
], ],
), // } ), // }
),
}
.into(),
), ),
}), );
);
test_const = test_const.map(|mut tc| { test_const = test_const.map(|mut tc| {
tc.vis.kind = ast::VisibilityKind::Public; tc.vis.kind = ast::VisibilityKind::Public;
tc tc

View File

@ -627,7 +627,7 @@ impl<'a> ExtCtxt<'a> {
span, span,
name, name,
AttrVec::new(), AttrVec::new(),
ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }), ast::ItemKind::Static(ast::Static { ty, mutability, expr: Some(expr) }.into()),
) )
} }
@ -643,7 +643,7 @@ impl<'a> ExtCtxt<'a> {
span, span,
name, name,
AttrVec::new(), AttrVec::new(),
ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr: Some(expr) }), ast::ItemKind::Const(ast::ConstItem { defaultness, ty, expr: Some(expr) }.into()),
) )
} }

View File

@ -805,8 +805,8 @@ trait UnusedDelimLint {
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) {
use ast::ItemKind::*; use ast::ItemKind::*;
if let Const(ast::ConstItem { expr: Some(expr), .. }) if let Const(box ast::ConstItem { expr: Some(expr), .. })
| Static(ast::Static { expr: Some(expr), .. }) = &item.kind | Static(box ast::Static { expr: Some(expr), .. }) = &item.kind
{ {
self.check_unused_delims_expr( self.check_unused_delims_expr(
cx, cx,

View File

@ -228,7 +228,7 @@ impl<'a> Parser<'a> {
self.bump(); // `static` self.bump(); // `static`
let m = self.parse_mutability(); let m = self.parse_mutability();
let (ident, ty, expr) = self.parse_item_global(Some(m))?; let (ident, ty, expr) = self.parse_item_global(Some(m))?;
(ident, ItemKind::Static(Static { ty, mutability: m, expr })) (ident, ItemKind::Static(Box::new(Static { ty, mutability: m, expr })))
} else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) { } else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) {
// CONST ITEM // CONST ITEM
if self.token.is_keyword(kw::Impl) { if self.token.is_keyword(kw::Impl) {
@ -237,7 +237,7 @@ impl<'a> Parser<'a> {
} else { } else {
self.recover_const_mut(const_span); self.recover_const_mut(const_span);
let (ident, ty, expr) = self.parse_item_global(None)?; let (ident, ty, expr) = self.parse_item_global(None)?;
(ident, ItemKind::Const(ConstItem { defaultness: def_(), ty, expr })) (ident, ItemKind::Const(Box::new(ConstItem { defaultness: def_(), ty, expr })))
} }
} else if self.check_keyword(kw::Trait) || self.check_auto_or_unsafe_trait_item() { } else if self.check_keyword(kw::Trait) || self.check_auto_or_unsafe_trait_item() {
// TRAIT ITEM // TRAIT ITEM
@ -863,13 +863,13 @@ impl<'a> Parser<'a> {
let kind = match AssocItemKind::try_from(kind) { let kind = match AssocItemKind::try_from(kind) {
Ok(kind) => kind, Ok(kind) => kind,
Err(kind) => match kind { Err(kind) => match kind {
ItemKind::Static(Static { ty, mutability: _, expr }) => { ItemKind::Static(box Static { ty, mutability: _, expr }) => {
self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span }); self.sess.emit_err(errors::AssociatedStaticItemNotAllowed { span });
AssocItemKind::Const(ConstItem { AssocItemKind::Const(Box::new(ConstItem {
defaultness: Defaultness::Final, defaultness: Defaultness::Final,
ty, ty,
expr, expr,
}) }))
} }
_ => return self.error_bad_item_kind(span, &kind, "`trait`s or `impl`s"), _ => return self.error_bad_item_kind(span, &kind, "`trait`s or `impl`s"),
}, },
@ -1119,7 +1119,7 @@ impl<'a> Parser<'a> {
let kind = match ForeignItemKind::try_from(kind) { let kind = match ForeignItemKind::try_from(kind) {
Ok(kind) => kind, Ok(kind) => kind,
Err(kind) => match kind { Err(kind) => match kind {
ItemKind::Const(ConstItem { ty, expr, .. }) => { ItemKind::Const(box ConstItem { ty, expr, .. }) => {
self.sess.emit_err(errors::ExternItemCannotBeConst { self.sess.emit_err(errors::ExternItemCannotBeConst {
ident_span: ident.span, ident_span: ident.span,
const_span: span.with_hi(ident.span.lo()), const_span: span.with_hi(ident.span.lo()),

View File

@ -688,7 +688,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> {
} }
// These items live in the value namespace. // These items live in the value namespace.
ItemKind::Static(ast::Static { mutability, .. }) => { ItemKind::Static(box ast::Static { mutability, .. }) => {
let res = Res::Def(DefKind::Static(mutability), def_id); let res = Res::Def(DefKind::Static(mutability), def_id);
self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion)); self.r.define(parent, ident, ValueNS, (res, vis, sp, expansion));
} }

View File

@ -2346,8 +2346,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}); });
} }
ItemKind::Static(ast::Static { ref ty, ref expr, .. }) ItemKind::Static(box ast::Static { ref ty, ref expr, .. })
| ItemKind::Const(ast::ConstItem { ref ty, ref expr, .. }) => { | ItemKind::Const(box ast::ConstItem { ref ty, ref expr, .. }) => {
self.with_static_rib(|this| { self.with_static_rib(|this| {
this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| { this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| {
this.visit_ty(ty); this.visit_ty(ty);
@ -2625,7 +2625,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
for item in trait_items { for item in trait_items {
self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id)); self.resolve_doc_links(&item.attrs, MaybeExported::Ok(item.id));
match &item.kind { match &item.kind {
AssocItemKind::Const(ast::ConstItem { ty, expr, .. }) => { AssocItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
self.visit_ty(ty); self.visit_ty(ty);
// Only impose the restrictions of `ConstRibKind` for an // Only impose the restrictions of `ConstRibKind` for an
// actual constant expression in a provided default. // actual constant expression in a provided default.
@ -2800,7 +2800,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
use crate::ResolutionError::*; use crate::ResolutionError::*;
self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis))); self.resolve_doc_links(&item.attrs, MaybeExported::ImplItem(trait_id.ok_or(&item.vis)));
match &item.kind { match &item.kind {
AssocItemKind::Const(ast::ConstItem { ty, expr, .. }) => { AssocItemKind::Const(box ast::ConstItem { ty, expr, .. }) => {
debug!("resolve_implementation AssocItemKind::Const"); debug!("resolve_implementation AssocItemKind::Const");
// If this is a trait impl, ensure the const // If this is a trait impl, ensure the const
// exists in trait // exists in trait

View File

@ -100,13 +100,13 @@ impl EarlyLintPass for RedundantStaticLifetimes {
} }
if !item.span.from_expansion() { if !item.span.from_expansion() {
if let ItemKind::Const(ConstItem { ty: ref var_type, .. }) = item.kind { if let ItemKind::Const(box ConstItem { ty: ref var_type, .. }) = item.kind {
Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime"); Self::visit_type(var_type, cx, "constants have by default a `'static` lifetime");
// Don't check associated consts because `'static` cannot be elided on those (issue // Don't check associated consts because `'static` cannot be elided on those (issue
// #2438) // #2438)
} }
if let ItemKind::Static(Static{ ty: ref var_type,.. }) = item.kind { if let ItemKind::Static(box Static { ty: ref var_type,.. }) = item.kind {
Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime"); Self::visit_type(var_type, cx, "statics have by default a `'static` lifetime");
} }
} }

View File

@ -286,8 +286,8 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
match (l, r) { match (l, r) {
(ExternCrate(l), ExternCrate(r)) => l == r, (ExternCrate(l), ExternCrate(r)) => l == r,
(Use(l), Use(r)) => eq_use_tree(l, r), (Use(l), Use(r)) => eq_use_tree(l, r),
(Static(ast::Static{ ty: lt, mutability: lm, expr: le}), Static(ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re), (Static(box ast::Static{ ty: lt, mutability: lm, expr: le}), Static(box ast::Static { ty: rt, mutability: rm, expr: re})) => lm == rm && eq_ty(lt, rt) && eq_expr_opt(le, re),
(Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re} )) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
( (
Fn(box ast::Fn { Fn(box ast::Fn {
defaultness: ld, defaultness: ld,
@ -451,7 +451,7 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool { pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
use AssocItemKind::*; use AssocItemKind::*;
match (l, r) { match (l, r) {
(Const(ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re), (Const(box ast::ConstItem { defaultness: ld, ty: lt, expr: le}), Const(box ast::ConstItem { defaultness: rd, ty: rt, expr: re})) => eq_defaultness(*ld, *rd) && eq_ty(lt, rt) && eq_expr_opt(le, re),
( (
Fn(box ast::Fn { Fn(box ast::Fn {
defaultness: ld, defaultness: ld,

View File

@ -1804,13 +1804,15 @@ pub(crate) struct StaticParts<'a> {
impl<'a> StaticParts<'a> { impl<'a> StaticParts<'a> {
pub(crate) fn from_item(item: &'a ast::Item) -> Self { pub(crate) fn from_item(item: &'a ast::Item) -> Self {
let (defaultness, prefix, ty, mutability, expr) = match item.kind { let (defaultness, prefix, ty, mutability, expr) = match &item.kind {
ast::ItemKind::Static(ast::Static { ref ty, mutability, ref expr}) => { ast::ItemKind::Static(s) => (None, "static", &s.ty, s.mutability, &s.expr),
(None, "static", ty, mutability, expr) ast::ItemKind::Const(c) => (
} Some(c.defaultness),
ast::ItemKind::Const(ast::ConstItem { defaultness, ref ty, ref expr}) => { "const",
(Some(defaultness), "const", ty, ast::Mutability::Not, expr) &c.ty,
} ast::Mutability::Not,
&c.expr,
),
_ => unreachable!(), _ => unreachable!(),
}; };
StaticParts { StaticParts {
@ -1826,10 +1828,8 @@ impl<'a> StaticParts<'a> {
} }
pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self { pub(crate) fn from_trait_item(ti: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr_opt) = match ti.kind { let (defaultness, ty, expr_opt) = match &ti.kind {
ast::AssocItemKind::Const(ast::ConstItem {defaultness, ref ty, ref expr}) => { ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
(defaultness, ty, expr)
}
_ => unreachable!(), _ => unreachable!(),
}; };
StaticParts { StaticParts {
@ -1845,8 +1845,8 @@ impl<'a> StaticParts<'a> {
} }
pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self { pub(crate) fn from_impl_item(ii: &'a ast::AssocItem) -> Self {
let (defaultness, ty, expr) = match ii.kind { let (defaultness, ty, expr) = match &ii.kind {
ast::AssocItemKind::Const(ast::ConstItem { defaultness, ref ty, ref expr}) => (defaultness, ty, expr), ast::AssocItemKind::Const(c) => (c.defaultness, &c.ty, &c.expr),
_ => unreachable!(), _ => unreachable!(),
}; };
StaticParts { StaticParts {