Skip to content

Commit 4eb94b4

Browse files
committed
AST/HIR: Use Mutability instead of bool in foreign statics
1 parent 53ffcd9 commit 4eb94b4

File tree

10 files changed

+14
-16
lines changed

10 files changed

+14
-16
lines changed

src/librustc/hir/lowering.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3742,7 +3742,7 @@ impl<'a> LoweringContext<'a> {
37423742
}
37433743
ForeignItemKind::Static(ref t, m) => {
37443744
hir::ForeignItemKind::Static(
3745-
self.lower_ty(t, ImplTraitContext::disallowed()), m)
3745+
self.lower_ty(t, ImplTraitContext::disallowed()), self.lower_mutability(m))
37463746
}
37473747
ForeignItemKind::Ty => hir::ForeignItemKind::Type,
37483748
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),

src/librustc/hir/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2405,9 +2405,8 @@ pub struct ForeignItem {
24052405
pub enum ForeignItemKind {
24062406
/// A foreign function.
24072407
Fn(P<FnDecl>, HirVec<Ident>, Generics),
2408-
/// A foreign static item (`static ext: u8`), with optional mutability
2409-
/// (the boolean is true when mutable).
2410-
Static(P<Ty>, bool),
2408+
/// A foreign static item (`static ext: u8`).
2409+
Static(P<Ty>, Mutability),
24112410
/// A foreign type.
24122411
Type,
24132412
}

src/librustc/hir/print.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'a> State<'a> {
466466
}
467467
hir::ForeignItemKind::Static(ref t, m) => {
468468
self.head(visibility_qualified(&item.vis, "static"))?;
469-
if m {
469+
if m == hir::MutMutable {
470470
self.word_space("mut")?;
471471
}
472472
self.print_ident(item.ident)?;

src/librustc_metadata/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1647,8 +1647,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
16471647
};
16481648
EntryKind::ForeignFn(self.lazy(&data))
16491649
}
1650-
hir::ForeignItemKind::Static(_, true) => EntryKind::ForeignMutStatic,
1651-
hir::ForeignItemKind::Static(_, false) => EntryKind::ForeignImmStatic,
1650+
hir::ForeignItemKind::Static(_, hir::MutMutable) => EntryKind::ForeignMutStatic,
1651+
hir::ForeignItemKind::Static(_, hir::MutImmutable) => EntryKind::ForeignImmStatic,
16521652
hir::ForeignItemKind::Type => EntryKind::ForeignType,
16531653
};
16541654

src/librustc_save_analysis/sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ impl Sig for ast::ForeignItem {
798798
}
799799
ast::ForeignItemKind::Static(ref ty, m) => {
800800
let mut text = "static ".to_owned();
801-
if m {
801+
if m == ast::Mutability::Mutable {
802802
text.push_str("mut ");
803803
}
804804
let name = self.ident.to_string();

src/librustc_typeck/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2369,10 +2369,10 @@ fn static_mutability<'a, 'tcx>(
23692369
match tcx.hir().get_if_local(def_id) {
23702370
Some(Node::Item(&hir::Item {
23712371
node: hir::ItemKind::Static(_, mutbl, _), ..
2372-
})) => Some(mutbl),
2372+
})) |
23732373
Some(Node::ForeignItem( &hir::ForeignItem {
23742374
node: hir::ForeignItemKind::Static(_, mutbl), ..
2375-
})) => Some(if mutbl { hir::MutMutable } else { hir::MutImmutable }),
2375+
})) => Some(mutbl),
23762376
Some(_) => None,
23772377
_ => bug!("static_mutability applied to non-local def-id {:?}", def_id),
23782378
}

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4055,7 +4055,7 @@ impl Clean<Item> for hir::ForeignItem {
40554055
hir::ForeignItemKind::Static(ref ty, mutbl) => {
40564056
ForeignStaticItem(Static {
40574057
type_: ty.clean(cx),
4058-
mutability: if mutbl {Mutable} else {Immutable},
4058+
mutability: mutbl.clean(cx),
40594059
expr: String::new(),
40604060
})
40614061
}

src/libsyntax/ast.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -2340,9 +2340,8 @@ pub struct ForeignItem {
23402340
pub enum ForeignItemKind {
23412341
/// A foreign function.
23422342
Fn(P<FnDecl>, Generics),
2343-
/// A foreign static item (`static ext: u8`), with optional mutability.
2344-
/// (The boolean is `true` for mutable items).
2345-
Static(P<Ty>, bool),
2343+
/// A foreign static item (`static ext: u8`).
2344+
Static(P<Ty>, Mutability),
23462345
/// A foreign type.
23472346
Ty,
23482347
/// A macro invocation.

src/libsyntax/parse/parser.rs

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

src/libsyntax/print/pprust.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ impl<'a> State<'a> {
11421142
}
11431143
ast::ForeignItemKind::Static(ref t, m) => {
11441144
self.head(visibility_qualified(&item.vis, "static"))?;
1145-
if m {
1145+
if m == ast::Mutability::Mutable {
11461146
self.word_space("mut")?;
11471147
}
11481148
self.print_ident(item.ident)?;

0 commit comments

Comments
 (0)