diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-04-21 15:29:58 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-04-21 15:29:58 +0300 |
| commit | 4eb94b44072697be70fc2a74ed9989e88f9cd70c (patch) | |
| tree | 876462433c27a3f8b34f94bb4a57bc753677b1b3 | |
| parent | 53ffcd96b7588669029467e5f23b699ff3283173 (diff) | |
| download | rust-4eb94b44072697be70fc2a74ed9989e88f9cd70c.tar.gz rust-4eb94b44072697be70fc2a74ed9989e88f9cd70c.zip | |
AST/HIR: Use `Mutability` instead of bool in foreign statics
| -rw-r--r-- | src/librustc/hir/lowering.rs | 2 | ||||
| -rw-r--r-- | src/librustc/hir/mod.rs | 5 | ||||
| -rw-r--r-- | src/librustc/hir/print.rs | 2 | ||||
| -rw-r--r-- | src/librustc_metadata/encoder.rs | 4 | ||||
| -rw-r--r-- | src/librustc_save_analysis/sig.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/collect.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/ast.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/print/pprust.rs | 2 |
10 files changed, 14 insertions, 16 deletions
diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 42ad571cf28..99cae00fafc 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -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"), diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index 7ed8c08c923..630c163bcaf 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -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, } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index d1020a2d151..dc87e13b739 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -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)?; diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 796d2f6a18b..a0f17a55a87 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -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, }; diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 76034f32c74..90fe6a60dd7 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -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(); diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5c0c2fece3d..afb30af054f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -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), } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 66fe7f177e6..586ae6659bb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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(), }) } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 0668730b3ef..a5472c622e6 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -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. diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 29d2d2ad73d..233ea472e98 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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()?; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index ca05ff71c94..d94e4762e67 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -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)?; |
