Skip to content

Commit 4a3ad46

Browse files
committed
Add version check for compound assignment operator traits
Fixes #71 Compound operator traits are made stable in Rust 1.8, hence the version check is required
1 parent c6846d6 commit 4a3ad46

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ lazy_static = "0.2.1"
1919

2020
[build-dependencies]
2121
rustc-serialize = "0.3.16"
22+
rustc_version = "0.1.7"
2223

2324
[lib]
2425
name = "arrayfire"

build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* -- Lots of reuse from: https://github.com/alexcrichton/git2-rs/blob/master/libgit2-sys/build.rs */
22
extern crate rustc_serialize;
3+
extern crate rustc_version;
34

45
use std::env;
56
use std::fs;
@@ -450,4 +451,8 @@ fn main() {
450451
for backend_dir in backend_dirs.iter() {
451452
println!("cargo:rustc-link-search=native={}", backend_dir);
452453
}
454+
// Directly check a semver version requirment
455+
if rustc_version::version_matches(">= 1.8.0") {
456+
println!("cargo:rustc-cfg=op_assign");
457+
}
453458
}

examples/unified.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,32 @@ extern crate arrayfire as af;
22

33
use af::*;
44

5+
#[cfg(op_assign)]
6+
fn helper(dims: Dim4) {
7+
let mut a = randu::<f32>(dims);
8+
let b = randu::<f32>(dims);
9+
print(&a);
10+
print(&b);
11+
a += b;
12+
print(&a);
13+
}
14+
15+
#[cfg(not(op_assign))]
16+
fn helper(dims: Dim4) {
17+
let b = randu::<f32>(dims);
18+
print(&b);
19+
}
20+
521
#[allow(unused_must_use)]
622
fn test_backend(){
723
info();
824

25+
println!("Create a 10-by-10 matrix of random floats on the compute device");
926
let num_rows: u64 = 10;
1027
let num_cols: u64 = 10;
1128
let dims = Dim4::new(&[num_rows, num_cols, 1, 1]);
1229

13-
println!("Create a 10-by-10 matrix of random floats on the compute device");
14-
let mut a = randu::<f32>(dims);
15-
let b = randu::<f32>(dims);
16-
print(&a);
17-
print(&b);
18-
a += b;
19-
print(&a);
30+
helper(dims)
2031
}
2132

2233

src/arith/mod.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,13 @@ use error::HANDLE_ERROR;
88
use self::libc::{c_int};
99
use data::{constant, tile};
1010
use self::num::Complex;
11-
use index::{Indexer, assign_gen};
12-
use seq::Seq;
13-
use std::mem;
1411

1512
type MutAfArray = *mut self::libc::c_longlong;
1613
type MutDouble = *mut self::libc::c_double;
1714
type MutUint = *mut self::libc::c_uint;
1815
type AfArray = self::libc::c_longlong;
1916

2017
use std::ops::{Add, Sub, Div, Mul, BitAnd, BitOr, BitXor, Not, Rem, Shl, Shr};
21-
use std::ops::{AddAssign, SubAssign, DivAssign, MulAssign, BitAndAssign, BitOrAssign, BitXorAssign,
22-
RemAssign, ShlAssign, ShrAssign};
2318

2419
#[allow(dead_code)]
2520
extern {
@@ -343,6 +338,18 @@ arith_func!(BitXor, bitxor, af_bitxor);
343338
arith_func!(Shl, shl, af_bitshiftl);
344339
arith_func!(Shr, shr, af_bitshiftr);
345340

341+
#[cfg(op_assign)]
342+
mod op_assign {
343+
344+
use array::Array;
345+
use super::*;
346+
use index::{Indexer, assign_gen};
347+
use seq::Seq;
348+
use std::mem;
349+
use std::ops::{AddAssign, SubAssign, DivAssign, MulAssign, RemAssign};
350+
use std::ops::{BitAndAssign, BitOrAssign, BitXorAssign, ShlAssign, ShrAssign};
351+
352+
346353
macro_rules! arith_assign_func {
347354
($op_name:ident, $fn_name:ident, $func: ident) => (
348355
impl $op_name<Array> for Array {
@@ -387,3 +394,5 @@ macro_rules! bit_assign_func {
387394
bit_assign_func!(BitAndAssign, bitand_assign, bitand);
388395
bit_assign_func!(BitOrAssign, bitor_assign, bitor);
389396
bit_assign_func!(BitXorAssign, bitxor_assign, bitxor);
397+
398+
}

0 commit comments

Comments
 (0)