- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
          Add contracts for all functions in Alignment
          #136578
        
          New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -507,6 +507,8 @@ pub const fn align_of<T>() -> usize { | |
| #[must_use] | ||
| #[stable(feature = "rust1", since = "1.0.0")] | ||
| #[rustc_const_stable(feature = "const_align_of_val", since = "1.85.0")] | ||
| #[rustc_allow_const_fn_unstable(contracts)] | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should add  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which functions would that affect? Ah, #136925 anyway needs to be resolved first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd still like to find a solution that does not require  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tautschnig did you try to make this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I finally tried adding  where the proposed fix won't actually work as the function is already marked with  | ||
| #[core::contracts::ensures(|result: &usize| result.is_power_of_two())] | ||
| pub const fn align_of_val<T: ?Sized>(val: &T) -> usize { | ||
| // SAFETY: val is a reference, so it's a valid raw pointer | ||
| unsafe { intrinsics::align_of_val(val) } | ||
|  | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that no backend actually overwrites this intrinsic. Why is it an intrinsic in the first place...? (Same for
contract_check_ensures.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other verification tools might tho. I need to ping the compiler team about design review of the existing design and long term solution.