diff --git a/rust/ql/lib/codeql/rust/internal/TypeInference.qll b/rust/ql/lib/codeql/rust/internal/TypeInference.qll index 96ebf10a0e4..8c2a648f49e 100644 --- a/rust/ql/lib/codeql/rust/internal/TypeInference.qll +++ b/rust/ql/lib/codeql/rust/internal/TypeInference.qll @@ -2826,20 +2826,10 @@ private AssociatedTypeTypeParameter getFutureOutputTypeParameter() { result.getTypeAlias() = any(FutureTrait ft).getOutputType() } -private predicate isReturnExprCfgAncestor(AstNode n) { - n instanceof ReturnExpr - or - exists(AstNode mid | - isReturnExprCfgAncestor(mid) and - n = mid.getParentNode() and - n.getEnclosingCfgScope() = mid.getEnclosingCfgScope() - ) -} - pragma[nomagic] predicate isUnitBlockExpr(BlockExpr be) { not be.getStmtList().hasTailExpr() and - not isReturnExprCfgAncestor(be) and + not be = any(Callable c).getBody() and not be.hasLabel() } diff --git a/rust/ql/test/library-tests/type-inference/main.rs b/rust/ql/test/library-tests/type-inference/main.rs index af39c583a46..d99d178ba8d 100644 --- a/rust/ql/test/library-tests/type-inference/main.rs +++ b/rust/ql/test/library-tests/type-inference/main.rs @@ -2865,7 +2865,7 @@ mod block_types { #[rustfmt::skip] fn f4(cond: bool) -> i32 { - let a = { // $ MISSING: certainType=a:() + let a = { // $ certainType=a:() if cond { return 12; }; 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 18da3cb4255..d9b5e5782ab 100644 --- a/rust/ql/test/library-tests/type-inference/type-inference.expected +++ b/rust/ql/test/library-tests/type-inference/type-inference.expected @@ -6476,8 +6476,11 @@ inferType | main.rs:2863:16:2863:16 | 0 | | {EXTERNAL LOCATION} | i32 | | main.rs:2867:11:2867:14 | cond | | {EXTERNAL LOCATION} | bool | | main.rs:2867:30:2875:5 | { ... } | | {EXTERNAL LOCATION} | i32 | +| main.rs:2868:13:2868:13 | a | | file://:0:0:0:0 | () | +| main.rs:2868:17:2872:9 | { ... } | | file://:0:0:0:0 | () | | main.rs:2869:13:2871:13 | if cond {...} | | file://:0:0:0:0 | () | | main.rs:2869:16:2869:19 | cond | | {EXTERNAL LOCATION} | bool | +| main.rs:2869:21:2871:13 | { ... } | | file://:0:0:0:0 | () | | main.rs:2870:24:2870:25 | 12 | | {EXTERNAL LOCATION} | i32 | | main.rs:2873:18:2873:26 | "a: {:?}\\n" | | file://:0:0:0:0 | & | | main.rs:2873:18:2873:26 | "a: {:?}\\n" | &T | {EXTERNAL LOCATION} | str | @@ -6485,6 +6488,7 @@ inferType | main.rs:2873:18:2873:29 | FormatArgsExpr | | {EXTERNAL LOCATION} | Arguments | | main.rs:2873:18:2873:29 | MacroExpr | | {EXTERNAL LOCATION} | Arguments | | main.rs:2873:18:2873:29 | { ... } | | file://:0:0:0:0 | () | +| main.rs:2873:29:2873:29 | a | | file://:0:0:0:0 | () | | main.rs:2874:9:2874:9 | 0 | | {EXTERNAL LOCATION} | i32 | | main.rs:2883:11:2918:1 | { ... } | | file://:0:0:0:0 | () | | main.rs:2884:5:2884:21 | ...::f(...) | | file://:0:0:0:0 | () |