Skip to content

Commit

Permalink
AST/HIR: Use Mutability instead of bool in foreign statics
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Apr 21, 2019
1 parent 53ffcd9 commit 4eb94b4
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/librustc/hir/lowering.rs
Expand Up @@ -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"),
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/hir/mod.rs
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/print.rs
Expand Up @@ -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)?;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -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,
};

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/sig.rs
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/collect.rs
Expand Up @@ -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),
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Expand Up @@ -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(),
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/libsyntax/ast.rs
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Expand Up @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Expand Up @@ -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)?;
Expand Down

0 comments on commit 4eb94b4

Please sign in to comment.