Skip to content

Commit 0b9321f

Browse files
committed
Fix copilot implementation
1 parent ad51b61 commit 0b9321f

File tree

9 files changed

+29
-45
lines changed

9 files changed

+29
-45
lines changed

rust/ql/.generated.list

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/.gitattributes

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/ql/lib/codeql/rust/elements/Const.qll

Lines changed: 0 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This module provides the public class `ConstAccess`.
3+
*/
4+
5+
private import internal.ConstImpl
6+
7+
final class ConstAccess = Impl::ConstAccess;

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
// generated by codegen, remove this comment if you wish to edit this file
21
/**
32
* This module provides a hand-modifiable wrapper around the generated class `Const`.
43
*
54
* INTERNAL: Do not use.
65
*/
76

87
private import codeql.rust.elements.internal.generated.Const
9-
private import codeql.rust.elements.PathExpr
10-
private import codeql.rust.elements.internal.PathExprBaseImpl::Impl as PathExprBaseImpl
8+
private import codeql.rust.elements.internal.PathExprImpl::Impl as PathExprImpl
119
private import codeql.rust.internal.PathResolution
1210

1311
/**
1412
* INTERNAL: This module contains the customizable definition of `Const` and should not
1513
* be referenced directly.
1614
*/
1715
module Impl {
16+
// the following QLdoc is generated: if you need to edit it, do it in the schema file
1817
/**
1918
* A constant item declaration.
2019
*
@@ -37,21 +36,14 @@ module Impl {
3736
* }
3837
* ```
3938
*/
40-
class ConstAccess extends PathExprBaseImpl::PathExprBase {
39+
class ConstAccess extends PathExprImpl::PathExpr {
4140
private Const c;
4241

43-
ConstAccess() {
44-
exists(PathExpr pe |
45-
pe = this and
46-
c = resolvePath(pe.getPath())
47-
)
48-
}
42+
ConstAccess() { c = resolvePath(this.getPath()) }
4943

5044
/** Gets the constant being accessed. */
5145
Const getConst() { result = c }
5246

53-
override string toStringImpl() { result = c.getName().getText() }
54-
5547
override string getAPrimaryQlClass() { result = "ConstAccess" }
5648
}
5749
}

rust/ql/lib/rust.qll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import codeql.rust.elements.ArithmeticOperation
99
import codeql.rust.elements.AssignmentOperation
1010
import codeql.rust.elements.BitwiseOperation
1111
import codeql.rust.elements.ComparisonOperation
12+
import codeql.rust.elements.ConstAccess
1213
import codeql.rust.elements.DerefExpr
1314
import codeql.rust.elements.LiteralExprExt
1415
import codeql.rust.elements.LogicalOperation

rust/ql/test/library-tests/const_access/Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
testFailures
2+
constAccess
3+
| main.rs:17:13:17:24 | GLOBAL_CONST | main.rs:1:1:1:29 | Const |
4+
| main.rs:19:13:19:24 | STRING_CONST | main.rs:2:1:2:35 | Const |
5+
| main.rs:21:13:21:33 | ...::ASSOC_CONST | main.rs:9:5:9:33 | Const |
6+
| main.rs:23:13:23:35 | ...::MODULE_CONST | main.rs:13:5:13:38 | Const |
7+
| main.rs:25:8:25:19 | GLOBAL_CONST | main.rs:1:1:1:29 | Const |
8+
| main.rs:29:16:29:36 | ...::ASSOC_CONST | main.rs:9:5:9:33 | Const |

rust/ql/test/library-tests/const_access/main.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,19 @@ mod my_module {
1414
}
1515

1616
fn use_consts() {
17-
// $ const_access=GLOBAL_CONST
18-
let x = GLOBAL_CONST;
19-
// $ const_access=GLOBAL_CONST
20-
println!("{}", GLOBAL_CONST);
17+
let x = GLOBAL_CONST; // $ const_access=GLOBAL_CONST
2118

22-
// $ const_access=STRING_CONST
23-
let s = STRING_CONST;
19+
let s = STRING_CONST; // $ const_access=STRING_CONST
2420

25-
// $ const_access=ASSOC_CONST
26-
let y = MyStruct::ASSOC_CONST;
21+
let y = MyStruct::ASSOC_CONST; // $ const_access=ASSOC_CONST
2722

28-
// $ const_access=MODULE_CONST
29-
let z = my_module::MODULE_CONST;
23+
let z = my_module::MODULE_CONST; // $ const_access=MODULE_CONST
3024

31-
// $ const_access=GLOBAL_CONST
32-
if GLOBAL_CONST > 0 {
25+
if GLOBAL_CONST > 0 { // $ const_access=GLOBAL_CONST
3326
println!("positive");
3427
}
3528

36-
// $ const_access=ASSOC_CONST
37-
let arr = [MyStruct::ASSOC_CONST; 5];
29+
let arr = [MyStruct::ASSOC_CONST; 5]; // $ const_access=ASSOC_CONST
3830
}
3931

4032
fn main() {

0 commit comments

Comments
 (0)