From d4768a7e258438301f040a0058ec0929b96846ea Mon Sep 17 00:00:00 2001 From: nsan1129 Date: Mon, 22 Jan 2018 12:14:19 -0800 Subject: [PATCH] Fix incoherent trait impls (incoherent_fundamental_impls). --- ocl/src/standard/buffer.rs | 3 +- ocl/src/standard/event.rs | 186 +++++++++++++++++++++++++------------ 2 files changed, 127 insertions(+), 62 deletions(-) diff --git a/ocl/src/standard/buffer.rs b/ocl/src/standard/buffer.rs index d918b1cec..59228c351 100644 --- a/ocl/src/standard/buffer.rs +++ b/ocl/src/standard/buffer.rs @@ -2319,7 +2319,8 @@ impl<'a, T> BufferBuilder<'a, T> where T: 'a + OclPrm { match self.queue_option { Some(qc) => { let len = match self.len { - 0 => panic!("ocl::BufferBuilder::build: The length must be set with '.len(...)'."), + 0 => panic!("ocl::BufferBuilder::build: The length must be set with \ + '.len(...)' and cannot be zero."), l @ _ => l, }; diff --git a/ocl/src/standard/event.rs b/ocl/src/standard/event.rs index 0b9009097..952e6d390 100644 --- a/ocl/src/standard/event.rs +++ b/ocl/src/standard/event.rs @@ -507,17 +507,28 @@ impl EventArray { } } -impl<'a, E> From for EventArray where E: Into { - fn from(event: E) -> EventArray { - let mut array = empty_event_array(); - array[0] = event.into(); - EventArray { - array: array, - len: 1, +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_into_event_array( + ($e:ty) => ( + impl<'a> From<$e> for EventArray { + fn from(event: $e) -> EventArray { + let mut array = empty_event_array(); + array[0] = event.into(); + + EventArray { + array: array, + len: 1, + } + } } - } -} + ) +); +from_event_into_event_array!(EventCore); +from_event_into_event_array!(Event); + impl<'a, E> From<&'a E> for EventArray where E: Into + Clone { #[inline] @@ -850,12 +861,21 @@ impl EventList { } } -impl<'a, E> From for EventList where E: Into { - #[inline] - fn from(event: E) -> EventList { - EventList { inner: Inner::Array(EventArray::from(event)) } - } -} +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_into_event_list( + ($e:ty) => ( + impl<'a> From<$e> for EventList { + #[inline] + fn from(event: $e) -> EventList { + EventList { inner: Inner::Array(EventArray::from(event)) } + } + } + ) +); +from_event_into_event_list!(EventCore); +from_event_into_event_list!(Event); impl<'a, E> From<&'a E> for EventList where E: Into + Clone { #[inline] @@ -871,13 +891,22 @@ impl<'a> From> for EventList { } } -impl<'a, E> From<&'a Option> for EventList where E: Into + Clone { - fn from(event: &Option) -> EventList { - let mut el = EventList::new(); - if let Some(ref e) = *event { el.push(e.clone().into()) } - el - } -} +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_option_ref_into_event_list( + ($e:ty) => ( + impl<'a> From<&'a Option<$e>> for EventList { + fn from(event: &Option<$e>) -> EventList { + let mut el = EventList::new(); + if let Some(ref e) = *event { el.push::(e.clone().into()) } + el + } + } + ) +); +from_event_option_ref_into_event_list!(EventCore); +from_event_option_ref_into_event_list!(Event); impl<'a, 'b, E> From> for EventList where 'b: 'a, E: Into + Clone { fn from(event: Option<&E>) -> EventList { @@ -905,21 +934,28 @@ impl<'a, E> From<&'a [E]> for EventList where E: Into + Clone { } } -impl<'a, E> From<&'a [Option]> for EventList where E: Into + Clone { - fn from(events: &[Option]) -> EventList { - let mut el = EventList::with_capacity(events.len()); - - for event in events { - if let Some(ref e) = *event { el.push(e.clone().into()) } +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_option_into_event_list( + ($e:ty) => ( + impl<'a> From<&'a [Option<$e>]> for EventList { + fn from(events: &[Option<$e>]) -> EventList { + let mut el = EventList::with_capacity(events.len()); + for event in events { + if let Some(ref e) = *event { el.push::(e.clone().into()) } + } + el + } } - el - } -} + ) +); +from_event_option_into_event_list!(EventCore); +from_event_option_into_event_list!(Event); impl<'a, 'b, E> From<&'a [Option<&'b E>]> for EventList where 'b: 'a, E: Into + Clone { fn from(events: &[Option<&E>]) -> EventList { let mut el = EventList::with_capacity(events.len()); - for event in events { if let Some(e) = *event { el.push(e.clone().into()) } } @@ -927,16 +963,24 @@ impl<'a, 'b, E> From<&'a [Option<&'b E>]> for EventList where 'b: 'a, E: Into From<&'a [&'b Option]> for EventList where 'b: 'a, E: Into + Clone { - fn from(events: &[&Option]) -> EventList { - let mut el = EventList::with_capacity(events.len()); - - for event in events { - if let Some(ref e) = **event { el.push(e.clone().into()) } +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_option_slice_into_event_list( + ($e:ty) => ( + impl<'a, 'b> From<&'a [&'b Option<$e>]> for EventList where 'b: 'a { + fn from(events: &[&Option<$e>]) -> EventList { + let mut el = EventList::with_capacity(events.len()); + for event in events { + if let Some(ref e) = **event { el.push::(e.clone().into()) } + } + el + } } - el - } -} + ) +); +from_event_option_slice_into_event_list!(EventCore); +from_event_option_slice_into_event_list!(Event); impl<'a, 'b, 'c, E> From<&'a [&'b Option<&'c E>]> for EventList where 'c: 'b, 'b: 'a, E: Into + Clone @@ -951,59 +995,79 @@ impl<'a, 'b, 'c, E> From<&'a [&'b Option<&'c E>]> for EventList } } -macro_rules! impl_event_list_from_arrays { - ($( $len:expr ),*) => ($( - impl<'e, E> From<[E; $len]> for EventList where E: Into { - fn from(events: [E; $len]) -> EventList { +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_option_array_into_event_list( + ($e:ty, $len:expr) => ( + impl<'e> From<[Option<$e>; $len]> for EventList { + fn from(events: [Option<$e>; $len]) -> EventList { let mut el = EventList::with_capacity(events.len()); for idx in 0..events.len() { - let event = unsafe { ptr::read(events.get_unchecked(idx)) }; - el.push(event.into()); + let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) }; + if let Some(event) = event_opt { el.push::(event.into()); } } - // Ownership has been unsafely transfered to the new event - // list without modifying the event reference count. Not - // forgetting the source array would cause a double drop. mem::forget(events); el } } - - impl<'e, E> From<[Option; $len]> for EventList where E: Into { - fn from(events: [Option; $len]) -> EventList { + ) +); + +// Due to a fix to coherence rules +// (https://github.com/rust-lang/rust/pull/46192) we must manually implement +// this for each event type. +macro_rules! from_event_option_ref_array_into_event_list( + ($e:ty, $len:expr) => ( + impl<'e, 'f> From<[&'f Option<$e>; $len]> for EventList where 'e: 'f { + fn from(events: [&'f Option<$e>; $len]) -> EventList { let mut el = EventList::with_capacity(events.len()); for idx in 0..events.len() { let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) }; - if let Some(event) = event_opt { el.push(event.into()); } + if let Some(ref event) = *event_opt { el.push::(event.clone().into()); } } mem::forget(events); el } } + ) +); - impl<'e, E> From<[Option<&'e E>; $len]> for EventList where E: Into + Clone { - fn from(events: [Option<&E>; $len]) -> EventList { +macro_rules! impl_event_list_from_arrays { + ($( $len:expr ),*) => ($( + impl<'e, E> From<[E; $len]> for EventList where E: Into { + fn from(events: [E; $len]) -> EventList { let mut el = EventList::with_capacity(events.len()); for idx in 0..events.len() { - let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) }; - if let Some(event) = event_opt { el.push(event.clone().into()); } + let event = unsafe { ptr::read(events.get_unchecked(idx)) }; + el.push(event.into()); } + // Ownership has been unsafely transfered to the new event + // list without modifying the event reference count. Not + // forgetting the source array would cause a double drop. mem::forget(events); el } } - impl<'e, 'f, E> From<[&'f Option; $len]> for EventList where 'e: 'f, E: Into + Clone { - fn from(events: [&'f Option; $len]) -> EventList { + from_event_option_array_into_event_list!(EventCore, $len); + from_event_option_array_into_event_list!(Event, $len); + + impl<'e, E> From<[Option<&'e E>; $len]> for EventList where E: Into + Clone { + fn from(events: [Option<&E>; $len]) -> EventList { let mut el = EventList::with_capacity(events.len()); for idx in 0..events.len() { let event_opt = unsafe { ptr::read(events.get_unchecked(idx)) }; - if let Some(ref event) = *event_opt { el.push(event.clone().into()); } + if let Some(event) = event_opt { el.push(event.clone().into()); } } mem::forget(events); el } } + from_event_option_ref_array_into_event_list!(EventCore, $len); + from_event_option_ref_array_into_event_list!(Event, $len); + impl<'e, 'f, E> From<[&'f Option<&'e E>; $len]> for EventList where 'e: 'f, E: Into + Clone { fn from(events: [&'f Option<&'e E>; $len]) -> EventList { let mut el = EventList::with_capacity(events.len());