diff --git a/rust/extractor/src/generated/.generated.list b/rust/extractor/src/generated/.generated.list index 82b6665615b..158f55acad5 100644 --- a/rust/extractor/src/generated/.generated.list +++ b/rust/extractor/src/generated/.generated.list @@ -1,2 +1,2 @@ mod.rs 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 4bcb9def847469aae9d8649461546b7c21ec97cf6e63d3cf394e339915ce65d7 -top.rs 060225ccbae440eef117e2ef0a82f3deba29e6ba2d35f00281f9c0e6a945e692 060225ccbae440eef117e2ef0a82f3deba29e6ba2d35f00281f9c0e6a945e692 +top.rs f7c07bc5a6ad3e1a3af05d16b5b448509f9f8403a510bfca1db42348d3c7038b f7c07bc5a6ad3e1a3af05d16b5b448509f9f8403a510bfca1db42348d3c7038b diff --git a/rust/extractor/src/generated/top.rs b/rust/extractor/src/generated/top.rs index caeeb7552a7..a79bfc7bd0a 100644 --- a/rust/extractor/src/generated/top.rs +++ b/rust/extractor/src/generated/top.rs @@ -1515,60 +1515,6 @@ impl From> for trap::Label { } } -#[derive(Debug)] -pub struct MacroStmts { - pub id: trap::TrapId, - pub expr: Option>, - pub statements: Vec>, -} - -impl trap::TrapEntry for MacroStmts { - fn extract_id(&mut self) -> trap::TrapId { - std::mem::replace(&mut self.id, trap::TrapId::Star) - } - - fn emit(self, id: trap::Label, out: &mut trap::Writer) { - out.add_tuple("macro_stmts", vec![id.into()]); - if let Some(v) = self.expr { - out.add_tuple("macro_stmts_exprs", vec![id.into(), v.into()]); - } - for (i, v) in self.statements.into_iter().enumerate() { - out.add_tuple("macro_stmts_statements", vec![id.into(), i.into(), v.into()]); - } - } -} - -impl trap::TrapClass for MacroStmts { - fn class_name() -> &'static str { "MacroStmts" } -} - -impl From> for trap::Label { - fn from(value: trap::Label) -> Self { - // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of AstNode - unsafe { - Self::from_untyped(value.as_untyped()) - } - } -} - -impl From> for trap::Label { - fn from(value: trap::Label) -> Self { - // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Locatable - unsafe { - Self::from_untyped(value.as_untyped()) - } - } -} - -impl From> for trap::Label { - fn from(value: trap::Label) -> Self { - // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Element - unsafe { - Self::from_untyped(value.as_untyped()) - } - } -} - #[derive(Debug)] pub struct MatchArm { pub id: trap::TrapId, @@ -6479,6 +6425,69 @@ impl From> for trap::Label { } } +#[derive(Debug)] +pub struct MacroStmts { + pub id: trap::TrapId, + pub expr: Option>, + pub statements: Vec>, +} + +impl trap::TrapEntry for MacroStmts { + fn extract_id(&mut self) -> trap::TrapId { + std::mem::replace(&mut self.id, trap::TrapId::Star) + } + + fn emit(self, id: trap::Label, out: &mut trap::Writer) { + out.add_tuple("macro_stmts", vec![id.into()]); + if let Some(v) = self.expr { + out.add_tuple("macro_stmts_exprs", vec![id.into(), v.into()]); + } + for (i, v) in self.statements.into_iter().enumerate() { + out.add_tuple("macro_stmts_statements", vec![id.into(), i.into(), v.into()]); + } + } +} + +impl trap::TrapClass for MacroStmts { + fn class_name() -> &'static str { "MacroStmts" } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Expr + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of AstNode + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Locatable + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + +impl From> for trap::Label { + fn from(value: trap::Label) -> Self { + // SAFETY: this is safe because in the dbscheme MacroStmts is a subclass of Element + unsafe { + Self::from_untyped(value.as_untyped()) + } + } +} + #[derive(Debug)] pub struct MacroTypeRepr { pub id: trap::TrapId, diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index 0ff3e721e23..bc447c524e8 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -1,4 +1,4 @@ -lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll d1cc3cfc9ae558b1cb473e3bfca66e5c424445b98ce343eb6f3050321fe4f8a0 8d00e385230b45360bc6281af01e0f674c58117593fd1b3cb7eb0c8a45517542 +lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll 08d3062aa600c5dceba897f067b1142a382b7a342acc9f7e7548b0b9df0dab36 b9bc250dbd89e95bf8fd12eacfa725ad1b50ac644599da6100cff33adfb8a18e lib/codeql/rust/elements/Abi.qll 4c973d28b6d628f5959d1f1cc793704572fd0acaae9a97dfce82ff9d73f73476 250f68350180af080f904cd34cb2af481c5c688dc93edf7365fd0ae99855e893 lib/codeql/rust/elements/Addressable.qll 13011bfd2e1556694c3d440cc34af8527da4df49ad92b62f2939d3699ff2cea5 ddb25935f7553a1a384b1abe2e4b4fa90ab50b952dadec32fd867afcb054f4be lib/codeql/rust/elements/ArgList.qll 661f5100f5d3ef8351452d9058b663a2a5c720eea8cf11bedd628969741486a2 28e424aac01a90fb58cd6f9f83c7e4cf379eea39e636bc0ba07efc818be71c71 @@ -95,7 +95,7 @@ lib/codeql/rust/elements/MacroExpr.qll ea9fed13f610bab1a2c4541c994510e0cb806530b lib/codeql/rust/elements/MacroItems.qll 00a5d41f7bb836d952abbd9382e42f72a9d81e65646a15a460b35ccd07a866c6 00efdb4d701b5599d76096f740da9ec157804865267b7e29bc2a214cbf03763e lib/codeql/rust/elements/MacroPat.qll dbf193b4fb544ac0b5a7dcfc31a6652de7239b6e643ff15b05868b2c142e940c 19b45c0a1eb1198e450c05d564b5d4aa0d6da29e7db84b9521eadf901e20a932 lib/codeql/rust/elements/MacroRules.qll a94535506798077043b9c1470992ac4310bf67bcce5f722080886d1b3e6d90d1 bd8e08a7171991abc85100b45267631e66d1b332caf1e5882cd17caee5cf18a3 -lib/codeql/rust/elements/MacroStmts.qll 6e9a1f90231cb72b27d3ff9479e399a9fba4abd0872a5005ab2fac45d5ca9be0 d6ca3a8254fc45794a93c451a3305c9b4be033a467ad72158d40d6f675a377a0 +lib/codeql/rust/elements/MacroStmts.qll 02c4e34d266d4564ea0433a3d6186402db516dc2dd9017d7c769a76300c2286d f4517fb9fea2ea64d4f2c1998a6899d2452878000ed6f8f31c5106ef0fb6783a lib/codeql/rust/elements/MacroTypeRepr.qll 92fa5f6d20cce8fa3f2b4b823a8a77fdb7c11f2c2b12b8f900828c3a54eca334 51289f2622d1bb58d9a093255da2c05084a0b184f02e69e2526ec7fefdfdfd75 lib/codeql/rust/elements/MatchArm.qll c39fd6cc0da24b1ff8d1e42835bcfee7695ad13580e3c7c50acd7c881b1cd894 62a31d2bd125e6aaebefc406e541a641271d3c497a377959f94dd4735b2bfbf8 lib/codeql/rust/elements/MatchArmList.qll e6c48fd7419d88e996b82eb45e4aa2686dfd079b283b02be7710192fb2cb93a0 0ec63a0ca56f5f7f80093fd3e77b198b74c6289e67be55dc6a4deb610753c7bd @@ -557,7 +557,7 @@ lib/codeql/rust/elements/internal/generated/MacroExpr.qll 03a1daa41866f51e479ac2 lib/codeql/rust/elements/internal/generated/MacroItems.qll 894890f61e118b3727d03ca813ae7220a15e45195f2d1d059cb1bba6802128c8 db3854b347f8782a3ec9f9a1439da822727b66f0bd33727383184ab65dbf29ac lib/codeql/rust/elements/internal/generated/MacroPat.qll 26bc55459a66359ad83ed7b25284a25cdbd48a868fd1bbf7e23e18b449395c43 f16ede334becba951873e585c52a3a9873c9251e3dab9a3c1a1681f632f2079f lib/codeql/rust/elements/internal/generated/MacroRules.qll 4fbd94f22b5ee0f3e5aaae39c2b9a5e9b7bf878a1017811ca589942f6de92843 49fb69543ee867bae196febea6918e621f335afdf4d3ccbf219965b37c7537b1 -lib/codeql/rust/elements/internal/generated/MacroStmts.qll cb4f3c2721a4d0c8522e51f567c675f4fc95f39bac8a2bd97e125d5553515ad2 09b5a739ccee75e6c556b34ecd6f78c7dc799029d9bc7df2e6169098d24f0ccd +lib/codeql/rust/elements/internal/generated/MacroStmts.qll d19f8b925d3b926c94e3d17c71aa4500899ec3cdd22c7e3428444e7e8e70bf97 69e64fc2089d6109de012956d1e9ddd86d468bb132e9b562efc06f359b00b0e7 lib/codeql/rust/elements/internal/generated/MacroTypeRepr.qll 4242e253fa36ee3f7d9d0677811ff5bc4ecfb02c76d768446a6a6dcd38061f68 a676632f3bb83142a0838601ae2a582d5c32d7939e4261eb8fccf3962bb06cb2 lib/codeql/rust/elements/internal/generated/MatchArm.qll f8c4c955c50f8398159c492d9d0a74f7b71e9510fcb8a3aab1d06e0f7e15b263 713939c7ef77ca73d95788096163c26213ab49f34ed41c6f4bc09a1ef9607b0d lib/codeql/rust/elements/internal/generated/MatchArmList.qll 13362680c037fe83fef4653562cc10a4429078316b5ec7c47b076336cf4aca2e 41c674293c13eceaca62134ae0c6778541f6a5201cbc5c146f0ba01b898dc267 @@ -579,7 +579,7 @@ lib/codeql/rust/elements/internal/generated/ParamList.qll c808c9d84dd7800573832b lib/codeql/rust/elements/internal/generated/ParenExpr.qll bc0731505bfe88516205ec360582a4222d2681d11342c93e15258590ddee82f2 d4bd6e0c80cf1d63746c88d4bcb3a01d4c75732e5da09e3ebd9437ced227fb60 lib/codeql/rust/elements/internal/generated/ParenPat.qll 4f168ef5d5bb87a903251cc31b2e44a759b099ec69c90af31783fbb15778c940 0e34f94a45a13396fd57d94c245dc64d1adde2ab0e22b56946f7e94c04e297fc lib/codeql/rust/elements/internal/generated/ParenTypeRepr.qll 40ab5c592e7699c621787793743e33988de71ff42ca27599f5ab3ddb70e3f7d8 12c0a6eed2202ee3e892f61da3b3ce77ac3190854cdf3097e8d2be98aa3cb91d -lib/codeql/rust/elements/internal/generated/ParentChild.qll d1770632e8d0c649ebcbcab9cbc653531ecf521bbf5d891941db8c0927ae6796 fb40a76aff319ec5f7dae9a05da083b337887b0918b3702641b39342213ddf6f +lib/codeql/rust/elements/internal/generated/ParentChild.qll 27c4e9351e8dcf0290a5959b634c15398196b312e75f7ef4716e7c56090a90aa 99b4716d995792105d1a20300f8710d3ae26ca59f3a0db076114509d8bdab85e lib/codeql/rust/elements/internal/generated/ParenthesizedArgList.qll c5fa328ea60d3a3333d7c7bb3480969c1873166c7ac8ebb9d0afad7a8099d1a8 2dbbb6200d96f7db7dea4a55bdeab8d67b14d39a43e0bd54ada019f7e466f163 lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4 lib/codeql/rust/elements/internal/generated/Path.qll 9b12afb46fc5a9ad3a811b05472621bbecccb900c47504feb7f29d96b28421ca bcacbffc36fb3e0c9b26523b5963af0ffa9fd6b19f00a2a31bdb2316071546bd @@ -594,7 +594,7 @@ lib/codeql/rust/elements/internal/generated/PtrTypeRepr.qll 51d1e9e683fc79dddbff lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll e5b8e69519012bbaae29dcb82d53f7f7ecce368c0358ec27ef6180b228a0057f e5b8e69519012bbaae29dcb82d53f7f7ecce368c0358ec27ef6180b228a0057f lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9 lib/codeql/rust/elements/internal/generated/RangePat.qll 80826a6a6868a803aa2372e31c52a03e1811a3f1f2abdb469f91ca0bfdd9ecb6 34ee1e208c1690cba505dff2c588837c0cd91e185e2a87d1fe673191962276a9 -lib/codeql/rust/elements/internal/generated/Raw.qll 6e33d9fa21ee3287a0ebc27856a09f4fdc4d587b5a31ff1c4337106de7ca1a2e eece38e6accb6b9d8838fd05edd7cbaf6f7ee37190adbef2b023ad91064d1622 +lib/codeql/rust/elements/internal/generated/Raw.qll 8aaa20dd4d49220f3eff2ac64f7a8d34f343d198b59785a06922c3642322e056 3d14ea25f0ad20af1bfb1b8e3e0e5fba9f1a1f764132c0d42972e08893ebd31b lib/codeql/rust/elements/internal/generated/RefExpr.qll 7d995884e3dc1c25fc719f5d7253179344d63650e217e9ff6530285fe7a57f64 f2c3c12551deea4964b66553fb9b6423ee16fec53bd63db4796191aa60dc6c66 lib/codeql/rust/elements/internal/generated/RefPat.qll 456ede39837463ee22a630ec7ab6c8630d3664a8ea206fcc6e4f199e92fa564c 5622062765f32930465ba6b170e986706f159f6070f48adee3c20e24e8df4e05 lib/codeql/rust/elements/internal/generated/RefTypeRepr.qll 3d8c0bd296d33b91a81633f697a43269a6538df06d277262d3990d3f6880ef57 13680f39e89bcd8299c218aba396f3deec804597e6f7cb7d4a7e7c748b6faa77 @@ -620,7 +620,7 @@ lib/codeql/rust/elements/internal/generated/StructFieldList.qll 8911a44217d091b0 lib/codeql/rust/elements/internal/generated/StructPat.qll c76fa005c2fd0448a8803233e1e8818c4123301eb66ac5cf69d0b9eaafc61e98 6e0dffccdce24bca20e87d5ba0f0995c9a1ae8983283e71e7dbfcf6fffc67a58 lib/codeql/rust/elements/internal/generated/StructPatField.qll 5b5c7302dbc4a902ca8e69ff31875c867e295a16a626ba3cef29cd0aa248f179 4e192a0df79947f5cb0d47fdbbba7986137a6a40a1be92ae119873e2fad67edf lib/codeql/rust/elements/internal/generated/StructPatFieldList.qll e34c003e660ba059ba81bb73b3c8d21bd2a47d0251569c46277dc9ccf2947b0a 85113f35ba5f6b9e01ad4072246a4de1ac0e4528348ac564868e96f34a3e09e2 -lib/codeql/rust/elements/internal/generated/Synth.qll 409b9ae5c78f47f271eb05a9eb7043df6cd6ca35ce381843714667f1f2dfdf9a aa4d5082abccd7cd47a493447eea79b0a3ff81439c333f05087030e76f0fa8e5 +lib/codeql/rust/elements/internal/generated/Synth.qll e35b960eeea21a70c94bd81001357fd18b1ecccef0a7b514e2a64e9091db21a2 319b9fa102d87d93d2157cd0fe7b5934d0892185e740d98b50c44cc5e99a4cd6 lib/codeql/rust/elements/internal/generated/SynthConstructors.qll fe007cf6eab5f0cf89ea1ea91e1f9b23e0fcf0f2872f52ef352584503f90aa29 fe007cf6eab5f0cf89ea1ea91e1f9b23e0fcf0f2872f52ef352584503f90aa29 lib/codeql/rust/elements/internal/generated/Token.qll 77a91a25ca5669703cf3a4353b591cef4d72caa6b0b9db07bb9e005d69c848d1 2fdffc4882ed3a6ca9ac6d1fb5f1ac5a471ca703e2ffdc642885fa558d6e373b lib/codeql/rust/elements/internal/generated/TokenTree.qll 8577c2b097c1be2f0f7daa5acfcf146f78674a424d99563e08a84dd3e6d91b46 d2f30764e84dbfc0a6a5d3d8a5f935cd432413688cb32da9c94e420fbc10665c diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll index 900580914e2..298d7e49438 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/ControlFlowGraphImpl.qll @@ -146,7 +146,7 @@ class MacroCallTree extends StandardPostOrderTree, MacroCall { override AstNode getChildNode(int i) { i = 0 and result = this.getExpanded() } } -class MacroStmtsTree extends StandardPreOrderTree, MacroStmts { +class MacroStmtsTree extends StandardPostOrderTree, MacroStmts { override AstNode getChildNode(int i) { result = this.getStatement(i) or diff --git a/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll b/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll index 12ef6847b82..34ccb8d2381 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll @@ -1900,6 +1900,58 @@ module MakeCfgNodes Input> { predicate hasMacroCall() { exists(this.getMacroCall()) } } + final private class ParentMacroStmts extends ParentAstNode, MacroStmts { + override predicate relevantChild(AstNode child) { + none() + or + child = this.getExpr() + } + } + + /** + * A sequence of statements generated by a `MacroCall`. For example: + * ```rust + * fn main() { + * println!("Hello, world!"); // This macro expands into a list of statements + * } + * ``` + */ + final class MacroStmtsCfgNode extends CfgNodeFinal, ExprCfgNode { + private MacroStmts node; + + MacroStmtsCfgNode() { node = this.getAstNode() } + + /** Gets the underlying `MacroStmts`. */ + MacroStmts getMacroStmts() { result = node } + + /** + * Gets the expression of this macro statements, if it exists. + */ + ExprCfgNode getExpr() { + any(ChildMapping mapping).hasCfgChild(node, node.getExpr(), this, result) + } + + /** + * Holds if `getExpr()` exists. + */ + predicate hasExpr() { exists(this.getExpr()) } + + /** + * Gets the `index`th statement of this macro statements (0-based). + */ + Stmt getStatement(int index) { result = node.getStatement(index) } + + /** + * Gets any of the statements of this macro statements. + */ + Stmt getAStatement() { result = this.getStatement(_) } + + /** + * Gets the number of statements of this macro statements. + */ + int getNumberOfStatements() { result = count(int i | exists(this.getStatement(i))) } + } + final private class ParentMatchExpr extends ParentAstNode, MatchExpr { override predicate relevantChild(AstNode child) { none() @@ -3723,6 +3775,18 @@ module MakeCfgNodes Input> { cfgNode ) or + pred = "getExpr" and + parent = + any(Nodes::MacroStmtsCfgNode cfgNode, MacroStmts astNode | + astNode = cfgNode.getMacroStmts() and + child = getDesugared(astNode.getExpr()) and + i = -1 and + hasCfgNode(child) and + not child = cfgNode.getExpr().getAstNode() + | + cfgNode + ) + or pred = "getScrutinee" and parent = any(Nodes::MatchExprCfgNode cfgNode, MatchExpr astNode | diff --git a/rust/ql/lib/codeql/rust/elements/MacroStmts.qll b/rust/ql/lib/codeql/rust/elements/MacroStmts.qll index 77416d93699..9ef0c12b35f 100644 --- a/rust/ql/lib/codeql/rust/elements/MacroStmts.qll +++ b/rust/ql/lib/codeql/rust/elements/MacroStmts.qll @@ -4,7 +4,6 @@ */ private import internal.MacroStmtsImpl -import codeql.rust.elements.AstNode import codeql.rust.elements.Expr import codeql.rust.elements.Stmt diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/MacroStmts.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/MacroStmts.qll index e80debcb27d..636e0d1ea09 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/MacroStmts.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/MacroStmts.qll @@ -6,8 +6,8 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.internal.generated.Raw -import codeql.rust.elements.internal.AstNodeImpl::Impl as AstNodeImpl import codeql.rust.elements.Expr +import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl import codeql.rust.elements.Stmt /** @@ -25,7 +25,7 @@ module Generated { * INTERNAL: Do not reference the `Generated::MacroStmts` class directly. * Use the subclass `MacroStmts`, where the following predicates are available. */ - class MacroStmts extends Synth::TMacroStmts, AstNodeImpl::AstNode { + class MacroStmts extends Synth::TMacroStmts, ExprImpl::Expr { override string getAPrimaryQlClass() { result = "MacroStmts" } /** diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll index 4268ef3f840..57e18e373b8 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll @@ -616,26 +616,6 @@ private module Impl { ) } - private Element getImmediateChildOfMacroStmts(MacroStmts e, int index, string partialPredicateCall) { - exists(int b, int bAstNode, int n, int nExpr, int nStatement | - b = 0 and - bAstNode = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfAstNode(e, i, _)) | i) and - n = bAstNode and - nExpr = n + 1 and - nStatement = nExpr + 1 + max(int i | i = -1 or exists(e.getStatement(i)) | i) and - ( - none() - or - result = getImmediateChildOfAstNode(e, index - b, partialPredicateCall) - or - index = n and result = e.getExpr() and partialPredicateCall = "Expr()" - or - result = e.getStatement(index - nExpr) and - partialPredicateCall = "Statement(" + (index - nExpr).toString() + ")" - ) - ) - } - private Element getImmediateChildOfMatchArm(MatchArm e, int index, string partialPredicateCall) { exists(int b, int bAstNode, int n, int nAttr, int nExpr, int nGuard, int nPat | b = 0 and @@ -2420,6 +2400,26 @@ private module Impl { ) } + private Element getImmediateChildOfMacroStmts(MacroStmts e, int index, string partialPredicateCall) { + exists(int b, int bExpr, int n, int nExpr, int nStatement | + b = 0 and + bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and + n = bExpr and + nExpr = n + 1 and + nStatement = nExpr + 1 + max(int i | i = -1 or exists(e.getStatement(i)) | i) and + ( + none() + or + result = getImmediateChildOfExpr(e, index - b, partialPredicateCall) + or + index = n and result = e.getExpr() and partialPredicateCall = "Expr()" + or + result = e.getStatement(index - nExpr) and + partialPredicateCall = "Statement(" + (index - nExpr).toString() + ")" + ) + ) + } + private Element getImmediateChildOfMacroTypeRepr( MacroTypeRepr e, int index, string partialPredicateCall ) { @@ -4156,8 +4156,6 @@ private module Impl { or result = getImmediateChildOfMacroItems(e, index, partialAccessor) or - result = getImmediateChildOfMacroStmts(e, index, partialAccessor) - or result = getImmediateChildOfMatchArm(e, index, partialAccessor) or result = getImmediateChildOfMatchArmList(e, index, partialAccessor) @@ -4304,6 +4302,8 @@ private module Impl { or result = getImmediateChildOfMacroPat(e, index, partialAccessor) or + result = getImmediateChildOfMacroStmts(e, index, partialAccessor) + or result = getImmediateChildOfMacroTypeRepr(e, index, partialAccessor) or result = getImmediateChildOfMatchExpr(e, index, partialAccessor) diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll index 3bd57ae9862..b1e26574de1 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll @@ -502,29 +502,6 @@ module Raw { Item getItem(int index) { macro_items_items(this, index, result) } } - /** - * INTERNAL: Do not use. - * A sequence of statements generated by a `MacroCall`. For example: - * ```rust - * fn main() { - * println!("Hello, world!"); // This macro expands into a list of statements - * } - * ``` - */ - class MacroStmts extends @macro_stmts, AstNode { - override string toString() { result = "MacroStmts" } - - /** - * Gets the expression of this macro statements, if it exists. - */ - Expr getExpr() { macro_stmts_exprs(this, result) } - - /** - * Gets the `index`th statement of this macro statements (0-based). - */ - Stmt getStatement(int index) { macro_stmts_statements(this, index, result) } - } - /** * INTERNAL: Do not use. * A match arm. For example: @@ -2401,6 +2378,29 @@ module Raw { MacroCall getMacroCall() { macro_pat_macro_calls(this, result) } } + /** + * INTERNAL: Do not use. + * A sequence of statements generated by a `MacroCall`. For example: + * ```rust + * fn main() { + * println!("Hello, world!"); // This macro expands into a list of statements + * } + * ``` + */ + class MacroStmts extends @macro_stmts, Expr { + override string toString() { result = "MacroStmts" } + + /** + * Gets the expression of this macro statements, if it exists. + */ + Expr getExpr() { macro_stmts_exprs(this, result) } + + /** + * Gets the `index`th statement of this macro statements (0-based). + */ + Stmt getStatement(int index) { macro_stmts_statements(this, index, result) } + } + /** * INTERNAL: Do not use. * A MacroTypeRepr. For example: diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll index 6d7c69fde13..abc696eb51e 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Synth.qll @@ -716,14 +716,14 @@ module Synth { TAsmOption or TAsmPiece or TAsmRegSpec or TAssocItem or TAssocItemList or TAttr or TCallable or TClosureBinder or TExpr or TExternItem or TExternItemList or TFieldList or TFormatArgsArg or TGenericArg or TGenericArgList or TGenericParam or TGenericParamList or - TItemList or TLabel or TLetElse or TMacroItems or TMacroStmts or TMatchArm or - TMatchArmList or TMatchGuard or TMeta or TName or TParamBase or TParamList or - TParenthesizedArgList or TPat or TPath or TPathSegment or TRename or TResolvable or - TRetTypeRepr or TReturnTypeSyntax or TSourceFile or TStmt or TStmtList or - TStructExprField or TStructExprFieldList or TStructField or TStructPatField or - TStructPatFieldList or TToken or TTokenTree or TTupleField or TTypeBound or - TTypeBoundList or TTypeRepr or TUseBoundGenericArg or TUseBoundGenericArgs or TUseTree or - TUseTreeList or TVariantDef or TVariantList or TVisibility or TWhereClause or TWherePred; + TItemList or TLabel or TLetElse or TMacroItems or TMatchArm or TMatchArmList or + TMatchGuard or TMeta or TName or TParamBase or TParamList or TParenthesizedArgList or + TPat or TPath or TPathSegment or TRename or TResolvable or TRetTypeRepr or + TReturnTypeSyntax or TSourceFile or TStmt or TStmtList or TStructExprField or + TStructExprFieldList or TStructField or TStructPatField or TStructPatFieldList or TToken or + TTokenTree or TTupleField or TTypeBound or TTypeBoundList or TTypeRepr or + TUseBoundGenericArg or TUseBoundGenericArgs or TUseTree or TUseTreeList or TVariantDef or + TVariantList or TVisibility or TWhereClause or TWherePred; /** * INTERNAL: Do not use. @@ -742,9 +742,9 @@ module Synth { TArrayExpr or TArrayExprInternal or TAsmExpr or TAwaitExpr or TBecomeExpr or TBinaryExpr or TBreakExpr or TCallExprBase or TCastExpr or TClosureExpr or TContinueExpr or TFieldExpr or TFormatArgsExpr or TIfExpr or TIndexExpr or TLabelableExpr or TLetExpr or TLiteralExpr or - TMacroExpr or TMatchExpr or TOffsetOfExpr or TParenExpr or TPathExprBase or TPrefixExpr or - TRangeExpr or TRefExpr or TReturnExpr or TStructExpr or TTryExpr or TTupleExpr or - TUnderscoreExpr or TYeetExpr or TYieldExpr; + TMacroExpr or TMacroStmts or TMatchExpr or TOffsetOfExpr or TParenExpr or TPathExprBase or + TPrefixExpr or TRangeExpr or TRefExpr or TReturnExpr or TStructExpr or TTryExpr or + TTupleExpr or TUnderscoreExpr or TYeetExpr or TYieldExpr; /** * INTERNAL: Do not use. @@ -1973,8 +1973,6 @@ module Synth { or result = convertMacroItemsFromRaw(e) or - result = convertMacroStmtsFromRaw(e) - or result = convertMatchArmFromRaw(e) or result = convertMatchArmListFromRaw(e) @@ -2129,6 +2127,8 @@ module Synth { or result = convertMacroExprFromRaw(e) or + result = convertMacroStmtsFromRaw(e) + or result = convertMatchExprFromRaw(e) or result = convertOffsetOfExprFromRaw(e) @@ -3573,8 +3573,6 @@ module Synth { or result = convertMacroItemsToRaw(e) or - result = convertMacroStmtsToRaw(e) - or result = convertMatchArmToRaw(e) or result = convertMatchArmListToRaw(e) @@ -3729,6 +3727,8 @@ module Synth { or result = convertMacroExprToRaw(e) or + result = convertMacroStmtsToRaw(e) + or result = convertMatchExprToRaw(e) or result = convertOffsetOfExprToRaw(e) diff --git a/rust/ql/lib/rust.dbscheme b/rust/ql/lib/rust.dbscheme index e8707b675dc..48a13c5eec3 100644 --- a/rust/ql/lib/rust.dbscheme +++ b/rust/ql/lib/rust.dbscheme @@ -182,7 +182,6 @@ named_crates( | @label | @let_else | @macro_items -| @macro_stmts | @match_arm | @match_arm_list | @match_guard @@ -439,6 +438,7 @@ closure_binder_generic_param_lists( | @let_expr | @literal_expr | @macro_expr +| @macro_stmts | @match_expr | @offset_of_expr | @paren_expr @@ -585,23 +585,6 @@ macro_items_items( int item: @item ref ); -macro_stmts( - unique int id: @macro_stmts -); - -#keyset[id] -macro_stmts_exprs( - int id: @macro_stmts ref, - int expr: @expr ref -); - -#keyset[id, index] -macro_stmts_statements( - int id: @macro_stmts ref, - int index: int ref, - int statement: @stmt ref -); - match_arms( unique int id: @match_arm ); @@ -2118,6 +2101,23 @@ macro_pat_macro_calls( int macro_call: @macro_call ref ); +macro_stmts( + unique int id: @macro_stmts +); + +#keyset[id] +macro_stmts_exprs( + int id: @macro_stmts ref, + int expr: @expr ref +); + +#keyset[id, index] +macro_stmts_statements( + int id: @macro_stmts ref, + int index: int ref, + int statement: @stmt ref +); + macro_type_reprs( unique int id: @macro_type_repr ); diff --git a/rust/ql/test/library-tests/controlflow/BasicBlocks.expected b/rust/ql/test/library-tests/controlflow/BasicBlocks.expected index d5d978b9f52..2b87a4996b1 100644 --- a/rust/ql/test/library-tests/controlflow/BasicBlocks.expected +++ b/rust/ql/test/library-tests/controlflow/BasicBlocks.expected @@ -560,9 +560,9 @@ dominates | test.rs:355:13:355:22 | Err(...) | test.rs:355:13:355:22 | Err(...) | | test.rs:362:5:365:5 | enter fn test_let_match | test.rs:362:5:365:5 | enter fn test_let_match | | test.rs:362:5:365:5 | enter fn test_let_match | test.rs:363:18:363:18 | n | -| test.rs:362:5:365:5 | enter fn test_let_match | test.rs:363:39:363:53 | MacroStmts | +| test.rs:362:5:365:5 | enter fn test_let_match | test.rs:363:39:363:53 | ExprStmt | | test.rs:363:18:363:18 | n | test.rs:363:18:363:18 | n | -| test.rs:363:39:363:53 | MacroStmts | test.rs:363:39:363:53 | MacroStmts | +| test.rs:363:39:363:53 | ExprStmt | test.rs:363:39:363:53 | ExprStmt | | test.rs:367:5:373:5 | enter fn test_let_with_return | test.rs:367:5:373:5 | enter fn test_let_with_return | | test.rs:367:5:373:5 | enter fn test_let_with_return | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | | test.rs:367:5:373:5 | enter fn test_let_with_return | test.rs:369:18:369:20 | ret | @@ -1258,7 +1258,7 @@ postDominance | test.rs:362:5:365:5 | enter fn test_let_match | test.rs:362:5:365:5 | enter fn test_let_match | | test.rs:363:18:363:18 | n | test.rs:362:5:365:5 | enter fn test_let_match | | test.rs:363:18:363:18 | n | test.rs:363:18:363:18 | n | -| test.rs:363:39:363:53 | MacroStmts | test.rs:363:39:363:53 | MacroStmts | +| test.rs:363:39:363:53 | ExprStmt | test.rs:363:39:363:53 | ExprStmt | | test.rs:367:5:373:5 | enter fn test_let_with_return | test.rs:367:5:373:5 | enter fn test_let_with_return | | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | test.rs:367:5:373:5 | enter fn test_let_with_return | | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | @@ -1629,7 +1629,7 @@ immediateDominator | test.rs:354:16:354:20 | value | test.rs:352:5:357:5 | enter fn test_match_with_no_arms | | test.rs:355:13:355:22 | Err(...) | test.rs:352:5:357:5 | enter fn test_match_with_no_arms | | test.rs:363:18:363:18 | n | test.rs:362:5:365:5 | enter fn test_let_match | -| test.rs:363:39:363:53 | MacroStmts | test.rs:362:5:365:5 | enter fn test_let_match | +| test.rs:363:39:363:53 | ExprStmt | test.rs:362:5:365:5 | enter fn test_let_match | | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | test.rs:367:5:373:5 | enter fn test_let_with_return | | test.rs:369:18:369:20 | ret | test.rs:367:5:373:5 | enter fn test_let_with_return | | test.rs:370:13:370:16 | None | test.rs:367:5:373:5 | enter fn test_let_with_return | diff --git a/rust/ql/test/library-tests/controlflow/Cfg.expected b/rust/ql/test/library-tests/controlflow/Cfg.expected index 1705b88e3d7..0b79e26e95a 100644 --- a/rust/ql/test/library-tests/controlflow/Cfg.expected +++ b/rust/ql/test/library-tests/controlflow/Cfg.expected @@ -391,40 +391,40 @@ edges | test.rs:171:17:171:29 | ...::_print | test.rs:171:26:171:28 | "1\\n" | | | test.rs:171:17:171:29 | MacroExpr | test.rs:170:22:172:13 | { ... } | | | test.rs:171:17:171:29 | println!... | test.rs:171:17:171:29 | MacroExpr | | -| test.rs:171:17:171:30 | ExprStmt | test.rs:171:26:171:28 | MacroStmts | | +| test.rs:171:17:171:30 | ExprStmt | test.rs:171:26:171:28 | ExprStmt | | | test.rs:171:26:171:28 | "1\\n" | test.rs:171:26:171:28 | FormatArgsExpr | | | test.rs:171:26:171:28 | ...::_print(...) | test.rs:171:26:171:28 | { ... } | | | test.rs:171:26:171:28 | ...::format_args_nl!... | test.rs:171:26:171:28 | MacroExpr | | | test.rs:171:26:171:28 | ExprStmt | test.rs:171:17:171:29 | ...::_print | | | test.rs:171:26:171:28 | FormatArgsExpr | test.rs:171:26:171:28 | ...::format_args_nl!... | | | test.rs:171:26:171:28 | MacroExpr | test.rs:171:26:171:28 | ...::_print(...) | | -| test.rs:171:26:171:28 | MacroStmts | test.rs:171:26:171:28 | ExprStmt | | -| test.rs:171:26:171:28 | { ... } | test.rs:171:17:171:29 | println!... | | +| test.rs:171:26:171:28 | MacroStmts | test.rs:171:17:171:29 | println!... | | +| test.rs:171:26:171:28 | { ... } | test.rs:171:26:171:28 | MacroStmts | | | test.rs:172:20:174:13 | { ... } | test.rs:170:13:174:13 | if cond2 {...} else {...} | | | test.rs:173:17:173:29 | ...::_print | test.rs:173:26:173:28 | "2\\n" | | | test.rs:173:17:173:29 | MacroExpr | test.rs:172:20:174:13 | { ... } | | | test.rs:173:17:173:29 | println!... | test.rs:173:17:173:29 | MacroExpr | | -| test.rs:173:17:173:30 | ExprStmt | test.rs:173:26:173:28 | MacroStmts | | +| test.rs:173:17:173:30 | ExprStmt | test.rs:173:26:173:28 | ExprStmt | | | test.rs:173:26:173:28 | "2\\n" | test.rs:173:26:173:28 | FormatArgsExpr | | | test.rs:173:26:173:28 | ...::_print(...) | test.rs:173:26:173:28 | { ... } | | | test.rs:173:26:173:28 | ...::format_args_nl!... | test.rs:173:26:173:28 | MacroExpr | | | test.rs:173:26:173:28 | ExprStmt | test.rs:173:17:173:29 | ...::_print | | | test.rs:173:26:173:28 | FormatArgsExpr | test.rs:173:26:173:28 | ...::format_args_nl!... | | | test.rs:173:26:173:28 | MacroExpr | test.rs:173:26:173:28 | ...::_print(...) | | -| test.rs:173:26:173:28 | MacroStmts | test.rs:173:26:173:28 | ExprStmt | | -| test.rs:173:26:173:28 | { ... } | test.rs:173:17:173:29 | println!... | | +| test.rs:173:26:173:28 | MacroStmts | test.rs:173:17:173:29 | println!... | | +| test.rs:173:26:173:28 | { ... } | test.rs:173:26:173:28 | MacroStmts | | | test.rs:175:13:175:25 | ...::_print | test.rs:175:22:175:24 | "3\\n" | | | test.rs:175:13:175:25 | MacroExpr | test.rs:169:18:176:9 | { ... } | | | test.rs:175:13:175:25 | println!... | test.rs:175:13:175:25 | MacroExpr | | -| test.rs:175:13:175:26 | ExprStmt | test.rs:175:22:175:24 | MacroStmts | | +| test.rs:175:13:175:26 | ExprStmt | test.rs:175:22:175:24 | ExprStmt | | | test.rs:175:22:175:24 | "3\\n" | test.rs:175:22:175:24 | FormatArgsExpr | | | test.rs:175:22:175:24 | ...::_print(...) | test.rs:175:22:175:24 | { ... } | | | test.rs:175:22:175:24 | ...::format_args_nl!... | test.rs:175:22:175:24 | MacroExpr | | | test.rs:175:22:175:24 | ExprStmt | test.rs:175:13:175:25 | ...::_print | | | test.rs:175:22:175:24 | FormatArgsExpr | test.rs:175:22:175:24 | ...::format_args_nl!... | | | test.rs:175:22:175:24 | MacroExpr | test.rs:175:22:175:24 | ...::_print(...) | | -| test.rs:175:22:175:24 | MacroStmts | test.rs:175:22:175:24 | ExprStmt | | -| test.rs:175:22:175:24 | { ... } | test.rs:175:13:175:25 | println!... | | +| test.rs:175:22:175:24 | MacroStmts | test.rs:175:13:175:25 | println!... | | +| test.rs:175:22:175:24 | { ... } | test.rs:175:22:175:24 | MacroStmts | | | test.rs:179:5:188:5 | enter fn test_nested_if_match | test.rs:179:29:179:29 | a | | | test.rs:179:5:188:5 | exit fn test_nested_if_match (normal) | test.rs:179:5:188:5 | exit fn test_nested_if_match | | | test.rs:179:29:179:29 | a | test.rs:179:29:179:29 | a | | @@ -889,7 +889,7 @@ edges | test.rs:362:46:365:5 | { ... } | test.rs:362:5:365:5 | exit fn test_let_match (normal) | | | test.rs:363:9:363:57 | let ... = a else {...} | test.rs:363:23:363:23 | a | | | test.rs:363:13:363:19 | Some(...) | test.rs:363:18:363:18 | n | match | -| test.rs:363:13:363:19 | Some(...) | test.rs:363:39:363:53 | MacroStmts | no-match | +| test.rs:363:13:363:19 | Some(...) | test.rs:363:39:363:53 | ExprStmt | no-match | | test.rs:363:18:363:18 | n | test.rs:363:18:363:18 | n | | | test.rs:363:18:363:18 | n | test.rs:364:9:364:9 | n | match | | test.rs:363:23:363:23 | a | test.rs:363:13:363:19 | Some(...) | | @@ -902,11 +902,11 @@ edges | test.rs:363:39:363:53 | ...::panic_fmt(...) | test.rs:363:39:363:53 | { ... } | | | test.rs:363:39:363:53 | ExprStmt | test.rs:363:32:363:54 | ...::panic_fmt | | | test.rs:363:39:363:53 | FormatArgsExpr | test.rs:363:39:363:53 | ...::const_format_args!... | | -| test.rs:363:39:363:53 | MacroExpr | test.rs:363:32:363:54 | panic!... | | | test.rs:363:39:363:53 | MacroExpr | test.rs:363:39:363:53 | ...::panic_fmt(...) | | -| test.rs:363:39:363:53 | MacroStmts | test.rs:363:39:363:53 | ExprStmt | | -| test.rs:363:39:363:53 | MacroStmts | test.rs:363:39:363:53 | MacroStmts | | -| test.rs:363:39:363:53 | { ... } | test.rs:363:39:363:53 | ...::panic_2021!... | | +| test.rs:363:39:363:53 | MacroExpr | test.rs:363:39:363:53 | MacroStmts | | +| test.rs:363:39:363:53 | MacroStmts | test.rs:363:32:363:54 | panic!... | | +| test.rs:363:39:363:53 | MacroStmts | test.rs:363:39:363:53 | ...::panic_2021!... | | +| test.rs:363:39:363:53 | { ... } | test.rs:363:39:363:53 | MacroStmts | | | test.rs:364:9:364:9 | n | test.rs:362:46:365:5 | { ... } | | | test.rs:367:5:373:5 | enter fn test_let_with_return | test.rs:367:29:367:29 | m | | | test.rs:367:5:373:5 | exit fn test_let_with_return (normal) | test.rs:367:5:373:5 | exit fn test_let_with_return | | @@ -1183,15 +1183,15 @@ edges | test.rs:495:9:495:33 | ...::_print | test.rs:495:18:495:32 | "hello, world!\\n" | | | test.rs:495:9:495:33 | MacroExpr | test.rs:494:26:496:5 | { ... } | | | test.rs:495:9:495:33 | println!... | test.rs:495:9:495:33 | MacroExpr | | -| test.rs:495:9:495:34 | ExprStmt | test.rs:495:18:495:32 | MacroStmts | | +| test.rs:495:9:495:34 | ExprStmt | test.rs:495:18:495:32 | ExprStmt | | | test.rs:495:18:495:32 | "hello, world!\\n" | test.rs:495:18:495:32 | FormatArgsExpr | | | test.rs:495:18:495:32 | ...::_print(...) | test.rs:495:18:495:32 | { ... } | | | test.rs:495:18:495:32 | ...::format_args_nl!... | test.rs:495:18:495:32 | MacroExpr | | | test.rs:495:18:495:32 | ExprStmt | test.rs:495:9:495:33 | ...::_print | | | test.rs:495:18:495:32 | FormatArgsExpr | test.rs:495:18:495:32 | ...::format_args_nl!... | | | test.rs:495:18:495:32 | MacroExpr | test.rs:495:18:495:32 | ...::_print(...) | | -| test.rs:495:18:495:32 | MacroStmts | test.rs:495:18:495:32 | ExprStmt | | -| test.rs:495:18:495:32 | { ... } | test.rs:495:9:495:33 | println!... | | +| test.rs:495:18:495:32 | MacroStmts | test.rs:495:9:495:33 | println!... | | +| test.rs:495:18:495:32 | { ... } | test.rs:495:18:495:32 | MacroStmts | | | test.rs:498:5:517:5 | enter fn async_block | test.rs:498:26:498:26 | b | | | test.rs:498:5:517:5 | exit fn async_block (normal) | test.rs:498:5:517:5 | exit fn async_block | | | test.rs:498:26:498:26 | b | test.rs:498:26:498:26 | b | | @@ -1207,15 +1207,15 @@ edges | test.rs:500:13:500:41 | ...::_print | test.rs:500:22:500:40 | "godbye, everyone!\\n" | | | test.rs:500:13:500:41 | MacroExpr | test.rs:499:26:501:9 | exit { ... } (normal) | | | test.rs:500:13:500:41 | println!... | test.rs:500:13:500:41 | MacroExpr | | -| test.rs:500:13:500:42 | ExprStmt | test.rs:500:22:500:40 | MacroStmts | | +| test.rs:500:13:500:42 | ExprStmt | test.rs:500:22:500:40 | ExprStmt | | | test.rs:500:22:500:40 | "godbye, everyone!\\n" | test.rs:500:22:500:40 | FormatArgsExpr | | | test.rs:500:22:500:40 | ...::_print(...) | test.rs:500:22:500:40 | { ... } | | | test.rs:500:22:500:40 | ...::format_args_nl!... | test.rs:500:22:500:40 | MacroExpr | | | test.rs:500:22:500:40 | ExprStmt | test.rs:500:13:500:41 | ...::_print | | | test.rs:500:22:500:40 | FormatArgsExpr | test.rs:500:22:500:40 | ...::format_args_nl!... | | | test.rs:500:22:500:40 | MacroExpr | test.rs:500:22:500:40 | ...::_print(...) | | -| test.rs:500:22:500:40 | MacroStmts | test.rs:500:22:500:40 | ExprStmt | | -| test.rs:500:22:500:40 | { ... } | test.rs:500:13:500:41 | println!... | | +| test.rs:500:22:500:40 | MacroStmts | test.rs:500:13:500:41 | println!... | | +| test.rs:500:22:500:40 | { ... } | test.rs:500:22:500:40 | MacroStmts | | | test.rs:502:9:504:10 | let ... = ... | test.rs:502:31:504:9 | { ... } | | | test.rs:502:13:502:27 | say_how_are_you | test.rs:502:13:502:27 | say_how_are_you | | | test.rs:502:13:502:27 | say_how_are_you | test.rs:505:9:505:28 | let ... = ... | match | @@ -1225,15 +1225,15 @@ edges | test.rs:503:13:503:36 | ...::_print | test.rs:503:22:503:35 | "how are you?\\n" | | | test.rs:503:13:503:36 | MacroExpr | test.rs:502:31:504:9 | exit { ... } (normal) | | | test.rs:503:13:503:36 | println!... | test.rs:503:13:503:36 | MacroExpr | | -| test.rs:503:13:503:37 | ExprStmt | test.rs:503:22:503:35 | MacroStmts | | +| test.rs:503:13:503:37 | ExprStmt | test.rs:503:22:503:35 | ExprStmt | | | test.rs:503:22:503:35 | "how are you?\\n" | test.rs:503:22:503:35 | FormatArgsExpr | | | test.rs:503:22:503:35 | ...::_print(...) | test.rs:503:22:503:35 | { ... } | | | test.rs:503:22:503:35 | ...::format_args_nl!... | test.rs:503:22:503:35 | MacroExpr | | | test.rs:503:22:503:35 | ExprStmt | test.rs:503:13:503:36 | ...::_print | | | test.rs:503:22:503:35 | FormatArgsExpr | test.rs:503:22:503:35 | ...::format_args_nl!... | | | test.rs:503:22:503:35 | MacroExpr | test.rs:503:22:503:35 | ...::_print(...) | | -| test.rs:503:22:503:35 | MacroStmts | test.rs:503:22:503:35 | ExprStmt | | -| test.rs:503:22:503:35 | { ... } | test.rs:503:13:503:36 | println!... | | +| test.rs:503:22:503:35 | MacroStmts | test.rs:503:13:503:36 | println!... | | +| test.rs:503:22:503:35 | { ... } | test.rs:503:22:503:35 | MacroStmts | | | test.rs:505:9:505:28 | let ... = ... | test.rs:505:20:505:27 | { ... } | | | test.rs:505:13:505:16 | noop | test.rs:505:13:505:16 | noop | | | test.rs:505:13:505:16 | noop | test.rs:506:9:506:26 | ExprStmt | match | @@ -1290,30 +1290,30 @@ edges | test.rs:533:13:533:49 | ...::panic_2021!... | test.rs:533:13:533:49 | MacroExpr | | | test.rs:533:13:533:49 | ...::panic_explicit | test.rs:533:13:533:49 | ...::panic_explicit(...) | | | test.rs:533:13:533:49 | ...::panic_explicit(...) | test.rs:533:13:533:49 | { ... } | | -| test.rs:533:13:533:49 | ExprStmt | test.rs:533:13:533:49 | MacroStmts | | +| test.rs:533:13:533:49 | ExprStmt | test.rs:533:13:533:49 | fn panic_cold_explicit | | | test.rs:533:13:533:49 | ExprStmt | test.rs:533:13:533:49 | panic_cold_explicit | | | test.rs:533:13:533:49 | MacroExpr | test.rs:532:9:534:9 | { ... } | | | test.rs:533:13:533:49 | MacroExpr | test.rs:533:13:533:49 | { ... } | | -| test.rs:533:13:533:49 | MacroStmts | test.rs:533:13:533:49 | fn panic_cold_explicit | | +| test.rs:533:13:533:49 | MacroStmts | test.rs:533:13:533:49 | ...::panic_2021!... | | | test.rs:533:13:533:49 | assert!... | test.rs:533:13:533:49 | MacroExpr | | | test.rs:533:13:533:49 | enter fn panic_cold_explicit | test.rs:533:13:533:49 | ...::panic_explicit | | | test.rs:533:13:533:49 | exit fn panic_cold_explicit (normal) | test.rs:533:13:533:49 | exit fn panic_cold_explicit | | | test.rs:533:13:533:49 | fn panic_cold_explicit | test.rs:533:13:533:49 | ExprStmt | | | test.rs:533:13:533:49 | panic_cold_explicit | test.rs:533:13:533:49 | panic_cold_explicit(...) | | | test.rs:533:13:533:49 | panic_cold_explicit(...) | test.rs:533:13:533:49 | { ... } | | -| test.rs:533:13:533:49 | { ... } | test.rs:533:13:533:49 | ...::panic_2021!... | | +| test.rs:533:13:533:49 | { ... } | test.rs:533:13:533:49 | MacroStmts | | | test.rs:533:13:533:49 | { ... } | test.rs:533:13:533:49 | exit fn panic_cold_explicit (normal) | | | test.rs:533:13:533:49 | { ... } | test.rs:533:21:533:48 | if ... {...} | | -| test.rs:533:13:533:50 | ExprStmt | test.rs:533:21:533:48 | MacroStmts | | +| test.rs:533:13:533:50 | ExprStmt | test.rs:533:21:533:42 | ...::size_of::<...> | | | test.rs:533:21:533:42 | ...::size_of::<...> | test.rs:533:21:533:44 | ...::size_of::<...>(...) | | | test.rs:533:21:533:44 | ...::size_of::<...>(...) | test.rs:533:48:533:48 | 0 | | | test.rs:533:21:533:48 | ... > ... | test.rs:533:21:533:48 | [boolean(false)] ! ... | true | | test.rs:533:21:533:48 | ... > ... | test.rs:533:21:533:48 | [boolean(true)] ! ... | false | -| test.rs:533:21:533:48 | MacroStmts | test.rs:533:21:533:42 | ...::size_of::<...> | | +| test.rs:533:21:533:48 | MacroStmts | test.rs:533:13:533:49 | assert!... | | | test.rs:533:21:533:48 | [boolean(false)] ! ... | test.rs:533:21:533:48 | if ... {...} | false | | test.rs:533:21:533:48 | [boolean(true)] ! ... | test.rs:533:13:533:49 | ExprStmt | true | | test.rs:533:21:533:48 | if ... {...} | test.rs:533:21:533:48 | { ... } | | -| test.rs:533:21:533:48 | { ... } | test.rs:533:13:533:49 | assert!... | | +| test.rs:533:21:533:48 | { ... } | test.rs:533:21:533:48 | MacroStmts | | | test.rs:533:48:533:48 | 0 | test.rs:533:21:533:48 | ... > ... | | | test.rs:536:9:536:10 | 42 | test.rs:529:41:537:5 | { ... } | | | test.rs:539:5:548:5 | enter fn const_block_panic | test.rs:540:9:540:30 | Const | | diff --git a/rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected b/rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected index 6c2a7c2ba85..a03453383b0 100644 --- a/rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected +++ b/rust/ql/test/library-tests/dataflow/local/DataFlowStep.expected @@ -10,12 +10,14 @@ localStep | main.rs:6:9:6:9 | s | main.rs:6:9:6:9 | s | | main.rs:6:9:6:14 | ...: i64 | main.rs:6:9:6:9 | s | | main.rs:7:14:7:20 | FormatArgsExpr | main.rs:7:14:7:20 | MacroExpr | +| main.rs:7:14:7:20 | MacroStmts | main.rs:7:5:7:21 | MacroExpr | | main.rs:7:14:7:20 | [post] MacroExpr | main.rs:7:14:7:20 | [post] FormatArgsExpr | | main.rs:10:13:10:14 | [SSA] sr | main.rs:11:20:11:21 | sr | | main.rs:10:13:10:14 | sr | main.rs:10:13:10:14 | [SSA] sr | | main.rs:10:13:10:14 | sr | main.rs:10:13:10:14 | sr | | main.rs:10:13:10:20 | ...: ... | main.rs:10:13:10:14 | sr | | main.rs:11:14:11:21 | FormatArgsExpr | main.rs:11:14:11:21 | MacroExpr | +| main.rs:11:14:11:21 | MacroStmts | main.rs:11:5:11:22 | MacroExpr | | main.rs:11:14:11:21 | [post] MacroExpr | main.rs:11:14:11:21 | [post] FormatArgsExpr | | main.rs:22:9:22:9 | [SSA] s | main.rs:23:10:23:10 | s | | main.rs:22:9:22:9 | s | main.rs:22:9:22:9 | [SSA] s | @@ -680,6 +682,7 @@ localStep | main.rs:462:16:462:16 | s | main.rs:462:16:462:16 | s | | main.rs:462:16:462:24 | ...: String | main.rs:462:16:462:16 | s | | main.rs:463:14:463:20 | FormatArgsExpr | main.rs:463:14:463:20 | MacroExpr | +| main.rs:463:14:463:20 | MacroStmts | main.rs:463:5:463:21 | MacroExpr | | main.rs:463:14:463:20 | [post] MacroExpr | main.rs:463:14:463:20 | [post] FormatArgsExpr | | main.rs:467:9:467:9 | [SSA] a | main.rs:468:13:468:13 | a | | main.rs:467:9:467:9 | a | main.rs:467:9:467:9 | [SSA] a | diff --git a/rust/ql/test/library-tests/variables/Cfg.expected b/rust/ql/test/library-tests/variables/Cfg.expected index 2f3d9927710..2c04ca30410 100644 --- a/rust/ql/test/library-tests/variables/Cfg.expected +++ b/rust/ql/test/library-tests/variables/Cfg.expected @@ -8,15 +8,15 @@ edges | main.rs:4:5:4:21 | ...::_print | main.rs:4:14:4:17 | "{}\\n" | | | main.rs:4:5:4:21 | MacroExpr | main.rs:3:23:5:1 | { ... } | | | main.rs:4:5:4:21 | println!... | main.rs:4:5:4:21 | MacroExpr | | -| main.rs:4:5:4:22 | ExprStmt | main.rs:4:14:4:20 | MacroStmts | | +| main.rs:4:5:4:22 | ExprStmt | main.rs:4:14:4:20 | ExprStmt | | | main.rs:4:14:4:17 | "{}\\n" | main.rs:4:20:4:20 | s | | | main.rs:4:14:4:20 | ...::_print(...) | main.rs:4:14:4:20 | { ... } | | | main.rs:4:14:4:20 | ...::format_args_nl!... | main.rs:4:14:4:20 | MacroExpr | | | main.rs:4:14:4:20 | ExprStmt | main.rs:4:5:4:21 | ...::_print | | | main.rs:4:14:4:20 | FormatArgsExpr | main.rs:4:14:4:20 | ...::format_args_nl!... | | | main.rs:4:14:4:20 | MacroExpr | main.rs:4:14:4:20 | ...::_print(...) | | -| main.rs:4:14:4:20 | MacroStmts | main.rs:4:14:4:20 | ExprStmt | | -| main.rs:4:14:4:20 | { ... } | main.rs:4:5:4:21 | println!... | | +| main.rs:4:14:4:20 | MacroStmts | main.rs:4:5:4:21 | println!... | | +| main.rs:4:14:4:20 | { ... } | main.rs:4:14:4:20 | MacroStmts | | | main.rs:4:20:4:20 | s | main.rs:4:14:4:20 | FormatArgsExpr | | | main.rs:7:1:9:1 | enter fn print_i64 | main.rs:7:14:7:14 | i | | | main.rs:7:1:9:1 | exit fn print_i64 (normal) | main.rs:7:1:9:1 | exit fn print_i64 | | @@ -27,15 +27,15 @@ edges | main.rs:8:5:8:21 | ...::_print | main.rs:8:14:8:17 | "{}\\n" | | | main.rs:8:5:8:21 | MacroExpr | main.rs:7:22:9:1 | { ... } | | | main.rs:8:5:8:21 | println!... | main.rs:8:5:8:21 | MacroExpr | | -| main.rs:8:5:8:22 | ExprStmt | main.rs:8:14:8:20 | MacroStmts | | +| main.rs:8:5:8:22 | ExprStmt | main.rs:8:14:8:20 | ExprStmt | | | main.rs:8:14:8:17 | "{}\\n" | main.rs:8:20:8:20 | i | | | main.rs:8:14:8:20 | ...::_print(...) | main.rs:8:14:8:20 | { ... } | | | main.rs:8:14:8:20 | ...::format_args_nl!... | main.rs:8:14:8:20 | MacroExpr | | | main.rs:8:14:8:20 | ExprStmt | main.rs:8:5:8:21 | ...::_print | | | main.rs:8:14:8:20 | FormatArgsExpr | main.rs:8:14:8:20 | ...::format_args_nl!... | | | main.rs:8:14:8:20 | MacroExpr | main.rs:8:14:8:20 | ...::_print(...) | | -| main.rs:8:14:8:20 | MacroStmts | main.rs:8:14:8:20 | ExprStmt | | -| main.rs:8:14:8:20 | { ... } | main.rs:8:5:8:21 | println!... | | +| main.rs:8:14:8:20 | MacroStmts | main.rs:8:5:8:21 | println!... | | +| main.rs:8:14:8:20 | { ... } | main.rs:8:14:8:20 | MacroStmts | | | main.rs:8:20:8:20 | i | main.rs:8:14:8:20 | FormatArgsExpr | | | main.rs:11:1:13:1 | enter fn print_i64_ref | main.rs:11:18:11:18 | i | | | main.rs:11:1:13:1 | exit fn print_i64_ref (normal) | main.rs:11:1:13:1 | exit fn print_i64_ref | | @@ -234,7 +234,7 @@ edges | main.rs:93:19:99:1 | { ... } | main.rs:93:1:99:1 | exit fn let_pattern4 (normal) | | | main.rs:94:5:97:10 | let ... = ... else {...} | main.rs:94:34:94:37 | Some | | | main.rs:94:9:94:16 | Some(...) | main.rs:94:14:94:15 | x5 | match | -| main.rs:94:9:94:16 | Some(...) | main.rs:96:13:96:19 | MacroStmts | no-match | +| main.rs:94:9:94:16 | Some(...) | main.rs:96:13:96:19 | ...::panic | no-match | | main.rs:94:14:94:15 | x5 | main.rs:94:14:94:15 | x5 | | | main.rs:94:14:94:15 | x5 | main.rs:98:5:98:18 | ExprStmt | match | | main.rs:94:34:94:37 | Some | main.rs:94:39:94:42 | "x5" | | @@ -242,9 +242,9 @@ edges | main.rs:94:39:94:42 | "x5" | main.rs:94:34:94:43 | Some(...) | | | main.rs:96:13:96:19 | "not yet implemented" | main.rs:96:13:96:19 | ...::panic(...) | | | main.rs:96:13:96:19 | ...::panic | main.rs:96:13:96:19 | "not yet implemented" | | -| main.rs:96:13:96:19 | ...::panic(...) | main.rs:96:13:96:19 | todo!... | | +| main.rs:96:13:96:19 | ...::panic(...) | main.rs:96:13:96:19 | MacroStmts | | | main.rs:96:13:96:19 | MacroExpr | main.rs:95:14:97:9 | { ... } | | -| main.rs:96:13:96:19 | MacroStmts | main.rs:96:13:96:19 | ...::panic | | +| main.rs:96:13:96:19 | MacroStmts | main.rs:96:13:96:19 | todo!... | | | main.rs:96:13:96:19 | todo!... | main.rs:96:13:96:19 | MacroExpr | | | main.rs:98:5:98:13 | print_str | main.rs:98:15:98:16 | x5 | | | main.rs:98:5:98:17 | print_str(...) | main.rs:93:19:99:1 | { ... } | | @@ -417,7 +417,7 @@ edges | main.rs:175:30:175:31 | 10 | main.rs:178:9:178:29 | ...::Hello {...} | no-match | | main.rs:175:30:175:36 | RangePat | main.rs:175:30:175:31 | 10 | match | | main.rs:175:35:175:36 | 12 | main.rs:175:35:175:36 | 12 | | -| main.rs:175:35:175:36 | 12 | main.rs:176:22:176:51 | MacroStmts | match | +| main.rs:175:35:175:36 | 12 | main.rs:176:22:176:51 | ExprStmt | match | | main.rs:175:35:175:36 | 12 | main.rs:178:9:178:29 | ...::Hello {...} | no-match | | main.rs:175:43:177:9 | { ... } | main.rs:171:5:180:5 | match msg { ... } | | | main.rs:176:13:176:52 | ...::_print | main.rs:176:22:176:51 | "Found an id in another range\\... | | @@ -429,8 +429,8 @@ edges | main.rs:176:22:176:51 | ExprStmt | main.rs:176:13:176:52 | ...::_print | | | main.rs:176:22:176:51 | FormatArgsExpr | main.rs:176:22:176:51 | ...::format_args_nl!... | | | main.rs:176:22:176:51 | MacroExpr | main.rs:176:22:176:51 | ...::_print(...) | | -| main.rs:176:22:176:51 | MacroStmts | main.rs:176:22:176:51 | ExprStmt | | -| main.rs:176:22:176:51 | { ... } | main.rs:176:13:176:52 | println!... | | +| main.rs:176:22:176:51 | MacroStmts | main.rs:176:13:176:52 | println!... | | +| main.rs:176:22:176:51 | { ... } | main.rs:176:22:176:51 | MacroStmts | | | main.rs:178:9:178:29 | ...::Hello {...} | main.rs:178:26:178:27 | id | match | | main.rs:178:26:178:27 | id | main.rs:178:26:178:27 | id | | | main.rs:178:26:178:27 | id | main.rs:179:13:179:21 | print_i64 | match | diff --git a/rust/schema/annotations.py b/rust/schema/annotations.py index a5c3ff56651..f783e72e619 100644 --- a/rust/schema/annotations.py +++ b/rust/schema/annotations.py @@ -87,7 +87,8 @@ class _: foo::bar; ``` """ - segment: _ | ql.db_table_name("path_segments_") | doc("last segment of this path") + segment: _ | ql.db_table_name("path_segments_") | doc( + "last segment of this path") @annotate(GenericArgList) @@ -1288,7 +1289,7 @@ class _: """ -@annotate(MacroStmts) +@annotate(MacroStmts, replace_bases={AstNode: Expr}, cfg=True) @rust.doc_test_signature(None) class _: """ @@ -1447,6 +1448,7 @@ class _: type_repr: optional["TypeRepr"] | child | rust.detach trait_type_repr: optional["PathTypeRepr"] | child | rust.detach + @annotate(PathTypeRepr) @qltest.test_with(Path) class _: