AST/HIR: Use Mutability instead of bool in foreign statics

This commit is contained in:
Vadim Petrochenkov 2019-04-21 15:29:58 +03:00
parent 53ffcd96b7
commit 4eb94b4407
10 changed files with 14 additions and 16 deletions

View File

@ -3742,7 +3742,7 @@ impl<'a> LoweringContext<'a> {
}
ForeignItemKind::Static(ref t, m) => {
hir::ForeignItemKind::Static(
self.lower_ty(t, ImplTraitContext::disallowed()), m)
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
}
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),

View File

@ -2405,9 +2405,8 @@ pub struct ForeignItem {
pub enum ForeignItemKind {
/// A foreign function.
Fn(P<FnDecl>, HirVec<Ident>, Generics),
/// A foreign static item (`static ext: u8`), with optional mutability
/// (the boolean is true when mutable).
Static(P<Ty>, bool),
/// A foreign static item (`static ext: u8`).
Static(P<Ty>, Mutability),
/// A foreign type.
Type,
}

View File

@ -466,7 +466,7 @@ impl<'a> State<'a> {
}
hir::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"))?;
if m {
if m == hir::MutMutable {
self.word_space("mut")?;
}
self.print_ident(item.ident)?;

View File

@ -1647,8 +1647,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
};
EntryKind::ForeignFn(self.lazy(&data))
}
hir::ForeignItemKind::Static(_, true) => EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, false) => EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Static(_, hir::MutMutable) => EntryKind::ForeignMutStatic,
hir::ForeignItemKind::Static(_, hir::MutImmutable) => EntryKind::ForeignImmStatic,
hir::ForeignItemKind::Type => EntryKind::ForeignType,
};

View File

@ -798,7 +798,7 @@ impl Sig for ast::ForeignItem {
}
ast::ForeignItemKind::Static(ref ty, m) => {
let mut text = "static ".to_owned();
if m {
if m == ast::Mutability::Mutable {
text.push_str("mut ");
}
let name = self.ident.to_string();

View File

@ -2369,10 +2369,10 @@ fn static_mutability<'a, 'tcx>(
match tcx.hir().get_if_local(def_id) {
Some(Node::Item(&hir::Item {
node: hir::ItemKind::Static(_, mutbl, _), ..
})) => Some(mutbl),
})) |
Some(Node::ForeignItem( &hir::ForeignItem {
node: hir::ForeignItemKind::Static(_, mutbl), ..
})) => Some(if mutbl { hir::MutMutable } else { hir::MutImmutable }),
})) => Some(mutbl),
Some(_) => None,
_ => bug!("static_mutability applied to non-local def-id {:?}", def_id),
}

View File

@ -4055,7 +4055,7 @@ impl Clean<Item> for hir::ForeignItem {
hir::ForeignItemKind::Static(ref ty, mutbl) => {
ForeignStaticItem(Static {
type_: ty.clean(cx),
mutability: if mutbl {Mutable} else {Immutable},
mutability: mutbl.clean(cx),
expr: String::new(),
})
}

View File

@ -2340,9 +2340,8 @@ pub struct ForeignItem {
pub enum ForeignItemKind {
/// A foreign function.
Fn(P<FnDecl>, Generics),
/// A foreign static item (`static ext: u8`), with optional mutability.
/// (The boolean is `true` for mutable items).
Static(P<Ty>, bool),
/// A foreign static item (`static ext: u8`).
Static(P<Ty>, Mutability),
/// A foreign type.
Ty,
/// A macro invocation.

View File

@ -7683,7 +7683,7 @@ impl<'a> Parser<'a> {
/// Assumes that the `static` keyword is already parsed.
fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: Span, attrs: Vec<Attribute>)
-> PResult<'a, ForeignItem> {
let mutbl = self.eat_keyword(keywords::Mut);
let mutbl = self.parse_mutability();
let ident = self.parse_ident()?;
self.expect(&token::Colon)?;
let ty = self.parse_ty()?;

View File

@ -1142,7 +1142,7 @@ impl<'a> State<'a> {
}
ast::ForeignItemKind::Static(ref t, m) => {
self.head(visibility_qualified(&item.vis, "static"))?;
if m {
if m == ast::Mutability::Mutable {
self.word_space("mut")?;
}
self.print_ident(item.ident)?;