html-to-markdown 2.24.1 → 2.24.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +9 -6
- data/ext/html-to-markdown-rb/native/Cargo.lock +13 -13
- data/ext/html-to-markdown-rb/native/Cargo.toml +1 -1
- data/lib/html_to_markdown/version.rb +1 -1
- data/rust-vendor/bytemuck/.cargo-checksum.json +1 -1
- data/rust-vendor/bytemuck/.cargo_vcs_info.json +1 -1
- data/rust-vendor/bytemuck/.github/workflows/rust.yml +4 -4
- data/rust-vendor/bytemuck/Cargo.lock +16 -9
- data/rust-vendor/bytemuck/Cargo.toml +6 -2
- data/rust-vendor/bytemuck/Cargo.toml.orig +7 -6
- data/rust-vendor/bytemuck/changelog.md +5 -0
- data/rust-vendor/bytemuck/src/must.rs +1 -1
- data/rust-vendor/bytemuck/src/pod.rs +13 -0
- data/rust-vendor/bytemuck/src/zeroable.rs +13 -0
- data/rust-vendor/bytemuck/src/zeroable_in_option.rs +2 -2
- data/rust-vendor/bytemuck/tests/std_tests.rs +1 -1
- data/rust-vendor/cc/.cargo-checksum.json +1 -1
- data/rust-vendor/cc/.cargo_vcs_info.json +1 -1
- data/rust-vendor/cc/CHANGELOG.md +8 -0
- data/rust-vendor/cc/Cargo.lock +3 -3
- data/rust-vendor/cc/Cargo.toml +2 -2
- data/rust-vendor/cc/Cargo.toml.orig +2 -2
- data/rust-vendor/cc/src/lib.rs +1 -0
- data/rust-vendor/cc/src/target/generated.rs +10 -0
- data/rust-vendor/find-msvc-tools/.cargo-checksum.json +1 -1
- data/rust-vendor/find-msvc-tools/.cargo_vcs_info.json +1 -1
- data/rust-vendor/find-msvc-tools/CHANGELOG.md +6 -0
- data/rust-vendor/find-msvc-tools/Cargo.lock +1 -1
- data/rust-vendor/find-msvc-tools/Cargo.toml +1 -1
- data/rust-vendor/find-msvc-tools/Cargo.toml.orig +1 -1
- data/rust-vendor/find-msvc-tools/src/find_tools.rs +55 -20
- data/rust-vendor/html-to-markdown-rs/src/converter/handlers/link.rs +1 -9
- data/rust-vendor/html-to-markdown-rs/src/converter/inline/link.rs +2 -11
- data/rust-vendor/html-to-markdown-rs/src/converter/list/definition.rs +30 -7
- data/rust-vendor/html-to-markdown-rs/src/converter/semantic/definition_list.rs +30 -7
- data/rust-vendor/html-to-markdown-rs/tests/issue_199_regressions.rs +15 -0
- data/rust-vendor/html-to-markdown-rs/tests/issue_200_regressions.rs +36 -0
- data/rust-vendor/zerocopy/.cargo-checksum.json +1 -1
- data/rust-vendor/zerocopy/.cargo_vcs_info.json +2 -1
- data/rust-vendor/zerocopy/Cargo.lock +3 -3
- data/rust-vendor/zerocopy/Cargo.toml +4 -4
- data/rust-vendor/zerocopy/Cargo.toml.orig +4 -4
- data/rust-vendor/zerocopy/src/doctests.rs +27 -0
- data/rust-vendor/zerocopy/src/error.rs +30 -0
- data/rust-vendor/zerocopy/src/layout.rs +239 -135
- data/rust-vendor/zerocopy/src/lib.rs +16 -0
- data/rust-vendor/zerocopy/src/macros.rs +255 -125
- data/rust-vendor/zerocopy/src/pointer/mod.rs +1 -1
- data/rust-vendor/zerocopy/src/pointer/ptr.rs +109 -23
- data/rust-vendor/zerocopy/src/util/macro_util.rs +344 -383
- data/rust-vendor/zerocopy/src/util/mod.rs +38 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-const.stderr +8 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-src-unsized.stderr +11 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-mutable.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-dst-not-references.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-src-unsized.stderr +11 -3
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-dst-not-tryfrombytes.stderr +0 -10
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-mutable.stderr +1 -1
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +0 -10
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-src-not-immutable-intobytes.stderr +1 -11
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-const.stderr +9 -0
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-src-unsized.stderr +16 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-mutable.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-dst-not-references.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-src-unsized.stderr +16 -8
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-dst-not-tryfrombytes.stderr +38 -38
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +33 -33
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-src-not-immutable-intobytes.stderr +12 -12
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-const.stderr +9 -0
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-src-unsized.stderr +16 -8
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-mutable.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-not-a-reference.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-dst-not-references.stderr +10 -0
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-src-unsized.stderr +16 -8
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-dst-not-tryfrombytes.stderr +38 -38
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-dst-not-immutable-tryfrombytes.stderr +33 -33
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-src-not-immutable-intobytes.stderr +12 -12
- data/rust-vendor/zerocopy-derive/.cargo-checksum.json +1 -1
- data/rust-vendor/zerocopy-derive/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zerocopy-derive/Cargo.lock +1 -1
- data/rust-vendor/zerocopy-derive/Cargo.toml +1 -1
- data/rust-vendor/zerocopy-derive/Cargo.toml.orig +1 -1
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/enum.stderr +3 -3
- data/rust-vendor/zerocopy-derive/tests/ui-nightly/struct.stderr +5 -5
- data/rust-vendor/zerocopy-derive/tests/ui-stable/enum.stderr +3 -3
- data/rust-vendor/zerocopy-derive/tests/ui-stable/struct.stderr +5 -5
- data/rust-vendor/zmij/.cargo-checksum.json +1 -1
- data/rust-vendor/zmij/.cargo_vcs_info.json +1 -1
- data/rust-vendor/zmij/Cargo.lock +16 -16
- data/rust-vendor/zmij/Cargo.toml +1 -1
- data/rust-vendor/zmij/Cargo.toml.orig +1 -1
- data/rust-vendor/zmij/README.md +1 -1
- data/rust-vendor/zmij/src/lib.rs +54 -93
- metadata +4 -50
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-mut-dst-unsized.stderr +0 -8
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-msrv/transmute-ref-dst-unsized.stderr +0 -8
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_mut-size-increase.stderr +0 -17
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-msrv/try_transmute_ref-size-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-mut-dst-unsized.stderr +0 -16
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-nightly/transmute-ref-dst-unsized.stderr +0 -16
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_mut-size-increase.stderr +0 -17
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-nightly/try_transmute_ref-size-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-mut-dst-unsized.stderr +0 -16
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.rs +0 -15
- data/rust-vendor/zerocopy/tests/ui-stable/transmute-ref-dst-unsized.stderr +0 -16
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.rs +0 -19
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_mut-size-increase.stderr +0 -17
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-alignment-increase.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-decrease.stderr +0 -9
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.rs +0 -18
- data/rust-vendor/zerocopy/tests/ui-stable/try_transmute_ref-size-increase.stderr +0 -9
|
@@ -751,8 +751,8 @@ mod cast_from {
|
|
|
751
751
|
// of the referent – it only modifies pointer metadata.
|
|
752
752
|
unsafe impl<Src, Dst> crate::pointer::cast::Cast<Src, Dst> for CastFrom<Dst>
|
|
753
753
|
where
|
|
754
|
-
Src: KnownLayout
|
|
755
|
-
Dst: KnownLayout
|
|
754
|
+
Src: KnownLayout + ?Sized,
|
|
755
|
+
Dst: KnownLayout + ?Sized,
|
|
756
756
|
{
|
|
757
757
|
}
|
|
758
758
|
|
|
@@ -760,8 +760,8 @@ mod cast_from {
|
|
|
760
760
|
// the referent (see inline comments for a more detailed proof of this).
|
|
761
761
|
unsafe impl<Src, Dst> crate::pointer::cast::CastExact<Src, Dst> for CastFrom<Dst>
|
|
762
762
|
where
|
|
763
|
-
Src: KnownLayout
|
|
764
|
-
Dst: KnownLayout
|
|
763
|
+
Src: KnownLayout + ?Sized,
|
|
764
|
+
Dst: KnownLayout + ?Sized,
|
|
765
765
|
{
|
|
766
766
|
}
|
|
767
767
|
|
|
@@ -771,8 +771,8 @@ mod cast_from {
|
|
|
771
771
|
// operations.
|
|
772
772
|
unsafe impl<Src, Dst> crate::pointer::cast::Project<Src, Dst> for CastFrom<Dst>
|
|
773
773
|
where
|
|
774
|
-
Src: KnownLayout
|
|
775
|
-
Dst: KnownLayout
|
|
774
|
+
Src: KnownLayout + ?Sized,
|
|
775
|
+
Dst: KnownLayout + ?Sized,
|
|
776
776
|
{
|
|
777
777
|
/// # PME
|
|
778
778
|
///
|
|
@@ -781,140 +781,228 @@ mod cast_from {
|
|
|
781
781
|
//
|
|
782
782
|
// FIXME(#1817): Support Sized->Unsized and Unsized->Sized casts
|
|
783
783
|
fn project(src: PtrInner<'_, Src>) -> *mut Dst {
|
|
784
|
-
// At compile time (specifically, post-monomorphization time), we
|
|
785
|
-
// need to compute two things:
|
|
786
|
-
// - Whether, given *any* `*Src`, it is possible to construct a
|
|
787
|
-
// `*Dst` which addresses the same number of bytes (ie, whether,
|
|
788
|
-
// for any `Src` pointer metadata, there exists `Dst` pointer
|
|
789
|
-
// metadata that addresses the same number of bytes)
|
|
790
|
-
// - If this is possible, any information necessary to perform the
|
|
791
|
-
// `Src`->`Dst` metadata conversion at runtime.
|
|
792
|
-
//
|
|
793
|
-
// Assume that `Src` and `Dst` are slice DSTs, and define:
|
|
794
|
-
// - `S_OFF = Src::LAYOUT.size_info.offset`
|
|
795
|
-
// - `S_ELEM = Src::LAYOUT.size_info.elem_size`
|
|
796
|
-
// - `D_OFF = Dst::LAYOUT.size_info.offset`
|
|
797
|
-
// - `D_ELEM = Dst::LAYOUT.size_info.elem_size`
|
|
798
|
-
//
|
|
799
|
-
// We are trying to solve the following equation:
|
|
800
|
-
//
|
|
801
|
-
// D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM
|
|
802
|
-
//
|
|
803
|
-
// At runtime, we will be attempting to compute `d_meta`, given
|
|
804
|
-
// `s_meta` (a runtime value) and all other parameters (which are
|
|
805
|
-
// compile-time values). We can solve like so:
|
|
806
|
-
//
|
|
807
|
-
// D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM
|
|
808
|
-
//
|
|
809
|
-
// d_meta * D_ELEM = S_OFF - D_OFF + s_meta * S_ELEM
|
|
810
|
-
//
|
|
811
|
-
// d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM
|
|
812
|
-
//
|
|
813
|
-
// Since `d_meta` will be a `usize`, we need the right-hand side to
|
|
814
|
-
// be an integer, and this needs to hold for *any* value of `s_meta`
|
|
815
|
-
// (in order for our conversion to be infallible - ie, to not have
|
|
816
|
-
// to reject certain values of `s_meta` at runtime). This means
|
|
817
|
-
// that:
|
|
818
|
-
// - `s_meta * S_ELEM` must be a multiple of `D_ELEM`
|
|
819
|
-
// - Since this must hold for any value of `s_meta`, `S_ELEM` must
|
|
820
|
-
// be a multiple of `D_ELEM`
|
|
821
|
-
// - `S_OFF - D_OFF` must be a multiple of `D_ELEM`
|
|
822
|
-
//
|
|
823
|
-
// Thus, let `OFFSET_DELTA_ELEMS = (S_OFF - D_OFF)/D_ELEM` and
|
|
824
|
-
// `ELEM_MULTIPLE = S_ELEM/D_ELEM`. We can rewrite the above
|
|
825
|
-
// expression as:
|
|
826
|
-
//
|
|
827
|
-
// d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM
|
|
828
|
-
//
|
|
829
|
-
// d_meta = OFFSET_DELTA_ELEMS + s_meta * ELEM_MULTIPLE
|
|
830
|
-
//
|
|
831
|
-
// Thus, we just need to compute the following and confirm that they
|
|
832
|
-
// have integer solutions in order to both a) determine whether
|
|
833
|
-
// infallible `Src` -> `Dst` casts are possible and, b) pre-compute
|
|
834
|
-
// the parameters necessary to perform those casts at runtime. These
|
|
835
|
-
// parameters are encapsulated in `CastParams`, which acts as a
|
|
836
|
-
// witness that such infallible casts are possible.
|
|
837
|
-
|
|
838
784
|
/// The parameters required in order to perform a pointer cast from
|
|
839
|
-
/// `Src` to `Dst
|
|
785
|
+
/// `Src` to `Dst`.
|
|
840
786
|
///
|
|
841
|
-
/// These are a compile-time function of the layouts of `Src`
|
|
842
|
-
/// `Dst`.
|
|
787
|
+
/// These are a compile-time function of the layouts of `Src`
|
|
788
|
+
/// and `Dst`.
|
|
843
789
|
///
|
|
844
790
|
/// # Safety
|
|
845
791
|
///
|
|
846
|
-
/// `offset_delta_elems` and `elem_multiple` must be valid as
|
|
847
|
-
/// described above.
|
|
848
|
-
///
|
|
849
792
|
/// `Src`'s alignment must not be smaller than `Dst`'s alignment.
|
|
793
|
+
struct CastParams<Src: ?Sized, Dst: ?Sized> {
|
|
794
|
+
inner: CastParamsInner,
|
|
795
|
+
_src: PhantomData<Src>,
|
|
796
|
+
_dst: PhantomData<Dst>,
|
|
797
|
+
}
|
|
798
|
+
|
|
850
799
|
#[derive(Copy, Clone)]
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
800
|
+
enum CastParamsInner {
|
|
801
|
+
// At compile time (specifically, post-monomorphization time),
|
|
802
|
+
// we need to compute two things:
|
|
803
|
+
// - Whether, given *any* `*Src`, it is possible to construct a
|
|
804
|
+
// `*Dst` which addresses the same number of bytes (ie,
|
|
805
|
+
// whether, for any `Src` pointer metadata, there exists `Dst`
|
|
806
|
+
// pointer metadata that addresses the same number of bytes)
|
|
807
|
+
// - If this is possible, any information necessary to perform
|
|
808
|
+
// the `Src`->`Dst` metadata conversion at runtime.
|
|
809
|
+
//
|
|
810
|
+
// Assume that `Src` and `Dst` are slice DSTs, and define:
|
|
811
|
+
// - `S_OFF = Src::LAYOUT.size_info.offset`
|
|
812
|
+
// - `S_ELEM = Src::LAYOUT.size_info.elem_size`
|
|
813
|
+
// - `D_OFF = Dst::LAYOUT.size_info.offset`
|
|
814
|
+
// - `D_ELEM = Dst::LAYOUT.size_info.elem_size`
|
|
815
|
+
//
|
|
816
|
+
// We are trying to solve the following equation:
|
|
817
|
+
//
|
|
818
|
+
// D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM
|
|
819
|
+
//
|
|
820
|
+
// At runtime, we will be attempting to compute `d_meta`, given
|
|
821
|
+
// `s_meta` (a runtime value) and all other parameters (which
|
|
822
|
+
// are compile-time values). We can solve like so:
|
|
823
|
+
//
|
|
824
|
+
// D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM
|
|
825
|
+
//
|
|
826
|
+
// d_meta * D_ELEM = S_OFF - D_OFF + s_meta * S_ELEM
|
|
827
|
+
//
|
|
828
|
+
// d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM
|
|
829
|
+
//
|
|
830
|
+
// Since `d_meta` will be a `usize`, we need the right-hand side
|
|
831
|
+
// to be an integer, and this needs to hold for *any* value of
|
|
832
|
+
// `s_meta` (in order for our conversion to be infallible - ie,
|
|
833
|
+
// to not have to reject certain values of `s_meta` at runtime).
|
|
834
|
+
// This means that:
|
|
835
|
+
//
|
|
836
|
+
// - `s_meta * S_ELEM` must be a multiple of `D_ELEM`
|
|
837
|
+
// - Since this must hold for any value of `s_meta`, `S_ELEM`
|
|
838
|
+
// must be a multiple of `D_ELEM`
|
|
839
|
+
// - `S_OFF - D_OFF` must be a multiple of `D_ELEM`
|
|
840
|
+
//
|
|
841
|
+
// Thus, let `OFFSET_DELTA_ELEMS = (S_OFF - D_OFF)/D_ELEM` and
|
|
842
|
+
// `ELEM_MULTIPLE = S_ELEM/D_ELEM`. We can rewrite the above
|
|
843
|
+
// expression as:
|
|
844
|
+
//
|
|
845
|
+
// d_meta = (S_OFF - D_OFF + s_meta * S_ELEM)/D_ELEM
|
|
846
|
+
//
|
|
847
|
+
// d_meta = OFFSET_DELTA_ELEMS + s_meta * ELEM_MULTIPLE
|
|
848
|
+
//
|
|
849
|
+
// Thus, we just need to compute the following and confirm that
|
|
850
|
+
// they have integer solutions in order to both a) determine
|
|
851
|
+
// whether infallible `Src` -> `Dst` casts are possible and, b)
|
|
852
|
+
// pre-compute the parameters necessary to perform those casts
|
|
853
|
+
// at runtime. These parameters are encapsulated in
|
|
854
|
+
// `CastParams`, which acts as a witness that such infallible
|
|
855
|
+
// casts are possible.
|
|
856
|
+
/// The parameters required in order to perform an
|
|
857
|
+
/// unsized-to-unsized pointer cast from `Src` to `Dst` as
|
|
858
|
+
/// described above.
|
|
859
|
+
///
|
|
860
|
+
/// # Safety
|
|
861
|
+
///
|
|
862
|
+
/// `Src` and `Dst` must both be slice DSTs.
|
|
863
|
+
///
|
|
864
|
+
/// `offset_delta_elems` and `elem_multiple` must be valid as
|
|
865
|
+
/// described above.
|
|
866
|
+
UnsizedToUnsized { offset_delta_elems: usize, elem_multiple: usize },
|
|
867
|
+
|
|
868
|
+
/// The metadata of a `Dst` which has the same size as `Src:
|
|
869
|
+
/// Sized`.
|
|
870
|
+
///
|
|
871
|
+
/// # Safety
|
|
872
|
+
///
|
|
873
|
+
/// `Src: Sized` and `Dst` must be a slice DST.
|
|
874
|
+
///
|
|
875
|
+
/// A raw `Dst` pointer with metadata `dst_meta` must address
|
|
876
|
+
/// `size_of::<Src>()` bytes.
|
|
877
|
+
SizedToUnsized { dst_meta: usize },
|
|
878
|
+
|
|
879
|
+
/// The metadata of a `Dst` which has the same size as `Src:
|
|
880
|
+
/// Sized`.
|
|
881
|
+
///
|
|
882
|
+
/// # Safety
|
|
883
|
+
///
|
|
884
|
+
/// `Src` and `Dst` must both be `Sized` and `size_of::<Src>()
|
|
885
|
+
/// == size_of::<Dst>()`.
|
|
886
|
+
SizedToSized,
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
impl<Src: ?Sized, Dst: ?Sized> Copy for CastParams<Src, Dst> {}
|
|
890
|
+
impl<Src: ?Sized, Dst: ?Sized> Clone for CastParams<Src, Dst> {
|
|
891
|
+
fn clone(&self) -> Self {
|
|
892
|
+
*self
|
|
893
|
+
}
|
|
854
894
|
}
|
|
855
895
|
|
|
856
|
-
impl CastParams {
|
|
857
|
-
const fn try_compute(
|
|
896
|
+
impl<Src: ?Sized, Dst: ?Sized> CastParams<Src, Dst> {
|
|
897
|
+
const fn try_compute(
|
|
898
|
+
src: &DstLayout,
|
|
899
|
+
dst: &DstLayout,
|
|
900
|
+
) -> Option<CastParams<Src, Dst>> {
|
|
858
901
|
if src.align.get() < dst.align.get() {
|
|
859
902
|
return None;
|
|
860
903
|
}
|
|
861
904
|
|
|
862
|
-
let
|
|
863
|
-
(
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
905
|
+
let inner = match (src.size_info, dst.size_info) {
|
|
906
|
+
(
|
|
907
|
+
SizeInfo::Sized { size: src_size },
|
|
908
|
+
SizeInfo::Sized { size: dst_size },
|
|
909
|
+
) => {
|
|
910
|
+
if src_size != dst_size {
|
|
911
|
+
return None;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// SAFETY: We checked above that `src_size ==
|
|
915
|
+
// dst_size`.
|
|
916
|
+
CastParamsInner::SizedToSized
|
|
917
|
+
}
|
|
918
|
+
(SizeInfo::Sized { size: src_size }, SizeInfo::SliceDst(dst)) => {
|
|
919
|
+
let offset_delta = if let Some(od) = src_size.checked_sub(dst.offset) {
|
|
920
|
+
od
|
|
921
|
+
} else {
|
|
922
|
+
return None;
|
|
923
|
+
};
|
|
869
924
|
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
925
|
+
let dst_elem_size = if let Some(e) = NonZeroUsize::new(dst.elem_size) {
|
|
926
|
+
e
|
|
927
|
+
} else {
|
|
928
|
+
return None;
|
|
929
|
+
};
|
|
875
930
|
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
};
|
|
931
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
932
|
+
// divide by zero.
|
|
933
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
934
|
+
let delta_mod_other_elem = offset_delta % dst_elem_size.get();
|
|
881
935
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
let delta_mod_other_elem = offset_delta % dst_elem_size.get();
|
|
936
|
+
if delta_mod_other_elem != 0 {
|
|
937
|
+
return None;
|
|
938
|
+
}
|
|
886
939
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
940
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
941
|
+
// divide by zero.
|
|
942
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
943
|
+
let dst_meta = offset_delta / dst_elem_size.get();
|
|
891
944
|
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
945
|
+
// SAFETY: The preceding math ensures that a `Dst`
|
|
946
|
+
// with `dst_meta` addresses `src_size` bytes.
|
|
947
|
+
CastParamsInner::SizedToUnsized { dst_meta }
|
|
948
|
+
}
|
|
949
|
+
(SizeInfo::SliceDst(src), SizeInfo::SliceDst(dst)) => {
|
|
950
|
+
let offset_delta = if let Some(od) = src.offset.checked_sub(dst.offset)
|
|
951
|
+
{
|
|
952
|
+
od
|
|
953
|
+
} else {
|
|
954
|
+
return None;
|
|
955
|
+
};
|
|
898
956
|
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
let dst_elem_size = if let Some(e) = NonZeroUsize::new(dst.elem_size) {
|
|
958
|
+
e
|
|
959
|
+
} else {
|
|
960
|
+
return None;
|
|
961
|
+
};
|
|
903
962
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
963
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
964
|
+
// divide by zero.
|
|
965
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
966
|
+
let delta_mod_other_elem = offset_delta % dst_elem_size.get();
|
|
967
|
+
|
|
968
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
969
|
+
// divide by zero.
|
|
970
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
971
|
+
let elem_remainder = src.elem_size % dst_elem_size.get();
|
|
972
|
+
|
|
973
|
+
if delta_mod_other_elem != 0
|
|
974
|
+
|| src.elem_size < dst.elem_size
|
|
975
|
+
|| elem_remainder != 0
|
|
976
|
+
{
|
|
977
|
+
return None;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
981
|
+
// divide by zero.
|
|
982
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
983
|
+
let offset_delta_elems = offset_delta / dst_elem_size.get();
|
|
984
|
+
|
|
985
|
+
// PANICS: `dst_elem_size: NonZeroUsize`, so this won't
|
|
986
|
+
// divide by zero.
|
|
987
|
+
#[allow(clippy::arithmetic_side_effects)]
|
|
988
|
+
let elem_multiple = src.elem_size / dst_elem_size.get();
|
|
989
|
+
|
|
990
|
+
CastParamsInner::UnsizedToUnsized {
|
|
991
|
+
// SAFETY: We checked above that this is an exact ratio.
|
|
992
|
+
offset_delta_elems,
|
|
993
|
+
// SAFETY: We checked above that this is an exact ratio.
|
|
994
|
+
elem_multiple,
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
_ => return None,
|
|
998
|
+
};
|
|
908
999
|
|
|
909
1000
|
// SAFETY: We checked above that `src.align >= dst.align`.
|
|
910
|
-
Some(CastParams {
|
|
911
|
-
// SAFETY: We checked above that this is an exact ratio.
|
|
912
|
-
offset_delta_elems,
|
|
913
|
-
// SAFETY: We checked above that this is an exact ratio.
|
|
914
|
-
elem_multiple,
|
|
915
|
-
})
|
|
1001
|
+
Some(CastParams { inner, _src: PhantomData, _dst: PhantomData })
|
|
916
1002
|
}
|
|
1003
|
+
}
|
|
917
1004
|
|
|
1005
|
+
impl<Src: KnownLayout + ?Sized, Dst: KnownLayout + ?Sized> CastParams<Src, Dst> {
|
|
918
1006
|
/// # Safety
|
|
919
1007
|
///
|
|
920
1008
|
/// `src_meta` describes a `Src` whose size is no larger than
|
|
@@ -922,41 +1010,57 @@ mod cast_from {
|
|
|
922
1010
|
///
|
|
923
1011
|
/// The returned metadata describes a `Dst` of the same size as
|
|
924
1012
|
/// the original `Src`.
|
|
925
|
-
|
|
1013
|
+
#[inline(always)]
|
|
1014
|
+
unsafe fn cast_metadata(
|
|
1015
|
+
self,
|
|
1016
|
+
src_meta: Src::PointerMetadata,
|
|
1017
|
+
) -> Dst::PointerMetadata {
|
|
926
1018
|
#[allow(unused)]
|
|
927
1019
|
use crate::util::polyfills::*;
|
|
928
1020
|
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
1021
|
+
let dst_meta = match self.inner {
|
|
1022
|
+
CastParamsInner::UnsizedToUnsized { offset_delta_elems, elem_multiple } => {
|
|
1023
|
+
let src_meta = src_meta.to_elem_count();
|
|
1024
|
+
#[allow(
|
|
1025
|
+
unstable_name_collisions,
|
|
1026
|
+
clippy::multiple_unsafe_ops_per_block
|
|
1027
|
+
)]
|
|
1028
|
+
// SAFETY: `self` is a witness that the following
|
|
1029
|
+
// equation holds:
|
|
1030
|
+
//
|
|
1031
|
+
// D_OFF + d_meta * D_ELEM = S_OFF + s_meta * S_ELEM
|
|
1032
|
+
//
|
|
1033
|
+
// Since the caller promises that `src_meta` is
|
|
1034
|
+
// valid `Src` metadata, this math will not
|
|
1035
|
+
// overflow, and the returned value will describe a
|
|
1036
|
+
// `Dst` of the same size.
|
|
1037
|
+
unsafe {
|
|
1038
|
+
offset_delta_elems
|
|
1039
|
+
.unchecked_add(src_meta.unchecked_mul(elem_multiple))
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
CastParamsInner::SizedToUnsized { dst_meta } => dst_meta,
|
|
1043
|
+
CastParamsInner::SizedToSized => 0,
|
|
1044
|
+
};
|
|
1045
|
+
Dst::PointerMetadata::from_elem_count(dst_meta)
|
|
942
1046
|
}
|
|
943
1047
|
}
|
|
944
1048
|
|
|
945
1049
|
trait Params<Src: ?Sized> {
|
|
946
|
-
const CAST_PARAMS: CastParams
|
|
1050
|
+
const CAST_PARAMS: CastParams<Src, Self>;
|
|
947
1051
|
}
|
|
948
1052
|
|
|
949
1053
|
impl<Src, Dst> Params<Src> for Dst
|
|
950
1054
|
where
|
|
951
1055
|
Src: KnownLayout + ?Sized,
|
|
952
|
-
Dst: KnownLayout
|
|
1056
|
+
Dst: KnownLayout + ?Sized,
|
|
953
1057
|
{
|
|
954
|
-
const CAST_PARAMS: CastParams =
|
|
1058
|
+
const CAST_PARAMS: CastParams<Src, Dst> =
|
|
955
1059
|
match CastParams::try_compute(&Src::LAYOUT, &Dst::LAYOUT) {
|
|
956
1060
|
Some(params) => params,
|
|
957
1061
|
None => const_panic!(
|
|
958
|
-
|
|
959
|
-
|
|
1062
|
+
"cannot `transmute_ref!` or `transmute_mut!` between incompatible types"
|
|
1063
|
+
),
|
|
960
1064
|
};
|
|
961
1065
|
}
|
|
962
1066
|
|
|
@@ -888,6 +888,12 @@ pub trait PointerMetadata: Copy + Eq + Debug {
|
|
|
888
888
|
/// `elems`. No other types are currently supported.
|
|
889
889
|
fn from_elem_count(elems: usize) -> Self;
|
|
890
890
|
|
|
891
|
+
/// Converts `self` to an element count.
|
|
892
|
+
///
|
|
893
|
+
/// If `Self = ()`, this returns `0`. If `Self = usize`, this returns
|
|
894
|
+
/// `self`. No other types are currently supported.
|
|
895
|
+
fn to_elem_count(self) -> usize;
|
|
896
|
+
|
|
891
897
|
/// Computes the size of the object with the given layout and pointer
|
|
892
898
|
/// metadata.
|
|
893
899
|
///
|
|
@@ -909,6 +915,11 @@ impl PointerMetadata for () {
|
|
|
909
915
|
#[allow(clippy::unused_unit)]
|
|
910
916
|
fn from_elem_count(_elems: usize) -> () {}
|
|
911
917
|
|
|
918
|
+
#[inline]
|
|
919
|
+
fn to_elem_count(self) -> usize {
|
|
920
|
+
0
|
|
921
|
+
}
|
|
922
|
+
|
|
912
923
|
#[inline]
|
|
913
924
|
fn size_for_metadata(self, layout: DstLayout) -> Option<usize> {
|
|
914
925
|
match layout.size_info {
|
|
@@ -926,6 +937,11 @@ impl PointerMetadata for usize {
|
|
|
926
937
|
elems
|
|
927
938
|
}
|
|
928
939
|
|
|
940
|
+
#[inline]
|
|
941
|
+
fn to_elem_count(self) -> usize {
|
|
942
|
+
self
|
|
943
|
+
}
|
|
944
|
+
|
|
929
945
|
#[inline]
|
|
930
946
|
fn size_for_metadata(self, layout: DstLayout) -> Option<usize> {
|
|
931
947
|
match layout.size_info {
|