@@ -9,79 +9,80 @@ private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl
9
9
10
10
/**
11
11
* Holds if the operator `op` with arity `arity` is overloaded to a trait with
12
- * the canonical path `path` and the method name `method`.
12
+ * the canonical path `path` and the method name `method`, and if it borrows its
13
+ * first `borrows` arguments.
13
14
*/
14
- private predicate isOverloaded ( string op , int arity , string path , string method ) {
15
+ private predicate isOverloaded ( string op , int arity , string path , string method , int borrows ) {
15
16
arity = 1 and
16
17
(
17
18
// Negation
18
- op = "-" and path = "core::ops::arith::Neg" and method = "neg"
19
+ op = "-" and path = "core::ops::arith::Neg" and method = "neg" and borrows = 0
19
20
or
20
21
// Not
21
- op = "!" and path = "core::ops::bit::Not" and method = "not"
22
+ op = "!" and path = "core::ops::bit::Not" and method = "not" and borrows = 0
22
23
or
23
24
// Dereference
24
- op = "*" and path = "core::ops::deref::Deref" and method = "deref"
25
+ op = "*" and path = "core::ops::deref::Deref" and method = "deref" and borrows = 0
25
26
)
26
27
or
27
28
arity = 2 and
28
29
(
29
30
// Comparison operators
30
- op = "==" and path = "core::cmp::PartialEq" and method = "eq"
31
+ op = "==" and path = "core::cmp::PartialEq" and method = "eq" and borrows = 2
31
32
or
32
- op = "!=" and path = "core::cmp::PartialEq" and method = "ne"
33
+ op = "!=" and path = "core::cmp::PartialEq" and method = "ne" and borrows = 2
33
34
or
34
- op = "<" and path = "core::cmp::PartialOrd" and method = "lt"
35
+ op = "<" and path = "core::cmp::PartialOrd" and method = "lt" and borrows = 2
35
36
or
36
- op = "<=" and path = "core::cmp::PartialOrd" and method = "le"
37
+ op = "<=" and path = "core::cmp::PartialOrd" and method = "le" and borrows = 2
37
38
or
38
- op = ">" and path = "core::cmp::PartialOrd" and method = "gt"
39
+ op = ">" and path = "core::cmp::PartialOrd" and method = "gt" and borrows = 2
39
40
or
40
- op = ">=" and path = "core::cmp::PartialOrd" and method = "ge"
41
+ op = ">=" and path = "core::cmp::PartialOrd" and method = "ge" and borrows = 2
41
42
or
42
43
// Arithmetic operators
43
- op = "+" and path = "core::ops::arith::Add" and method = "add"
44
+ op = "+" and path = "core::ops::arith::Add" and method = "add" and borrows = 0
44
45
or
45
- op = "-" and path = "core::ops::arith::Sub" and method = "sub"
46
+ op = "-" and path = "core::ops::arith::Sub" and method = "sub" and borrows = 0
46
47
or
47
- op = "*" and path = "core::ops::arith::Mul" and method = "mul"
48
+ op = "*" and path = "core::ops::arith::Mul" and method = "mul" and borrows = 0
48
49
or
49
- op = "/" and path = "core::ops::arith::Div" and method = "div"
50
+ op = "/" and path = "core::ops::arith::Div" and method = "div" and borrows = 0
50
51
or
51
- op = "%" and path = "core::ops::arith::Rem" and method = "rem"
52
+ op = "%" and path = "core::ops::arith::Rem" and method = "rem" and borrows = 0
52
53
or
53
54
// Arithmetic assignment expressions
54
- op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign"
55
+ op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign" and borrows = 1
55
56
or
56
- op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign"
57
+ op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign" and borrows = 1
57
58
or
58
- op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign"
59
+ op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign" and borrows = 1
59
60
or
60
- op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign"
61
+ op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign" and borrows = 1
61
62
or
62
- op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign"
63
+ op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign" and borrows = 1
63
64
or
64
65
// Bitwise operators
65
- op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand"
66
+ op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand" and borrows = 0
66
67
or
67
- op = "|" and path = "core::ops::bit::BitOr" and method = "bitor"
68
+ op = "|" and path = "core::ops::bit::BitOr" and method = "bitor" and borrows = 0
68
69
or
69
- op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor"
70
+ op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor" and borrows = 0
70
71
or
71
- op = "<<" and path = "core::ops::bit::Shl" and method = "shl"
72
+ op = "<<" and path = "core::ops::bit::Shl" and method = "shl" and borrows = 0
72
73
or
73
- op = ">>" and path = "core::ops::bit::Shr" and method = "shr"
74
+ op = ">>" and path = "core::ops::bit::Shr" and method = "shr" and borrows = 0
74
75
or
75
76
// Bitwise assignment operators
76
- op = "&=" and path = "core::ops::bit::BitAndAssign" and method = "bitand_assign"
77
+ op = "&=" and path = "core::ops::bit::BitAndAssign" and method = "bitand_assign" and borrows = 1
77
78
or
78
- op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign"
79
+ op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign" and borrows = 1
79
80
or
80
- op = "^=" and path = "core::ops::bit::BitXorAssign" and method = "bitxor_assign"
81
+ op = "^=" and path = "core::ops::bit::BitXorAssign" and method = "bitxor_assign" and borrows = 1
81
82
or
82
- op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign"
83
+ op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign" and borrows = 1
83
84
or
84
- op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign"
85
+ op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign" and borrows = 1
85
86
)
86
87
}
87
88
@@ -114,9 +115,9 @@ module Impl {
114
115
* Holds if this operation is overloaded to the method `methodName` of the
115
116
* trait `trait`.
116
117
*/
117
- predicate isOverloaded ( Trait trait , string methodName ) {
118
+ predicate isOverloaded ( Trait trait , string methodName , int borrows ) {
118
119
isOverloaded ( this .getOperatorName ( ) , this .getNumberOfOperands ( ) , trait .getCanonicalPath ( ) ,
119
- methodName )
120
+ methodName , borrows )
120
121
}
121
122
}
122
123
}
0 commit comments