Skip to content

Commit f2aa519

Browse files
Undinyopox
authored andcommitted
GRAM: allow unsafe modifier for extern block item
Note, `unsafe` is semantically invalid in case of extern block item. The corresponding change is made to improve error message. See the corresponding change in rustc: rust-lang/rust#75857
1 parent b7dfd57 commit f2aa519

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

src/main/grammars/RustParser.bnf

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ upper ModDeclItem ::= unsafe? mod identifier ';' {
708708
elementTypeFactory = "org.rust.lang.core.stubs.StubImplementationsKt.factory"
709709
}
710710

711-
upper ForeignModItem ::= ExternAbi ForeignModBody {
711+
upper ForeignModItem ::= unsafe? ExternAbi ForeignModBody {
712712
name = ""
713713
implements = [ "org.rust.lang.core.psi.ext.RsItemElement"
714714
"org.rust.lang.core.psi.ext.RsInnerAttributeOwner" ]

src/main/kotlin/org/rust/lang/core/parser/RustParserDefinition.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ class RustParserDefinition : ParserDefinition {
104104
/**
105105
* Should be increased after any change of parser rules
106106
*/
107-
const val PARSER_VERSION: Int = LEXER_VERSION + 30
107+
const val PARSER_VERSION: Int = LEXER_VERSION + 31
108108
}
109109
}

src/test/resources/org/rust/lang/core/parser/fixtures/complete/extern_block.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ extern "C" {}
1616
extern "R\u{0075}st" {}
1717
extern r"system" {}
1818
extern 'C' {} // semantically invalid
19+
pub extern {} // semantically invalid
20+
unsafe extern {} // semantically invalid
21+
pub unsafe extern {} // semantically invalid

src/test/resources/org/rust/lang/core/parser/fixtures/complete/extern_block.txt

+37
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,41 @@ FILE
193193
PsiElement({)('{')
194194
PsiElement(})('}')
195195
PsiWhiteSpace(' ')
196+
RsForeignModItemImpl(FOREIGN_MOD_ITEM)
197+
PsiComment(<EOL_COMMENT>)('// semantically invalid')
198+
PsiWhiteSpace('\n')
199+
RsVisImpl(VIS)
200+
PsiElement(pub)('pub')
201+
PsiWhiteSpace(' ')
202+
RsExternAbiImpl(EXTERN_ABI)
203+
PsiElement(extern)('extern')
204+
PsiWhiteSpace(' ')
205+
PsiElement({)('{')
206+
PsiElement(})('}')
207+
PsiWhiteSpace(' ')
208+
RsForeignModItemImpl(FOREIGN_MOD_ITEM)
209+
PsiComment(<EOL_COMMENT>)('// semantically invalid')
210+
PsiWhiteSpace('\n')
211+
PsiElement(unsafe)('unsafe')
212+
PsiWhiteSpace(' ')
213+
RsExternAbiImpl(EXTERN_ABI)
214+
PsiElement(extern)('extern')
215+
PsiWhiteSpace(' ')
216+
PsiElement({)('{')
217+
PsiElement(})('}')
218+
PsiWhiteSpace(' ')
219+
RsForeignModItemImpl(FOREIGN_MOD_ITEM)
220+
PsiComment(<EOL_COMMENT>)('// semantically invalid')
221+
PsiWhiteSpace('\n')
222+
RsVisImpl(VIS)
223+
PsiElement(pub)('pub')
224+
PsiWhiteSpace(' ')
225+
PsiElement(unsafe)('unsafe')
226+
PsiWhiteSpace(' ')
227+
RsExternAbiImpl(EXTERN_ABI)
228+
PsiElement(extern)('extern')
229+
PsiWhiteSpace(' ')
230+
PsiElement({)('{')
231+
PsiElement(})('}')
232+
PsiWhiteSpace(' ')
196233
PsiComment(<EOL_COMMENT>)('// semantically invalid')

0 commit comments

Comments
 (0)