Skip to content

Commit 5855baf

Browse files
authored
Merge pull request RustPython#834 from dkaste/rust-2018-macros
Make macros comply fully with Rust 2018
2 parents 143e329 + a8e064b commit 5855baf

File tree

15 files changed

+23
-24
lines changed

15 files changed

+23
-24
lines changed

vm/src/macros.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ macro_rules! replace_expr {
99

1010
#[macro_export]
1111
macro_rules! count_tts {
12-
($($tts:tt)*) => {0usize $(+ replace_expr!($tts 1usize))*};
12+
($($tts:tt)*) => {0usize $(+ $crate::replace_expr!($tts 1usize))*};
1313
}
1414

1515
#[macro_export]
@@ -20,6 +20,8 @@ macro_rules! type_check {
2020
let arg = &$args.args[$arg_count];
2121

2222
if !$crate::obj::objtype::isinstance(arg, &expected_type) {
23+
use $crate::pyobject::TypeProtocol;
24+
2325
let arg_typ = arg.class();
2426
let expected_type_name = $vm.to_pystr(&expected_type)?;
2527
let actual_type = $vm.to_pystr(&arg_typ)?;
@@ -45,14 +47,14 @@ macro_rules! arg_check {
4547
}
4648
};
4749
( $vm: ident, $args:ident, required=[$( ($arg_name:ident, $arg_type:expr) ),*] ) => {
48-
arg_check!($vm, $args, required=[$( ($arg_name, $arg_type) ),*], optional=[]);
50+
$crate::arg_check!($vm, $args, required=[$( ($arg_name, $arg_type) ),*], optional=[]);
4951
};
5052
( $vm: ident, $args:ident, required=[$( ($arg_name:ident, $arg_type:expr) ),*], optional=[$( ($optional_arg_name:ident, $optional_arg_type:expr) ),*] ) => {
5153
let mut arg_count = 0;
5254

5355
// use macro magic to compile-time count number of required and optional arguments
54-
let minimum_arg_count = count_tts!($($arg_name)*);
55-
let maximum_arg_count = minimum_arg_count + count_tts!($($optional_arg_name)*);
56+
let minimum_arg_count = $crate::count_tts!($($arg_name)*);
57+
let maximum_arg_count = minimum_arg_count + $crate::count_tts!($($optional_arg_name)*);
5658

5759
// verify that the number of given arguments is right
5860
if $args.args.len() < minimum_arg_count || $args.args.len() > maximum_arg_count {
@@ -72,7 +74,7 @@ macro_rules! arg_check {
7274
// check if the type matches. If not, return with error
7375
// assign the arg to a variable
7476
$(
75-
type_check!($vm, $args, arg_count, $arg_name, $arg_type);
77+
$crate::type_check!($vm, $args, arg_count, $arg_name, $arg_type);
7678
let $arg_name = &$args.args[arg_count];
7779
#[allow(unused_assignments)]
7880
{
@@ -85,7 +87,7 @@ macro_rules! arg_check {
8587
// assign the arg to a variable
8688
$(
8789
let $optional_arg_name = if arg_count < $args.args.len() {
88-
type_check!($vm, $args, arg_count, $optional_arg_name, $optional_arg_type);
90+
$crate::type_check!($vm, $args, arg_count, $optional_arg_name, $optional_arg_type);
8991
let ret = Some(&$args.args[arg_count]);
9092
#[allow(unused_assignments)]
9193
{
@@ -226,7 +228,7 @@ macro_rules! match_class {
226228
($obj:expr, $binding:ident @ $class:ty => $expr:expr, $($rest:tt)*) => {
227229
match $obj.downcast::<$class>() {
228230
Ok($binding) => $expr,
229-
Err(_obj) => match_class!(_obj, $($rest)*),
231+
Err(_obj) => $crate::match_class!(_obj, $($rest)*),
230232
}
231233
};
232234

@@ -236,7 +238,7 @@ macro_rules! match_class {
236238
if $obj.payload_is::<$class>() {
237239
$expr
238240
} else {
239-
match_class!($obj, $($rest)*)
241+
$crate::match_class!($obj, $($rest)*)
240242
}
241243
};
242244
}

vm/src/obj/objbool.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use num_traits::Zero;
22

33
use crate::function::PyFuncArgs;
4-
use crate::pyobject::{
5-
IntoPyObject, PyContext, PyObjectRef, PyResult, TryFromObject, TypeProtocol,
6-
};
4+
use crate::pyobject::{IntoPyObject, PyContext, PyObjectRef, PyResult, TryFromObject};
75
use crate::vm::VirtualMachine;
86

97
use super::objint::PyInt;

vm/src/obj/objellipsis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::function::PyFuncArgs;
2-
use crate::pyobject::{PyContext, PyResult, TypeProtocol};
2+
use crate::pyobject::{PyContext, PyResult};
33
use crate::vm::VirtualMachine;
44

55
pub fn init(context: &PyContext) {

vm/src/obj/objlist.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use num_traits::{One, Signed, ToPrimitive, Zero};
99
use crate::function::{OptionalArg, PyFuncArgs};
1010
use crate::pyobject::{
1111
IdProtocol, PyContext, PyIterable, PyObjectRef, PyRef, PyResult, PyValue, TryFromObject,
12-
TypeProtocol,
1312
};
1413
use crate::vm::{ReprGuard, VirtualMachine};
1514

vm/src/obj/objslice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use num_bigint::BigInt;
22

33
use crate::function::PyFuncArgs;
4-
use crate::pyobject::{PyContext, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
4+
use crate::pyobject::{PyContext, PyObjectRef, PyRef, PyResult, PyValue};
55
use crate::vm::VirtualMachine;
66

77
use super::objint;

vm/src/stdlib/io.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::obj::objbytes;
2020
use crate::obj::objint;
2121
use crate::obj::objstr;
2222
use crate::obj::objtype::PyClassRef;
23-
use crate::pyobject::{BufferProtocol, PyObjectRef, PyRef, PyResult, PyValue, TypeProtocol};
23+
use crate::pyobject::{BufferProtocol, PyObjectRef, PyRef, PyResult, PyValue};
2424
use crate::vm::VirtualMachine;
2525

2626
fn compute_c_flag(mode: &str) -> u16 {

vm/src/stdlib/keyword.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustpython_parser::lexer;
66

77
use crate::function::PyFuncArgs;
88
use crate::obj::objstr;
9-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
9+
use crate::pyobject::{PyObjectRef, PyResult};
1010
use crate::vm::VirtualMachine;
1111

1212
fn keyword_iskeyword(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/stdlib/math.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use statrs::function::gamma::{gamma, ln_gamma};
88

99
use crate::function::PyFuncArgs;
1010
use crate::obj::objfloat;
11-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
11+
use crate::pyobject::{PyObjectRef, PyResult};
1212
use crate::vm::VirtualMachine;
1313

1414
// Helper macro:

vm/src/stdlib/os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::obj::objint;
1212
use crate::obj::objint::PyIntRef;
1313
use crate::obj::objstr;
1414
use crate::obj::objstr::PyStringRef;
15-
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult, TypeProtocol};
15+
use crate::pyobject::{ItemProtocol, PyObjectRef, PyResult};
1616
use crate::vm::VirtualMachine;
1717

1818
#[cfg(unix)]

vm/src/stdlib/pystruct.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use num_traits::ToPrimitive;
1515

1616
use crate::function::PyFuncArgs;
1717
use crate::obj::{objbool, objbytes, objfloat, objint, objstr, objtype};
18-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
18+
use crate::pyobject::{PyObjectRef, PyResult};
1919
use crate::VirtualMachine;
2020

2121
#[derive(Debug)]

vm/src/stdlib/random.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rand::distributions::{Distribution, Normal};
44

55
use crate::function::PyFuncArgs;
66
use crate::obj::objfloat;
7-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
7+
use crate::pyobject::{PyObjectRef, PyResult};
88
use crate::vm::VirtualMachine;
99

1010
pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {

vm/src/stdlib/socket.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::obj::objbytes;
1010
use crate::obj::objint;
1111
use crate::obj::objsequence::get_elements;
1212
use crate::obj::objstr;
13-
use crate::pyobject::{PyObjectRef, PyRef, PyResult, PyValue, TryFromObject, TypeProtocol};
13+
use crate::pyobject::{PyObjectRef, PyRef, PyResult, PyValue, TryFromObject};
1414
use crate::vm::VirtualMachine;
1515

1616
use crate::obj::objtype::PyClassRef;

vm/src/stdlib/time_module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH};
55

66
use crate::function::PyFuncArgs;
77
use crate::obj::objfloat;
8-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
8+
use crate::pyobject::{PyObjectRef, PyResult};
99
use crate::vm::VirtualMachine;
1010

1111
fn time_sleep(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/stdlib/tokenize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustpython_parser::lexer;
88

99
use crate::function::PyFuncArgs;
1010
use crate::obj::objstr;
11-
use crate::pyobject::{PyObjectRef, PyResult, TypeProtocol};
11+
use crate::pyobject::{PyObjectRef, PyResult};
1212
use crate::vm::VirtualMachine;
1313

1414
fn tokenize_tokenize(vm: &VirtualMachine, args: PyFuncArgs) -> PyResult {

vm/src/sysmodule.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{env, mem};
44
use crate::frame::FrameRef;
55
use crate::function::{OptionalArg, PyFuncArgs};
66
use crate::obj::objstr::PyStringRef;
7-
use crate::pyobject::{ItemProtocol, PyContext, PyObjectRef, PyResult, TypeProtocol};
7+
use crate::pyobject::{ItemProtocol, PyContext, PyObjectRef, PyResult};
88
use crate::vm::VirtualMachine;
99

1010
/*

0 commit comments

Comments
 (0)