Skip to content

Commit ddbf54b

Browse files
committed
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.
1 parent 2c4923e commit ddbf54b

File tree

65 files changed

+522
-165
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+522
-165
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
548548
gate_all!(pin_ergonomics, "pinned reference syntax is experimental");
549549
gate_all!(unsafe_fields, "`unsafe` fields are experimental");
550550
gate_all!(unsafe_binders, "unsafe binder types are experimental");
551-
gate_all!(rustc_contracts, "contracts are experimental");
552-
gate_all!(rustc_contracts_internals, "contract internal machinery is for internal use only");
551+
gate_all!(contracts, "contracts are incomplete");
552+
gate_all!(contracts_internals, "contract internal machinery is for internal use only");
553553

554554
if !visitor.features.never_patterns() {
555555
if let Some(spans) = spans.get(&sym::never_patterns) {

compiler/rustc_builtin_macros/src/contracts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn expand_contract_clause(
123123

124124
// Record the span as a contract attribute expansion.
125125
// This is used later to stop users from using the extended syntax directly
126-
// which is gated via `rustc_contracts_internals`.
126+
// which is gated via `contracts_internals`.
127127
ecx.psess().contract_attribute_spans.push(attr_span);
128128

129129
Ok(new_tts)
@@ -137,7 +137,7 @@ fn expand_requires_tts(
137137
) -> Result<TokenStream, ErrorGuaranteed> {
138138
expand_contract_clause(_ecx, attr_span, annotated, |new_tts| {
139139
new_tts.push_tree(TokenTree::Token(
140-
token::Token::from_ast_ident(Ident::new(kw::RustcContractRequires, attr_span)),
140+
token::Token::from_ast_ident(Ident::new(kw::ContractRequires, attr_span)),
141141
Spacing::Joint,
142142
));
143143
new_tts.push_tree(TokenTree::Token(
@@ -162,7 +162,7 @@ fn expand_ensures_tts(
162162
) -> Result<TokenStream, ErrorGuaranteed> {
163163
expand_contract_clause(_ecx, attr_span, annotated, |new_tts| {
164164
new_tts.push_tree(TokenTree::Token(
165-
token::Token::from_ast_ident(Ident::new(kw::RustcContractEnsures, attr_span)),
165+
token::Token::from_ast_ident(Ident::new(kw::ContractEnsures, attr_span)),
166166
Spacing::Joint,
167167
));
168168
new_tts.push_tree(TokenTree::Delimited(

compiler/rustc_feature/src/unstable.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ declare_features! (
404404
/// Allows the use of `#[cfg(<true/false>)]`.
405405
(unstable, cfg_boolean_literals, "1.83.0", Some(131204)),
406406
/// Allows the use of `#[cfg(contract_checks)` to check if contract checks are enabled.
407-
(unstable, cfg_contract_checks, "CURRENT_RUSTC_VERSION", Some(133866)),
407+
(unstable, cfg_contract_checks, "CURRENT_RUSTC_VERSION", Some(128044)),
408408
/// Allows the use of `#[cfg(overflow_checks)` to check if integer overflow behaviour.
409409
(unstable, cfg_overflow_checks, "1.71.0", Some(111466)),
410410
/// Provides the relocation model information as cfg entry
@@ -447,6 +447,10 @@ declare_features! (
447447
(unstable, const_trait_impl, "1.42.0", Some(67792)),
448448
/// Allows the `?` operator in const contexts.
449449
(unstable, const_try, "1.56.0", Some(74935)),
450+
/// Allows use of contracts attributes.
451+
(incomplete, contracts, "CURRENT_RUSTC_VERSION", Some(128044)),
452+
/// Allows access to internal machinery used to implement contracts.
453+
(internal, contracts_internals, "CURRENT_RUSTC_VERSION", Some(128044)),
450454
/// Allows coroutines to be cloned.
451455
(unstable, coroutine_clone, "1.65.0", Some(95360)),
452456
/// Allows defining coroutines.
@@ -608,10 +612,6 @@ declare_features! (
608612
(unstable, return_type_notation, "1.70.0", Some(109417)),
609613
/// Allows `extern "rust-cold"`.
610614
(unstable, rust_cold_cc, "1.63.0", Some(97544)),
611-
/// Allows use of contracts attributes.
612-
(unstable, rustc_contracts, "CURRENT_RUSTC_VERSION", Some(133866)),
613-
/// Allows access to internal machinery used to implement contracts.
614-
(unstable, rustc_contracts_internals, "CURRENT_RUSTC_VERSION", Some(133866)),
615615
/// Allows use of x86 SHA512, SM3 and SM4 target-features and intrinsics
616616
(unstable, sha512_sm_x86, "1.82.0", Some(126624)),
617617
/// Allows the use of SIMD types in functions declared in `extern` blocks.

compiler/rustc_parse/src/parser/generics.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -297,29 +297,29 @@ impl<'a> Parser<'a> {
297297
})
298298
}
299299

300-
/// Parses a rustc-internal fn contract
301-
/// (`rustc_contract_requires(WWW) rustc_contract_ensures(ZZZ)`)
300+
/// Parses an experimental fn contract
301+
/// (`contract_requires(WWW) contract_ensures(ZZZ)`)
302302
pub(super) fn parse_contract(
303303
&mut self,
304304
) -> PResult<'a, Option<rustc_ast::ptr::P<ast::FnContract>>> {
305305
let gate = |span| {
306306
if self.psess.contract_attribute_spans.contains(span) {
307307
// span was generated via a builtin contracts attribute, so gate as end-user visible
308-
self.psess.gated_spans.gate(sym::rustc_contracts, span);
308+
self.psess.gated_spans.gate(sym::contracts, span);
309309
} else {
310310
// span was not generated via a builtin contracts attribute, so gate as internal machinery
311-
self.psess.gated_spans.gate(sym::rustc_contracts_internals, span);
311+
self.psess.gated_spans.gate(sym::contracts_internals, span);
312312
}
313313
};
314314

315-
let requires = if self.eat_keyword_noexpect(exp!(RustcContractRequires).kw) {
315+
let requires = if self.eat_keyword_noexpect(exp!(ContractRequires).kw) {
316316
let precond = self.parse_expr()?;
317317
gate(precond.span);
318318
Some(precond)
319319
} else {
320320
None
321321
};
322-
let ensures = if self.eat_keyword_noexpect(exp!(RustcContractEnsures).kw) {
322+
let ensures = if self.eat_keyword_noexpect(exp!(ContractEnsures).kw) {
323323
let postcond = self.parse_expr()?;
324324
gate(postcond.span);
325325
Some(postcond)

compiler/rustc_parse/src/parser/token_type.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub enum TokenType {
8383
KwCatch,
8484
KwConst,
8585
KwContinue,
86+
KwContractEnsures,
87+
KwContractRequires,
8688
KwCrate,
8789
KwDefault,
8890
KwDyn,
@@ -108,8 +110,6 @@ pub enum TokenType {
108110
KwRef,
109111
KwReturn,
110112
KwReuse,
111-
KwRustcContractEnsures,
112-
KwRustcContractRequires,
113113
KwSafe,
114114
KwSelfUpper,
115115
KwStatic,
@@ -219,6 +219,8 @@ impl TokenType {
219219
KwCatch,
220220
KwConst,
221221
KwContinue,
222+
KwContractEnsures,
223+
KwContractRequires,
222224
KwCrate,
223225
KwDefault,
224226
KwDyn,
@@ -244,8 +246,6 @@ impl TokenType {
244246
KwRef,
245247
KwReturn,
246248
KwReuse,
247-
KwRustcContractEnsures,
248-
KwRustcContractRequires,
249249
KwSafe,
250250
KwSelfUpper,
251251
KwStatic,
@@ -293,6 +293,8 @@ impl TokenType {
293293
TokenType::KwCatch => Some(kw::Catch),
294294
TokenType::KwConst => Some(kw::Const),
295295
TokenType::KwContinue => Some(kw::Continue),
296+
TokenType::KwContractEnsures => Some(kw::ContractEnsures),
297+
TokenType::KwContractRequires => Some(kw::ContractRequires),
296298
TokenType::KwCrate => Some(kw::Crate),
297299
TokenType::KwDefault => Some(kw::Default),
298300
TokenType::KwDyn => Some(kw::Dyn),
@@ -318,8 +320,6 @@ impl TokenType {
318320
TokenType::KwRef => Some(kw::Ref),
319321
TokenType::KwReturn => Some(kw::Return),
320322
TokenType::KwReuse => Some(kw::Reuse),
321-
TokenType::KwRustcContractEnsures => Some(kw::RustcContractEnsures),
322-
TokenType::KwRustcContractRequires => Some(kw::RustcContractRequires),
323323
TokenType::KwSafe => Some(kw::Safe),
324324
TokenType::KwSelfUpper => Some(kw::SelfUpper),
325325
TokenType::KwStatic => Some(kw::Static),
@@ -525,6 +525,8 @@ macro_rules! exp {
525525
(Catch) => { exp!(@kw, Catch, KwCatch) };
526526
(Const) => { exp!(@kw, Const, KwConst) };
527527
(Continue) => { exp!(@kw, Continue, KwContinue) };
528+
(ContractEnsures) => { exp!(@kw, ContractEnsures, KwContractEnsures) };
529+
(ContractRequires) => { exp!(@kw, ContractRequires, KwContractRequires) };
528530
(Crate) => { exp!(@kw, Crate, KwCrate) };
529531
(Default) => { exp!(@kw, Default, KwDefault) };
530532
(Dyn) => { exp!(@kw, Dyn, KwDyn) };
@@ -550,8 +552,6 @@ macro_rules! exp {
550552
(Ref) => { exp!(@kw, Ref, KwRef) };
551553
(Return) => { exp!(@kw, Return, KwReturn) };
552554
(Reuse) => { exp!(@kw, Reuse, KwReuse) };
553-
(RustcContractEnsures) => { exp!(@kw, RustcContractEnsures, KwRustcContractEnsures) };
554-
(RustcContractRequires) => { exp!(@kw, RustcContractRequires, KwRustcContractRequires) };
555555
(Safe) => { exp!(@kw, Safe, KwSafe) };
556556
(SelfUpper) => { exp!(@kw, SelfUpper, KwSelfUpper) };
557557
(Static) => { exp!(@kw, Static, KwStatic) };

compiler/rustc_span/src/symbol.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ symbols! {
118118
MacroRules: "macro_rules",
119119
Raw: "raw",
120120
Reuse: "reuse",
121-
RustcContractEnsures: "rustc_contract_ensures",
122-
RustcContractRequires: "rustc_contract_requires",
121+
ContractEnsures: "contract_ensures",
122+
ContractRequires: "contract_requires",
123123
Safe: "safe",
124124
Union: "union",
125125
Yeet: "yeet",
@@ -682,7 +682,9 @@ symbols! {
682682
contract_check_ensures,
683683
contract_check_requires,
684684
contract_checks,
685+
contracts,
685686
contracts_ensures,
687+
contracts_internals,
686688
contracts_requires,
687689
convert_identity,
688690
copy,
@@ -1716,8 +1718,6 @@ symbols! {
17161718
rustc_const_stable,
17171719
rustc_const_stable_indirect,
17181720
rustc_const_unstable,
1719-
rustc_contracts,
1720-
rustc_contracts_internals,
17211721
rustc_conversion_suggestion,
17221722
rustc_deallocator,
17231723
rustc_def_path,

library/core/src/contracts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_require
66
/// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }`
77
/// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }`
88
/// (including the implicit return of the tail expression, if any).
9-
#[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
9+
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
1010
#[lang = "contract_build_check_ensures"]
1111
#[track_caller]
1212
pub fn build_check_ensures<Ret, C>(cond: C) -> impl (Fn(Ret) -> Ret) + Copy

library/core/src/intrinsics/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4051,8 +4051,8 @@ pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize)
40514051
/// checking is turned on, so that we can specify contracts in libstd
40524052
/// and let an end user opt into turning them on.
40534053
#[cfg(not(bootstrap))]
4054-
#[rustc_const_unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
4055-
#[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
4054+
#[rustc_const_unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
4055+
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
40564056
#[inline(always)]
40574057
#[rustc_intrinsic]
40584058
pub const fn contract_checks() -> bool {
@@ -4067,7 +4067,7 @@ pub const fn contract_checks() -> bool {
40674067
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
40684068
/// returns false.
40694069
#[cfg(not(bootstrap))]
4070-
#[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
4070+
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
40714071
#[lang = "contract_check_requires"]
40724072
#[rustc_intrinsic]
40734073
pub fn contract_check_requires<C: Fn() -> bool>(cond: C) {
@@ -4082,7 +4082,7 @@ pub fn contract_check_requires<C: Fn() -> bool>(cond: C) {
40824082
/// By default, if `contract_checks` is enabled, this will panic with no unwind if the condition
40834083
/// returns false.
40844084
#[cfg(not(bootstrap))]
4085-
#[unstable(feature = "rustc_contracts_internals", issue = "133866" /* compiler-team#759 */)]
4085+
#[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)]
40864086
#[rustc_intrinsic]
40874087
pub fn contract_check_ensures<'a, Ret, C: Fn(&'a Ret) -> bool>(ret: &'a Ret, cond: C) {
40884088
if contract_checks() && !cond(ret) {

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub mod autodiff {
248248
}
249249

250250
#[cfg(not(bootstrap))]
251-
#[unstable(feature = "rustc_contracts", issue = "133866")]
251+
#[unstable(feature = "contracts", issue = "128044")]
252252
pub mod contracts;
253253

254254
#[unstable(feature = "cfg_match", issue = "115585")]

library/core/src/macros/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1783,8 +1783,8 @@ pub(crate) mod builtin {
17831783
/// eventually parsed as a unary closure expression that is
17841784
/// invoked on a reference to the return value.
17851785
#[cfg(not(bootstrap))]
1786-
#[unstable(feature = "rustc_contracts", issue = "133866")]
1787-
#[allow_internal_unstable(rustc_contracts_internals)]
1786+
#[unstable(feature = "contracts", issue = "128044")]
1787+
#[allow_internal_unstable(contracts_internals)]
17881788
#[rustc_builtin_macro]
17891789
pub macro contracts_ensures($item:item) {
17901790
/* compiler built-in */
@@ -1796,8 +1796,8 @@ pub(crate) mod builtin {
17961796
/// eventually parsed as an boolean expression with access to the
17971797
/// function's formal parameters
17981798
#[cfg(not(bootstrap))]
1799-
#[unstable(feature = "rustc_contracts", issue = "133866")]
1800-
#[allow_internal_unstable(rustc_contracts_internals)]
1799+
#[unstable(feature = "contracts", issue = "128044")]
1800+
#[allow_internal_unstable(contracts_internals)]
18011801
#[rustc_builtin_macro]
18021802
pub macro contracts_requires($item:item) {
18031803
/* compiler built-in */

tests/ui/contracts/contract-annotation-limitations.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
//! Test for some of the existing limitations and the current error messages.
22
//! Some of these limitations may be removed in the future.
33
4-
#![feature(rustc_contracts)]
4+
#![feature(contracts)]
5+
//~^ WARN the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
56
#![allow(dead_code)]
67

78
/// Represent a 5-star system.
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
error: contract annotations is only supported in functions with bodies
2-
--> $DIR/contract-annotation-limitations.rs:17:5
2+
--> $DIR/contract-annotation-limitations.rs:18:5
33
|
44
LL | #[core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: contract annotations is only supported in functions with bodies
8-
--> $DIR/contract-annotation-limitations.rs:21:5
8+
--> $DIR/contract-annotation-limitations.rs:22:5
99
|
1010
LL | #[core::contracts::ensures(|ret| ret.is_none_or(Stars::is_valid))]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

13-
error: aborting due to 2 previous errors
13+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
14+
--> $DIR/contract-annotation-limitations.rs:4:12
15+
|
16+
LL | #![feature(contracts)]
17+
| ^^^^^^^^^
18+
|
19+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
20+
= note: `#[warn(incomplete_features)]` on by default
21+
22+
error: aborting due to 2 previous errors; 1 warning emitted
1423

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-generics.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-generics.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-generics.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-generics.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

tests/ui/contracts/contract-attributes-generics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
//@ [chk_fail_post] compile-flags: -Zcontract-checks=yes
1717
//@ [chk_const_fail] compile-flags: -Zcontract-checks=yes
1818

19-
#![feature(rustc_contracts)]
19+
#![feature(contracts)]
20+
//~^ WARN the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
2021

2122
use std::ops::Sub;
2223

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-generics.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/contract-attributes-nest.rs:19:12
3+
|
4+
LL | #![feature(contracts)]
5+
| ^^^^^^^^^
6+
|
7+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)