Skip to content

Return false for zero in i32::{is_positive,is_negative} specs#171

Merged
coord-e merged 1 commit into
mainfrom
coord-e/exclude-zero-is_pos_neg
Jul 5, 2026
Merged

Return false for zero in i32::{is_positive,is_negative} specs#171
coord-e merged 1 commit into
mainfrom
coord-e/exclude-zero-is_pos_neg

Conversation

@coord-e

@coord-e coord-e commented Jul 5, 2026

Copy link
Copy Markdown
Owner

fix #170

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes unsoundness in Thrust’s Rust-stdlib extern specs by correcting the 0 boundary case for i32::is_positive and i32::is_negative (issue #170), aligning the model with real Rust behavior so 0 is neither positive nor negative.

Changes:

  • Update _extern_spec_i32_is_positive postcondition to make result == true iff x > 0.
  • Update _extern_spec_i32_is_negative postcondition to make result == true iff x < 0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread std.rs
Comment on lines 707 to 711
#[thrust_macros::requires(true)]
#[thrust_macros::ensures((x < 0 && result == false) || (x >= 0 && result == true))]
#[thrust_macros::ensures((x <= 0 && result == false) || (x > 0 && result == true))]
fn _extern_spec_i32_is_positive(x: i32) -> bool {
i32::is_positive(x)
}
Comment thread std.rs
Comment on lines 714 to 718
#[thrust_macros::requires(true)]
#[thrust_macros::ensures((x <= 0 && result == true) || (x > 0 && result == false))]
#[thrust_macros::ensures((x < 0 && result == true) || (x >= 0 && result == false))]
fn _extern_spec_i32_is_negative(x: i32) -> bool {
i32::is_negative(x)
}
@coord-e coord-e merged commit 5648fd2 into main Jul 5, 2026
7 checks passed
@coord-e coord-e deleted the coord-e/exclude-zero-is_pos_neg branch July 5, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unsound: i32::is_positive/is_negative extern specs classify 0 as positive/negative, verifying panicking programs as safe

2 participants