Skip to content

Commit 17befeb

Browse files
authored
Unrolled build for #147710
Rollup merge of #147710 - chenyukang:yukang-fix-ice-contracts-async, r=jackh726 Fix ICE when using contracts on async functions Fixes #145333 contract is not supported for async functions right now, it's not properly lowered and getting HirId will ICE. This PR adds checking for async function in expanding AST phase, it's better until we want to fully support async for contracts feature.
2 parents 57ef8d6 + 0935df7 commit 17befeb

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)