Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/rustc_builtin_macros/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ fn expand_contract_clause(
.span_err(attr_span, "contract annotations can only be used on functions"));
}

// Contracts are not yet supported on async/gen functions
if new_tts.iter().any(|tt| is_kw(tt, kw::Async) || is_kw(tt, kw::Gen)) {
return Err(ecx.sess.dcx().span_err(
attr_span,
"contract annotations are not yet supported on async or gen functions",
));
}

// Found the `fn` keyword, now find either the `where` token or the function body.
let next_tt = loop {
let Some(tt) = cursor.next() else {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/contracts/async-fn-contract-ice-145333.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ compile-flags: --crate-type=lib
//@ edition: 2021
#![feature(contracts)]
//~^ WARN the feature `contracts` is incomplete

#[core::contracts::ensures(|ret| *ret)]
//~^ ERROR contract annotations are not yet supported on async or gen functions
async fn _always_true(b: bool) -> bool {
b
}
17 changes: 17 additions & 0 deletions tests/ui/contracts/async-fn-contract-ice-145333.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
error: contract annotations are not yet supported on async or gen functions
--> $DIR/async-fn-contract-ice-145333.rs:6:1
|
LL | #[core::contracts::ensures(|ret| *ret)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/async-fn-contract-ice-145333.rs:3:12
|
LL | #![feature(contracts)]
| ^^^^^^^^^
|
= note: see issue #128044 <https://github.com/rust-lang/rust/issues/128044> for more information
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to 1 previous error; 1 warning emitted

Loading