Add support for 'extern const fn'

This works just as you might expect - an 'extern const fn' is a 'const
fn' that is callable from foreign code.

Currently, panicking is not allowed in consts. When RFC 2345 is
stabilized, then panicking in an 'extern const 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.
This commit is contained in:
Aaron Hill 2019-09-29 19:22:18 -04:00
parent 7130fc54e0
commit 73b50d211b
No known key found for this signature in database
GPG key ID: B4087E510E98B164
18 changed files with 302 additions and 21 deletions

View file

@ -1486,6 +1486,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>> {