Skip to content
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

building with stable rust instead of nightly #3

Closed
aurelien-naldi opened this issue Dec 11, 2018 · 3 comments
Closed

building with stable rust instead of nightly #3

aurelien-naldi opened this issue Dec 11, 2018 · 3 comments

Comments

@aurelien-naldi
Copy link
Contributor

I would like to use this crate without having to rely on the nightly toolchain. I could build clingo-rs with the stable toolchain (using rust 1.31) after replacing std::ptr::Unique with std::ptr::NonNull (according to rust-lang/rust#27730, Unique will remain unstable for ever).

After this change, "cargo test" fails (but it was already failing before) but all examples seem to run properly.

Do you think it is a valid change or is there something which can be corrupted by using NonNull instead of Unique?

@sthiele
Copy link
Member

sthiele commented Dec 11, 2018

Yes, doc tests are failing because of some example code in the doc strings.
I should add an ignore to this code.
For replacing Unique:
I'm not an expert on this, but from what I read it is probably the safer to use *mut T.
Do you have other reasons to use NonNull?

@aurelien-naldi
Copy link
Contributor Author

I'm new to rust and I'm not sure why Unique was here in the first place so I mostly tried NonNull after getting the following compiler message:
use of unstable library feature 'ptr_internals': use NonNull instead and consider PhantomData (if you also use #[may_dangle]), Send, and/or Sync

From what I understand, replacing Unique with NonNull is trivial and makes it clear that the pointer is valid, while switching to *mut seems to require slightly more work .

  • 2 match blocks are used to guard the creation of the struct holding the pointer, they can be replaced by a direct is_null() check
  • it is accessed through as_ptr() everywhere else, so there are about 20 such calls to remove.

The build and example work with these two options, I can prepare a pull request with the one you prefer.

@sthiele
Copy link
Member

sthiele commented Dec 13, 2018

With using NotNull you give the compiler a guarantee so checks can be optimized. The guarantees are actually weaker than Unique so replacing it should not create safety problems.

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

No branches or pull requests

2 participants