-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Rust: Account for borrows in operators in type inference #19789
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
Open
paldepind
wants to merge
4
commits into
github:main
Choose a base branch
from
paldepind:rust/operator-borrowing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,79 +9,80 @@ private import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl | |
|
||
/** | ||
* Holds if the operator `op` with arity `arity` is overloaded to a trait with | ||
* the canonical path `path` and the method name `method`. | ||
* the canonical path `path` and the method name `method`, and if it borrows its | ||
* first `borrows` arguments. | ||
*/ | ||
private predicate isOverloaded(string op, int arity, string path, string method) { | ||
private predicate isOverloaded(string op, int arity, string path, string method, int borrows) { | ||
arity = 1 and | ||
( | ||
// Negation | ||
op = "-" and path = "core::ops::arith::Neg" and method = "neg" | ||
op = "-" and path = "core::ops::arith::Neg" and method = "neg" and borrows = 0 | ||
or | ||
// Not | ||
op = "!" and path = "core::ops::bit::Not" and method = "not" | ||
op = "!" and path = "core::ops::bit::Not" and method = "not" and borrows = 0 | ||
or | ||
// Dereference | ||
op = "*" and path = "core::ops::deref::Deref" and method = "deref" | ||
op = "*" and path = "core::ops::deref::Deref" and method = "deref" and borrows = 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note, |
||
) | ||
or | ||
arity = 2 and | ||
( | ||
// Comparison operators | ||
op = "==" and path = "core::cmp::PartialEq" and method = "eq" | ||
op = "==" and path = "core::cmp::PartialEq" and method = "eq" and borrows = 2 | ||
or | ||
op = "!=" and path = "core::cmp::PartialEq" and method = "ne" | ||
op = "!=" and path = "core::cmp::PartialEq" and method = "ne" and borrows = 2 | ||
or | ||
op = "<" and path = "core::cmp::PartialOrd" and method = "lt" | ||
op = "<" and path = "core::cmp::PartialOrd" and method = "lt" and borrows = 2 | ||
or | ||
op = "<=" and path = "core::cmp::PartialOrd" and method = "le" | ||
op = "<=" and path = "core::cmp::PartialOrd" and method = "le" and borrows = 2 | ||
or | ||
op = ">" and path = "core::cmp::PartialOrd" and method = "gt" | ||
op = ">" and path = "core::cmp::PartialOrd" and method = "gt" and borrows = 2 | ||
or | ||
op = ">=" and path = "core::cmp::PartialOrd" and method = "ge" | ||
op = ">=" and path = "core::cmp::PartialOrd" and method = "ge" and borrows = 2 | ||
or | ||
// Arithmetic operators | ||
op = "+" and path = "core::ops::arith::Add" and method = "add" | ||
op = "+" and path = "core::ops::arith::Add" and method = "add" and borrows = 0 | ||
or | ||
op = "-" and path = "core::ops::arith::Sub" and method = "sub" | ||
op = "-" and path = "core::ops::arith::Sub" and method = "sub" and borrows = 0 | ||
or | ||
op = "*" and path = "core::ops::arith::Mul" and method = "mul" | ||
op = "*" and path = "core::ops::arith::Mul" and method = "mul" and borrows = 0 | ||
or | ||
op = "/" and path = "core::ops::arith::Div" and method = "div" | ||
op = "/" and path = "core::ops::arith::Div" and method = "div" and borrows = 0 | ||
or | ||
op = "%" and path = "core::ops::arith::Rem" and method = "rem" | ||
op = "%" and path = "core::ops::arith::Rem" and method = "rem" and borrows = 0 | ||
or | ||
// Arithmetic assignment expressions | ||
op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign" | ||
op = "+=" and path = "core::ops::arith::AddAssign" and method = "add_assign" and borrows = 1 | ||
or | ||
op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign" | ||
op = "-=" and path = "core::ops::arith::SubAssign" and method = "sub_assign" and borrows = 1 | ||
or | ||
op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign" | ||
op = "*=" and path = "core::ops::arith::MulAssign" and method = "mul_assign" and borrows = 1 | ||
or | ||
op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign" | ||
op = "/=" and path = "core::ops::arith::DivAssign" and method = "div_assign" and borrows = 1 | ||
or | ||
op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign" | ||
op = "%=" and path = "core::ops::arith::RemAssign" and method = "rem_assign" and borrows = 1 | ||
or | ||
// Bitwise operators | ||
op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand" | ||
op = "&" and path = "core::ops::bit::BitAnd" and method = "bitand" and borrows = 0 | ||
or | ||
op = "|" and path = "core::ops::bit::BitOr" and method = "bitor" | ||
op = "|" and path = "core::ops::bit::BitOr" and method = "bitor" and borrows = 0 | ||
or | ||
op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor" | ||
op = "^" and path = "core::ops::bit::BitXor" and method = "bitxor" and borrows = 0 | ||
or | ||
op = "<<" and path = "core::ops::bit::Shl" and method = "shl" | ||
op = "<<" and path = "core::ops::bit::Shl" and method = "shl" and borrows = 0 | ||
or | ||
op = ">>" and path = "core::ops::bit::Shr" and method = "shr" | ||
op = ">>" and path = "core::ops::bit::Shr" and method = "shr" and borrows = 0 | ||
or | ||
// Bitwise assignment operators | ||
op = "&=" and path = "core::ops::bit::BitAndAssign" and method = "bitand_assign" | ||
op = "&=" and path = "core::ops::bit::BitAndAssign" and method = "bitand_assign" and borrows = 1 | ||
or | ||
op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign" | ||
op = "|=" and path = "core::ops::bit::BitOrAssign" and method = "bitor_assign" and borrows = 1 | ||
or | ||
op = "^=" and path = "core::ops::bit::BitXorAssign" and method = "bitxor_assign" | ||
op = "^=" and path = "core::ops::bit::BitXorAssign" and method = "bitxor_assign" and borrows = 1 | ||
or | ||
op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign" | ||
op = "<<=" and path = "core::ops::bit::ShlAssign" and method = "shl_assign" and borrows = 1 | ||
or | ||
op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign" | ||
op = ">>=" and path = "core::ops::bit::ShrAssign" and method = "shr_assign" and borrows = 1 | ||
) | ||
} | ||
|
||
|
@@ -114,9 +115,9 @@ module Impl { | |
* Holds if this operation is overloaded to the method `methodName` of the | ||
* trait `trait`. | ||
*/ | ||
predicate isOverloaded(Trait trait, string methodName) { | ||
predicate isOverloaded(Trait trait, string methodName, int borrows) { | ||
isOverloaded(this.getOperatorName(), this.getNumberOfOperands(), trait.getCanonicalPath(), | ||
methodName) | ||
methodName, borrows) | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider extracting
TArgumentPosition
and theArgumentPosition
class into their own file (e.g.,ArgumentPosition.qll
) to improve modularity and reduce the size ofCallImpl.qll
.Copilot uses AI. Check for mistakes.