Fix ICE when using contracts on async functions
This commit is contained in:
parent
2f7620a5cc
commit
0935df7829
3 changed files with 35 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
10
tests/ui/contracts/async-fn-contract-ice-145333.rs
Normal file
10
tests/ui/contracts/async-fn-contract-ice-145333.rs
Normal file
|
|
@ -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
tests/ui/contracts/async-fn-contract-ice-145333.stderr
Normal file
17
tests/ui/contracts/async-fn-contract-ice-145333.stderr
Normal file
|
|
@ -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…
Add table
Add a link
Reference in a new issue