Skip to content

Commit 27c84a5

Browse files
authored
Merge pull request #567 from jturner314/rust-2018
Update ndarray to Rust 2018 edition
2 parents 5d2f7f6 + eacc789 commit 27c84a5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+217
-221
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ sudo: required
44
dist: trusty
55
matrix:
66
include:
7-
- rust: 1.30.0
7+
- rust: 1.31.0
88
env:
99
- FEATURES='test docs'
1010
- rust: stable

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
name = "ndarray"
44
version = "0.12.1"
5+
edition = "2018"
56
authors = [
67
"bluss",
78
"Jim Turner"

src/aliases.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
//!
33
44
#[allow(deprecated)]
5-
use ::{
5+
use crate::{
66
Ix,
77
Array,
88
ArrayView,
99
ArrayViewMut,
1010
RcArray,
1111
IxDynImpl,
1212
};
13-
use ::dimension::Dim;
13+
use crate::dimension::Dim;
1414

1515
/// Create a zero-dimensional index
1616
#[allow(non_snake_case)]

src/array_serde.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use serde::ser::{SerializeSeq, SerializeStruct};
1212
use std::fmt;
1313
use std::marker::PhantomData;
1414

15-
use imp_prelude::*;
15+
use crate::imp_prelude::*;
1616

1717
use super::arraytraits::ARRAY_FORMAT_VERSION;
1818
use super::Iter;
19-
use IntoDimension;
19+
use crate::IntoDimension;
2020

2121
/// Verifies that the version of the deserialized array matches the current
2222
/// `ARRAY_FORMAT_VERSION`.
@@ -25,10 +25,10 @@ pub fn verify_version<E>(v: u8) -> Result<(), E>
2525
{
2626
if v != ARRAY_FORMAT_VERSION {
2727
let err_msg = format!("unknown array version: {}", v);
28-
try!(Err(de::Error::custom(err_msg)));
28+
Err(de::Error::custom(err_msg))
29+
} else {
30+
Ok(())
2931
}
30-
31-
Ok(())
3232
}
3333

3434
/// **Requires crate feature `"serde-1"`**
@@ -84,10 +84,10 @@ impl<A, D, S> Serialize for ArrayBase<S, D>
8484
fn serialize<Se>(&self, serializer: Se) -> Result<Se::Ok, Se::Error>
8585
where Se: Serializer
8686
{
87-
let mut state = try!(serializer.serialize_struct("Array", 3));
88-
try!(state.serialize_field("v", &ARRAY_FORMAT_VERSION));
89-
try!(state.serialize_field("dim", &self.raw_dim()));
90-
try!(state.serialize_field("data", &Sequence(self.iter())));
87+
let mut state = serializer.serialize_struct("Array", 3)?;
88+
state.serialize_field("v", &ARRAY_FORMAT_VERSION)?;
89+
state.serialize_field("dim", &self.raw_dim())?;
90+
state.serialize_field("data", &Sequence(self.iter()))?;
9191
state.end()
9292
}
9393
}
@@ -103,9 +103,9 @@ impl<'a, A, D> Serialize for Sequence<'a, A, D>
103103
where S: Serializer
104104
{
105105
let iter = &self.0;
106-
let mut seq = try!(serializer.serialize_seq(Some(iter.len())));
106+
let mut seq = serializer.serialize_seq(Some(iter.len()))?;
107107
for elt in iter.clone() {
108-
try!(seq.serialize_element(elt));
108+
seq.serialize_element(elt)?;
109109
}
110110
seq.end()
111111
}
@@ -197,23 +197,23 @@ impl<'de, A, Di, S> Visitor<'de> for ArrayVisitor<S,Di>
197197
fn visit_seq<V>(self, mut visitor: V) -> Result<ArrayBase<S, Di>, V::Error>
198198
where V: SeqAccess<'de>,
199199
{
200-
let v: u8 = match try!(visitor.next_element()) {
200+
let v: u8 = match visitor.next_element()? {
201201
Some(value) => value,
202202
None => {
203203
return Err(de::Error::invalid_length(0, &self));
204204
}
205205
};
206206

207-
try!(verify_version(v));
207+
verify_version(v)?;
208208

209-
let dim: Di = match try!(visitor.next_element()) {
209+
let dim: Di = match visitor.next_element()? {
210210
Some(value) => value,
211211
None => {
212212
return Err(de::Error::invalid_length(1, &self));
213213
}
214214
};
215215

216-
let data: Vec<A> = match try!(visitor.next_element()) {
216+
let data: Vec<A> = match visitor.next_element()? {
217217
Some(value) => value,
218218
None => {
219219
return Err(de::Error::invalid_length(2, &self));
@@ -234,35 +234,35 @@ impl<'de, A, Di, S> Visitor<'de> for ArrayVisitor<S,Di>
234234
let mut data: Option<Vec<A>> = None;
235235
let mut dim: Option<Di> = None;
236236

237-
while let Some(key) = try!(visitor.next_key()) {
237+
while let Some(key) = visitor.next_key()? {
238238
match key {
239239
ArrayField::Version => {
240-
let val = try!(visitor.next_value());
241-
try!(verify_version(val));
240+
let val = visitor.next_value()?;
241+
verify_version(val)?;
242242
v = Some(val);
243243
},
244244
ArrayField::Data => {
245-
data = Some(try!(visitor.next_value()));
245+
data = Some(visitor.next_value()?);
246246
},
247247
ArrayField::Dim => {
248-
dim = Some(try!(visitor.next_value()));
248+
dim = Some(visitor.next_value()?);
249249
},
250250
}
251251
}
252252

253253
let _v = match v {
254254
Some(v) => v,
255-
None => try!(Err(de::Error::missing_field("v"))),
255+
None => Err(de::Error::missing_field("v"))?,
256256
};
257257

258258
let data = match data {
259259
Some(data) => data,
260-
None => try!(Err(de::Error::missing_field("data"))),
260+
None => Err(de::Error::missing_field("data"))?,
261261
};
262262

263263
let dim = match dim {
264264
Some(dim) => dim,
265-
None => try!(Err(de::Error::missing_field("dim"))),
265+
None => Err(de::Error::missing_field("dim"))?,
266266
};
267267

268268
if let Ok(array) = ArrayBase::from_shape_vec(dim, data) {

src/arrayformat.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use super::{
1212
Dimension,
1313
NdProducer,
1414
};
15-
use dimension::IntoDimension;
15+
use crate::dimension::IntoDimension;
1616

1717
fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
1818
mut format: F)
@@ -33,7 +33,7 @@ fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
3333
Some(ix) => ix,
3434
};
3535
for _ in 0..ndim {
36-
try!(write!(f, "["));
36+
write!(f, "[")?;
3737
}
3838
let mut first = true;
3939
// Simply use the indexed iterator, and take the index wraparounds
@@ -52,33 +52,33 @@ fn format_array<A, S, D, F>(view: &ArrayBase<S, D>, f: &mut fmt::Formatter,
5252
// # of ['s needed
5353
let n = ndim - i - 1;
5454
for _ in 0..n {
55-
try!(write!(f, "]"));
55+
write!(f, "]")?;
5656
}
57-
try!(write!(f, ","));
58-
try!(write!(f, "\n"));
57+
write!(f, ",")?;
58+
write!(f, "\n")?;
5959
for _ in 0..ndim - n {
60-
try!(write!(f, " "));
60+
write!(f, " ")?;
6161
}
6262
for _ in 0..n {
63-
try!(write!(f, "["));
63+
write!(f, "[")?;
6464
}
6565
first = true;
6666
update_index = true;
6767
break;
6868
}
6969
}
7070
if !first {
71-
try!(write!(f, ", "));
71+
write!(f, ", ")?;
7272
}
7373
first = false;
74-
try!(format(elt, f));
74+
format(elt, f)?;
7575

7676
if update_index {
7777
last_index = index;
7878
}
7979
}
8080
for _ in 0..ndim {
81-
try!(write!(f, "]"));
81+
write!(f, "]")?;
8282
}
8383
Ok(())
8484
}

src/arraytraits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ use std::ops::{
1515
IndexMut,
1616
};
1717

18-
use imp_prelude::*;
19-
use iter::{
18+
use crate::imp_prelude::*;
19+
use crate::iter::{
2020
Iter,
2121
IterMut,
2222
};
23-
use {
23+
use crate::{
2424
NdIndex,
2525
};
2626

27-
use numeric_util;
28-
use {Zip, FoldWhile};
27+
use crate::numeric_util;
28+
use crate::{Zip, FoldWhile};
2929

3030
#[cold]
3131
#[inline(never)]

src/data_traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::mem::{self, size_of};
1212
use std::sync::Arc;
1313

14-
use {
14+
use crate::{
1515
ArrayBase,
1616
Dimension,
1717
RawViewRepr,
@@ -52,7 +52,7 @@ pub unsafe trait RawDataMut : RawData {
5252
/// If `Self` provides safe mutable access to array elements, then it
5353
/// **must** panic or ensure that the data is unique.
5454
#[doc(hidden)]
55-
fn try_ensure_unique<D>(&mut ArrayBase<Self, D>)
55+
fn try_ensure_unique<D>(_: &mut ArrayBase<Self, D>)
5656
where Self: Sized,
5757
D: Dimension;
5858

src/dimension/axes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
use {Dimension, Axis, Ix, Ixs};
2+
use crate::{Dimension, Axis, Ix, Ixs};
33

44
/// Create a new Axes iterator
55
pub fn axes_of<'a, D>(d: &'a D, strides: &'a D) -> Axes<'a, D>

src/dimension/conversion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
//! Tuple to array conversion, IntoDimension, and related things
1010
1111
use std::ops::{Index, IndexMut};
12-
use libnum::Zero;
12+
use num_traits::Zero;
1313

14-
use {Ix, Ix1, IxDyn, Dimension, Dim, IxDynImpl};
14+
use crate::{Ix, Ix1, IxDyn, Dimension, Dim, IxDynImpl};
1515

1616
/// $m: macro callback
1717
/// $m is called with $arg and then the indices corresponding to the size argument

src/dimension/dim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use itertools::zip;
1212

1313
use super::IntoDimension;
1414
use super::Dimension;
15-
use Ix;
15+
use crate::Ix;
1616

1717
/// Dimension description.
1818
///

src/dimension/dimension_trait.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use std::ops::{Add, Sub, Mul, AddAssign, SubAssign, MulAssign};
1313

1414
use itertools::{enumerate, izip, zip};
1515

16-
use {Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, SliceOrIndex, IxDynImpl};
17-
use IntoDimension;
18-
use RemoveAxis;
19-
use {ArrayView1, ArrayViewMut1};
20-
use Axis;
16+
use crate::{Ix, Ixs, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, SliceOrIndex, IxDynImpl};
17+
use crate::IntoDimension;
18+
use crate::RemoveAxis;
19+
use crate::{ArrayView1, ArrayViewMut1};
20+
use crate::Axis;
2121
use super::{
2222
stride_offset,
2323
stride_offset_checked,

src/dimension/dynindeximpl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{
55
Deref,
66
DerefMut,
77
};
8-
use imp_prelude::*;
8+
use crate::imp_prelude::*;
99

1010
const CAP: usize = 4;
1111

@@ -53,7 +53,7 @@ impl Default for IxDynRepr<Ix> {
5353
}
5454

5555

56-
use ::libnum::Zero;
56+
use num_traits::Zero;
5757

5858
impl<T: Copy + Zero> IxDynRepr<T> {
5959
pub fn copy_from(x: &[T]) -> Self {

src/dimension/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
// option. This file may not be copied, modified, or distributed
77
// except according to those terms.
88

9-
use {Ix, Ixs, Slice, SliceOrIndex};
10-
use error::{from_kind, ErrorKind, ShapeError};
9+
use crate::{Ix, Ixs, Slice, SliceOrIndex};
10+
use crate::error::{from_kind, ErrorKind, ShapeError};
1111
use itertools::izip;
1212
use num_integer::div_floor;
1313

@@ -621,11 +621,11 @@ mod test {
621621
max_abs_offset_check_overflow, slice_min_max, slices_intersect,
622622
solve_linear_diophantine_eq, IntoDimension
623623
};
624-
use error::{from_kind, ErrorKind};
624+
use crate::{Dim, Dimension, Ix0, Ix1, Ix2, Ix3, IxDyn};
625+
use crate::error::{from_kind, ErrorKind};
626+
use crate::slice::Slice;
625627
use num_integer::gcd;
626628
use quickcheck::{quickcheck, TestResult};
627-
use slice::{Slice, SliceOrIndex};
628-
use {Dim, Dimension, Ix0, Ix1, Ix2, Ix3, IxDyn};
629629

630630
#[test]
631631
fn slice_indexing_uncommon_strides() {

src/dimension/ndindex.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ use std::fmt::Debug;
33

44
use itertools::zip;
55

6-
use {Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, Dim, Dimension, IntoDimension};
7-
use {
8-
IxDynImpl,
9-
};
6+
use crate::{Ix, Ix0, Ix1, Ix2, Ix3, Ix4, Ix5, Ix6, IxDyn, IxDynImpl, Dim, Dimension, IntoDimension};
107
use super::{stride_offset, stride_offset_checked};
118

129
/// Tuple or fixed size arrays that can be used to index an array.

src/dimension/remove_axis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// except according to those terms.
88

99

10-
use {Ix, Ix0, Ix1, Dimension, Dim, Axis};
10+
use crate::{Ix, Ix0, Ix1, Dimension, Dim, Axis};
1111

1212
/// Array shape with a next smaller dimension.
1313
///

src/free_functions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use std::slice;
1010
use std::mem::{size_of, forget};
1111

12-
use dimension;
13-
use imp_prelude::*;
12+
use crate::dimension;
13+
use crate::imp_prelude::*;
1414

1515
/// Create an [**`Array`**](type.Array.html) with one, two or
1616
/// three dimensions.

0 commit comments

Comments
 (0)