diff options
| author | bors <bors@rust-lang.org> | 2019-10-07 00:12:12 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-07 00:12:12 +0000 |
| commit | 4ac4809ccf5f77083ae7155dcc83e921341c2614 (patch) | |
| tree | 4a1db137f47b0a1e888027b3f19454963b14e177 /src/libsyntax/parse/parser.rs | |
| parent | 09868a56c95f7bc7b6ee3ab7611e3ca551031dbd (diff) | |
| parent | a4cad414ad42d36adfe27ac4b9271831e8af5125 (diff) | |
| download | rust-4ac4809ccf5f77083ae7155dcc83e921341c2614.tar.gz rust-4ac4809ccf5f77083ae7155dcc83e921341c2614.zip | |
Auto merge of #64906 - Aaron1011:feature/extern-const-fn, r=Centril
Add support for `const unsafe? extern fn` This works just as you might expect - an `const extern fn` is a `const fn` that is callable from foreign code. Currently, panicking is not allowed in `const`s. When https://github.com/rust-lang/rfcs/pull/2345 (https://github.com/rust-lang/rust/issues/51999) is stabilized, then panicking in an `const extern fn` will produce a compile-time error when invoked at compile time, and an abort when invoked at runtime. Since this is extending the language (we're allowing the `const` keyword in a new context), I believe that this will need an FCP. However, it's a very minor change, so I didn't think that filing an RFC was necessary. This will allow libc (and other FFI crates) to make many functions `const`, without having to give up on making them `extern` as well. Tracking issue: https://github.com/rust-lang/rust/issues/64926.
Diffstat (limited to 'src/libsyntax/parse/parser.rs')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index d4a6e9f6c6b..93165b09649 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1487,6 +1487,15 @@ impl<'a> Parser<'a> { Ok(()) } + /// Parses `extern` followed by an optional ABI string, or nothing. + fn parse_extern_abi(&mut self) -> PResult<'a, Abi> { + if self.eat_keyword(kw::Extern) { + Ok(self.parse_opt_abi()?.unwrap_or(Abi::C)) + } else { + Ok(Abi::Rust) + } + } + /// Parses a string as an ABI spec on an extern type or module. Consumes /// the `extern` keyword, if one is found. fn parse_opt_abi(&mut self) -> PResult<'a, Option<Abi>> { |
