From bf0dc3c4d17412761d6c0bec6de048d3a8848be1 Mon Sep 17 00:00:00 2001 From: Tom Hvitved Date: Thu, 13 Nov 2025 14:30:16 +0100 Subject: [PATCH] Rust: Use `useUniversalConditions() { none() }` --- rust/ql/lib/codeql/rust/internal/TypeInference.qll | 6 ++++++ .../library-tests/type-inference/type-inference.expected | 6 ------ .../codeql/typeinference/internal/TypeInference.qll | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index 0c54481b504..46df7547b2e 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -3074,6 +3074,8 @@ private module AwaitSatisfiesConstraintInput implements SatisfiesConstraintInput exists(term) and constraint.(TraitType).getTrait() instanceof FutureTrait } + + predicate useUniversalConditions() { none() } } pragma[nomagic] @@ -3249,6 +3251,8 @@ private module ForIterableSatisfiesConstraintInput implements t instanceof IntoIteratorTrait ) } + + predicate useUniversalConditions() { none() } } pragma[nomagic] @@ -3303,6 +3307,8 @@ private module InvokedClosureSatisfiesConstraintInput implements exists(term) and constraint.(TraitType).getTrait() instanceof FnOnceTrait } + + predicate useUniversalConditions() { none() } } /** Gets the type of `ce` when viewed as an implementation of `FnOnce`. */ diff --git a/rust/ql/test/library-tests/type-inference/type-inference.expected b/rust/ql/test/library-tests/type-inference/type-inference.expected index 5b73cb2e29d..641294130b1 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -5399,7 +5399,6 @@ inferType | main.rs:2612:40:2612:40 | 1 | | {EXTERNAL LOCATION} | i32 | | main.rs:2612:43:2612:44 | { ... } | | {EXTERNAL LOCATION} | () | | main.rs:2613:9:2613:41 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2613:13:2613:13 | i | | {EXTERNAL LOCATION} | Item | | main.rs:2613:13:2613:13 | i | | {EXTERNAL LOCATION} | i32 | | main.rs:2613:18:2613:26 | [...] | | {EXTERNAL LOCATION} | [;] | | main.rs:2613:18:2613:26 | [...] | [T;...] | {EXTERNAL LOCATION} | i32 | @@ -5573,7 +5572,6 @@ inferType | main.rs:2652:26:2652:26 | c | | main.rs:2596:5:2596:24 | MyCallable | | main.rs:2652:26:2652:33 | c.call() | | {EXTERNAL LOCATION} | i64 | | main.rs:2657:9:2657:25 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2657:13:2657:13 | i | | {EXTERNAL LOCATION} | Item | | main.rs:2657:13:2657:13 | i | | {EXTERNAL LOCATION} | i32 | | main.rs:2657:18:2657:18 | 0 | | {EXTERNAL LOCATION} | i32 | | main.rs:2657:18:2657:22 | 0..10 | | {EXTERNAL LOCATION} | Range | @@ -5602,7 +5600,6 @@ inferType | main.rs:2659:21:2659:25 | 0..10 | Idx | {EXTERNAL LOCATION} | i32 | | main.rs:2659:24:2659:25 | 10 | | {EXTERNAL LOCATION} | i32 | | main.rs:2660:9:2660:25 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2660:13:2660:13 | i | | {EXTERNAL LOCATION} | Item | | main.rs:2660:13:2660:13 | i | | {EXTERNAL LOCATION} | i32 | | main.rs:2660:18:2660:22 | range | | {EXTERNAL LOCATION} | Range | | main.rs:2660:18:2660:22 | range | Idx | {EXTERNAL LOCATION} | i32 | @@ -5626,7 +5623,6 @@ inferType | main.rs:2666:20:2666:23 | 0u16 | | {EXTERNAL LOCATION} | u16 | | main.rs:2667:18:2667:22 | 10u16 | | {EXTERNAL LOCATION} | u16 | | main.rs:2669:9:2669:26 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2669:13:2669:13 | u | | {EXTERNAL LOCATION} | Item | | main.rs:2669:13:2669:13 | u | | {EXTERNAL LOCATION} | u16 | | main.rs:2669:18:2669:23 | range1 | | {EXTERNAL LOCATION} | Range | | main.rs:2669:18:2669:23 | range1 | Idx | {EXTERNAL LOCATION} | u16 | @@ -5795,7 +5791,6 @@ inferType | main.rs:2701:33:2701:37 | "two" | | {EXTERNAL LOCATION} | & | | main.rs:2701:33:2701:37 | "two" | &T | {EXTERNAL LOCATION} | str | | main.rs:2702:9:2702:33 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2702:13:2702:15 | key | | {EXTERNAL LOCATION} | Item | | main.rs:2702:13:2702:15 | key | | {EXTERNAL LOCATION} | & | | main.rs:2702:13:2702:15 | key | &T | {EXTERNAL LOCATION} | i32 | | main.rs:2702:20:2702:23 | map1 | | {EXTERNAL LOCATION} | HashMap | @@ -5813,7 +5808,6 @@ inferType | main.rs:2702:20:2702:30 | map1.keys() | V.T.&T | {EXTERNAL LOCATION} | str | | main.rs:2702:32:2702:33 | { ... } | | {EXTERNAL LOCATION} | () | | main.rs:2703:9:2703:37 | for ... in ... { ... } | | {EXTERNAL LOCATION} | () | -| main.rs:2703:13:2703:17 | value | | {EXTERNAL LOCATION} | Item | | main.rs:2703:13:2703:17 | value | | {EXTERNAL LOCATION} | & | | main.rs:2703:13:2703:17 | value | &T | {EXTERNAL LOCATION} | Box | | main.rs:2703:13:2703:17 | value | &T.A | {EXTERNAL LOCATION} | Global | diff --git a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll index a03af8f4ffe..7669c252c78 100644 --- a/shared/typeinference/codeql/typeinference/internal/TypeInference.qll +++ b/shared/typeinference/codeql/typeinference/internal/TypeInference.qll @@ -992,7 +992,7 @@ module Make1 Input1> { TypeMention constraintMention ) { exists(Type type | hasTypeConstraint(tt, type, constraint) | - useUniversalConditions() and + useUniversalConditions() and // todo: remove, and instead check constraints not exists(countConstraintImplementations(type, constraint)) and conditionSatisfiesConstraintTypeAt(abs, condition, constraintMention, _, _) and resolveTypeMentionRoot(condition) = abs.getATypeParameter() and