Merge branch 'main' into badalloc

This commit is contained in:
Geoffrey White
2025-04-08 10:15:38 +01:00
63 changed files with 7030 additions and 778 deletions

View File

@@ -0,0 +1,6 @@
extensions:
- addsTo:
pack: codeql/rust-all
extensible: summaryModel
data:
- ["repo:https://github.com/rust-lang/futures-rs:futures-executor", "crate::local_pool::block_on", "Argument[0]", "ReturnValue", "value", "manual"]

View File

@@ -194,21 +194,11 @@ abstract class ItemNode extends Locatable {
this = result.(ImplOrTraitItemNode).getAnItemInSelfScope()
or
name = "crate" and
result =
any(CrateItemNode crate |
this = crate.getASourceFile()
or
this = crate.getModuleNode()
)
this = result.(CrateItemNode).getARootModuleNode()
or
// todo: implement properly
name = "$crate" and
result =
any(CrateItemNode crate |
this = crate.getASourceFile()
or
this = crate.getModuleNode()
).(Crate).getADependency*() and
result = any(CrateItemNode crate | this = crate.getARootModuleNode()).(Crate).getADependency*() and
result.(CrateItemNode).isPotentialDollarCrateTarget()
}
@@ -237,7 +227,7 @@ abstract private class ModuleLikeNode extends ItemNode {
predicate isRoot() {
this instanceof SourceFileItemNode
or
this = any(CrateItemNode c).getModuleNode()
this = any(Crate c).getModule()
}
}
@@ -294,6 +284,15 @@ class CrateItemNode extends ItemNode instanceof Crate {
)
}
/**
* Gets a root module node belonging to this crate.
*/
ModuleLikeNode getARootModuleNode() {
result = this.getASourceFile()
or
result = super.getModule()
}
pragma[nomagic]
predicate isPotentialDollarCrateTarget() {
exists(string name, RelevantPath p |
@@ -373,6 +372,8 @@ abstract class ImplOrTraitItemNode extends ItemNode {
/** Gets an item that may refer to this node using `Self`. */
pragma[nomagic]
ItemNode getAnItemInSelfScope() {
result = this
or
result.getImmediateParent() = this
or
exists(ItemNode mid |

View File

@@ -53,11 +53,31 @@ class TypeReprMention extends TypeMention, TypeRepr {
or
result = this.(PathTypeRepr).getPath().(PathMention).resolveType()
}
override Type resolveTypeAt(TypePath path) {
result = this.(PathTypeRepr).getPath().(PathMention).resolveTypeAt(path)
or
not exists(this.(PathTypeRepr).getPath()) and
result = super.resolveTypeAt(path)
}
}
class PathMention extends TypeMention, Path {
/** Holds if `path` resolves to the type alias `alias` with the definition `rhs`. */
private predicate resolvePathAlias(Path path, TypeAlias alias, TypeReprMention rhs) {
alias = resolvePath(path) and rhs = alias.getTypeRepr()
}
abstract class PathMention extends TypeMention, Path {
override TypeMention getTypeArgument(int i) {
result = this.getSegment().getGenericArgList().getTypeArg(i)
}
}
class NonAliasPathMention extends PathMention {
NonAliasPathMention() { not resolvePathAlias(this, _, _) }
override TypeMention getTypeArgument(int i) {
result = super.getTypeArgument(i)
or
// `Self` paths inside `impl` blocks have implicit type arguments that are
// the type parameters of the `impl` block. For example, in
@@ -98,6 +118,33 @@ class PathMention extends TypeMention, Path {
}
}
class AliasPathMention extends PathMention {
TypeAlias alias;
TypeReprMention rhs;
AliasPathMention() { resolvePathAlias(this, alias, rhs) }
/** Get the `i`th type parameter of the alias itself. */
private TypeParameter getTypeParameter(int i) {
result = TTypeParamTypeParameter(alias.getGenericParamList().getTypeParam(i))
}
override Type resolveType() { result = rhs.resolveType() }
override Type resolveTypeAt(TypePath path) {
result = rhs.resolveTypeAt(path) and
not result = this.getTypeParameter(_)
or
exists(TypeParameter tp, TypeMention arg, TypePath prefix, TypePath suffix, int i |
tp = rhs.resolveTypeAt(prefix) and
tp = this.getTypeParameter(i) and
arg = this.getTypeArgument(i) and
result = arg.resolveTypeAt(suffix) and
path = prefix.append(suffix)
)
}
}
// Used to represent implicit `Self` type arguments in traits and `impl` blocks,
// see `PathMention` for details.
class TypeParamMention extends TypeMention, TypeParam {