Skip to content
Open
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
2 changes: 1 addition & 1 deletion library/core/src/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use crate::macros::builtin::{contracts_ensures as ensures, contracts_require
#[lang = "contract_build_check_ensures"]
pub const fn build_check_ensures<Ret, C>(cond: C) -> C
where
C: Fn(&Ret) -> bool + Copy + 'static,
C: Fn(&Ret) -> bool + Copy,
{
cond
}
30 changes: 30 additions & 0 deletions tests/ui/contracts/ensures-lifetime.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//@ run-pass
//@ compile-flags: -Zcontract-checks=yes

#![feature(core_intrinsics)]
#![feature(contracts)]
//~^ WARN the feature `contracts` is incomplete and may not be safe to use
//and/or cause compiler crashes [incomplete_features]
#![allow(unused)]

// Regression test to allow contract `ensures` clauses to reference non-static
// references and non-static types. Previously, contracts in the below functions
// would raise type/lifetime errors due a `'static` bound on the `ensures`
// closure.

extern crate core;
use core::contracts::ensures;

#[ensures(|_| { x; true })]
pub fn noop<T>(x: &T) {}

#[ensures(move |_| { x; true })]
pub fn noop_mv<T>(x: &T) {}

#[ensures(|_| { x; true })]
pub fn noop_ptr<T>(x: *const T) {}

#[ensures(move |_| { x; true })]
pub fn noop_ptr_mv<T>(x: *const T) {}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/contracts/ensures-lifetime.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/ensures-lifetime.rs:5: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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may add #![allow(incomplete_features)] to suppress this warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out! So far all the other contract UI tests have included this warning in the stderr, so I followed that pattern.


warning: 1 warning emitted

Loading