Skip to content

Commit 6521e75

Browse files
Improve PhantomData held by curve adaptors (#15881)
# Objective The previous `PhantomData` instances were written somewhat lazily, so they were just things like `PhantomData<T>` for curves with an output type of `T`. This looks innocuous, but it unnecessarily constrains `Send/Sync` inference based on `T`. See [here](https://doc.rust-lang.org/nomicon/phantom-data.html#table-of-phantomdata-patterns). ## Solution Switch to `PhantomData` of the form `PhantomData<fn() -> T>` for most of these adaptors. Since they only have a functional relationship to `T` (i.e. it shows up in the return type of trait methods), this is more accurate. ## Testing Tested by compiling Bevy. Co-authored-by: François Mockers <[email protected]>
1 parent d82d6ff commit 6521e75

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

crates/bevy_math/src/curve/adaptors.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct FunctionCurve<T, F> {
8585
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
8686
pub(crate) f: F,
8787
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
88-
pub(crate) _phantom: PhantomData<T>,
88+
pub(crate) _phantom: PhantomData<fn() -> T>,
8989
}
9090

9191
impl<T, F> Debug for FunctionCurve<T, F> {
@@ -186,7 +186,7 @@ pub struct MapCurve<S, T, C, F> {
186186
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
187187
pub(crate) f: F,
188188
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
189-
pub(crate) _phantom: PhantomData<(S, T)>,
189+
pub(crate) _phantom: PhantomData<(fn() -> S, fn(S) -> T)>,
190190
}
191191

192192
impl<S, T, C, F> Debug for MapCurve<S, T, C, F>
@@ -283,7 +283,7 @@ pub struct ReparamCurve<T, C, F> {
283283
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
284284
pub(crate) f: F,
285285
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
286-
pub(crate) _phantom: PhantomData<T>,
286+
pub(crate) _phantom: PhantomData<fn() -> T>,
287287
}
288288

289289
impl<T, C, F> Debug for ReparamCurve<T, C, F>
@@ -377,7 +377,7 @@ pub struct LinearReparamCurve<T, C> {
377377
/// Invariants: This interval must always be bounded.
378378
pub(crate) new_domain: Interval,
379379
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
380-
pub(crate) _phantom: PhantomData<T>,
380+
pub(crate) _phantom: PhantomData<fn() -> T>,
381381
}
382382

383383
impl<T, C> Curve<T> for LinearReparamCurve<T, C>
@@ -410,7 +410,7 @@ pub struct CurveReparamCurve<T, C, D> {
410410
pub(crate) base: C,
411411
pub(crate) reparam_curve: D,
412412
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
413-
pub(crate) _phantom: PhantomData<T>,
413+
pub(crate) _phantom: PhantomData<fn() -> T>,
414414
}
415415

416416
impl<T, C, D> Curve<T> for CurveReparamCurve<T, C, D>
@@ -442,7 +442,7 @@ where
442442
pub struct GraphCurve<T, C> {
443443
pub(crate) base: C,
444444
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
445-
pub(crate) _phantom: PhantomData<T>,
445+
pub(crate) _phantom: PhantomData<fn() -> T>,
446446
}
447447

448448
impl<T, C> Curve<(f32, T)> for GraphCurve<T, C>
@@ -474,7 +474,7 @@ pub struct ZipCurve<S, T, C, D> {
474474
pub(crate) first: C,
475475
pub(crate) second: D,
476476
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
477-
pub(crate) _phantom: PhantomData<(S, T)>,
477+
pub(crate) _phantom: PhantomData<fn() -> (S, T)>,
478478
}
479479

480480
impl<S, T, C, D> Curve<(S, T)> for ZipCurve<S, T, C, D>
@@ -514,7 +514,7 @@ pub struct ChainCurve<T, C, D> {
514514
pub(crate) first: C,
515515
pub(crate) second: D,
516516
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
517-
pub(crate) _phantom: PhantomData<T>,
517+
pub(crate) _phantom: PhantomData<fn() -> T>,
518518
}
519519

520520
impl<T, C, D> Curve<T> for ChainCurve<T, C, D>
@@ -563,7 +563,7 @@ where
563563
pub struct ReverseCurve<T, C> {
564564
pub(crate) curve: C,
565565
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
566-
pub(crate) _phantom: PhantomData<T>,
566+
pub(crate) _phantom: PhantomData<fn() -> T>,
567567
}
568568

569569
impl<T, C> Curve<T> for ReverseCurve<T, C>
@@ -605,7 +605,7 @@ pub struct RepeatCurve<T, C> {
605605
pub(crate) domain: Interval,
606606
pub(crate) curve: C,
607607
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
608-
pub(crate) _phantom: PhantomData<T>,
608+
pub(crate) _phantom: PhantomData<fn() -> T>,
609609
}
610610

611611
impl<T, C> Curve<T> for RepeatCurve<T, C>
@@ -653,7 +653,7 @@ where
653653
pub struct ForeverCurve<T, C> {
654654
pub(crate) curve: C,
655655
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
656-
pub(crate) _phantom: PhantomData<T>,
656+
pub(crate) _phantom: PhantomData<fn() -> T>,
657657
}
658658

659659
impl<T, C> Curve<T> for ForeverCurve<T, C>
@@ -697,7 +697,7 @@ where
697697
pub struct PingPongCurve<T, C> {
698698
pub(crate) curve: C,
699699
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
700-
pub(crate) _phantom: PhantomData<T>,
700+
pub(crate) _phantom: PhantomData<fn() -> T>,
701701
}
702702

703703
impl<T, C> Curve<T> for PingPongCurve<T, C>
@@ -754,7 +754,7 @@ pub struct ContinuationCurve<T, C, D> {
754754
// cache the offset in the curve directly to prevent triple sampling for every sample we make
755755
pub(crate) offset: T,
756756
#[cfg_attr(feature = "bevy_reflect", reflect(ignore))]
757-
pub(crate) _phantom: PhantomData<T>,
757+
pub(crate) _phantom: PhantomData<fn() -> T>,
758758
}
759759

760760
impl<T, C, D> Curve<T> for ContinuationCurve<T, C, D>

0 commit comments

Comments
 (0)