From 45e6b5d65609d8cfe408c1853bb8b87df0f51e1f Mon Sep 17 00:00:00 2001 From: Jim Turner Date: Fri, 3 Nov 2017 17:25:48 -0400 Subject: [PATCH] Fix trait bound on arr1 (op) &arr2 The implementation of `arr1 (op) &arr2` mutates `arr1` for efficiency, but this caused surprising behavior if `arr1` was `ArrayViewMut`. This commit requires that `arr` own its data to avoid surprising side effects. This is an example of the old behavior that was surprising: ```rust extern crate ndarray; fn main() { let mut a = array![1., 2.]; let b = array![3., 4.]; // Prints a = [1, 2]. println!("a = {}", a); { let a_view_mut = a.view_mut(); // Prints a + b = [4, 6]. println!("a + b = {}", a_view_mut + &b); } // Prints a = [4, 6]; would expect a = [1, 2]. println!("a = {}", a); } ``` Note that while this is a breaking change, the stricter trait bound is actually the correct bound according to the documentation. --- src/impl_ops.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/impl_ops.rs b/src/impl_ops.rs index c588a892d..362a0e05a 100644 --- a/src/impl_ops.rs +++ b/src/impl_ops.rs @@ -82,7 +82,7 @@ impl $trt> for ArrayBase /// **Panics** if broadcasting isn’t possible. impl<'a, A, S, S2, D, E> $trt<&'a ArrayBase> for ArrayBase where A: Clone + $trt, - S: DataMut, + S: DataOwned + DataMut, S2: Data, D: Dimension, E: Dimension,