StaticForeignItem and StaticItem are the same
This commit is contained in:
parent
cb8a7ea0ed
commit
3e59f0c3c5
@ -3184,38 +3184,6 @@ pub struct StaticItem {
|
|||||||
pub expr: Option<P<Expr>>,
|
pub expr: Option<P<Expr>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A static item in `extern` block.
|
|
||||||
// This struct is identical to StaticItem for now but it's going to have a safety attribute.
|
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
|
||||||
pub struct StaticForeignItem {
|
|
||||||
pub ty: P<Ty>,
|
|
||||||
pub safety: Safety,
|
|
||||||
pub mutability: Mutability,
|
|
||||||
pub expr: Option<P<Expr>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StaticItem> for StaticForeignItem {
|
|
||||||
fn from(static_item: StaticItem) -> StaticForeignItem {
|
|
||||||
StaticForeignItem {
|
|
||||||
ty: static_item.ty,
|
|
||||||
safety: static_item.safety,
|
|
||||||
mutability: static_item.mutability,
|
|
||||||
expr: static_item.expr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<StaticForeignItem> for StaticItem {
|
|
||||||
fn from(static_item: StaticForeignItem) -> StaticItem {
|
|
||||||
StaticItem {
|
|
||||||
ty: static_item.ty,
|
|
||||||
safety: static_item.safety,
|
|
||||||
mutability: static_item.mutability,
|
|
||||||
expr: static_item.expr,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub struct ConstItem {
|
pub struct ConstItem {
|
||||||
pub defaultness: Defaultness,
|
pub defaultness: Defaultness,
|
||||||
@ -3430,7 +3398,7 @@ fn try_from(item_kind: ItemKind) -> Result<AssocItemKind, ItemKind> {
|
|||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub enum ForeignItemKind {
|
pub enum ForeignItemKind {
|
||||||
/// A foreign static item (`static FOO: u8`).
|
/// A foreign static item (`static FOO: u8`).
|
||||||
Static(Box<StaticForeignItem>),
|
Static(Box<StaticItem>),
|
||||||
/// An foreign function.
|
/// An foreign function.
|
||||||
Fn(Box<Fn>),
|
Fn(Box<Fn>),
|
||||||
/// An foreign type.
|
/// An foreign type.
|
||||||
|
@ -1310,12 +1310,7 @@ pub fn noop_flat_map_item<K: NoopVisitItemKind>(
|
|||||||
impl NoopVisitItemKind for ForeignItemKind {
|
impl NoopVisitItemKind for ForeignItemKind {
|
||||||
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
|
fn noop_visit(&mut self, visitor: &mut impl MutVisitor) {
|
||||||
match self {
|
match self {
|
||||||
ForeignItemKind::Static(box StaticForeignItem {
|
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
|
||||||
ty,
|
|
||||||
mutability: _,
|
|
||||||
expr,
|
|
||||||
safety: _,
|
|
||||||
}) => {
|
|
||||||
visitor.visit_ty(ty);
|
visitor.visit_ty(ty);
|
||||||
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
visit_opt(expr, |expr| visitor.visit_expr(expr));
|
||||||
}
|
}
|
||||||
|
@ -672,12 +672,7 @@ fn walk<'a, V: Visitor<'a>>(
|
|||||||
) -> V::Result {
|
) -> V::Result {
|
||||||
let &Item { id, span, ident, ref vis, .. } = item;
|
let &Item { id, span, ident, ref vis, .. } = item;
|
||||||
match self {
|
match self {
|
||||||
ForeignItemKind::Static(box StaticForeignItem {
|
ForeignItemKind::Static(box StaticItem { ty, mutability: _, expr, safety: _ }) => {
|
||||||
ty,
|
|
||||||
mutability: _,
|
|
||||||
expr,
|
|
||||||
safety: _,
|
|
||||||
}) => {
|
|
||||||
try_visit!(visitor.visit_ty(ty));
|
try_visit!(visitor.visit_ty(ty));
|
||||||
visit_opt!(visitor, visit_expr, expr);
|
visit_opt!(visitor, visit_expr, expr);
|
||||||
}
|
}
|
||||||
|
@ -664,12 +664,7 @@ fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir
|
|||||||
|
|
||||||
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics, safety)
|
hir::ForeignItemKind::Fn(fn_dec, fn_args, generics, safety)
|
||||||
}
|
}
|
||||||
ForeignItemKind::Static(box StaticForeignItem {
|
ForeignItemKind::Static(box StaticItem { ty, mutability, expr: _, safety }) => {
|
||||||
ty,
|
|
||||||
mutability,
|
|
||||||
expr: _,
|
|
||||||
safety,
|
|
||||||
}) => {
|
|
||||||
let ty = self
|
let ty = self
|
||||||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
|
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::StaticTy));
|
||||||
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
|
let safety = self.lower_safety(*safety, hir::Safety::Unsafe);
|
||||||
|
@ -1232,7 +1232,7 @@ fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
|||||||
self.check_foreign_ty_genericless(generics, where_clauses);
|
self.check_foreign_ty_genericless(generics, where_clauses);
|
||||||
self.check_foreign_item_ascii_only(fi.ident);
|
self.check_foreign_item_ascii_only(fi.ident);
|
||||||
}
|
}
|
||||||
ForeignItemKind::Static(box StaticForeignItem { expr, safety, .. }) => {
|
ForeignItemKind::Static(box StaticItem { expr, safety, .. }) => {
|
||||||
self.check_foreign_item_safety(fi.span, *safety);
|
self.check_foreign_item_safety(fi.span, *safety);
|
||||||
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|b| b.span));
|
self.check_foreign_kind_bodyless(fi.ident, "static", expr.as_ref().map(|b| b.span));
|
||||||
self.check_foreign_item_ascii_only(fi.ident);
|
self.check_foreign_item_ascii_only(fi.ident);
|
||||||
|
@ -37,12 +37,7 @@ fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
|
|||||||
ast::ForeignItemKind::Fn(box ast::Fn { defaultness, sig, generics, body }) => {
|
ast::ForeignItemKind::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::ForeignItemKind::Static(box ast::StaticForeignItem {
|
ast::ForeignItemKind::Static(box ast::StaticItem { ty, mutability, expr, safety }) => {
|
||||||
ty,
|
|
||||||
mutability,
|
|
||||||
expr,
|
|
||||||
safety,
|
|
||||||
}) => {
|
|
||||||
self.print_safety(*safety);
|
self.print_safety(*safety);
|
||||||
self.print_item_const(
|
self.print_item_const(
|
||||||
ident,
|
ident,
|
||||||
|
@ -1228,7 +1228,7 @@ pub fn parse_foreign_item(
|
|||||||
ident_span: ident.span,
|
ident_span: ident.span,
|
||||||
const_span,
|
const_span,
|
||||||
});
|
});
|
||||||
ForeignItemKind::Static(Box::new(StaticForeignItem {
|
ForeignItemKind::Static(Box::new(StaticItem {
|
||||||
ty,
|
ty,
|
||||||
mutability: Mutability::Not,
|
mutability: Mutability::Not,
|
||||||
expr,
|
expr,
|
||||||
|
@ -217,12 +217,7 @@ fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) {
|
|||||||
|
|
||||||
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
|
||||||
let def_kind = match fi.kind {
|
let def_kind = match fi.kind {
|
||||||
ForeignItemKind::Static(box StaticForeignItem {
|
ForeignItemKind::Static(box StaticItem { ty: _, mutability, expr: _, safety }) => {
|
||||||
ty: _,
|
|
||||||
mutability,
|
|
||||||
expr: _,
|
|
||||||
safety,
|
|
||||||
}) => {
|
|
||||||
let safety = match safety {
|
let safety = match safety {
|
||||||
ast::Safety::Unsafe(_) | ast::Safety::Default => hir::Safety::Unsafe,
|
ast::Safety::Unsafe(_) | ast::Safety::Default => hir::Safety::Unsafe,
|
||||||
ast::Safety::Safe(_) => hir::Safety::Safe,
|
ast::Safety::Safe(_) => hir::Safety::Safe,
|
||||||
|
@ -449,13 +449,13 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
|
|||||||
use ForeignItemKind::*;
|
use ForeignItemKind::*;
|
||||||
match (l, r) {
|
match (l, r) {
|
||||||
(
|
(
|
||||||
Static(box StaticForeignItem {
|
Static(box StaticItem {
|
||||||
ty: lt,
|
ty: lt,
|
||||||
mutability: lm,
|
mutability: lm,
|
||||||
expr: le,
|
expr: le,
|
||||||
safety: ls,
|
safety: ls,
|
||||||
}),
|
}),
|
||||||
Static(box StaticForeignItem {
|
Static(box StaticItem {
|
||||||
ty: rt,
|
ty: rt,
|
||||||
mutability: rm,
|
mutability: rm,
|
||||||
expr: re,
|
expr: re,
|
||||||
|
Loading…
Reference in New Issue
Block a user