diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index 9b2ffcb798c6..fb9f082c05e5 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -187,7 +187,6 @@ lib/codeql/rust/elements/internal/AwaitExprConstructor.qll 44ff1653e73d5b9f6885c lib/codeql/rust/elements/internal/BecomeExprConstructor.qll ba073aaa256cb8827a0307c3128d50f62b11aac0b1f324e48c95f30351a9b942 3a787ded505c3158fa4f4923f66e8ecdcb7b5f86f27f64c5412dc32dca031f18 lib/codeql/rust/elements/internal/BinaryExprConstructor.qll 7f9b17757f78b9fb7c46e21d2040a77fa50083bef4911c8464991c3d1ad91d87 a59390cd8e896c0bfbdc9ba0674e06d980ffcefa710fbc9886be52ed427e9717 lib/codeql/rust/elements/internal/BlockExprConstructor.qll 438337c807645e98a01440f3f4610d68b0567ba15c8f51dc43bf5a30c9af3696 48ce7a546910c884619762349b8ada9836284f8008298fdb0070a38f7ddf25a0 -lib/codeql/rust/elements/internal/BlockExprImpl.qll 36ac09e4a6eeeec22919b62b1d004bdb5bb2527e67932c308aec383a770768d6 3b4b2a2014f6fe075c63a2d633b297566b548ef2e4343cadf067a9edbcadc876 lib/codeql/rust/elements/internal/BoxPatConstructor.qll 153f110ba25fd6c889092bfd16f73bb610fa60d6e0c8965d5f44d2446fcd48a2 9324cf0d8aa29945551bf8ab64801d598f57aab8cd4e19bcd4e9ef8a4a4e06eb lib/codeql/rust/elements/internal/BreakExprConstructor.qll 356be043c28e0b34fdf925a119c945632ee883c6f5ebb9a27003c6a8d250afd9 bb77e66b04bb9489340e7506931559b94285c6904b6f9d2f83b214cba4f3cfd5 lib/codeql/rust/elements/internal/CallExprBaseImpl.qll d2749cc1a9d7ee8bf7f34b6c3e0238a576a68e439a8c10a503c164ff45ffcbeb ffc7b0a8841945fe6736b0e1aed7d9ed69185db03dee2b16da121325b39397c7 @@ -263,7 +262,6 @@ lib/codeql/rust/elements/internal/MacroCallConstructor.qll 707fee4fba1fd632cd001 lib/codeql/rust/elements/internal/MacroDefConstructor.qll 382a3bdf46905d112ee491620cc94f87d584d72f49e01eb1483f749e4709c055 eb61b90d8d8d655c2b00ff576ae20c8da9709eeef754212bc64d8e1558ad05ce lib/codeql/rust/elements/internal/MacroDefImpl.qll f26e787ffd43e8cb079db01eba04412dbf32c338938acf1bc09a2f094bbdfdfe 044f43bc94fe4b6df22afae32e9f039d1d0d9e85ad9f24b6388be71211c37ce5 lib/codeql/rust/elements/internal/MacroExprConstructor.qll b12edb21ea189a1b28d96309c69c3d08e08837621af22edd67ff9416c097d2df d35bc98e7b7b5451930214c0d93dce33a2c7b5b74f36bf99f113f53db1f19c14 -lib/codeql/rust/elements/internal/MacroExprImpl.qll 92dd9f658a85ae407e055f090385f451084de59190d8a00c7e1fba453c3eced4 89d544634fecdbead2ff06a26fc8132e127dab07f38b9322fa14dc55657b9f1a lib/codeql/rust/elements/internal/MacroItemsConstructor.qll 8e9ab7ec1e0f50a22605d4e993f99a85ca8059fbb506d67bc8f5a281af367b05 2602f9db31ea0c48192c3dde3bb5625a8ed1cae4cd3408729b9e09318d5bd071 lib/codeql/rust/elements/internal/MacroItemsImpl.qll 76fd50a1f27336e9efc6d3f73ef4d724f19627cadbaa805d1e14d2cfa4f19899 40c0e512090050b39b69128730f4f4581f51ffd3c687fb52913617bd70a144e9 lib/codeql/rust/elements/internal/MacroPatConstructor.qll 24744c1bbe21c1d249a04205fb09795ae38ed106ba1423e86ccbc5e62359eaa2 4fac3f731a1ffd87c1230d561c5236bd28dcde0d1ce0dcd7d7a84ba393669d4a diff --git a/rust/ql/.gitattributes b/rust/ql/.gitattributes index c14303dc341a..77783a050f94 100644 --- a/rust/ql/.gitattributes +++ b/rust/ql/.gitattributes @@ -189,7 +189,6 @@ /lib/codeql/rust/elements/internal/BecomeExprConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/BinaryExprConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/BlockExprConstructor.qll linguist-generated -/lib/codeql/rust/elements/internal/BlockExprImpl.qll linguist-generated /lib/codeql/rust/elements/internal/BoxPatConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/BreakExprConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/CallExprBaseImpl.qll linguist-generated @@ -265,7 +264,6 @@ /lib/codeql/rust/elements/internal/MacroDefConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/MacroDefImpl.qll linguist-generated /lib/codeql/rust/elements/internal/MacroExprConstructor.qll linguist-generated -/lib/codeql/rust/elements/internal/MacroExprImpl.qll linguist-generated /lib/codeql/rust/elements/internal/MacroItemsConstructor.qll linguist-generated /lib/codeql/rust/elements/internal/MacroItemsImpl.qll linguist-generated /lib/codeql/rust/elements/internal/MacroPatConstructor.qll linguist-generated diff --git a/rust/ql/lib/codeql/rust/elements/internal/BlockExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/BlockExprImpl.qll index 9011109b194e..039e9fe7f83a 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/BlockExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/BlockExprImpl.qll @@ -1,4 +1,3 @@ -// generated by codegen, remove this comment if you wish to edit this file /** * This module provides a hand-modifiable wrapper around the generated class `BlockExpr`. * @@ -12,6 +11,7 @@ private import codeql.rust.elements.internal.generated.BlockExpr * be referenced directly. */ module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file /** * A block expression. For example: * ```rust @@ -26,5 +26,16 @@ module Impl { * } * ``` */ - class BlockExpr extends Generated::BlockExpr { } + class BlockExpr extends Generated::BlockExpr { + override string getType() { + result = super.getType() + or + not exists(super.getType()) and + ( + result = this.getStmtList().getTailExpr().getType() + or + not exists(this.getStmtList().getTailExpr()) and result = "()" + ) + } + } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll index cb17fa523617..21b730bf1354 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FormatTemplateVariableAccessImpl.qll @@ -11,6 +11,7 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.Format private import codeql.rust.elements.NamedFormatArgument private import codeql.Locations +private import codeql.rust.elements.Variable /** * INTERNAL: This module contains the customizable definition of `FormatTemplateVariableAccess` and should not @@ -36,5 +37,9 @@ module Impl { /** Gets the underlying `NamedFormatArgument` . */ NamedFormatArgument getArgument() { result = argument } + + override string getType() { + result = any(Variable v | v.getAnAccess() = this).getPat().getType() + } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/IfExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/IfExprImpl.qll index c90ee6ccdc06..3b4d6f4c7f08 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/IfExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/IfExprImpl.qll @@ -39,5 +39,13 @@ module Impl { or index = 3 and this.hasElse() and result = "else {...}" } + + override string getType() { + result = super.getType() + or + // For some reason rust-analyzer does not return a type for a chained `if`, so we use the parent's type instead. + not exists(super.getType()) and + result = any(IfExpr parent | parent.getElse() = this).getType() + } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll index f68c79da16b1..6005f34fd675 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/LiteralExprImpl.qll @@ -5,6 +5,8 @@ */ private import codeql.rust.elements.internal.generated.LiteralExpr +private import codeql.rust.elements.FormatArgsExpr +private import codeql.rust.elements.LiteralPat /** * INTERNAL: This module contains the customizable definition of `LiteralExpr` and should not @@ -41,5 +43,13 @@ module Impl { if v.length() > 30 then result = v.substring(0, 30) + "..." else result = v ) } + + override string getType() { + result = super.getType() + or + exists(FormatArgsExpr f | f.getTemplate() = this and result = "&str") + or + result = any(LiteralPat p | p.getLiteral() = this).getType() + } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/MacroExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/MacroExprImpl.qll index 42c46e9e60b6..2261b89816e0 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/MacroExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/MacroExprImpl.qll @@ -1,4 +1,3 @@ -// generated by codegen, remove this comment if you wish to edit this file /** * This module provides a hand-modifiable wrapper around the generated class `MacroExpr`. * @@ -6,17 +5,35 @@ */ private import codeql.rust.elements.internal.generated.MacroExpr +private import codeql.rust.elements.MacroStmts /** * INTERNAL: This module contains the customizable definition of `MacroExpr` and should not * be referenced directly. */ module Impl { + // the following QLdoc is generated: if you need to edit it, do it in the schema file /** * A MacroExpr. For example: * ```rust * todo!() * ``` */ - class MacroExpr extends Generated::MacroExpr { } + class MacroExpr extends Generated::MacroExpr { + override string getType() { + result = super.getType() + or + not exists(super.getType()) and + ( + result = this.getMacroCall().getExpanded().(Expr).getType() or + result = typeOf(this.getMacroCall().getExpanded().(MacroStmts)) + ) + } + } + + string typeOf(MacroStmts stmts) { + result = stmts.getExpr().getType() + or + not exists(stmts.getExpr()) and result = "()" + } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll index 19445493c889..531682e96dc3 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/PathExprImpl.qll @@ -5,6 +5,7 @@ */ private import codeql.rust.elements.internal.generated.PathExpr +private import codeql.rust.elements.CallExpr /** * INTERNAL: This module contains the customizable definition of `PathExpr` and should not @@ -25,5 +26,22 @@ module Impl { override string toString() { result = this.toAbbreviatedString() } override string toAbbreviatedString() { result = this.getPath().toString() } + + override string getType() { + result = super.getType() + or + // Special case for `rustc_box`; these get translated to `box X` in the HIR layer. + // ```rust + // #[rustc_box] + // alloc.boxed::Box::new(X) + // ``` + not exists(super.getType()) and + exists(CallExpr c, string tp | + c.getAnAttr().getMeta().getPath().getPart().getNameRef().getText() = "rustc_box" and + this = c.getExpr() and + tp = c.getArgList().getArg(0).getType() and + result = "fn new(T) -> Box".replaceAll("T", tp) + ) + } } }