1
Fork 0

Rename rustc_contract to contract

This has now been approved as a language feature and no longer needs
a `rustc_` prefix.

Also change the `contracts` feature to be marked as incomplete and
`contracts_internals` as internal.
This commit is contained in:
Celina G. Val 2025-01-30 17:06:09 -08:00
parent 2c4923e6bc
commit ddbf54b67d
65 changed files with 522 additions and 165 deletions

View file

@ -297,29 +297,29 @@ impl<'a> Parser<'a> {
})
}
/// Parses a rustc-internal fn contract
/// (`rustc_contract_requires(WWW) rustc_contract_ensures(ZZZ)`)
/// Parses an experimental fn contract
/// (`contract_requires(WWW) contract_ensures(ZZZ)`)
pub(super) fn parse_contract(
&mut self,
) -> PResult<'a, Option<rustc_ast::ptr::P<ast::FnContract>>> {
let gate = |span| {
if self.psess.contract_attribute_spans.contains(span) {
// span was generated via a builtin contracts attribute, so gate as end-user visible
self.psess.gated_spans.gate(sym::rustc_contracts, span);
self.psess.gated_spans.gate(sym::contracts, span);
} else {
// span was not generated via a builtin contracts attribute, so gate as internal machinery
self.psess.gated_spans.gate(sym::rustc_contracts_internals, span);
self.psess.gated_spans.gate(sym::contracts_internals, span);
}
};
let requires = if self.eat_keyword_noexpect(exp!(RustcContractRequires).kw) {
let requires = if self.eat_keyword_noexpect(exp!(ContractRequires).kw) {
let precond = self.parse_expr()?;
gate(precond.span);
Some(precond)
} else {
None
};
let ensures = if self.eat_keyword_noexpect(exp!(RustcContractEnsures).kw) {
let ensures = if self.eat_keyword_noexpect(exp!(ContractEnsures).kw) {
let postcond = self.parse_expr()?;
gate(postcond.span);
Some(postcond)

View file

@ -83,6 +83,8 @@ pub enum TokenType {
KwCatch,
KwConst,
KwContinue,
KwContractEnsures,
KwContractRequires,
KwCrate,
KwDefault,
KwDyn,
@ -108,8 +110,6 @@ pub enum TokenType {
KwRef,
KwReturn,
KwReuse,
KwRustcContractEnsures,
KwRustcContractRequires,
KwSafe,
KwSelfUpper,
KwStatic,
@ -219,6 +219,8 @@ impl TokenType {
KwCatch,
KwConst,
KwContinue,
KwContractEnsures,
KwContractRequires,
KwCrate,
KwDefault,
KwDyn,
@ -244,8 +246,6 @@ impl TokenType {
KwRef,
KwReturn,
KwReuse,
KwRustcContractEnsures,
KwRustcContractRequires,
KwSafe,
KwSelfUpper,
KwStatic,
@ -293,6 +293,8 @@ impl TokenType {
TokenType::KwCatch => Some(kw::Catch),
TokenType::KwConst => Some(kw::Const),
TokenType::KwContinue => Some(kw::Continue),
TokenType::KwContractEnsures => Some(kw::ContractEnsures),
TokenType::KwContractRequires => Some(kw::ContractRequires),
TokenType::KwCrate => Some(kw::Crate),
TokenType::KwDefault => Some(kw::Default),
TokenType::KwDyn => Some(kw::Dyn),
@ -318,8 +320,6 @@ impl TokenType {
TokenType::KwRef => Some(kw::Ref),
TokenType::KwReturn => Some(kw::Return),
TokenType::KwReuse => Some(kw::Reuse),
TokenType::KwRustcContractEnsures => Some(kw::RustcContractEnsures),
TokenType::KwRustcContractRequires => Some(kw::RustcContractRequires),
TokenType::KwSafe => Some(kw::Safe),
TokenType::KwSelfUpper => Some(kw::SelfUpper),
TokenType::KwStatic => Some(kw::Static),
@ -525,6 +525,8 @@ macro_rules! exp {
(Catch) => { exp!(@kw, Catch, KwCatch) };
(Const) => { exp!(@kw, Const, KwConst) };
(Continue) => { exp!(@kw, Continue, KwContinue) };
(ContractEnsures) => { exp!(@kw, ContractEnsures, KwContractEnsures) };
(ContractRequires) => { exp!(@kw, ContractRequires, KwContractRequires) };
(Crate) => { exp!(@kw, Crate, KwCrate) };
(Default) => { exp!(@kw, Default, KwDefault) };
(Dyn) => { exp!(@kw, Dyn, KwDyn) };
@ -550,8 +552,6 @@ macro_rules! exp {
(Ref) => { exp!(@kw, Ref, KwRef) };
(Return) => { exp!(@kw, Return, KwReturn) };
(Reuse) => { exp!(@kw, Reuse, KwReuse) };
(RustcContractEnsures) => { exp!(@kw, RustcContractEnsures, KwRustcContractEnsures) };
(RustcContractRequires) => { exp!(@kw, RustcContractRequires, KwRustcContractRequires) };
(Safe) => { exp!(@kw, Safe, KwSafe) };
(SelfUpper) => { exp!(@kw, SelfUpper, KwSelfUpper) };
(Static) => { exp!(@kw, Static, KwStatic) };