Permalink
Browse files

Problem: upcoming 2018 edition of Rust

It's changing quite a bit of things and I don't want to be left alone
with a codebase on an aging edition. SIT is too young for that.

Solution: fix the code to make it compilable on both 2015 and 2018
editions, but don't commit to 2018 just yet.
  • Loading branch information...
yrashk committed Nov 5, 2018
1 parent 7d46e38 commit ea9b986017c87241107ea6caf54d1fb5bc16d373

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -2,7 +2,7 @@
use serde_json::{Map, Value};
use record::{RecordOwningContainer, RecordContainerReduction};
use crate::record::{RecordOwningContainer, RecordContainerReduction};
/// Because of SIT's extensible nature, item can
/// be used to represent a wild variety of entities, such
@@ -55,11 +55,11 @@ pub mod repository;
#[cfg(feature = "deprecated-item-api")]
pub mod item;
#[cfg(feature = "deprecated-item-api")]
pub use item::Item;
pub use crate::item::Item;
pub mod record;
pub use record::Record;
pub use repository::{Repository, Error as RepositoryError};
pub use crate::record::Record;
pub use crate::repository::{Repository, Error as RepositoryError};
pub mod reducers;
pub use reducers::Reducer;
pub use crate::reducers::Reducer;
#[cfg(feature = "duktape")]
pub mod duktape;
@@ -1,7 +1,7 @@
//! Record is an immutable collection of files
use std::io::{self, Read};
use hash::{Hasher, HashingAlgorithm};
use crate::hash::{Hasher, HashingAlgorithm};
use std::path::PathBuf;
/// Record's file
@@ -212,7 +212,7 @@ mod ordered_files_tests {
let ordered_files1_ = OrderedFiles::from(i1.clone().into_iter().map(|v| (v, &[][..])));
let ordered_files2 = OrderedFiles::from(i2.clone().into_iter().map(|v| (v, &[][..])));
let ordered_files2_ = OrderedFiles::from(i2.clone().into_iter().map(|v| (v, &[][..])));
let ordered_files = ordered_files1 + ::std::iter::once(ordered_files2);
let ordered_files = ordered_files1 + std::iter::once(ordered_files2);
for i in ordered_files1_.0 {
assert!(ordered_files.0.iter().find(|f| f.name() == i.name()).is_some());
}
@@ -254,7 +254,7 @@ pub(crate) fn split_path<S: AsRef<str>>(s: S, length: usize) -> PathBuf {
/// Record is an immutable collection of files
pub trait Record {
/// Implementation's type for reading files
type Read : ::std::io::Read;
type Read : std::io::Read;
/// Implementation's type for non-encoded hash
type Hash : AsRef<[u8]>;
/// Implementation's type for file names
@@ -302,7 +302,7 @@ pub trait Record {
pub trait RecordContainer {
/// Error type used by the implementation
type Error: ::std::error::Error + ::std::fmt::Debug;
type Error: std::error::Error + std::fmt::Debug;
/// Record type used by the implementation
type Record : super::Record;
/// Type used to list records that can be referenced as a slice of records
@@ -410,7 +410,7 @@ pub trait RecordExt: Record {
let name = name.as_ref().into();
match reader.read_to_end(&mut buf) {
Ok(_) => {
match ::std::str::from_utf8(&buf) {
match std::str::from_utf8(&buf) {
Err(_) => {
let mut typ = JsonMap::new();
typ.insert("type".into(), JsonValue::String("binary".into()));
@@ -438,9 +438,9 @@ pub trait RecordExt: Record {
impl<T> RecordExt for T where T: Record {}
use reducers::Reducer;
use crate::reducers::Reducer;
#[derive(Debug, Error)]
pub enum ReductionError<Err: ::std::error::Error + ::std::fmt::Debug> {
pub enum ReductionError<Err: std::error::Error + std::fmt::Debug> {
ImplementationError(Err)
}
@@ -3,14 +3,15 @@ use std::io::Read;
use super::Reducer;
use serde_json::{Map, Value as JsonValue};
use std::marker::PhantomData;
use ::Record;
use duktape;
use crate::Record;
use crate::duktape;
use std::ptr;
use std::ffi::{CString, CStr, OsStr};
use std::path::{Path, PathBuf};
use std::fs;
use std::io;
use path::HasPath;
use crate::path::HasPath;
use crate::RepositoryError;
#[cfg(feature = "duktape-mmap")]
use memmap;
@@ -32,9 +33,9 @@ impl<T> SourceFiles for T where T: IntoIterator<Item = PathBuf> {
}
}
impl<'a, MI> SourceFiles for &'a ::Repository<MI> where MI: ::repository::ModuleIterator<PathBuf, ::repository::Error> {
impl<'a, MI> SourceFiles for &'a crate::Repository<MI> where MI: crate::repository::ModuleIterator<PathBuf, crate::repository::Error> {
type Iter = ::std::vec::IntoIter<PathBuf>;
type Iter = std::vec::IntoIter<PathBuf>;
fn source_files(self) -> Result<Self::Iter, Error> {
let mut files = vec![];
@@ -69,8 +70,8 @@ unsafe impl<R: Record> Send for DuktapeReducer<R> {}
#[derive(Debug, Error)]
pub enum Error {
IoError(::std::io::Error),
RepositoryError(::repository::Error),
IoError(std::io::Error),
RepositoryError(RepositoryError),
#[error(no_from, non_std)]
ExecutionError {
error: String,
@@ -89,9 +90,9 @@ impl<R: Record> Drop for DuktapeReducer<R> {
}
}
}
unsafe extern "C" fn fatal_handler(_udata: *mut ::std::os::raw::c_void, msg: *const ::std::os::raw::c_char) {
eprintln!("duktape aborted: {}", ::std::ffi::CStr::from_ptr(msg).to_str().unwrap());
::std::process::exit(1);
unsafe extern "C" fn fatal_handler(_udata: *mut std::os::raw::c_void, msg: *const std::os::raw::c_char) {
eprintln!("duktape aborted: {}", std::ffi::CStr::from_ptr(msg).to_str().unwrap());
std::process::exit(1);
}
impl<R: Record> DuktapeReducer<R> {
@@ -317,7 +318,7 @@ impl<R: Record> DuktapeReducer<R> {
duktape::DUK_COMPILE_FUNCTION | duktape::DUK_COMPILE_STRLEN);
if res as u32 == duktape::DUK_EXEC_ERROR {
let err = ::std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(context, -1, ptr::null_mut())).to_str().unwrap();
let err = std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(context, -1, ptr::null_mut())).to_str().unwrap();
return Err(Error::CompileError { file, error: err.into() })
} else {
// clean up safe compilation results
@@ -500,7 +501,7 @@ impl<R: Record + HasPath> Reducer for DuktapeReducer<R> {
// now, check for error
if res as u32 == duktape::DUK_EXEC_ERROR {
let err = ::std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(ctx, -1, ptr::null_mut()));
let err = std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(ctx, -1, ptr::null_mut()));
{
let mut arr = state.entry(String::from("errors")).or_insert(JsonValue::Array(vec![]));
let mut error = Map::new();
@@ -520,7 +521,7 @@ impl<R: Record + HasPath> Reducer for DuktapeReducer<R> {
// restore previous state
duktape::duk_copy(ctx, -2, -1);
} else {
let err = format!("TypeError: invalid return value {}, expected an object", ::std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(ctx, -1, ptr::null_mut())).to_string_lossy());
let err = format!("TypeError: invalid return value {}, expected an object", std::ffi::CStr::from_ptr(duktape::duk_safe_to_lstring(ctx, -1, ptr::null_mut())).to_string_lossy());
{
let mut arr = state.entry(String::from("errors")).or_insert(JsonValue::Array(vec![]));
let mut error = Map::new();
@@ -541,7 +542,7 @@ impl<R: Record + HasPath> Reducer for DuktapeReducer<R> {
duktape::duk_json_encode(ctx, -1);
let json = duktape::duk_get_string(ctx, -1);
let json = ::std::ffi::CStr::from_ptr(json);
let json = std::ffi::CStr::from_ptr(json);
#[cfg(feature = "cesu8")]
let map: Map<String, JsonValue> = match cesu8::from_cesu8(json.to_bytes()) {
Ok(s) => serde_json::from_str(&s),
@@ -562,9 +563,9 @@ impl<R: Record + HasPath> Reducer for DuktapeReducer<R> {
mod tests {
use tempdir::TempDir;
use super::*;
use ::Repository;
use record::{RecordOwningContainer, RecordContainerReduction};
use path::HasPath;
use crate::Repository;
use crate::record::{RecordOwningContainer, RecordContainerReduction};
use crate::path::HasPath;
#[test]
fn undefined_result() {
@@ -742,7 +743,7 @@ mod tests {
fs::create_dir_all(repo.path().join("reducers")).unwrap();
let mut f = fs::File::create(repo.path().join("reducers/reducer.js")).unwrap();
f.write(b"module.exports = 'hello'").unwrap();
let res: Result<DuktapeReducer<::repository::Record>, _> = DuktapeReducer::new(&repo);
let res: Result<DuktapeReducer<crate::repository::Record>, _> = DuktapeReducer::new(&repo);
assert!(res.is_err());
let reducer_file = repo.path().join("reducers/reducer.js");
let err = res.unwrap_err();
@@ -804,7 +805,7 @@ mod tests {
fs::create_dir_all(repo.path().join("reducers")).unwrap();
let mut f = fs::File::create(repo.path().join("reducers/reducer.js")).unwrap();
f.write(b"function(state) { return state }").unwrap();
let res = DuktapeReducer::<::repository::Record>::new(&repo);
let res = DuktapeReducer::<crate::repository::Record>::new(&repo);
assert!(res.is_err());
let reducer_file = repo.path().join("reducers/reducer.js");
let err = res.unwrap_err();
@@ -829,7 +830,7 @@ mod tests {
fs::create_dir_all(repo.path().join("reducers")).unwrap();
let mut f = fs::File::create(repo.path().join("reducers/reducer.js")).unwrap();
f.write(b"module.exports = function(state) { return Object.assign{\"hello\": 1}, state); }").unwrap();
let res = DuktapeReducer::<::repository::Record>::new(&repo);
let res = DuktapeReducer::<crate::repository::Record>::new(&repo);
assert!(res.is_err());
let reducer_file = repo.path().join("reducers/reducer.js");
let err = res.unwrap_err();
@@ -1047,7 +1048,7 @@ mod tests {
let err_str = "Error: module not found: \"index.js\"";
assert_matches!(DuktapeReducer::<::repository::Record>::new(&repo),
assert_matches!(DuktapeReducer::<crate::repository::Record>::new(&repo),
Err(Error::ExecutionError { ref error }) if error == err_str);
}
@@ -1065,7 +1066,7 @@ mod tests {
f.write(b"module.exports = require(\"reducer/index.js\");").unwrap();
let err_str = "Error: module not found: \"reducer/index.js\"";
assert_matches!(DuktapeReducer::<::repository::Record>::new(&repo),
assert_matches!(DuktapeReducer::<crate::repository::Record>::new(&repo),
Err(Error::ExecutionError { ref error }) if error == err_str);
}
@@ -1088,7 +1089,7 @@ mod tests {
let err_str = "TypeError: cannot resolve module id: ../reducer.js";
assert_matches!(DuktapeReducer::<::repository::Record>::new(&repo),
assert_matches!(DuktapeReducer::<crate::repository::Record>::new(&repo),
Err(Error::ExecutionError { ref error }) if error == err_str);
}
@@ -1106,7 +1107,7 @@ mod tests {
let err_str = "TypeError: cannot resolve module id: /reducer.js";
assert_matches!(DuktapeReducer::<::repository::Record>::new(&repo),
assert_matches!(DuktapeReducer::<crate::repository::Record>::new(&repo),
Err(Error::ExecutionError { ref error }) if error == err_str);
}
@@ -1146,7 +1147,7 @@ mod tests {
f.write(b"module.exports = function(state, record) { return {\"hello\": record.hash}; }").unwrap();
repo.new_record(vec![(".type/SummaryChanged", &b""[..]), ("text", &b"Title"[..])].into_iter(), true).unwrap();
let result: Result<DuktapeReducer<::repository::Record>, _> = DuktapeReducer::new(&repo);
let result: Result<DuktapeReducer<crate::repository::Record>, _> = DuktapeReducer::new(&repo);
assert!(result.is_err());
let err = result.unwrap_err();
let err_str = "Error: module not found: \"reducer/index.js\"";
Oops, something went wrong.

0 comments on commit ea9b986

Please sign in to comment.