Skip to content

Commit c4ed7ec

Browse files
authored
Add #[kani::unstable] attribute (rust-lang#2373)
Add the #[unstable] attribute that will allow us to mark unstable APIs. This PR only adds the attributes and we still need to add the option to enable them and to error out if the user is trying to use an unstable item without explicitly opting-in.
1 parent 55d1557 commit c4ed7ec

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

kani-compiler/src/kani_middle/attributes.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ enum KaniAttributeKind {
2626
ShouldPanic,
2727
Solver,
2828
Stub,
29+
/// Attribute used to mark unstable APIs.
30+
Unstable,
2931
Unwind,
3032
}
3133

@@ -113,6 +115,10 @@ pub fn extract_harness_attributes(tcx: TyCtxt, def_id: DefId) -> Option<HarnessA
113115
parse_unwind(tcx, expect_single(tcx, kind, &attributes))
114116
}
115117
KaniAttributeKind::Proof => harness.proof = true,
118+
KaniAttributeKind::Unstable => {
119+
// Internal attribute which shouldn't exist here.
120+
unreachable!()
121+
}
116122
};
117123
harness
118124
},

library/kani/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

4+
// Required so we can use kani_macros attributes.
5+
#![feature(register_tool)]
6+
#![register_tool(kanitool)]
47
// Used for rustc_diagnostic_item.
58
#![feature(rustc_attrs)]
69
// This is required for the optimized version of `any_array()`

library/kani_macros/src/lib.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ pub fn stub(attr: TokenStream, item: TokenStream) -> TokenStream {
7373
pub fn solver(attr: TokenStream, item: TokenStream) -> TokenStream {
7474
attr_impl::solver(attr, item)
7575
}
76+
77+
/// Mark an API as unstable. This should only be used inside the Kani sysroot.
78+
/// See https://model-checking.github.io/kani/rfc/rfcs/0006-unstable-api.html for more details.
79+
#[doc(hidden)]
80+
#[proc_macro_attribute]
81+
pub fn unstable(attr: TokenStream, item: TokenStream) -> TokenStream {
82+
attr_impl::unstable(attr, item)
83+
}
84+
7685
/// Allow users to auto generate Arbitrary implementations by using `#[derive(Arbitrary)]` macro.
7786
#[proc_macro_error]
7887
#[proc_macro_derive(Arbitrary)]
@@ -176,9 +185,10 @@ mod sysroot {
176185
}
177186

178187
kani_attribute!(should_panic, no_args);
179-
kani_attribute!(unwind);
180-
kani_attribute!(stub);
181188
kani_attribute!(solver);
189+
kani_attribute!(stub);
190+
kani_attribute!(unstable);
191+
kani_attribute!(unwind);
182192
}
183193

184194
/// This module provides dummy implementations of Kani attributes which cannot be interpreted by
@@ -207,7 +217,8 @@ mod regular {
207217
}
208218

209219
no_op!(should_panic);
210-
no_op!(unwind);
211-
no_op!(stub);
212220
no_op!(solver);
221+
no_op!(stub);
222+
no_op!(unstable);
223+
no_op!(unwind);
213224
}

0 commit comments

Comments
 (0)