mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Rust: Fix bad join
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
* INTERNAL: Do not use.
|
||||
*/
|
||||
|
||||
private import codeql.files.FileSystem
|
||||
private import codeql.rust.elements.internal.generated.Function
|
||||
private import codeql.rust.elements.Comment
|
||||
|
||||
@@ -28,6 +29,30 @@ module Impl {
|
||||
class Function extends Generated::Function {
|
||||
override string toStringImpl() { result = "fn " + this.getName().getText() }
|
||||
|
||||
pragma[nomagic]
|
||||
private predicate hasPotentialCommentAt(File f, int line) {
|
||||
f = this.getLocation().getFile() and
|
||||
// When a function is preceded by comments its start line is the line of
|
||||
// the first comment. Hence all relevant comments are found by including
|
||||
// comments from the start line and up to the line with the function
|
||||
// name.
|
||||
line in [this.getLocation().getStartLine() .. this.getName().getLocation().getStartLine()]
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a comment preceding this function.
|
||||
*
|
||||
* A comment is considered preceding if it occurs immediately before this
|
||||
* function or if only other comments occur between the comment and this
|
||||
* function.
|
||||
*/
|
||||
Comment getAPrecedingComment() {
|
||||
exists(File f, int line |
|
||||
this.hasPotentialCommentAt(f, line) and
|
||||
result.getLocation().hasLocationFileInfo(f, line, _, _, _)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a comment preceding this function.
|
||||
*
|
||||
|
||||
@@ -5,7 +5,7 @@ private module InlineMadTestLang implements InlineMadTestLangSig {
|
||||
class Callable = R::Function;
|
||||
|
||||
string getComment(R::Function callable) {
|
||||
result = callable.getPrecedingComment().getCommentText()
|
||||
result = callable.getAPrecedingComment().getCommentText()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ module ResolveTest implements TestSig {
|
||||
string getARelevantTag() { result = ["method", "fieldof"] }
|
||||
|
||||
private predicate functionHasValue(Function f, string value) {
|
||||
f.getPrecedingComment().getCommentText() = value
|
||||
f.getAPrecedingComment().getCommentText() = value
|
||||
or
|
||||
not exists(f.getPrecedingComment()) and
|
||||
not exists(f.getAPrecedingComment()) and
|
||||
value = f.getName().getText()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user