Skip to content

Commit 0935df7

Browse files
committed
Fix ICE when using contracts on async functions
1 parent 2f7620a commit 0935df7

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

compiler/rustc_builtin_macros/src/contracts.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ fn expand_contract_clause(
7171
.span_err(attr_span, "contract annotations can only be used on functions"));
7272
}
7373

74+
// Contracts are not yet supported on async/gen functions
75+
if new_tts.iter().any(|tt| is_kw(tt, kw::Async) || is_kw(tt, kw::Gen)) {
76+
return Err(ecx.sess.dcx().span_err(
77+
attr_span,
78+
"contract annotations are not yet supported on async or gen functions",
79+
));
80+
}
81+
7482
// Found the `fn` keyword, now find either the `where` token or the function body.
7583
let next_tt = loop {
7684
let Some(tt) = cursor.next() else {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//@ compile-flags: --crate-type=lib
2+
//@ edition: 2021
3+
#![feature(contracts)]
4+
//~^ WARN the feature `contracts` is incomplete
5+
6+
#[core::contracts::ensures(|ret| *ret)]
7+
//~^ ERROR contract annotations are not yet supported on async or gen functions
8+
async fn _always_true(b: bool) -> bool {
9+
b
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: contract annotations are not yet supported on async or gen functions
2+
--> $DIR/async-fn-contract-ice-145333.rs:6:1
3+
|
4+
LL | #[core::contracts::ensures(|ret| *ret)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
8+
--> $DIR/async-fn-contract-ice-145333.rs:3:12
9+
|
10+
LL | #![feature(contracts)]
11+
| ^^^^^^^^^
12+
|
13+
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
14+
= note: `#[warn(incomplete_features)]` on by default
15+
16+
error: aborting due to 1 previous error; 1 warning emitted
17+

0 commit comments

Comments
 (0)