Skip to content

Commit b2c515c

Browse files
Merge pull request RustPython#1129 from RustPython/coolreader18/no-bare-trait-objects
Cover up bare trait objects with a dyn
2 parents 5edcecb + 9204035 commit b2c515c

File tree

8 files changed

+70
-38
lines changed

8 files changed

+70
-38
lines changed

derive/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Diagnostic {
9494
}
9595
}
9696

97-
pub fn spanned_error<T: Into<String>>(node: &ToTokens, text: T) -> Diagnostic {
97+
pub fn spanned_error<T: Into<String>>(node: &dyn ToTokens, text: T) -> Diagnostic {
9898
Diagnostic {
9999
inner: Repr::Single {
100100
text: text.into(),

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fn main() {
2828
}
2929
}
3030

31-
fn run() -> Result<(), Box<std::error::Error>> {
31+
fn run() -> Result<(), Box<dyn std::error::Error>> {
3232
env_logger::init();
3333
let app = App::new("RustPython")
3434
.version(crate_version!())

vm/src/dictdatatype.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl<T: Clone> Dict<T> {
188188
position.size != self.size || self.entries.len() != position.entries_size
189189
}
190190

191-
pub fn keys<'a>(&'a self) -> Box<Iterator<Item = PyObjectRef> + 'a> {
191+
pub fn keys<'a>(&'a self) -> Box<dyn Iterator<Item = PyObjectRef> + 'a> {
192192
Box::new(
193193
self.entries
194194
.iter()

vm/src/obj/objset.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ impl PySetInner {
107107
fn _compare_inner(
108108
&self,
109109
other: &PySetInner,
110-
size_func: &Fn(usize, usize) -> bool,
110+
size_func: fn(usize, usize) -> bool,
111111
swap: bool,
112112
vm: &VirtualMachine,
113113
) -> PyResult {
@@ -127,7 +127,7 @@ impl PySetInner {
127127
fn eq(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
128128
self._compare_inner(
129129
other,
130-
&|zelf: usize, other: usize| -> bool { zelf != other },
130+
|zelf: usize, other: usize| -> bool { zelf != other },
131131
false,
132132
vm,
133133
)
@@ -136,7 +136,7 @@ impl PySetInner {
136136
fn ge(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
137137
self._compare_inner(
138138
other,
139-
&|zelf: usize, other: usize| -> bool { zelf < other },
139+
|zelf: usize, other: usize| -> bool { zelf < other },
140140
false,
141141
vm,
142142
)
@@ -145,7 +145,7 @@ impl PySetInner {
145145
fn gt(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
146146
self._compare_inner(
147147
other,
148-
&|zelf: usize, other: usize| -> bool { zelf <= other },
148+
|zelf: usize, other: usize| -> bool { zelf <= other },
149149
false,
150150
vm,
151151
)
@@ -154,7 +154,7 @@ impl PySetInner {
154154
fn le(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
155155
self._compare_inner(
156156
other,
157-
&|zelf: usize, other: usize| -> bool { zelf < other },
157+
|zelf: usize, other: usize| -> bool { zelf < other },
158158
true,
159159
vm,
160160
)
@@ -163,7 +163,7 @@ impl PySetInner {
163163
fn lt(&self, other: &PySetInner, vm: &VirtualMachine) -> PyResult {
164164
self._compare_inner(
165165
other,
166-
&|zelf: usize, other: usize| -> bool { zelf <= other },
166+
|zelf: usize, other: usize| -> bool { zelf <= other },
167167
true,
168168
vm,
169169
)

vm/src/obj/objstr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ fn do_cformat_specifier(
11591159

11601160
fn try_update_quantity_from_tuple(
11611161
vm: &VirtualMachine,
1162-
elements: &mut Iterator<Item = PyObjectRef>,
1162+
elements: &mut dyn Iterator<Item = PyObjectRef>,
11631163
q: &mut Option<CFormatQuantity>,
11641164
mut tuple_index: usize,
11651165
) -> PyResult<usize> {

vm/src/stdlib/hashlib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
198198

199199
/// Generic wrapper patching around the hashing libraries.
200200
struct HashWrapper {
201-
inner: Box<DynDigest>,
201+
inner: Box<dyn DynDigest>,
202202
}
203203

204204
impl HashWrapper {

vm/src/stdlib/os.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ impl DirEntryRef {
307307
fn perform_on_metadata(
308308
self,
309309
follow_symlinks: FollowSymlinks,
310-
action: &Fn(fs::Metadata) -> bool,
310+
action: fn(fs::Metadata) -> bool,
311311
vm: &VirtualMachine,
312312
) -> PyResult<bool> {
313313
let metadata = match follow_symlinks.follow_symlinks {
@@ -321,15 +321,15 @@ impl DirEntryRef {
321321
fn is_dir(self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {
322322
self.perform_on_metadata(
323323
follow_symlinks,
324-
&|meta: fs::Metadata| -> bool { meta.is_dir() },
324+
|meta: fs::Metadata| -> bool { meta.is_dir() },
325325
vm,
326326
)
327327
}
328328

329329
fn is_file(self, follow_symlinks: FollowSymlinks, vm: &VirtualMachine) -> PyResult<bool> {
330330
self.perform_on_metadata(
331331
follow_symlinks,
332-
&|meta: fs::Metadata| -> bool { meta.is_file() },
332+
|meta: fs::Metadata| -> bool { meta.is_file() },
333333
vm,
334334
)
335335
}

vm/src/stdlib/pystruct.rs

+56-24
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ fn get_int(vm: &VirtualMachine, arg: &PyObjectRef) -> PyResult<BigInt> {
108108
objint::to_int(vm, arg, 10)
109109
}
110110

111-
fn pack_i8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
111+
fn pack_i8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
112112
let v = get_int(vm, arg)?.to_i8().unwrap();
113113
data.write_i8(v).unwrap();
114114
Ok(())
115115
}
116116

117-
fn pack_u8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
117+
fn pack_u8(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
118118
let v = get_int(vm, arg)?.to_u8().unwrap();
119119
data.write_u8(v).unwrap();
120120
Ok(())
121121
}
122122

123-
fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()> {
123+
fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut dyn Write) -> PyResult<()> {
124124
if objtype::isinstance(&arg, &vm.ctx.bool_type()) {
125125
let v = if objbool::get_value(arg) { 1 } else { 0 };
126126
data.write_u8(v).unwrap();
@@ -130,7 +130,11 @@ fn pack_bool(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResu
130130
}
131131
}
132132

133-
fn pack_i16<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
133+
fn pack_i16<Endianness>(
134+
vm: &VirtualMachine,
135+
arg: &PyObjectRef,
136+
data: &mut dyn Write,
137+
) -> PyResult<()>
134138
where
135139
Endianness: byteorder::ByteOrder,
136140
{
@@ -139,7 +143,11 @@ where
139143
Ok(())
140144
}
141145

142-
fn pack_u16<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
146+
fn pack_u16<Endianness>(
147+
vm: &VirtualMachine,
148+
arg: &PyObjectRef,
149+
data: &mut dyn Write,
150+
) -> PyResult<()>
143151
where
144152
Endianness: byteorder::ByteOrder,
145153
{
@@ -148,7 +156,11 @@ where
148156
Ok(())
149157
}
150158

151-
fn pack_i32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
159+
fn pack_i32<Endianness>(
160+
vm: &VirtualMachine,
161+
arg: &PyObjectRef,
162+
data: &mut dyn Write,
163+
) -> PyResult<()>
152164
where
153165
Endianness: byteorder::ByteOrder,
154166
{
@@ -157,7 +169,11 @@ where
157169
Ok(())
158170
}
159171

160-
fn pack_u32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
172+
fn pack_u32<Endianness>(
173+
vm: &VirtualMachine,
174+
arg: &PyObjectRef,
175+
data: &mut dyn Write,
176+
) -> PyResult<()>
161177
where
162178
Endianness: byteorder::ByteOrder,
163179
{
@@ -166,7 +182,11 @@ where
166182
Ok(())
167183
}
168184

169-
fn pack_i64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
185+
fn pack_i64<Endianness>(
186+
vm: &VirtualMachine,
187+
arg: &PyObjectRef,
188+
data: &mut dyn Write,
189+
) -> PyResult<()>
170190
where
171191
Endianness: byteorder::ByteOrder,
172192
{
@@ -175,7 +195,11 @@ where
175195
Ok(())
176196
}
177197

178-
fn pack_u64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
198+
fn pack_u64<Endianness>(
199+
vm: &VirtualMachine,
200+
arg: &PyObjectRef,
201+
data: &mut dyn Write,
202+
) -> PyResult<()>
179203
where
180204
Endianness: byteorder::ByteOrder,
181205
{
@@ -184,7 +208,11 @@ where
184208
Ok(())
185209
}
186210

187-
fn pack_f32<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
211+
fn pack_f32<Endianness>(
212+
vm: &VirtualMachine,
213+
arg: &PyObjectRef,
214+
data: &mut dyn Write,
215+
) -> PyResult<()>
188216
where
189217
Endianness: byteorder::ByteOrder,
190218
{
@@ -193,7 +221,11 @@ where
193221
Ok(())
194222
}
195223

196-
fn pack_f64<Endianness>(vm: &VirtualMachine, arg: &PyObjectRef, data: &mut Write) -> PyResult<()>
224+
fn pack_f64<Endianness>(
225+
vm: &VirtualMachine,
226+
arg: &PyObjectRef,
227+
data: &mut dyn Write,
228+
) -> PyResult<()>
197229
where
198230
Endianness: byteorder::ByteOrder,
199231
{
@@ -214,7 +246,7 @@ fn pack_item<Endianness>(
214246
vm: &VirtualMachine,
215247
code: &FormatCode,
216248
arg: &PyObjectRef,
217-
data: &mut Write,
249+
data: &mut dyn Write,
218250
) -> PyResult<()>
219251
where
220252
Endianness: byteorder::ByteOrder,
@@ -287,28 +319,28 @@ fn struct_pack(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
287319
}
288320
}
289321

290-
fn unpack_i8(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
322+
fn unpack_i8(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
291323
match rdr.read_i8() {
292324
Err(err) => panic!("Error in reading {:?}", err),
293325
Ok(v) => Ok(vm.ctx.new_int(v)),
294326
}
295327
}
296328

297-
fn unpack_u8(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
329+
fn unpack_u8(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
298330
match rdr.read_u8() {
299331
Err(err) => panic!("Error in reading {:?}", err),
300332
Ok(v) => Ok(vm.ctx.new_int(v)),
301333
}
302334
}
303335

304-
fn unpack_bool(vm: &VirtualMachine, rdr: &mut Read) -> PyResult {
336+
fn unpack_bool(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult {
305337
match rdr.read_u8() {
306338
Err(err) => panic!("Error in reading {:?}", err),
307339
Ok(v) => Ok(vm.ctx.new_bool(v > 0)),
308340
}
309341
}
310342

311-
fn unpack_i16<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
343+
fn unpack_i16<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
312344
where
313345
Endianness: byteorder::ByteOrder,
314346
{
@@ -318,7 +350,7 @@ where
318350
}
319351
}
320352

321-
fn unpack_u16<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
353+
fn unpack_u16<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
322354
where
323355
Endianness: byteorder::ByteOrder,
324356
{
@@ -328,7 +360,7 @@ where
328360
}
329361
}
330362

331-
fn unpack_i32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
363+
fn unpack_i32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
332364
where
333365
Endianness: byteorder::ByteOrder,
334366
{
@@ -338,7 +370,7 @@ where
338370
}
339371
}
340372

341-
fn unpack_u32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
373+
fn unpack_u32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
342374
where
343375
Endianness: byteorder::ByteOrder,
344376
{
@@ -348,7 +380,7 @@ where
348380
}
349381
}
350382

351-
fn unpack_i64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
383+
fn unpack_i64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
352384
where
353385
Endianness: byteorder::ByteOrder,
354386
{
@@ -358,7 +390,7 @@ where
358390
}
359391
}
360392

361-
fn unpack_u64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
393+
fn unpack_u64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
362394
where
363395
Endianness: byteorder::ByteOrder,
364396
{
@@ -368,7 +400,7 @@ where
368400
}
369401
}
370402

371-
fn unpack_f32<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
403+
fn unpack_f32<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
372404
where
373405
Endianness: byteorder::ByteOrder,
374406
{
@@ -378,7 +410,7 @@ where
378410
}
379411
}
380412

381-
fn unpack_f64<Endianness>(vm: &VirtualMachine, rdr: &mut Read) -> PyResult
413+
fn unpack_f64<Endianness>(vm: &VirtualMachine, rdr: &mut dyn Read) -> PyResult
382414
where
383415
Endianness: byteorder::ByteOrder,
384416
{
@@ -419,7 +451,7 @@ fn struct_unpack(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {
419451
Ok(vm.ctx.new_tuple(items))
420452
}
421453

422-
fn unpack_code<Endianness>(vm: &VirtualMachine, code: &FormatCode, rdr: &mut Read) -> PyResult
454+
fn unpack_code<Endianness>(vm: &VirtualMachine, code: &FormatCode, rdr: &mut dyn Read) -> PyResult
423455
where
424456
Endianness: byteorder::ByteOrder,
425457
{

0 commit comments

Comments
 (0)