Skip to content

Commit d4768a7

Browse files
committed
Fix incoherent trait impls (incoherent_fundamental_impls).
1 parent c5a1eed commit d4768a7

File tree

2 files changed

+127
-62
lines changed

2 files changed

+127
-62
lines changed

ocl/src/standard/buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,8 @@ impl<'a, T> BufferBuilder<'a, T> where T: 'a + OclPrm {
23192319
match self.queue_option {
23202320
Some(qc) => {
23212321
let len = match self.len {
2322-
0 => panic!("ocl::BufferBuilder::build: The length must be set with '.len(...)'."),
2322+
0 => panic!("ocl::BufferBuilder::build: The length must be set with \
2323+
'.len(...)' and cannot be zero."),
23232324
l @ _ => l,
23242325
};
23252326

ocl/src/standard/event.rs

Lines changed: 125 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,28 @@ impl EventArray {
507507
}
508508
}
509509

510-
impl<'a, E> From<E> for EventArray where E: Into<Event> {
511-
fn from(event: E) -> EventArray {
512-
let mut array = empty_event_array();
513-
array[0] = event.into();
514510

515-
EventArray {
516-
array: array,
517-
len: 1,
511+
// Due to a fix to coherence rules
512+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
513+
// this for each event type.
514+
macro_rules! from_event_into_event_array(
515+
($e:ty) => (
516+
impl<'a> From<$e> for EventArray {
517+
fn from(event: $e) -> EventArray {
518+
let mut array = empty_event_array();
519+
array[0] = event.into();
520+
521+
EventArray {
522+
array: array,
523+
len: 1,
524+
}
525+
}
518526
}
519-
}
520-
}
527+
)
528+
);
529+
from_event_into_event_array!(EventCore);
530+
from_event_into_event_array!(Event);
531+
521532

522533
impl<'a, E> From<&'a E> for EventArray where E: Into<Event> + Clone {
523534
#[inline]
@@ -850,12 +861,21 @@ impl EventList {
850861
}
851862
}
852863

853-
impl<'a, E> From<E> for EventList where E: Into<Event> {
854-
#[inline]
855-
fn from(event: E) -> EventList {
856-
EventList { inner: Inner::Array(EventArray::from(event)) }
857-
}
858-
}
864+
// Due to a fix to coherence rules
865+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
866+
// this for each event type.
867+
macro_rules! from_event_into_event_list(
868+
($e:ty) => (
869+
impl<'a> From<$e> for EventList {
870+
#[inline]
871+
fn from(event: $e) -> EventList {
872+
EventList { inner: Inner::Array(EventArray::from(event)) }
873+
}
874+
}
875+
)
876+
);
877+
from_event_into_event_list!(EventCore);
878+
from_event_into_event_list!(Event);
859879

860880
impl<'a, E> From<&'a E> for EventList where E: Into<Event> + Clone {
861881
#[inline]
@@ -871,13 +891,22 @@ impl<'a> From<Vec<Event>> for EventList {
871891
}
872892
}
873893

874-
impl<'a, E> From<&'a Option<E>> for EventList where E: Into<Event> + Clone {
875-
fn from(event: &Option<E>) -> EventList {
876-
let mut el = EventList::new();
877-
if let Some(ref e) = *event { el.push(e.clone().into()) }
878-
el
879-
}
880-
}
894+
// Due to a fix to coherence rules
895+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
896+
// this for each event type.
897+
macro_rules! from_event_option_ref_into_event_list(
898+
($e:ty) => (
899+
impl<'a> From<&'a Option<$e>> for EventList {
900+
fn from(event: &Option<$e>) -> EventList {
901+
let mut el = EventList::new();
902+
if let Some(ref e) = *event { el.push::<Event>(e.clone().into()) }
903+
el
904+
}
905+
}
906+
)
907+
);
908+
from_event_option_ref_into_event_list!(EventCore);
909+
from_event_option_ref_into_event_list!(Event);
881910

882911
impl<'a, 'b, E> From<Option<&'b E>> for EventList where 'b: 'a, E: Into<Event> + Clone {
883912
fn from(event: Option<&E>) -> EventList {
@@ -905,38 +934,53 @@ impl<'a, E> From<&'a [E]> for EventList where E: Into<Event> + Clone {
905934
}
906935
}
907936

908-
impl<'a, E> From<&'a [Option<E>]> for EventList where E: Into<Event> + Clone {
909-
fn from(events: &[Option<E>]) -> EventList {
910-
let mut el = EventList::with_capacity(events.len());
911-
912-
for event in events {
913-
if let Some(ref e) = *event { el.push(e.clone().into()) }
937+
// Due to a fix to coherence rules
938+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
939+
// this for each event type.
940+
macro_rules! from_event_option_into_event_list(
941+
($e:ty) => (
942+
impl<'a> From<&'a [Option<$e>]> for EventList {
943+
fn from(events: &[Option<$e>]) -> EventList {
944+
let mut el = EventList::with_capacity(events.len());
945+
for event in events {
946+
if let Some(ref e) = *event { el.push::<Event>(e.clone().into()) }
947+
}
948+
el
949+
}
914950
}
915-
el
916-
}
917-
}
951+
)
952+
);
953+
from_event_option_into_event_list!(EventCore);
954+
from_event_option_into_event_list!(Event);
918955

919956
impl<'a, 'b, E> From<&'a [Option<&'b E>]> for EventList where 'b: 'a, E: Into<Event> + Clone {
920957
fn from(events: &[Option<&E>]) -> EventList {
921958
let mut el = EventList::with_capacity(events.len());
922-
923959
for event in events {
924960
if let Some(e) = *event { el.push(e.clone().into()) }
925961
}
926962
el
927963
}
928964
}
929965

930-
impl<'a, 'b, E> From<&'a [&'b Option<E>]> for EventList where 'b: 'a, E: Into<Event> + Clone {
931-
fn from(events: &[&Option<E>]) -> EventList {
932-
let mut el = EventList::with_capacity(events.len());
933-
934-
for event in events {
935-
if let Some(ref e) = **event { el.push(e.clone().into()) }
966+
// Due to a fix to coherence rules
967+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
968+
// this for each event type.
969+
macro_rules! from_event_option_slice_into_event_list(
970+
($e:ty) => (
971+
impl<'a, 'b> From<&'a [&'b Option<$e>]> for EventList where 'b: 'a {
972+
fn from(events: &[&Option<$e>]) -> EventList {
973+
let mut el = EventList::with_capacity(events.len());
974+
for event in events {
975+
if let Some(ref e) = **event { el.push::<Event>(e.clone().into()) }
976+
}
977+
el
978+
}
936979
}
937-
el
938-
}
939-
}
980+
)
981+
);
982+
from_event_option_slice_into_event_list!(EventCore);
983+
from_event_option_slice_into_event_list!(Event);
940984

941985
impl<'a, 'b, 'c, E> From<&'a [&'b Option<&'c E>]> for EventList
942986
where 'c: 'b, 'b: 'a, E: Into<Event> + Clone
@@ -951,59 +995,79 @@ impl<'a, 'b, 'c, E> From<&'a [&'b Option<&'c E>]> for EventList
951995
}
952996
}
953997

954-
macro_rules! impl_event_list_from_arrays {
955-
($( $len:expr ),*) => ($(
956-
impl<'e, E> From<[E; $len]> for EventList where E: Into<Event> {
957-
fn from(events: [E; $len]) -> EventList {
998+
// Due to a fix to coherence rules
999+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
1000+
// this for each event type.
1001+
macro_rules! from_event_option_array_into_event_list(
1002+
($e:ty, $len:expr) => (
1003+
impl<'e> From<[Option<$e>; $len]> for EventList {
1004+
fn from(events: [Option<$e>; $len]) -> EventList {
9581005
let mut el = EventList::with_capacity(events.len());
9591006
for idx in 0..events.len() {
960-
let event = unsafe { ptr::read(events.get_unchecked(idx)) };
961-
el.push(event.into());
1007+
let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) };
1008+
if let Some(event) = event_opt { el.push::<Event>(event.into()); }
9621009
}
963-
// Ownership has been unsafely transfered to the new event
964-
// list without modifying the event reference count. Not
965-
// forgetting the source array would cause a double drop.
9661010
mem::forget(events);
9671011
el
9681012
}
9691013
}
970-
971-
impl<'e, E> From<[Option<E>; $len]> for EventList where E: Into<Event> {
972-
fn from(events: [Option<E>; $len]) -> EventList {
1014+
)
1015+
);
1016+
1017+
// Due to a fix to coherence rules
1018+
// (https://github.com/rust-lang/rust/pull/46192) we must manually implement
1019+
// this for each event type.
1020+
macro_rules! from_event_option_ref_array_into_event_list(
1021+
($e:ty, $len:expr) => (
1022+
impl<'e, 'f> From<[&'f Option<$e>; $len]> for EventList where 'e: 'f {
1023+
fn from(events: [&'f Option<$e>; $len]) -> EventList {
9731024
let mut el = EventList::with_capacity(events.len());
9741025
for idx in 0..events.len() {
9751026
let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) };
976-
if let Some(event) = event_opt { el.push(event.into()); }
1027+
if let Some(ref event) = *event_opt { el.push::<Event>(event.clone().into()); }
9771028
}
9781029
mem::forget(events);
9791030
el
9801031
}
9811032
}
1033+
)
1034+
);
9821035

983-
impl<'e, E> From<[Option<&'e E>; $len]> for EventList where E: Into<Event> + Clone {
984-
fn from(events: [Option<&E>; $len]) -> EventList {
1036+
macro_rules! impl_event_list_from_arrays {
1037+
($( $len:expr ),*) => ($(
1038+
impl<'e, E> From<[E; $len]> for EventList where E: Into<Event> {
1039+
fn from(events: [E; $len]) -> EventList {
9851040
let mut el = EventList::with_capacity(events.len());
9861041
for idx in 0..events.len() {
987-
let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) };
988-
if let Some(event) = event_opt { el.push(event.clone().into()); }
1042+
let event = unsafe { ptr::read(events.get_unchecked(idx)) };
1043+
el.push(event.into());
9891044
}
1045+
// Ownership has been unsafely transfered to the new event
1046+
// list without modifying the event reference count. Not
1047+
// forgetting the source array would cause a double drop.
9901048
mem::forget(events);
9911049
el
9921050
}
9931051
}
9941052

995-
impl<'e, 'f, E> From<[&'f Option<E>; $len]> for EventList where 'e: 'f, E: Into<Event> + Clone {
996-
fn from(events: [&'f Option<E>; $len]) -> EventList {
1053+
from_event_option_array_into_event_list!(EventCore, $len);
1054+
from_event_option_array_into_event_list!(Event, $len);
1055+
1056+
impl<'e, E> From<[Option<&'e E>; $len]> for EventList where E: Into<Event> + Clone {
1057+
fn from(events: [Option<&E>; $len]) -> EventList {
9971058
let mut el = EventList::with_capacity(events.len());
9981059
for idx in 0..events.len() {
9991060
let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) };
1000-
if let Some(ref event) = *event_opt { el.push(event.clone().into()); }
1061+
if let Some(event) = event_opt { el.push(event.clone().into()); }
10011062
}
10021063
mem::forget(events);
10031064
el
10041065
}
10051066
}
10061067

1068+
from_event_option_ref_array_into_event_list!(EventCore, $len);
1069+
from_event_option_ref_array_into_event_list!(Event, $len);
1070+
10071071
impl<'e, 'f, E> From<[&'f Option<&'e E>; $len]> for EventList where 'e: 'f, E: Into<Event> + Clone {
10081072
fn from(events: [&'f Option<&'e E>; $len]) -> EventList {
10091073
let mut el = EventList::with_capacity(events.len());

0 commit comments

Comments
 (0)