Skip to content

Commit f45d2d5

Browse files
committed
temp
1 parent 7a7a127 commit f45d2d5

File tree

7 files changed

+63
-23
lines changed

7 files changed

+63
-23
lines changed

rust/ql/lib/codeql/rust/dataflow/internal/DataFlowImpl.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ final class DataFlowCallable extends TDataFlowCallable {
5353
}
5454

5555
/** Gets the location of this callable. */
56-
Location getLocation() { result = this.asCfgScope().getLocation() }
56+
Location getLocation() {
57+
result = [this.asCfgScope().getLocation(), this.asSummarizedCallable().getLocation()]
58+
}
5759
}
5860

5961
final class DataFlowCall extends TDataFlowCall {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ module Impl {
2121
* ```
2222
*/
2323
class Union extends Generated::Union {
24+
/** Gets the record field named `name`, if any. */
25+
pragma[nomagic]
26+
StructField getStructField(string name) {
27+
result = this.getStructFieldList().getAField() and
28+
result.getName().getText() = name
29+
}
30+
2431
override string toStringImpl() { result = "union " + this.getName().getText() }
2532
}
2633
}

rust/ql/lib/codeql/rust/internal/Type.qll

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ newtype TType =
4242
TStruct(Struct s) or
4343
TEnum(Enum e) or
4444
TTrait(Trait t) or
45+
TUnion(Union u) or
4546
TArrayType() or // todo: add size?
4647
TRefType() or // todo: add mut?
4748
TImplTraitType(ImplTraitTypeRepr impl) or
@@ -227,6 +228,31 @@ class TraitType extends Type, TTrait {
227228
override Location getLocation() { result = trait.getLocation() }
228229
}
229230

231+
/** A union type. */
232+
class UnionType extends StructOrEnumType, TUnion {
233+
private Union union;
234+
235+
UnionType() { this = TUnion(union) }
236+
237+
override ItemNode asItemNode() { result = union }
238+
239+
override StructField getStructField(string name) { result = union.getStructField(name) }
240+
241+
override TupleField getTupleField(int i) { none() }
242+
243+
override TypeParameter getPositionalTypeParameter(int i) {
244+
result = TTypeParamTypeParameter(union.getGenericParamList().getTypeParam(i))
245+
}
246+
247+
override TypeMention getTypeParameterDefault(int i) {
248+
result = union.getGenericParamList().getTypeParam(i).getDefaultType()
249+
}
250+
251+
override string toString() { result = union.getName().getText() }
252+
253+
override Location getLocation() { result = union.getLocation() }
254+
}
255+
230256
/**
231257
* An array type.
232258
*

rust/ql/lib/codeql/rust/internal/TypeInference.qll

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -960,14 +960,14 @@ private newtype TSelfParamType =
960960
* }
961961
* ```
962962
*
963-
* param | `impl` or trait | type
964-
* -- | -- | --
965-
* `self1` | `trait T1` | `T1`
966-
* `self1` | `trait T2` | `T2`
967-
* `self2` | `trait T1` | `T1`
968-
* `self2` | `trait T2` | `T2`
963+
* param | `impl` or trait | type
964+
* ------- | --------------- | --
965+
* `self1` | `trait T1` | `T1`
966+
* `self1` | `trait T2` | `T2`
967+
* `self2` | `trait T1` | `T1`
968+
* `self2` | `trait T2` | `T2`
969969
* `self2` | `impl T2 for X` | `X`
970-
* `self3` | `trait T2` | `T2`
970+
* `self3` | `trait T2` | `T2`
971971
* `self4` | `impl T2 for X` | `X`
972972
* `self5` | `impl T2 for X` | `X`
973973
*/
@@ -1139,6 +1139,7 @@ private module MethodCallResolution {
11391139
result = this.getACandidateReceiverTypeAtNoBorrow(path, derefChain) and
11401140
exists(Type rootType, string name, int arity, string derefChainBorrow |
11411141
derefChainBorrow = derefChain + ";" and
1142+
not derefChain.matches("%.ref") and // no need to try a borrow if the last thing we did was a deref
11421143
this.isMethodCall0(rootType, name, arity, derefChainBorrow)
11431144
|
11441145
forall(Impl impl, SelfParamType self | methodCandidate(rootType, name, arity, impl, self) |
@@ -1435,7 +1436,7 @@ private module MethodCallMatchingInput implements MatchingWithStateInputSig {
14351436

14361437
final private class MethodCallFinal = MethodCallResolution::MethodCall;
14371438

1438-
final class Access extends MethodCallFinal {
1439+
class Access extends MethodCallFinal {
14391440
pragma[nomagic]
14401441
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
14411442
exists(TypeMention arg |
@@ -1853,7 +1854,7 @@ private module CallExprMatchingInput implements MatchingInputSig {
18531854

18541855
class AccessPosition = DeclarationPosition;
18551856

1856-
final class Access extends FunctionCallResolution::FunctionCall {
1857+
class Access extends FunctionCallResolution::FunctionCall {
18571858
pragma[nomagic]
18581859
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) {
18591860
exists(TypeMention arg | result = arg.resolveTypeAt(path) |
@@ -2074,7 +2075,7 @@ private module OperationMatchingInput implements MatchingInputSig {
20742075

20752076
class AccessPosition = MethodCallMatchingInput::AccessPosition;
20762077

2077-
final class Access extends OperationResolution::Op {
2078+
class Access extends OperationResolution::Op {
20782079
Type getTypeArgument(TypeArgumentPosition apos, TypePath path) { none() }
20792080

20802081
AstNode getNodeAt(AccessPosition apos) {

rust/ql/lib/codeql/rust/internal/TypeMention.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ class NonAliasPathTypeMention extends PathTypeMention {
242242
else result = TTrait(trait)
243243
)
244244
or
245+
result = TUnion(resolved)
246+
or
245247
result = TTypeParamTypeParameter(resolved)
246248
or
247249
result = TAssociatedTypeTypeParameter(resolved)

rust/ql/test/library-tests/dataflow/global/viableCallable.expected

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
| main.rs:13:5:13:13 | source(...) | main.rs:1:1:3:1 | fn source |
22
| main.rs:17:13:17:23 | get_data(...) | main.rs:12:1:14:1 | fn get_data |
33
| main.rs:18:5:18:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
4-
| main.rs:27:10:27:14 | * ... | file://:0:0:0:0 | fn deref |
5-
| main.rs:27:10:27:14 | * ... | file://:0:0:0:0 | fn deref |
6-
| main.rs:31:10:31:14 | * ... | file://:0:0:0:0 | fn deref |
7-
| main.rs:31:10:31:14 | * ... | file://:0:0:0:0 | fn deref |
4+
| main.rs:27:10:27:14 | * ... | {EXTERNAL LOCATION} | fn deref |
5+
| main.rs:27:10:27:14 | * ... | {EXTERNAL LOCATION} | fn deref |
6+
| main.rs:31:10:31:14 | * ... | {EXTERNAL LOCATION} | fn deref |
7+
| main.rs:31:10:31:14 | * ... | {EXTERNAL LOCATION} | fn deref |
88
| main.rs:37:5:37:22 | sink(...) | main.rs:5:1:7:1 | fn sink |
99
| main.rs:37:10:37:21 | a.get_data() | main.rs:30:5:32:5 | fn get_data |
1010
| main.rs:38:5:38:32 | ... .set_data(...) | main.rs:26:5:28:5 | fn set_data |
@@ -63,10 +63,10 @@
6363
| main.rs:212:13:212:34 | ...::new(...) | main.rs:205:5:208:5 | fn new |
6464
| main.rs:212:24:212:33 | source(...) | main.rs:1:1:3:1 | fn source |
6565
| main.rs:214:5:214:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
66-
| main.rs:228:10:228:14 | * ... | file://:0:0:0:0 | fn deref |
67-
| main.rs:228:10:228:14 | * ... | file://:0:0:0:0 | fn deref |
68-
| main.rs:236:11:236:15 | * ... | file://:0:0:0:0 | fn deref |
69-
| main.rs:236:11:236:15 | * ... | file://:0:0:0:0 | fn deref |
66+
| main.rs:228:10:228:14 | * ... | {EXTERNAL LOCATION} | fn deref |
67+
| main.rs:228:10:228:14 | * ... | {EXTERNAL LOCATION} | fn deref |
68+
| main.rs:236:11:236:15 | * ... | {EXTERNAL LOCATION} | fn deref |
69+
| main.rs:236:11:236:15 | * ... | {EXTERNAL LOCATION} | fn deref |
7070
| main.rs:242:28:242:36 | source(...) | main.rs:1:1:3:1 | fn source |
7171
| main.rs:244:13:244:17 | ... + ... | main.rs:220:5:223:5 | fn add |
7272
| main.rs:245:5:245:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
@@ -83,8 +83,8 @@
8383
| main.rs:266:5:266:10 | ... *= ... | main.rs:227:5:229:5 | fn mul_assign |
8484
| main.rs:267:5:267:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
8585
| main.rs:270:28:270:37 | source(...) | main.rs:1:1:3:1 | fn source |
86-
| main.rs:272:13:272:29 | * ... | file://:0:0:0:0 | fn deref |
87-
| main.rs:272:13:272:29 | * ... | file://:0:0:0:0 | fn deref |
86+
| main.rs:272:13:272:29 | * ... | {EXTERNAL LOCATION} | fn deref |
87+
| main.rs:272:13:272:29 | * ... | {EXTERNAL LOCATION} | fn deref |
8888
| main.rs:272:14:272:29 | ...::deref(...) | main.rs:235:5:237:5 | fn deref |
8989
| main.rs:273:5:273:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
9090
| main.rs:275:28:275:37 | source(...) | main.rs:1:1:3:1 | fn source |
@@ -106,10 +106,10 @@
106106
| main.rs:326:17:326:25 | source(...) | main.rs:1:1:3:1 | fn source |
107107
| main.rs:327:9:327:15 | sink(...) | main.rs:5:1:7:1 | fn sink |
108108
| main.rs:330:5:330:17 | sink(...) | main.rs:5:1:7:1 | fn sink |
109-
| main.rs:334:13:334:55 | ...::block_on(...) | file://:0:0:0:0 | fn block_on |
109+
| main.rs:334:13:334:55 | ...::block_on(...) | {EXTERNAL LOCATION} | fn block_on |
110110
| main.rs:334:41:334:54 | async_source(...) | main.rs:315:1:319:1 | fn async_source |
111111
| main.rs:335:5:335:11 | sink(...) | main.rs:5:1:7:1 | fn sink |
112-
| main.rs:337:5:337:62 | ...::block_on(...) | file://:0:0:0:0 | fn block_on |
112+
| main.rs:337:5:337:62 | ...::block_on(...) | {EXTERNAL LOCATION} | fn block_on |
113113
| main.rs:337:33:337:61 | test_async_await_async_part(...) | main.rs:321:1:331:1 | fn test_async_await_async_part |
114114
| main.rs:341:5:341:22 | data_out_of_call(...) | main.rs:16:1:19:1 | fn data_out_of_call |
115115
| main.rs:342:5:342:35 | data_out_of_call_side_effect1(...) | main.rs:35:1:40:1 | fn data_out_of_call_side_effect1 |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
query: viableCallable.ql
2+
postprocess: utils/test/ExternalLocationPostProcessing.ql

0 commit comments

Comments
 (0)