-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Rust: Strengthen modeling of the Clone trait
#19442
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
Conversation
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.
Pull Request Overview
This PR enhances the CodeQL model of Rust’s Clone trait by inserting implicit borrows and updating test expectations to reflect that clone dereferences its receiver, and adjusts related debug/test code.
- Updated
MyOption::clonedandClone::clonesummaries to includeReferenceon theselfargument - Adjusted expected model files and inline-flow tests to remove now-unneeded generated clone edges
- Refined the
CloneCallablemodel to only matchArgument[self].Referenceand updated a debug filter path
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/ql/test/utils-tests/modelgenerator/option.rs | Added .Reference in summaries for cloned and clone methods |
| rust/ql/test/utils-tests/modelgenerator/CaptureSummaryModels.expected | Updated expected summaries for Clone::clone; removed cloned entry |
| rust/ql/test/library-tests/dataflow/modeled/main.rs | Marked missing flow tests for clonable types due to lack of builtins |
| rust/ql/test/library-tests/dataflow/modeled/inline-flow.expected | Removed generated clone edges from inline-flow expectations |
| rust/ql/lib/codeql/rust/internal/TypeInference.qll | Changed debug filter from plugin.rs to main.rs at line 28 |
| rust/ql/lib/codeql/rust/frameworks/stdlib/Clone.qll | Restricted CloneCallable.propagatesFlow input to Argument[self].Reference |
Comments suppressed due to low confidence (1)
rust/ql/test/utils-tests/modelgenerator/CaptureSummaryModels.expected:4
- Also add an
Expected summary missingentry for the<crate::option::MyOption>::clonedmethod to mirror the updated summaries and ensure the test suite covers bothclonedandclone.
| Expected summary missing: repo::test;<crate::option::MyOption as crate::clone::Clone>::clone;Argument[self].Reference.Field[crate::option::MyOption::MySome(0)];ReturnValue.Field[crate::option::MyOption::MySome(0)];value;dfc-generated |
paldepind
left a comment
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.
Makes sense to me 👍
| sink(a); // $ hasValueFlow=12 | ||
| let b = a.clone(); | ||
| sink(b); // $ hasValueFlow=12 | ||
| sink(b); // $ MISSING: hasValueFlow=12 - lack of builtins means that we cannot resolve clone call above, and hence not insert implicit borrow |
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.
If stuff like this persists being an issue, for some reason, we could reinstate the old heuristic only in the cases where no type is inferred for a method receiver.
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.
Makes sense, though builtins should be extracted soonish.
The clone method takes a
&selfparameter, meaning that in terms of data flow it dereferences the receiver argument. Now that we have a principled way of inserting implicit borrows, it makes sense to strengthen the modeling of theClonetrait.Related, I also updated some expected flow summaries related to
clone.