mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 11:48:30 +00:00
AST/HIR: Use Mutability
instead of bool in foreign statics
This commit is contained in:
parent
53ffcd96b7
commit
4eb94b4407
@ -3742,7 +3742,7 @@ impl<'a> LoweringContext<'a> {
|
|||||||
}
|
}
|
||||||
ForeignItemKind::Static(ref t, m) => {
|
ForeignItemKind::Static(ref t, m) => {
|
||||||
hir::ForeignItemKind::Static(
|
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::Ty => hir::ForeignItemKind::Type,
|
||||||
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),
|
ForeignItemKind::Macro(_) => panic!("shouldn't exist here"),
|
||||||
|
@ -2405,9 +2405,8 @@ pub struct ForeignItem {
|
|||||||
pub enum ForeignItemKind {
|
pub enum ForeignItemKind {
|
||||||
/// A foreign function.
|
/// A foreign function.
|
||||||
Fn(P<FnDecl>, HirVec<Ident>, Generics),
|
Fn(P<FnDecl>, HirVec<Ident>, Generics),
|
||||||
/// A foreign static item (`static ext: u8`), with optional mutability
|
/// A foreign static item (`static ext: u8`).
|
||||||
/// (the boolean is true when mutable).
|
Static(P<Ty>, Mutability),
|
||||||
Static(P<Ty>, bool),
|
|
||||||
/// A foreign type.
|
/// A foreign type.
|
||||||
Type,
|
Type,
|
||||||
}
|
}
|
||||||
|
@ -466,7 +466,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
hir::ForeignItemKind::Static(ref t, m) => {
|
hir::ForeignItemKind::Static(ref t, m) => {
|
||||||
self.head(visibility_qualified(&item.vis, "static"))?;
|
self.head(visibility_qualified(&item.vis, "static"))?;
|
||||||
if m {
|
if m == hir::MutMutable {
|
||||||
self.word_space("mut")?;
|
self.word_space("mut")?;
|
||||||
}
|
}
|
||||||
self.print_ident(item.ident)?;
|
self.print_ident(item.ident)?;
|
||||||
|
@ -1647,8 +1647,8 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
|
|||||||
};
|
};
|
||||||
EntryKind::ForeignFn(self.lazy(&data))
|
EntryKind::ForeignFn(self.lazy(&data))
|
||||||
}
|
}
|
||||||
hir::ForeignItemKind::Static(_, true) => EntryKind::ForeignMutStatic,
|
hir::ForeignItemKind::Static(_, hir::MutMutable) => EntryKind::ForeignMutStatic,
|
||||||
hir::ForeignItemKind::Static(_, false) => EntryKind::ForeignImmStatic,
|
hir::ForeignItemKind::Static(_, hir::MutImmutable) => EntryKind::ForeignImmStatic,
|
||||||
hir::ForeignItemKind::Type => EntryKind::ForeignType,
|
hir::ForeignItemKind::Type => EntryKind::ForeignType,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -798,7 +798,7 @@ impl Sig for ast::ForeignItem {
|
|||||||
}
|
}
|
||||||
ast::ForeignItemKind::Static(ref ty, m) => {
|
ast::ForeignItemKind::Static(ref ty, m) => {
|
||||||
let mut text = "static ".to_owned();
|
let mut text = "static ".to_owned();
|
||||||
if m {
|
if m == ast::Mutability::Mutable {
|
||||||
text.push_str("mut ");
|
text.push_str("mut ");
|
||||||
}
|
}
|
||||||
let name = self.ident.to_string();
|
let name = self.ident.to_string();
|
||||||
|
@ -2369,10 +2369,10 @@ fn static_mutability<'a, 'tcx>(
|
|||||||
match tcx.hir().get_if_local(def_id) {
|
match tcx.hir().get_if_local(def_id) {
|
||||||
Some(Node::Item(&hir::Item {
|
Some(Node::Item(&hir::Item {
|
||||||
node: hir::ItemKind::Static(_, mutbl, _), ..
|
node: hir::ItemKind::Static(_, mutbl, _), ..
|
||||||
})) => Some(mutbl),
|
})) |
|
||||||
Some(Node::ForeignItem( &hir::ForeignItem {
|
Some(Node::ForeignItem( &hir::ForeignItem {
|
||||||
node: hir::ForeignItemKind::Static(_, mutbl), ..
|
node: hir::ForeignItemKind::Static(_, mutbl), ..
|
||||||
})) => Some(if mutbl { hir::MutMutable } else { hir::MutImmutable }),
|
})) => Some(mutbl),
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
_ => bug!("static_mutability applied to non-local def-id {:?}", def_id),
|
_ => 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) => {
|
hir::ForeignItemKind::Static(ref ty, mutbl) => {
|
||||||
ForeignStaticItem(Static {
|
ForeignStaticItem(Static {
|
||||||
type_: ty.clean(cx),
|
type_: ty.clean(cx),
|
||||||
mutability: if mutbl {Mutable} else {Immutable},
|
mutability: mutbl.clean(cx),
|
||||||
expr: String::new(),
|
expr: String::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -2340,9 +2340,8 @@ pub struct ForeignItem {
|
|||||||
pub enum ForeignItemKind {
|
pub enum ForeignItemKind {
|
||||||
/// A foreign function.
|
/// A foreign function.
|
||||||
Fn(P<FnDecl>, Generics),
|
Fn(P<FnDecl>, Generics),
|
||||||
/// A foreign static item (`static ext: u8`), with optional mutability.
|
/// A foreign static item (`static ext: u8`).
|
||||||
/// (The boolean is `true` for mutable items).
|
Static(P<Ty>, Mutability),
|
||||||
Static(P<Ty>, bool),
|
|
||||||
/// A foreign type.
|
/// A foreign type.
|
||||||
Ty,
|
Ty,
|
||||||
/// A macro invocation.
|
/// A macro invocation.
|
||||||
|
@ -7683,7 +7683,7 @@ impl<'a> Parser<'a> {
|
|||||||
/// Assumes that the `static` keyword is already parsed.
|
/// Assumes that the `static` keyword is already parsed.
|
||||||
fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: Span, attrs: Vec<Attribute>)
|
fn parse_item_foreign_static(&mut self, vis: ast::Visibility, lo: Span, attrs: Vec<Attribute>)
|
||||||
-> PResult<'a, ForeignItem> {
|
-> PResult<'a, ForeignItem> {
|
||||||
let mutbl = self.eat_keyword(keywords::Mut);
|
let mutbl = self.parse_mutability();
|
||||||
let ident = self.parse_ident()?;
|
let ident = self.parse_ident()?;
|
||||||
self.expect(&token::Colon)?;
|
self.expect(&token::Colon)?;
|
||||||
let ty = self.parse_ty()?;
|
let ty = self.parse_ty()?;
|
||||||
|
@ -1142,7 +1142,7 @@ impl<'a> State<'a> {
|
|||||||
}
|
}
|
||||||
ast::ForeignItemKind::Static(ref t, m) => {
|
ast::ForeignItemKind::Static(ref t, m) => {
|
||||||
self.head(visibility_qualified(&item.vis, "static"))?;
|
self.head(visibility_qualified(&item.vis, "static"))?;
|
||||||
if m {
|
if m == ast::Mutability::Mutable {
|
||||||
self.word_space("mut")?;
|
self.word_space("mut")?;
|
||||||
}
|
}
|
||||||
self.print_ident(item.ident)?;
|
self.print_ident(item.ident)?;
|
||||||
|
Loading…
Reference in New Issue
Block a user