Skip to content

Commit 5c5cbfd

Browse files
committed
Remove impl<C> $op_trait<PreAlpha<C>> for {f32,f64} impls to work around issue #283
1 parent 35f0b78 commit 5c5cbfd

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

palette/Cargo.toml

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ std = ["approx?/std"]
3838
[lib]
3939
bench = false
4040

41+
[[example]]
42+
name = "issue_283"
43+
path = "regression_tests/issue_283.rs"
44+
4145
[dependencies]
4246
palette_derive = { version = "0.7.0", path = "../palette_derive" }
4347
fast-srgb8 = "1.0.0"
@@ -76,6 +80,7 @@ serde = "1"
7680
serde_derive = "1"
7781
serde_json = "1"
7882
enterpolation = "0.2.0"
83+
scad = "1.2.2" # For regression testing #283
7984

8085
[dev-dependencies.clap]
8186
version = "3.2.23"

palette/regression_tests/issue_283.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Checks that issue #283 (fixed in 0.7.1) doesn't re-appear. The cause was the
2+
// existence of `impl Mul<PreAlpha<C>> for f32` and `impl Mul<PreAlpha<C>> for
3+
// f64`.
4+
5+
// Both of these uses are necessary for triggering the issue
6+
#[allow(unused_imports)]
7+
use palette::Oklch;
8+
#[allow(unused_imports)]
9+
use scad::OffsetType;
10+
11+
fn main() {
12+
println!("{}", 42.0 * 1.0); // bug also happens when specifying f32 or f64
13+
}

palette/src/blend/pre_alpha.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,22 @@ macro_rules! impl_scalar_binop {
296296
}
297297
}
298298

299-
impl<C> $op_trait<PreAlpha<C>> for $ty
300-
where
301-
C: Premultiply<Scalar = $ty>,
302-
$ty: $op_trait<$ty, Output = $ty> + $op_trait<C, Output = C>,
303-
{
304-
type Output = PreAlpha<C>;
305-
306-
fn $op_trait_fn(self, color: PreAlpha<C>) -> Self::Output {
307-
PreAlpha {
308-
color: $op_trait::<C>::$op_trait_fn(self, color.color),
309-
alpha: $op_trait::<$ty>::$op_trait_fn(self, color.alpha),
310-
}
311-
}
312-
}
299+
// // Disabled as work-around for https://github.com/Ogeon/palette/issues/283
300+
// // Blocked by https://github.com/rust-lang/rust/issues/80542
301+
// impl<C> $op_trait<PreAlpha<C>> for $ty
302+
// where
303+
// C: Premultiply<Scalar = $ty>,
304+
// $ty: $op_trait<$ty, Output = $ty> + $op_trait<C, Output = C>,
305+
// {
306+
// type Output = PreAlpha<C>;
307+
//
308+
// fn $op_trait_fn(self, color: PreAlpha<C>) -> Self::Output {
309+
// PreAlpha {
310+
// color: $op_trait::<C>::$op_trait_fn(self, color.color),
311+
// alpha: $op_trait::<$ty>::$op_trait_fn(self, color.alpha),
312+
// }
313+
// }
314+
// }
313315

314316
impl<C> $op_assign_trait<$ty> for PreAlpha<C>
315317
where

0 commit comments

Comments
 (0)