Skip to content

Commit f0cdbb3

Browse files
authored
remove impl ToColor for isize (#1473)
* remove `impl ToColor for isize` - there is an impl for `u32` already, that impl is now the only one so rustc easily figures out the number type, that does not have to be explicitly annotated anymore. - `isize` is not always wide enough to represent all colors. writing 0xff0000ffisize compiles on 64 bit systems but not on 32 or 16 bit systems. (deny-by-default warning, if `allow`ed it will panic at runtime) * update changelog
1 parent 829071a commit f0cdbb3

File tree

2 files changed

+3
-17
lines changed

2 files changed

+3
-17
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ when upgrading from a version of rust-sdl2 to another.
33

44
### Next
55

6+
[PR #1473](https://github.com/Rust-SDL2/rust-sdl2/pull/1473) **BREAKING CHANGE** Fix UB in `ToColor` implementations and remove implementation for `isize`.
7+
68
[PR #1414](https://github.com/Rust-SDL2/rust-sdl2/pull/1414) Use `TTF_GlyphIsProvided32` and `TTF_GlyphMetrics32` instead of the 16 bit ones.
79

810
[PR #1435](https://github.com/Rust-SDL2/rust-sdl2/pull/1435) **BREAKING CHANGE** Fix some undefined behavior. Breaking changes: `mixer::Chunk`'s fields are now private and callbacks to `TimerSubsystem::add_timer` must now live for `'static`, also allowing some lifetime parameters to be removed.

src/sdl2/gfx/primitives.rs

+1-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use libc::c_void;
55
use libc::{c_char, c_int};
66
use pixels;
77
use render::Canvas;
8-
use std::convert::TryFrom;
98
use std::ffi::CString;
109
use std::ptr;
1110
use surface::Surface;
@@ -36,6 +35,7 @@ impl ToColor for (u8, u8, u8, u8) {
3635
}
3736
}
3837

38+
// for 0xXXXXXXXX
3939
impl ToColor for u32 {
4040
#[inline]
4141
fn as_rgba(&self) -> (u8, u8, u8, u8) {
@@ -49,22 +49,6 @@ impl ToColor for u32 {
4949
}
5050
}
5151

52-
// for 0xXXXXXXXX
53-
impl ToColor for isize {
54-
#[inline]
55-
fn as_rgba(&self) -> (u8, u8, u8, u8) {
56-
let [r, g, b, a] = u32::try_from(*self)
57-
.expect("Can't convert to Color Type")
58-
.to_be_bytes();
59-
(r, g, b, a)
60-
}
61-
62-
#[inline]
63-
fn as_u32(&self) -> u32 {
64-
u32::try_from(*self).expect("Can't convert to Color Type")
65-
}
66-
}
67-
6852
/// For drawing with rust-sdl2 Renderer
6953
pub trait DrawRenderer {
7054
fn pixel<C: ToColor>(&self, x: i16, y: i16, color: C) -> Result<(), String>;

0 commit comments

Comments
 (0)