File tree 6 files changed +948
-954
lines changed
codeql/rust/elements/internal
test/library-tests/type-inference
6 files changed +948
-954
lines changed Original file line number Diff line number Diff line change 5
5
*/
6
6
7
7
private import codeql.rust.elements.internal.generated.Function
8
+ private import codeql.rust.elements.Comment
8
9
9
10
/**
10
11
* INTERNAL: This module contains the customizable definition of `Function` and should not
@@ -26,5 +27,22 @@ module Impl {
26
27
*/
27
28
class Function extends Generated:: Function {
28
29
override string toStringImpl ( ) { result = "fn " + this .getName ( ) .getText ( ) }
30
+
31
+ /**
32
+ * Gets a comment preceding this function.
33
+ *
34
+ * A comment is considered preceding if it occurs immediately before this
35
+ * function or if only other comments occur between the comment and this
36
+ * function.
37
+ */
38
+ Comment getPrecedingComment ( ) {
39
+ result .getLocation ( ) .getFile ( ) = this .getLocation ( ) .getFile ( ) and
40
+ // When a function is preceded by comments its start line is the line of
41
+ // the first comment. Hence all relevant comments are found by including
42
+ // comments from the start line and up to the line with the function
43
+ // name.
44
+ this .getLocation ( ) .getStartLine ( ) <= result .getLocation ( ) .getStartLine ( ) and
45
+ result .getLocation ( ) .getStartLine ( ) <= this .getName ( ) .getLocation ( ) .getStartLine ( )
46
+ }
29
47
}
30
48
}
Original file line number Diff line number Diff line change @@ -5,16 +5,7 @@ private module InlineMadTestLang implements InlineMadTestLangSig {
5
5
class Callable = R:: Function ;
6
6
7
7
string getComment ( R:: Function callable ) {
8
- exists ( R:: Comment comment |
9
- result = comment .getCommentText ( ) and
10
- comment .getLocation ( ) .getFile ( ) = callable .getLocation ( ) .getFile ( ) and
11
- // When a function is preceded by comments its start line is the line of
12
- // the first comment. Hence all relevant comments are found by including
13
- // comments from the start line and up to the line with the function
14
- // name.
15
- callable .getLocation ( ) .getStartLine ( ) <= comment .getLocation ( ) .getStartLine ( ) and
16
- comment .getLocation ( ) .getStartLine ( ) <= callable .getName ( ) .getLocation ( ) .getStartLine ( )
17
- )
8
+ result = callable .getPrecedingComment ( ) .getCommentText ( )
18
9
}
19
10
}
20
11
Original file line number Diff line number Diff line change @@ -9,6 +9,6 @@ trait T1<T>: T2<S<T>> {
9
9
10
10
trait T2 < T > : T1 < S < T > > {
11
11
fn bar ( self ) {
12
- self . foo ( )
12
+ self . foo ( ) // $ method=foo
13
13
}
14
14
}
You can’t perform that action at this time.
0 commit comments