Skip to content

Commit 3a157b7

Browse files
committed
Rust: Move isOverloaded predicate inside Impl module
1 parent 2bfb8d4 commit 3a157b7

File tree

2 files changed

+86
-80
lines changed

2 files changed

+86
-80
lines changed

rust/ql/lib/codeql/rust/elements/internal/OperationImpl.qll

Lines changed: 85 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,90 +7,96 @@
77
private import rust
88
private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl
99

10-
/**
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`, and if it borrows its
13-
* first `borrows` arguments.
14-
*/
15-
predicate isOverloaded(string op, int arity, string path, string method, int borrows) {
16-
arity = 1 and
17-
(
18-
// Negation
19-
op = "-" and path = "core::ops::arith::Neg" and method = "neg" and borrows = 0
20-
or
21-
// Not
22-
op = "!" and path = "core::ops::bit::Not" and method = "not" and borrows = 0
23-
or
24-
// Dereference
25-
op = "*" and path = "core::ops::deref::Deref" and method = "deref" and borrows = 1
26-
)
27-
or
28-
arity = 2 and
29-
(
30-
// Comparison operators
31-
op = "==" and path = "core::cmp::PartialEq" and method = "eq" and borrows = 2
32-
or
33-
op = "!=" and path = "core::cmp::PartialEq" and method = "ne" and borrows = 2
34-
or
35-
op = "<" and path = "core::cmp::PartialOrd" and method = "lt" and borrows = 2
36-
or
37-
op = "<=" and path = "core::cmp::PartialOrd" and method = "le" and borrows = 2
38-
or
39-
op = ">" and path = "core::cmp::PartialOrd" and method = "gt" and borrows = 2
40-
or
41-
op = ">=" and path = "core::cmp::PartialOrd" and method = "ge" and borrows = 2
42-
or
43-
// Arithmetic operators
44-
op = "+" and path = "core::ops::arith::Add" and method = "add" and borrows = 0
45-
or
46-
op = "-" and path = "core::ops::arith::Sub" and method = "sub" and borrows = 0
47-
or
48-
op = "*" and path = "core::ops::arith::Mul" and method = "mul" and borrows = 0
49-
or
50-
op = "/" and path = "core::ops::arith::Div" and method = "div" and borrows = 0
51-
or
52-
op = "%" and path = "core::ops::arith::Rem" and method = "rem" and borrows = 0
53-
or
54-
// Arithmetic assignment expressions
55-
op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign" and borrows = 1
56-
or
57-
op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign" and borrows = 1
58-
or
59-
op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign" and borrows = 1
60-
or
61-
op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign" and borrows = 1
62-
or
63-
op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign" and borrows = 1
64-
or
65-
// Bitwise operators
66-
op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand" and borrows = 0
67-
or
68-
op = "|" and path = "core::ops::bit::BitOr" and method = "bitor" and borrows = 0
69-
or
70-
op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor" and borrows = 0
71-
or
72-
op = "<<" and path = "core::ops::bit::Shl" and method = "shl" and borrows = 0
73-
or
74-
op = ">>" and path = "core::ops::bit::Shr" and method = "shr" and borrows = 0
75-
or
76-
// Bitwise assignment operators
77-
op = "&=" and path = "core::ops::bit::BitAndAssign" and method = "bitand_assign" and borrows = 1
78-
or
79-
op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign" and borrows = 1
80-
or
81-
op = "^=" and path = "core::ops::bit::BitXorAssign" and method = "bitxor_assign" and borrows = 1
82-
or
83-
op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign" and borrows = 1
84-
or
85-
op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign" and borrows = 1
86-
)
87-
}
88-
8910
/**
9011
* INTERNAL: This module contains the customizable definition of `Operation` and should not
9112
* be referenced directly.
9213
*/
9314
module Impl {
15+
/**
16+
* Holds if the operator `op` with arity `arity` is overloaded to a trait with
17+
* the canonical path `path` and the method name `method`, and if it borrows its
18+
* first `borrows` arguments.
19+
*/
20+
predicate isOverloaded(string op, int arity, string path, string method, int borrows) {
21+
arity = 1 and
22+
(
23+
// Negation
24+
op = "-" and path = "core::ops::arith::Neg" and method = "neg" and borrows = 0
25+
or
26+
// Not
27+
op = "!" and path = "core::ops::bit::Not" and method = "not" and borrows = 0
28+
or
29+
// Dereference
30+
op = "*" and path = "core::ops::deref::Deref" and method = "deref" and borrows = 1
31+
)
32+
or
33+
arity = 2 and
34+
(
35+
// Comparison operators
36+
op = "==" and path = "core::cmp::PartialEq" and method = "eq" and borrows = 2
37+
or
38+
op = "!=" and path = "core::cmp::PartialEq" and method = "ne" and borrows = 2
39+
or
40+
op = "<" and path = "core::cmp::PartialOrd" and method = "lt" and borrows = 2
41+
or
42+
op = "<=" and path = "core::cmp::PartialOrd" and method = "le" and borrows = 2
43+
or
44+
op = ">" and path = "core::cmp::PartialOrd" and method = "gt" and borrows = 2
45+
or
46+
op = ">=" and path = "core::cmp::PartialOrd" and method = "ge" and borrows = 2
47+
or
48+
// Arithmetic operators
49+
op = "+" and path = "core::ops::arith::Add" and method = "add" and borrows = 0
50+
or
51+
op = "-" and path = "core::ops::arith::Sub" and method = "sub" and borrows = 0
52+
or
53+
op = "*" and path = "core::ops::arith::Mul" and method = "mul" and borrows = 0
54+
or
55+
op = "/" and path = "core::ops::arith::Div" and method = "div" and borrows = 0
56+
or
57+
op = "%" and path = "core::ops::arith::Rem" and method = "rem" and borrows = 0
58+
or
59+
// Arithmetic assignment expressions
60+
op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign" and borrows = 1
61+
or
62+
op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign" and borrows = 1
63+
or
64+
op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign" and borrows = 1
65+
or
66+
op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign" and borrows = 1
67+
or
68+
op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign" and borrows = 1
69+
or
70+
// Bitwise operators
71+
op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand" and borrows = 0
72+
or
73+
op = "|" and path = "core::ops::bit::BitOr" and method = "bitor" and borrows = 0
74+
or
75+
op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor" and borrows = 0
76+
or
77+
op = "<<" and path = "core::ops::bit::Shl" and method = "shl" and borrows = 0
78+
or
79+
op = ">>" and path = "core::ops::bit::Shr" and method = "shr" and borrows = 0
80+
or
81+
// Bitwise assignment operators
82+
op = "&=" and
83+
path = "core::ops::bit::BitAndAssign" and
84+
method = "bitand_assign" and
85+
borrows = 1
86+
or
87+
op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign" and borrows = 1
88+
or
89+
op = "^=" and
90+
path = "core::ops::bit::BitXorAssign" and
91+
method = "bitxor_assign" and
92+
borrows = 1
93+
or
94+
op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign" and borrows = 1
95+
or
96+
op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign" and borrows = 1
97+
)
98+
}
99+
94100
/**
95101
* An operation, for example `&&`, `+=`, `!` or `*`.
96102
*/

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@ private predicate inferNonMethodCallType =
27552755
* A matching configuration for resolving types of operations like `a + b`.
27562756
*/
27572757
private module OperationMatchingInput implements MatchingInputSig {
2758-
private import codeql.rust.elements.internal.OperationImpl as OperationImpl
2758+
private import codeql.rust.elements.internal.OperationImpl::Impl as OperationImpl
27592759
import FunctionPositionMatchingInput
27602760

27612761
class Declaration extends MethodCallMatchingInput::Declaration {

0 commit comments

Comments
 (0)