mirror of
https://github.com/github/codeql.git
synced 2026-02-11 20:51:06 +01:00
Rust: Minor tweaks in type inference
This commit is contained in:
@@ -20,12 +20,11 @@ final class AssocType extends TypeAlias {
|
||||
}
|
||||
|
||||
/** Gets an associated type of `trait` or of a supertrait of `trait`. */
|
||||
AssocType getTraitAssocType(Trait trait) {
|
||||
result.getTrait() = trait.getSupertrait*()
|
||||
}
|
||||
AssocType getTraitAssocType(Trait trait) { result.getTrait() = trait.getSupertrait*() }
|
||||
|
||||
/** Holds if `path` is of the form `<type as trait>::name` */
|
||||
predicate asTraitPath(Path path, TypeRepr typeRepr, Path traitPath, string name) {
|
||||
pragma[nomagic]
|
||||
predicate pathTypeAsTraitAssoc(Path path, TypeRepr typeRepr, Path traitPath, string name) {
|
||||
exists(PathSegment segment |
|
||||
segment = path.getQualifier().getSegment() and
|
||||
typeRepr = segment.getTypeRepr() and
|
||||
@@ -45,8 +44,8 @@ predicate tpAssociatedType(TypeParam tp, AssocType assoc, Path path) {
|
||||
resolvePath(path) = assoc
|
||||
or
|
||||
exists(PathTypeRepr typeRepr, Path traitPath, string name |
|
||||
asTraitPath(path, typeRepr, traitPath, name) and
|
||||
tp = resolvePath(typeRepr.(PathTypeRepr).getPath()) and
|
||||
pathTypeAsTraitAssoc(path, typeRepr, traitPath, name) and
|
||||
tp = resolvePath(typeRepr.getPath()) and
|
||||
assoc = resolvePath(traitPath).(TraitItemNode).getAssocItem(name)
|
||||
)
|
||||
}
|
||||
@@ -8,7 +8,7 @@ private import codeql.rust.elements.internal.generated.Raw
|
||||
private import codeql.rust.elements.internal.generated.Synth
|
||||
private import codeql.rust.frameworks.stdlib.Stdlib
|
||||
private import codeql.rust.frameworks.stdlib.Builtins as Builtins
|
||||
private import AssociatedTypes
|
||||
private import AssociatedType
|
||||
|
||||
/**
|
||||
* Holds if a dyn trait type for the trait `trait` should have a type parameter
|
||||
|
||||
@@ -6,7 +6,7 @@ private import codeql.rust.frameworks.stdlib.Stdlib
|
||||
private import Type
|
||||
private import TypeAbstraction
|
||||
private import TypeInference
|
||||
private import AssociatedTypes
|
||||
private import AssociatedType
|
||||
|
||||
bindingset[trait, name]
|
||||
pragma[inline_late]
|
||||
@@ -390,7 +390,7 @@ private module MkTypeMention<getAdditionalPathTypeAtSig/2 getAdditionalPathTypeA
|
||||
// Handles paths of the form `Self::AssocType` within a trait block
|
||||
result = TAssociatedTypeTypeParameter(resolvePath(this.getQualifier()), resolved)
|
||||
or
|
||||
result.(TypeParamAssociatedTypeTypeParameter).getPath() = this
|
||||
result.(TypeParamAssociatedTypeTypeParameter).getAPath() = this
|
||||
}
|
||||
|
||||
override Type resolvePathTypeAt(TypePath typePath) {
|
||||
@@ -710,7 +710,7 @@ private predicate pathConcreteTypeAssocType(
|
||||
// path of the form `<Type as Trait>::AssocType`
|
||||
// ^^^ tm ^^^^^^^^^ name
|
||||
exists(string name, Path traitPath |
|
||||
asTraitPath(path, tm, traitPath, name) and
|
||||
pathTypeAsTraitAssoc(path, tm, traitPath, name) and
|
||||
trait = resolvePath(traitPath) and
|
||||
getTraitAssocType(trait, name) = alias
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user