diff options
| author | Celina G. Val <celinval@amazon.com> | 2025-04-07 17:42:08 -0700 | 
|---|---|---|
| committer | Celina G. Val <celinval@amazon.com> | 2025-04-08 10:46:31 -0700 | 
| commit | 3feac59b794acf326c0efebaabd500e47fc65ba9 (patch) | |
| tree | c522cc6dfe56fda0621496f4146f9ad12f170237 /library/core/src/contracts.rs | |
| parent | b9754f9e7bfe2d8eed780962b550a25a87118ce4 (diff) | |
| download | rust-3feac59b794acf326c0efebaabd500e47fc65ba9.tar.gz rust-3feac59b794acf326c0efebaabd500e47fc65ba9.zip | |
Fix unreachable expression warning
Invert the order that we pass the arguments to the `contract_check_ensures` function to avoid the warning when the tail of the function is unreachable. Note that the call itself is also unreachable, but we have already handled that case by ignoring unreachable call for contract calls.
Diffstat (limited to 'library/core/src/contracts.rs')
| -rw-r--r-- | library/core/src/contracts.rs | 15 | 
1 files changed, 10 insertions, 5 deletions
| diff --git a/library/core/src/contracts.rs b/library/core/src/contracts.rs index 82922642018..53f459debab 100644 --- a/library/core/src/contracts.rs +++ b/library/core/src/contracts.rs @@ -2,15 +2,20 @@ pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_requires as requires}; -/// Emitted by rustc as a desugaring of `#[ensures(PRED)] fn foo() -> R { ... [return R;] ... }` -/// into: `fn foo() { let _check = build_check_ensures(|ret| PRED) ... [return _check(R);] ... }` -/// (including the implicit return of the tail expression, if any). +/// This is an identity function used as part of the desugaring of the `#[ensures]` attribute. /// -/// This call helps with type inference for the predicate. +/// This is an existing hack to allow users to omit the type of the return value in their ensures +/// attribute. +/// +/// Ideally, rustc should be able to generate the type annotation. +/// The existing lowering logic makes it rather hard to add the explicit type annotation, +/// while the function call is fairly straight forward. #[unstable(feature = "contracts_internals", issue = "128044" /* compiler-team#759 */)] +// Similar to `contract_check_requires`, we need to use the user-facing +// `contracts` feature rather than the perma-unstable `contracts_internals`. +// Const-checking doesn't honor allow internal unstable logic used by contract expansion. #[rustc_const_unstable(feature = "contracts", issue = "128044")] #[lang = "contract_build_check_ensures"] -#[track_caller] pub const fn build_check_ensures<Ret, C>(cond: C) -> C where C: Fn(&Ret) -> bool + Copy + 'static, | 
