Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions rust/ql/lib/codeql/rust/internal/PathResolution.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1202,18 +1202,21 @@ final class TypeParamItemNode extends NamedItemNode, TypeItemNode instanceof Typ
}

pragma[nomagic]
Path getABoundPath() { result = this.getTypeBoundAt(_, _).getTypeRepr().(PathTypeRepr).getPath() }

pragma[nomagic]
ItemNode resolveBound(int index) {
Path getBoundPath(int index) {
result =
rank[index + 1](int i, int j |
|
resolvePath(this.getTypeBoundAt(i, j).getTypeRepr().(PathTypeRepr).getPath()) order by i, j
this.getTypeBoundAt(i, j).getTypeRepr().(PathTypeRepr).getPath() order by i, j
)
}

ItemNode resolveABound() { result = resolvePath(this.getABoundPath()) }
pragma[nomagic]
Path getABoundPath() { result = this.getBoundPath(_) }

pragma[nomagic]
ItemNode resolveBound(int index) { result = resolvePath(this.getBoundPath(index)) }

ItemNode resolveABound() { result = this.resolveBound(_) }

pragma[nomagic]
ItemNode resolveAdditionalBound(ItemNode constrainingItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ private import TypeInference
* Holds if `traitBound` is the first non-trivial trait bound of `tp`.
*/
pragma[nomagic]
private predicate hasFirstNonTrivialTraitBound(TypeParamItemNode tp, Trait traitBound) {
private predicate hasFirstNonTrivialTraitBound(TypeParamItemNode tp, Path traitBound) {
traitBound =
min(Trait trait, int i |
trait = tp.resolveBound(i) and
min(Trait trait, Path path, int i |
path = tp.getBoundPath(i) and
trait = resolvePath(path) and
// Exclude traits that are known to not narrow things down very much.
not trait.getName().getText() =
[
Expand All @@ -27,7 +28,7 @@ private predicate hasFirstNonTrivialTraitBound(TypeParamItemNode tp, Trait trait
"Send", "Sync", "Unpin", "UnwindSafe", "RefUnwindSafe"
]
|
trait order by i
path order by i
)
}

Expand Down Expand Up @@ -103,11 +104,11 @@ module SatisfiesBlanketConstraint<
}

private module SatisfiesBlanketConstraintInput implements
SatisfiesTypeInputSig<ArgumentTypeAndBlanketOffset>
SatisfiesConstraintInputSig<ArgumentTypeAndBlanketOffset, TypeMention>
{
pragma[nomagic]
additional predicate relevantConstraint(
ArgumentTypeAndBlanketOffset ato, ImplItemNode impl, Trait traitBound
ArgumentTypeAndBlanketOffset ato, ImplItemNode impl, Path traitBound
) {
exists(ArgumentType at, TypePath blanketPath, TypeParam blanketTypeParam |
ato = MkArgumentTypeAndBlanketOffset(at, blanketPath) and
Expand All @@ -117,24 +118,24 @@ module SatisfiesBlanketConstraint<
}

pragma[nomagic]
predicate relevantConstraint(ArgumentTypeAndBlanketOffset ato, Type constraint) {
relevantConstraint(ato, _, constraint.(TraitType).getTrait())
predicate relevantConstraint(ArgumentTypeAndBlanketOffset ato, TypeMention constraint) {
relevantConstraint(ato, _, constraint)
}
}

private module SatisfiesBlanketConstraint =
SatisfiesType<ArgumentTypeAndBlanketOffset, SatisfiesBlanketConstraintInput>;
SatisfiesConstraint<ArgumentTypeAndBlanketOffset, TypeMention, SatisfiesBlanketConstraintInput>;

/**
* Holds if the argument type `at` satisfies the first non-trivial blanket
* constraint of `impl`, or if there are no non-trivial constraints of `impl`.
*/
pragma[nomagic]
predicate satisfiesBlanketConstraint(ArgumentType at, ImplItemNode impl) {
exists(ArgumentTypeAndBlanketOffset ato, Trait traitBound |
exists(ArgumentTypeAndBlanketOffset ato, Path traitBound |
ato = MkArgumentTypeAndBlanketOffset(at, _) and
SatisfiesBlanketConstraintInput::relevantConstraint(ato, impl, traitBound) and
SatisfiesBlanketConstraint::satisfiesConstraint(ato, TTrait(traitBound), _, _)
SatisfiesBlanketConstraint::satisfiesConstraint(ato, traitBound, _, _)
)
or
exists(TypeParam blanketTypeParam |
Expand All @@ -149,10 +150,10 @@ module SatisfiesBlanketConstraint<
*/
pragma[nomagic]
predicate dissatisfiesBlanketConstraint(ArgumentType at, ImplItemNode impl) {
exists(ArgumentTypeAndBlanketOffset ato, Trait traitBound |
exists(ArgumentTypeAndBlanketOffset ato, Path traitBound |
ato = MkArgumentTypeAndBlanketOffset(at, _) and
SatisfiesBlanketConstraintInput::relevantConstraint(ato, impl, traitBound) and
SatisfiesBlanketConstraint::dissatisfiesConstraint(ato, TTrait(traitBound))
SatisfiesBlanketConstraint::dissatisfiesConstraint(ato, traitBound)
)
}
}
Loading
Loading