Skip to content

Commit

Permalink
Fix warnings for deprecated syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
murarth committed Dec 25, 2019
1 parent e4d207e commit 28edb52
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 42 deletions.
8 changes: 4 additions & 4 deletions src/ketos/any.rs
Expand Up @@ -12,7 +12,7 @@ pub struct TraitObject {
// Implements downcast methods for a trait object type
macro_rules! impl_any_cast {
( $ty:ident ) => {
impl $ty {
impl dyn $ty {
/// Returns whether the contained value is of the given type.
pub fn is<T: $ty>(&self) -> bool {
self.type_id() == ::std::any::TypeId::of::<T>()
Expand Down Expand Up @@ -97,7 +97,7 @@ mod test {

#[test]
fn test_downcast() {
let a: Box<SomeTrait> = Box::new(Dummy{a: 0});
let a: Box<dyn SomeTrait> = Box::new(Dummy{a: 0});

let b = SomeTrait::downcast::<Dumber>(a).unwrap_err();
let c = SomeTrait::downcast::<Dummy>(b).unwrap();
Expand All @@ -107,7 +107,7 @@ mod test {

#[test]
fn test_downcast_rc() {
let a: Rc<SomeTrait> = Rc::new(Dummy{a: 0});
let a: Rc<dyn SomeTrait> = Rc::new(Dummy{a: 0});

let b = SomeTrait::downcast_rc::<Dumber>(a).unwrap_err();
let c = SomeTrait::downcast_rc::<Dummy>(b).unwrap();
Expand All @@ -117,7 +117,7 @@ mod test {

#[test]
fn test_downcast_ref() {
let mut a: Box<SomeTrait> = Box::new(Dummy{a: 0});
let mut a: Box<dyn SomeTrait> = Box::new(Dummy{a: 0});

{
let r = a.downcast_mut::<Dummy>().unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/ketos/error.rs
Expand Up @@ -64,7 +64,7 @@ error_type!{
/// Code execution breached configured restrictions
RestrictError(RestrictError),
/// Customized error value implementing `std::error::Error`
Custom(Box<StdError>),
Custom(Box<dyn StdError>),
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/ketos/interpreter.rs
Expand Up @@ -47,7 +47,7 @@ pub struct Builder {
restrict: Option<RestrictConfig>,
io: Option<Rc<GlobalIo>>,
struct_defs: Option<Rc<RefCell<StructDefMap>>>,
module_loader: Option<Box<ModuleLoader>>,
module_loader: Option<Box<dyn ModuleLoader>>,
search_paths: Option<Vec<PathBuf>>,
}

Expand Down Expand Up @@ -135,7 +135,7 @@ impl Builder {
}

/// Sets the module loader in the new scope.
pub fn module_loader(mut self, loader: Box<ModuleLoader>) -> Self {
pub fn module_loader(mut self, loader: Box<dyn ModuleLoader>) -> Self {
exclude!(self.context, "module_loader", "context");
exclude!(self.scope, "module_loader", "scope");
exclude!(self.search_paths, "module_loader", "search_paths");
Expand Down Expand Up @@ -186,7 +186,7 @@ impl Builder {
Rc::new(GlobalScope::new(name, names, codemap, modules, io, defs))
}

fn build_loader(&mut self) -> Box<ModuleLoader> {
fn build_loader(&mut self) -> Box<dyn ModuleLoader> {
match (self.module_loader.take(), self.search_paths.take()) {
(Some(loader), _) => loader,
(None, Some(paths)) =>
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Interpreter {
}

/// Creates a new `Interpreter` using the given `ModuleLoader` instance.
pub fn with_loader(loader: Box<ModuleLoader>) -> Interpreter {
pub fn with_loader(loader: Box<dyn ModuleLoader>) -> Interpreter {
let mut names = NameStore::new();
let name = names.add("main");

Expand Down
6 changes: 3 additions & 3 deletions src/ketos/io.rs
Expand Up @@ -11,16 +11,16 @@ use crate::name::{NameDisplay, NameStore};
/// Contains global shared I/O objects
pub struct GlobalIo {
/// Shared standard output writer
pub stdout: Rc<SharedWrite>,
pub stdout: Rc<dyn SharedWrite>,

/// Shared standard error writer
pub stderr: Rc<SharedWrite>,
pub stderr: Rc<dyn SharedWrite>,
}

impl GlobalIo {
/// Creates a `GlobalIo` instance using the given `stdout` and `stderr`
/// writers.
pub fn new(stdout: Rc<SharedWrite>, stderr: Rc<SharedWrite>) -> GlobalIo {
pub fn new(stdout: Rc<dyn SharedWrite>, stderr: Rc<dyn SharedWrite>) -> GlobalIo {
GlobalIo{ stdout, stderr }
}

Expand Down
2 changes: 1 addition & 1 deletion src/ketos/lexer.rs
Expand Up @@ -262,7 +262,7 @@ impl<'lex> Lexer<'lex> {
Some((_, '@')) => Ok((Token::CommaAt, 2)),
_ => Ok((Token::Comma, 1)),
},
'-' | '0' ... '9' => parse_number(&self.input[ind..]),
'-' | '0' ..= '9' => parse_number(&self.input[ind..]),
'"' => Ok(parse_string(&self.input[ind..], self.code_offset + lo)?),
'#' => match chars.next() {
Some((_, 'b')) => {
Expand Down
4 changes: 2 additions & 2 deletions src/ketos/module.rs
Expand Up @@ -210,14 +210,14 @@ impl ModuleCode {

/// Loads modules into the running program and caches previously loaded modules
pub struct ModuleRegistry {
loader: Box<ModuleLoader>,
loader: Box<dyn ModuleLoader>,
modules: RefCell<NameMap<Module>>,
}

impl ModuleRegistry {
/// Creates a new `ModuleRegistry` using the given `ModuleLoader`
/// to load new modules.
pub fn new(loader: Box<ModuleLoader>) -> ModuleRegistry {
pub fn new(loader: Box<dyn ModuleLoader>) -> ModuleRegistry {
ModuleRegistry{
loader,
modules: RefCell::new(NameMap::new()),
Expand Down
2 changes: 1 addition & 1 deletion src/ketos/name.rs
Expand Up @@ -290,7 +290,7 @@ impl<'a, T: NameDisplay> fmt::Display for NameDisplayer<'a, T> {
}
}

impl NameDisplay for Box<StdError> {
impl NameDisplay for Box<dyn StdError> {
fn fmt(&self, _names: &NameStore, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Display::fmt(self, f)
}
Expand Down
32 changes: 16 additions & 16 deletions src/ketos/string_fmt.rs
Expand Up @@ -1676,29 +1676,29 @@ fn get_roman_digit(n: u32, old: bool) -> Roman {
if old {
match n {
n if n >= 1000 => Roman::One('M', 1000),
500 ... 999 => Roman::One('D', 500),
100 ... 499 => Roman::One('C', 100),
50 ... 99 => Roman::One('L', 50),
10 ... 49 => Roman::One('X', 10),
5 ... 9 => Roman::One('V', 5),
1 ... 4 => Roman::One('I', 1),
500 ..= 999 => Roman::One('D', 500),
100 ..= 499 => Roman::One('C', 100),
50 ..= 99 => Roman::One('L', 50),
10 ..= 49 => Roman::One('X', 10),
5 ..= 9 => Roman::One('V', 5),
1 ..= 4 => Roman::One('I', 1),
_ => panic!("no roman numeral zero")
}
} else {
match n {
n if n >= 1000 => Roman::One( 'M', 1000),
900 ... 999 => Roman::Two('C', 'M', 900),
500 ... 899 => Roman::One( 'D', 500),
400 ... 499 => Roman::Two('C', 'D', 400),
100 ... 399 => Roman::One( 'C', 100),
90 ... 99 => Roman::Two('X', 'C', 90),
50 ... 89 => Roman::One( 'L', 50),
40 ... 49 => Roman::Two('X', 'L', 40),
10 ... 39 => Roman::One( 'X', 10),
900 ..= 999 => Roman::Two('C', 'M', 900),
500 ..= 899 => Roman::One( 'D', 500),
400 ..= 499 => Roman::Two('C', 'D', 400),
100 ..= 399 => Roman::One( 'C', 100),
90 ..= 99 => Roman::Two('X', 'C', 90),
50 ..= 89 => Roman::One( 'L', 50),
40 ..= 49 => Roman::Two('X', 'L', 40),
10 ..= 39 => Roman::One( 'X', 10),
9 => Roman::Two('I', 'X', 9),
5 ... 8 => Roman::One( 'V', 5),
5 ..= 8 => Roman::One( 'V', 5),
4 => Roman::Two('I', 'V', 4),
1 ... 3 => Roman::One( 'I', 1),
1 ..= 3 => Roman::One( 'I', 1),
_ => panic!("no roman numeral zero")
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/ketos/structs.rs
Expand Up @@ -306,7 +306,7 @@ pub struct StructDef {
/// Struct name
name: Name,
/// Implementation of struct definition
def: Box<StructDefinition>,
def: Box<dyn StructDefinition>,
}

impl fmt::Debug for StructDef {
Expand Down Expand Up @@ -334,7 +334,7 @@ fn ptr_eq<T>(a: *const T, b: *const T) -> bool {

impl StructDef {
/// Creates a new `StructDef` with the given name and fields.
pub fn new(name: Name, def: Box<StructDefinition>) -> StructDef {
pub fn new(name: Name, def: Box<dyn StructDefinition>) -> StructDef {
StructDef{ name, def }
}

Expand All @@ -344,7 +344,7 @@ impl StructDef {
}

/// Returns a reference to the `StructDefinition` implementation.
pub fn def(&self) -> &StructDefinition {
pub fn def(&self) -> &dyn StructDefinition {
&*self.def
}
}
10 changes: 5 additions & 5 deletions src/ketos/value.rs
Expand Up @@ -66,7 +66,7 @@ pub enum Value {
/// Compiled bytecode function
Lambda(Lambda),
/// Boxed value of a foreign type
Foreign(Rc<ForeignValue>),
Foreign(Rc<dyn ForeignValue>),
}

impl Value {
Expand Down Expand Up @@ -395,7 +395,7 @@ pub trait ForeignValue: Any + fmt::Debug {
/// `ExecError::CannotCompare(..)` should be returned.
///
/// The default implementation unconditionally returns an error.
fn compare_to(&self, rhs: &ForeignValue) -> Result<Ordering, ExecError> {
fn compare_to(&self, rhs: &dyn ForeignValue) -> Result<Ordering, ExecError> {
Err(ExecError::CannotCompare(self.type_name()))
}

Expand All @@ -417,14 +417,14 @@ pub trait ForeignValue: Any + fmt::Debug {
/// A type implementing `ForeignValue` need only implement `is_identical`
/// if it contains a float-type value or emulates some equality relationship
/// similar to `NaN`.
fn is_identical_to(&self, rhs: &ForeignValue) -> bool {
fn is_identical_to(&self, rhs: &dyn ForeignValue) -> bool {
self.is_equal_to(rhs).unwrap_or(false)
}

/// Tests for equality between two values of a foreign type.
///
/// The default implementation unconditionally returns an error.
fn is_equal_to(&self, rhs: &ForeignValue) -> Result<bool, ExecError> {
fn is_equal_to(&self, rhs: &dyn ForeignValue) -> Result<bool, ExecError> {
Err(ExecError::TypeMismatch{
lhs: self.type_name(),
rhs: rhs.type_name(),
Expand Down Expand Up @@ -501,7 +501,7 @@ impl<F> fmt::Debug for ForeignFn<F> {

impl<F> ForeignValue for ForeignFn<F>
where F: Any + Fn(&Context, &mut [Value]) -> Result<Value, Error> {
fn compare_to(&self, _rhs: &ForeignValue) -> Result<Ordering, ExecError> {
fn compare_to(&self, _rhs: &dyn ForeignValue) -> Result<Ordering, ExecError> {
Err(ExecError::CannotCompare("foreign-fn"))
}

Expand Down
4 changes: 2 additions & 2 deletions tests/foreign.rs
Expand Up @@ -13,7 +13,7 @@ pub struct MyType {
}

impl ketos::ForeignValue for MyType {
fn compare_to(&self, rhs: &ForeignValue) -> Result<Ordering, ExecError> {
fn compare_to(&self, rhs: &dyn ForeignValue) -> Result<Ordering, ExecError> {
match rhs.downcast_ref::<MyType>() {
Some(rhs) => Ok(self.cmp(rhs)),
None => Err(ExecError::TypeMismatch{
Expand All @@ -23,7 +23,7 @@ impl ketos::ForeignValue for MyType {
}
}

fn is_equal_to(&self, rhs: &ForeignValue) -> Result<bool, ExecError> {
fn is_equal_to(&self, rhs: &dyn ForeignValue) -> Result<bool, ExecError> {
match rhs.downcast_ref::<MyType>() {
Some(rhs) => Ok(*self == *rhs),
None => Err(ExecError::TypeMismatch{
Expand Down

0 comments on commit 28edb52

Please sign in to comment.