Skip to content
Permalink
Browse files

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

  • Loading branch information...
petrochenkov committed Apr 21, 2019
1 parent 53ffcd9 commit 4eb94b44072697be70fc2a74ed9989e88f9cd70c
@@ -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"),
@@ -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,
}
@@ -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)?;
@@ -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,
};

@@ -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();
@@ -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),
}
@@ -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(),
})
}
@@ -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.
@@ -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()?;
@@ -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)?;

0 comments on commit 4eb94b4

Please sign in to comment.
You can’t perform that action at this time.