Add safe/unsafe to static inside extern blocks
This commit is contained in:
parent
b4cbdb7246
commit
bac72cf7cf
27 changed files with 152 additions and 57 deletions
|
@ -226,10 +226,11 @@ impl<'a> Parser<'a> {
|
|||
self.expect_keyword(kw::Extern)?;
|
||||
self.parse_item_foreign_mod(attrs, safety)?
|
||||
} else if self.is_static_global() {
|
||||
let safety = self.parse_safety(Case::Sensitive);
|
||||
// STATIC ITEM
|
||||
self.bump(); // `static`
|
||||
let mutability = self.parse_mutability();
|
||||
let (ident, item) = self.parse_static_item(mutability)?;
|
||||
let (ident, item) = self.parse_static_item(safety, mutability)?;
|
||||
(ident, ItemKind::Static(Box::new(item)))
|
||||
} else if let Const::Yes(const_span) = self.parse_constness(Case::Sensitive) {
|
||||
// CONST ITEM
|
||||
|
@ -952,7 +953,7 @@ impl<'a> Parser<'a> {
|
|||
let kind = match AssocItemKind::try_from(kind) {
|
||||
Ok(kind) => kind,
|
||||
Err(kind) => match kind {
|
||||
ItemKind::Static(box StaticItem { ty, mutability: _, expr }) => {
|
||||
ItemKind::Static(box StaticItem { ty, safety: _, mutability: _, expr }) => {
|
||||
self.dcx().emit_err(errors::AssociatedStaticItemNotAllowed { span });
|
||||
AssocItemKind::Const(Box::new(ConstItem {
|
||||
defaultness: Defaultness::Final,
|
||||
|
@ -1259,7 +1260,10 @@ impl<'a> Parser<'a> {
|
|||
matches!(token.kind, token::BinOp(token::Or) | token::OrOr)
|
||||
})
|
||||
} else {
|
||||
false
|
||||
let quals: &[Symbol] = &[kw::Unsafe, kw::Safe];
|
||||
// `$qual static`
|
||||
quals.iter().any(|&kw| self.check_keyword(kw))
|
||||
&& self.look_ahead(1, |t| t.is_keyword(kw::Static))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1320,7 +1324,11 @@ impl<'a> Parser<'a> {
|
|||
/// ```ebnf
|
||||
/// Static = "static" "mut"? $ident ":" $ty (= $expr)? ";" ;
|
||||
/// ```
|
||||
fn parse_static_item(&mut self, mutability: Mutability) -> PResult<'a, (Ident, StaticItem)> {
|
||||
fn parse_static_item(
|
||||
&mut self,
|
||||
safety: Safety,
|
||||
mutability: Mutability,
|
||||
) -> PResult<'a, (Ident, StaticItem)> {
|
||||
let ident = self.parse_ident()?;
|
||||
|
||||
if self.token.kind == TokenKind::Lt && self.may_recover() {
|
||||
|
@ -1341,7 +1349,7 @@ impl<'a> Parser<'a> {
|
|||
|
||||
self.expect_semi()?;
|
||||
|
||||
Ok((ident, StaticItem { ty, mutability, expr }))
|
||||
Ok((ident, StaticItem { ty, safety, mutability, expr }))
|
||||
}
|
||||
|
||||
/// Parse a constant item with the prefix `"const"` already parsed.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue