Skip to content

Cover up bare trait objects with a dyn #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion derive/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!())
Expand Down
2 changes: 1 addition & 1 deletion vm/src/dictdatatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions vm/src/obj/objset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion vm/src/obj/objstr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion vm/src/stdlib/hashlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions vm/src/stdlib/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -321,15 +321,15 @@ 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,
)
}

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,
)
}
Expand Down
80 changes: 56 additions & 24 deletions vm/src/stdlib/pystruct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
Expand Down Expand Up @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand All @@ -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,
{
Expand Down Expand Up @@ -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,
{
Expand Down