Cover up bare trait objects with a dyn

This commit is contained in:
coolreader18 committed 2019-07-10 09:41:58 -05:00
1 parent 5edcecbdd6
commit 9204035d97
8 files changed
+70 -38

No files matched your search

+1 -1
View File
@@ -94,7 +94,7 @@ impl Diagnostic {
}
}
pub fn spanned_error<T: Into<String>>(node: &ToTokens, text: T) -> Diagnostic {
pub fn spanned_error<T: Into<String>>(node: &dyn ToTokens, text: T) -> Diagnostic {
Diagnostic {
inner: Repr::Single {
text: text.into(),
+1 -1
View File
@@ -28,7 +28,7 @@ fn main() {
}
}
fn run() -> Result<(), Box<std::error::Error>> {
fn run() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
let app = App::new("RustPython")
.version(crate_version!())
+1 -1
View File
@@ -188,7 +188,7 @@ impl<T: Clone> Dict<T> {
position.size != self.size || self.entries.len() != position.entries_size
}
pub fn keys<'a>(&'a self) -> Box<Iterator<Item = PyObjectRef> + 'a> {
pub fn keys<'a>(&'a self) -> Box<dyn Iterator<Item = PyObjectRef> + 'a> {
Box::new(
self.entries
.iter()
+6 -6
View File
@@ -107,7 +107,7 @@ impl PySetInner {
fn _compare_inner(
&self,
other: &PySetInner,
size_func: &Fn(usize, usize) -> bool,
size_func: fn(usize, usize) -> bool,
swap: bool,
vm: &VirtualMachine,
) -> PyResult {
@@ -127,7 +127,7 @@ impl PySetInner {
fn eq(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
self._compare_inner(
other,
&|zelf: usize, other: usize| -> bool { zelf != other },
|zelf: usize, other: usize| -> bool { zelf != other },
false,
vm,
)
@@ -136,7 +136,7 @@ impl PySetInner {
fn ge(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
self._compare_inner(
other,
&|zelf: usize, other: usize| -> bool { zelf < other },
|zelf: usize, other: usize| -> bool { zelf < other },
false,
vm,
)
@@ -145,7 +145,7 @@ impl PySetInner {
fn gt(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
self._compare_inner(
other,
&|zelf: usize, other: usize| -> bool { zelf <= other },
|zelf: usize, other: usize| -> bool { zelf <= other },
false,
vm,
)
@@ -154,7 +154,7 @@ impl PySetInner {
fn le(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
self._compare_inner(
other,
&|zelf: usize, other: usize| -> bool { zelf < other },
|zelf: usize, other: usize| -> bool { zelf < other },
true,
vm,
)
@@ -163,7 +163,7 @@ impl PySetInner {
fn lt(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
self._compare_inner(
other,
&|zelf: usize, other: usize| -> bool { zelf <= other },
|zelf: usize, other: usize| -> bool { zelf <= other },
true,
vm,
)
+1 -1
View File
@@ -1159,7 +1159,7 @@ fn do_cformat_specifier(
fn try_update_quantity_from_tuple(
vm: &VirtualMachine,
elements: &mut Iterator<Item = PyObjectRef>,
elements: &mut dyn Iterator<Item = PyObjectRef>,
q: &mut Option<CFormatQuantity>,
mut tuple_index: usize,
) -> PyResult<usize> {
+1 -1
View File
@@ -198,7 +198,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
/// Generic wrapper patching around the hashing libraries.
struct HashWrapper {
inner: Box<DynDigest>,
inner: Box<dyn DynDigest>,
}
impl HashWrapper {
+3 -3
View File
@@ -307,7 +307,7 @@ impl DirEntryRef {
fn perform_on_metadata(
self,
follow_symlinks: FollowSymlinks,
action: &Fn(fs::Metadata) -> bool,
action: fn(fs::Metadata) -> bool,
vm: &VirtualMachine,
) -> PyResult<bool> {
let metadata = match follow_symlinks.follow_symlinks {
@@ -321,7 +321,7 @@ impl DirEntryRef {
fn is_dir(self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {
self.perform_on_metadata(
follow_symlinks,
&|meta: fs::Metadata| -> bool { meta.is_dir() },
|meta: fs::Metadata| -> bool { meta.is_dir() },
vm,
)
}
@@ -329,7 +329,7 @@ impl DirEntryRef {
fn is_file(self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {
self.perform_on_metadata(
follow_symlinks,
&|meta: fs::Metadata| -> bool { meta.is_file() },
|meta: fs::Metadata| -> bool { meta.is_file() },
vm,
)
}
+56 -24
View File
@@ -108,19 +108,19 @@ fn get_int(vm: &VirtualMachine, arg: &PyObjectRef) -> PyResult<BigInt> {
objint::to_int(vm, arg, 10)
}
fn pack_i8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
fn pack_i8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
let v = get_int(vm, arg)?.to_i8().unwrap();
data.write_i8(v).unwrap();
Ok(())
}
fn pack_u8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
fn pack_u8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
let v = get_int(vm, arg)?.to_u8().unwrap();
data.write_u8(v).unwrap();
Ok(())
}
fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
if objtype::isinstance(&arg, &vm.ctx.bool_type()) {
let v = if objbool::get_value(arg) { 1 } else { 0 };
data.write_u8(v).unwrap();
@@ -130,7 +130,11 @@ fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResu
}
}
fn pack_i16<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_i16<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -139,7 +143,11 @@ where
Ok(())
}
fn pack_u16<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_u16<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -148,7 +156,11 @@ where
Ok(())
}
fn pack_i32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_i32<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -157,7 +169,11 @@ where
Ok(())
}
fn pack_u32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_u32<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -166,7 +182,11 @@ where
Ok(())
}
fn pack_i64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_i64<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -175,7 +195,11 @@ where
Ok(())
}
fn pack_u64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_u64<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -184,7 +208,11 @@ where
Ok(())
}
fn pack_f32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_f32<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -193,7 +221,11 @@ where
Ok(())
}
fn pack_f64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
fn pack_f64<Endianness>(
vm: &VirtualMachine,
arg: &PyObjectRef,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
{
@@ -214,7 +246,7 @@ fn pack_item<Endianness>(
vm: &VirtualMachine,
code: &FormatCode,
arg: &PyObjectRef,
data: &mut Write,
data: &mut dyn Write,
) -> PyResult<()>
where
Endianness: byteorder::ByteOrder,
@@ -287,28 +319,28 @@ fn struct_pack(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
}
}
fn unpack_i8(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
fn unpack_i8(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
match rdr.read_i8() {
Err(err) => panic!("Error in reading {:?}", err),
Ok(v) => Ok(vm.ctx.new_int(v)),
}
}
fn unpack_u8(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
fn unpack_u8(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
match rdr.read_u8() {
Err(err) => panic!("Error in reading {:?}", err),
Ok(v) => Ok(vm.ctx.new_int(v)),
}
}
fn unpack_bool(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
fn unpack_bool(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
match rdr.read_u8() {
Err(err) => panic!("Error in reading {:?}", err),
Ok(v) => Ok(vm.ctx.new_bool(v > 0)),
}
}
fn unpack_i16<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_i16<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -318,7 +350,7 @@ where
}
}
fn unpack_u16<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_u16<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -328,7 +360,7 @@ where
}
}
fn unpack_i32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_i32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -338,7 +370,7 @@ where
}
}
fn unpack_u32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_u32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -348,7 +380,7 @@ where
}
}
fn unpack_i64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_i64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -358,7 +390,7 @@ where
}
}
fn unpack_u64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_u64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -368,7 +400,7 @@ where
}
}
fn unpack_f32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_f32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -378,7 +410,7 @@ where
}
}
fn unpack_f64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
fn unpack_f64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{
@@ -419,7 +451,7 @@ fn struct_unpack(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
Ok(vm.ctx.new_tuple(items))
}
fn unpack_code<Endianness>(vm: &VirtualMachine, code: &FormatCode, rdr: &mut Read) -> PyResult
fn unpack_code<Endianness>(vm: &VirtualMachine, code: &FormatCode, rdr: &mut dyn Read) -> PyResult
where
Endianness: byteorder::ByteOrder,
{