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

Misc cleanups before allowing usage with stable Rust #23

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

bonzini
Copy link

@bonzini bonzini commented Nov 4, 2024

It is actually not that hard to make pinned_init usable with stable Rust. In particular:

  • new_uninit has been stabilized (and anyway in the end it was just a glorified Box::<MaybeUninit<T>>::new())
  • allocator_api is needed to have fallible allocation, but not if you just replace core::alloc::AllocError with core::convert::Infallible
  • get_mut_unchecked is needed if you need Arc, but otherwise is not necessary.

This pull request fixes CI and isolates a little bit more the pieces of code that refer to Arc or feature(allocator_api). The idea is that these are mostly uncontroversial changes that should not hamper readability and maintainability, and therefore can be committed separately.

Please let me know if I should submit separately the small changes to src/lib.rs, for example via the rust-for-linux mailing list.

new_uninit is stable as of 1.82.0, there is no need to require it.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Some of the error messages have changed in nightly Rust, since the
.stderr files were last checked.  Update everything.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Reuse examples/error.rs so that the error returned by EvenU64::new2() is
not core::alloc::AllocError.  This will allow running the test without
the allocator_api feature.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The big_struct_in_place example only uses init!, which has no dependency
on the allocator API (which provides the functionality of fallible
initialization).  Do not enable allocator_api.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Run nightly cargo fmt so that the corresponding GitHub check passes.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@bonzini
Copy link
Author

bonzini commented Nov 4, 2024

Successful CI run at bonzini#1

Prefer inspect_err over map_err, when the resulting error is the
same as the argument.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Arc support in pinned_init requires a specific unstable feature,
get_mut_unchecked.  Separate the tests for Arc to a different function,
so that in the future it is easier to only require get_mut_unchecked
when a specific feature is added.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
The only dependency of the InPlaceInit trait on the allocator API is the
AllocError type.  Replace it with Infallible instead, i.e. allow any
error as long as it has an "impl From<Infallible> for MyError" - which
can have a trivial implementation as seen in examples/rror.rs.

While admittedly of limited usefulness due to orphan rules, this is
a first step towards allowing usage of pinned_init entirely without
the allocator API, and therefore on stable Rust.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
@y86-dev
Copy link
Member

y86-dev commented Nov 7, 2024

thanks for the PR! I am currently very busy, so I might take some time before getting this in

@bonzini
Copy link
Author

bonzini commented Nov 7, 2024

Thanks, could you at least approval the workflow so that I can fix any issues?

@y86-dev
Copy link
Member

y86-dev commented Nov 7, 2024

there is one issue with a ui test that the main branch is also failing at the moment, so I expect it to also fail here. I'll fix that (hopefully) soon

@bonzini
Copy link
Author

bonzini commented Nov 7, 2024

I think it's one of those that I fixed. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants