Separate contract feature gates for the internal machinery

The extended syntax for function signature that includes contract clauses
should never be user exposed versus the interface we want to ship
externally eventually.
This commit is contained in:
Felix S. Klock II 2024-12-03 16:13:00 +00:00 committed by Celina G. Val
parent b279ff9dcf
commit 6a6c6b891b
20 changed files with 210 additions and 28 deletions

View file

@ -4,7 +4,7 @@ use rustc_ast::{
WhereClause, token,
};
use rustc_errors::{Applicability, PResult};
use rustc_span::{Ident, Span, kw};
use rustc_span::{Ident, Span, kw, sym};
use thin_vec::ThinVec;
use super::{ForceCollect, Parser, Trailing, UsePreAttrPos};
@ -302,13 +302,27 @@ impl<'a> Parser<'a> {
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);
} 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);
}
};
let requires = if self.eat_keyword_noexpect(exp!(RustcContractRequires).kw) {
Some(self.parse_expr()?)
let precond = self.parse_expr()?;
gate(precond.span);
Some(precond)
} else {
None
};
let ensures = if self.eat_keyword_noexpect(exp!(RustcContractEnsures).kw) {
Some(self.parse_expr()?)
let postcond = self.parse_expr()?;
gate(postcond.span);
Some(postcond)
} else {
None
};