From e49a5be62f4cd70a4c9e3564f06299364139282b Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 22 Nov 2024 12:16:12 +0100 Subject: [PATCH 1/3] Rust: fix parent/child relationship for format entities --- rust/ql/.generated.list | 32 +++++++++++-------- rust/ql/.gitattributes | 12 +++++-- .../internal/generated/CfgNodes.qll | 21 +++++++++++- rust/ql/lib/codeql/rust/elements/Format.qll | 1 + .../codeql/rust/elements/FormatArgsExpr.qll | 7 +++- .../codeql/rust/elements/FormatArgument.qll | 1 + .../elements/internal/FormatArgsExprImpl.qll | 14 ++++---- .../elements/internal/FormatArgumentImpl.qll | 2 ++ .../rust/elements/internal/FormatImpl.qll | 2 ++ .../elements/internal/generated/Format.qll | 11 +++++++ .../internal/generated/FormatArgsExpr.qll | 22 ++++++++++++- .../internal/generated/FormatArgument.qll | 11 +++++++ .../internal/generated/ParentChild.qll | 16 ++++++++-- .../rust/elements/internal/generated/Raw.qll | 6 +++- .../generated/.generated_tests.list | 6 ++-- .../extractor-tests/generated/.gitattributes | 4 ++- .../generated/FormatArgsExpr/Format.expected | 9 ++++++ .../generated/FormatArgsExpr/Format.ql | 12 +++++++ .../FormatArgsExpr/FormatArgsArg.expected | 8 +++++ .../FormatArgsArg.ql | 0 .../FormatArgsArg_getExpr.expected | 8 +++++ .../FormatArgsArg_getExpr.ql | 0 .../FormatArgsArg_getName.expected | 2 ++ .../FormatArgsArg_getName.ql | 0 .../FormatArgsExpr/FormatArgsExpr.expected | 7 ++++ .../FormatArgsExpr/FormatArgsExpr.ql | 9 ++++-- .../FormatArgsExpr_getArg.expected | 8 +++++ .../FormatArgsExpr_getFormat.expected | 9 ++++++ .../FormatArgsExpr_getFormat.ql | 7 ++++ .../FormatArgsExpr_getTemplate.expected | 7 ++++ .../FormatArgsExpr_getVariable.expected | 5 +++ .../FormatArgsExpr/FormatArgument.expected | 10 ++++++ .../FormatArgsExpr/FormatArgument.ql | 11 +++++++ .../FormatArgument_getVariable.expected | 5 +++ .../FormatArgument_getVariable.ql | 7 ++++ .../FormatTemplateVariableAccess.expected | 5 +++ .../FormatTemplateVariableAccess.ql | 7 ++++ .../Format_getArgument.expected | 10 ++++++ .../FormatArgsExpr/Format_getArgument.ql | 7 ++++ .../generated/FormatArgsExpr/gen_format.rs | 6 ++++ .../gen_format_args_arg.rs | 0 .../FormatArgsExpr/gen_format_args_expr.rs | 6 +++- .../FormatArgsExpr/gen_format_argument.rs | 8 +++++ rust/schema/annotations.py | 17 +++++++--- 44 files changed, 317 insertions(+), 41 deletions(-) create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.expected rename rust/ql/test/extractor-tests/generated/{FormatArgsArg => FormatArgsExpr}/FormatArgsArg.ql (100%) create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.expected rename rust/ql/test/extractor-tests/generated/{FormatArgsArg => FormatArgsExpr}/FormatArgsArg_getExpr.ql (100%) create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.expected rename rust/ql/test/extractor-tests/generated/{FormatArgsArg => FormatArgsExpr}/FormatArgsArg_getName.ql (100%) create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getVariable.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.expected create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format.rs rename rust/ql/test/extractor-tests/generated/{FormatArgsArg => FormatArgsExpr}/gen_format_args_arg.rs (100%) create mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_argument.rs diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index e3fe15f3e5bf..1d4dabf28710 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -1,4 +1,4 @@ -lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll e7bcae1016e1853d46d9c91dc5f9b81e81d207fdf91fdaa6eadb3bf185879674 541d386db1f0b662d0cbe1aface1bc6e4b1bc484d1230b95523f35ca63c08875 +lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll a2d9717410e73aca512cad3af633700158ddd80b1c07dfd6ebe0f84723b4ac5b 3cfd6ae768958db3a4d633b4d781a8f4be80eb7a0d2ee871773584128e4551fd lib/codeql/rust/elements/Abi.qll 4c973d28b6d628f5959d1f1cc793704572fd0acaae9a97dfce82ff9d73f73476 250f68350180af080f904cd34cb2af481c5c688dc93edf7365fd0ae99855e893 lib/codeql/rust/elements/ArgList.qll 661f5100f5d3ef8351452d9058b663a2a5c720eea8cf11bedd628969741486a2 28e424aac01a90fb58cd6f9f83c7e4cf379eea39e636bc0ba07efc818be71c71 lib/codeql/rust/elements/ArrayExpr.qll a3e6e122632f4011644ec31b37f88b32fe3f2b7e388e7e878a6883309937049f 12ccb5873d95c433da5606fd371d182ef2f71b78d0c53c2d6dec10fa45852bdc @@ -41,10 +41,10 @@ lib/codeql/rust/elements/FieldList.qll bd243adc4696c60f636055a1c2da28039fe202847 lib/codeql/rust/elements/FnPtrType.qll c4a90dc660cf620972dc23b95494f5caf9f050eabd4bdb52fdc061f8797ba9a1 f8defc91582fa503607664668f9e2e6c2cd8b320c7c449610f21e52e332a129f lib/codeql/rust/elements/ForExpr.qll 312804d53dd9236a2f2a15c9d6ec348b46e139a54eb5893e7e12487725df7444 fa5e20099b1179033bc209bad3548e3d1d4019c7fe0e455cec8ca1a9d48692ab lib/codeql/rust/elements/ForType.qll 0036bed8749358c356d78c4a0eef40d73e2796284293cde5604ae70ddd6d0470 4edcaf8f7c67d42ebe3ebb1be6a7643758717d4fe88f5f648b6a1c5ff4ee4de7 -lib/codeql/rust/elements/Format.qll 506172d176f4b965f428585c032464f4abe07a0e47c574f8e011d8641ec45370 653e81bf233b8729649064de64f4a7a8533f8864ac6d2ea913f347088c924c60 +lib/codeql/rust/elements/Format.qll 51222fa2d2e85d496ab093d74d3bc606ede3ce48f926106e059dc8478e657203 b4da6be38413c86f2e9d82004624abab16e23ef238197a5c85246009cce276d5 lib/codeql/rust/elements/FormatArgsArg.qll 5bc9b4cd1bac7131165836e93838c45452a08ea6011741cbddace3cbf9c69440 f825140e98dc9800d5c045402186793c7b21511448e2f6bf6402d1e06305219c -lib/codeql/rust/elements/FormatArgsExpr.qll f2ffad5a1105b29a8437c8ed6cf918cfcf4d65ac164bbf1be0585c3b673ca749 3ba20dc312a0a994bb43b37b2db72cbd4e06061b97918fa0e84ce355070ffbeb -lib/codeql/rust/elements/FormatArgument.qll bdd93e1da78637f19beee6f953d3a45512100e925d90cb5ad08a097f412009b8 2a0ae7eb885615e380f925c0d130a1b795bf3c395486550a1f1c9c82848f8d77 +lib/codeql/rust/elements/FormatArgsExpr.qll 8127cbe4082f7acc3d8a05298c2c9bea302519b8a6cd2d158a83c516d18fc487 88cf9b3bedd69a1150968f9a465c904bbb6805da0e0b90cfd1fc0dab1f6d9319 +lib/codeql/rust/elements/FormatArgument.qll f6fe17ee1481c353dd42edae8b5fa79aeb99dff25b4842ec9a6f267b1837d1e3 5aed19c2daf2383b89ad7fd527375641cff26ddee7afddb89bc0d18d520f4034 lib/codeql/rust/elements/FormatTemplateVariableAccess.qll ff3218a1dda30c232d0ecd9d1c60bbb9f3973456ef0bee1d1a12ad14b1e082b5 e4316291c939800d8b34d477d92be9404a30d52b7eee37302aef3d3205cf4ae0 lib/codeql/rust/elements/Function.qll 2c76c2c7036891996b1f0ebde16c414edf37ebb44ff9c3483088dc6218733e07 d84d017d98aa240bf3bee6502a030aa8cfb7ed95425ffa9853e73b41485e1f4a lib/codeql/rust/elements/GenericArg.qll 5f11ce0e3c5f08de84db61f56ba1b984652455ba6b95a8b8a5b5a235913d4072 756b6a73d66fde45bdcc65ce2362a5b1391af2927e6d54b6550b3ecd5fd11e75 @@ -494,10 +494,10 @@ lib/codeql/rust/elements/internal/generated/FieldList.qll 43c13c6e3c9ba75a7a4cb8 lib/codeql/rust/elements/internal/generated/FnPtrType.qll 748d766dbefd19a7d644734c57885eeede66897029bbfe1b87919517f43bfde2 5a7d80acc00e56594ed85026a8ea4923104d2e98c2e42db8c5bcd32ddd164e48 lib/codeql/rust/elements/internal/generated/ForExpr.qll 541b62b48911d4999f9ed64ab6c8b9910073ac4add0225761f319677328cf120 976c3a91c9eedfb1e2d9ea76ac501348643b3d23c723d7a777042258d416d091 lib/codeql/rust/elements/internal/generated/ForType.qll 3d43d044a1189281f09c55caafb6c8020a836f49e2866077086101925a573cf2 646b59bfd1b428aaf7211f574c49f79cb4c6a79ca151aa0663b2b31480298721 -lib/codeql/rust/elements/internal/generated/Format.qll 37ad20cf2bf363b4027a8913d095292c8a4eb8ccdf2a9965f2fb7d41930f9bfe 329b89cdd75ce951269273dd18897e32ff5cfcc94f451001c64143386c1e48dd +lib/codeql/rust/elements/internal/generated/Format.qll df7ef61e6ba61fa0eb093f8e6b3e7a0329104e03f659c9507db9535b8b4ea759 ef8ddd98405fc84938ad8cd5f87d2858e01d06a6bb00566a785a984b60a79dc6 lib/codeql/rust/elements/internal/generated/FormatArgsArg.qll e07a1ae310f590003f1b88fada7dcf4847c99adb9d4c838d1c88e66e1da85c5f 0ef7342451fe2cb06e765fb4b33bb8c4a9b927f5edbc8feb5c6ba3655697f447 -lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll 40d6daa7d2bafb33798a21d79774dc802cfbd7a31618ac3bd0149399ea2bf893 d1172e2151791228559004792e125fc4625f6a26ffad25f29efb0ad263bf8795 -lib/codeql/rust/elements/internal/generated/FormatArgument.qll 00646f38217a66978b8b2648cca39dddbed22ece693b26cb682f019fbfedda95 e364e085f967847a7ed21b76156a9203d64032f0f0eea357b4779885a41bf9a7 +lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll 8aed8715a27d3af3de56ded4610c6792a25216b1544eb7e57c8b0b37c14bd9c1 590a2b0063d2ecd00bbbd1ce29603c8fd69972e34e6daddf309c915ce4ec1375 +lib/codeql/rust/elements/internal/generated/FormatArgument.qll cd05153276e63e689c95d5537fbc7d892615f62e110323759ef02e23a7587407 be2a4531b498f01625effa4c631d51ee8857698b00cfb829074120a0f2696d57 lib/codeql/rust/elements/internal/generated/FormatTemplateVariableAccess.qll a6175214fad445df9234b3ee9bf5147da75baf82473fb8d384b455e3add0dac1 a928db0ff126b2e54a18f5c488232abd1bd6c5eda24591d3c3bb80c6ee71c770 lib/codeql/rust/elements/internal/generated/Function.qll f285ee0c771f897eba6db34a7e98f3cfb7db91b0df252ff4b37fc9d779de0bfb 07401e832565ff376acda219514c2e2bbe4ae5058c76a73b40ca6ca66f1626c7 lib/codeql/rust/elements/internal/generated/GenericArg.qll 464da0ba1c5ddcd1be68617167f177773d99b5ac4775ec8ea24d503e789a9099 6faa1033d59baf7c210ac4837a55781cfc054b7acbad8027faf4630dbfa6e101 @@ -549,7 +549,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 ce24b8f8ecbf0f204af200317405724063887257460c80cf250c39b2fdf37185 e7c87d37e1a0ca7ea03840017e1aa9ddb7f927f1f3b6396c0305b46aeee33db6 lib/codeql/rust/elements/internal/generated/ParenType.qll 9cc954d73f8330dcac7b475f97748b63af5c8766dee9d2f2872c0a7e4c903537 c07534c8a9c683c4a9b11d490095647e420de0a0bfc23273eaf6f31b00244273 -lib/codeql/rust/elements/internal/generated/ParentChild.qll b4d25c43ed44715053255c3c2f8aeb8d21826adc365f24026b2123a4f25cba86 1bc4bb0380a1a8b69055ffeac203b11b2a1b94e5ad88d1b32ff659e8feb26016 +lib/codeql/rust/elements/internal/generated/ParentChild.qll c1eca840f6c97dc3c7fec5deaf1be98c17558610ffc37b503571779afdadc912 9564f6ae3803505c2bc086b76e43570127a13374655d2013c77ce1863e0c1397 lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4 lib/codeql/rust/elements/internal/generated/Path.qll f2b1be2f8f44001a6533533c978c4a9a8b7d64838d6f39eef5f0c0e7890611b8 d724a00a38f42429ffa8fb3bffbb5ec69e16a32ceeeb1d1f026fc7adf87424a8 lib/codeql/rust/elements/internal/generated/PathExpr.qll 2096e3c1db22ee488a761690adabfc9cfdea501c99f7c5d96c0019cb113fc506 54245ce0449c4e263173213df01e079d5168a758503a5dbd61b25ad35a311140 @@ -562,7 +562,7 @@ lib/codeql/rust/elements/internal/generated/PtrType.qll 40099c5a4041314b66932dfd lib/codeql/rust/elements/internal/generated/PureSynthConstructors.qll ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590 ea294a3ba33fd1bc632046c4fedbcb84dcb961a8e4599969d65893b19d90e590 lib/codeql/rust/elements/internal/generated/RangeExpr.qll 23cca03bf43535f33b22a38894f70d669787be4e4f5b8fe5c8f7b964d30e9027 18624cef6c6b679eeace2a98737e472432e0ead354cca02192b4d45330f047c9 lib/codeql/rust/elements/internal/generated/RangePat.qll efd93730de217cf50dcba5875595263a5eadf9f7e4e1272401342a094d158614 229b251b3d118932e31e78ac4dfb75f48b766f240f20d436062785606d44467b -lib/codeql/rust/elements/internal/generated/Raw.qll 5f83209cda8319c5c6c932631b60c6f2163d2d9cf7be63f63523e2206c01d004 3581039746e86365f37644e86ac2c89d67e2123aa1b039d9e0afdffc7156c96d +lib/codeql/rust/elements/internal/generated/Raw.qll d679e866776a927f61d62ba980203e1142454606bdac69cc9b6720679ca5bbdd f47922df7f8c8efba0e2e5adde030247e43f02e9df7d263096c697bfe65c4277 lib/codeql/rust/elements/internal/generated/RecordExpr.qll eb6cb662e463f9260efae1a6ce874fa781172063b916ef1963f861e9942d308d 1a21cbccc8f3799ff13281e822818ebfb21d81591720a427cac3625512cb9d40 lib/codeql/rust/elements/internal/generated/RecordExprField.qll 7e9f8663d3b74ebbc9603b10c9912f082febba6bd73d344b100bbd3edf837802 fbe6b578e7fd5d5a6f21bbb8c388957ab7210a6a249ec71510a50fb35b319ea1 lib/codeql/rust/elements/internal/generated/RecordExprFieldList.qll 179a97211fe7aa6265085d4d54115cdbc0e1cd7c9b2135591e8f36d6432f13d3 dd44bbbc1e83a1ed3a587afb729d7debf7aeb7b63245de181726af13090e50c0 @@ -752,13 +752,19 @@ test/extractor-tests/generated/ForExpr/ForExpr_getPat.ql 1e0205a9b3a58fd2ddba49e test/extractor-tests/generated/ForType/ForType.ql ba930d0c4fe52d57449ce4025b1c3e49c688afc5ef18ee8ac1ed7a9fd3eb8d41 08e9aa0301a942f6f9564ddeddc69606f3e2916e1b551cc56ae3b6048c56ce61 test/extractor-tests/generated/ForType/ForType_getGenericParamList.ql e25cd79737bbae92d8f417c6bbf6fb8ae660976b8005cd91d0900c7076fdd827 b1e32b7e3ca9f29a4564f83e37ae53de6baf04837a393e6dedc64a01cc7d10e8 test/extractor-tests/generated/ForType/ForType_getTy.ql e932d3412828bb83afc42e2dc1a4cbe9fcf25ec9a9617ec138722f834091a61a 298fc9df34b2cb436c8f180c4d229341ee4a73e3c451b905f017f32a6f65056c -test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.ql a521903c73f79e2616f7b8ef76790e11cbf432f8437825d52d117da232022b9e 4cb195d09ecb51e5bbd5c1c069ec1720f74fc074efc88b0f5c07cfc140167775 -test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.ql 7e1a7f902fb661660760d2a2f3f4cb6818a0c9f5b5061ede6ae80223774e4e09 8a50f64cba6f56320631206c801160201e3c98e74367bb035d689baaa9b4e411 -test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.ql 0e2f24388d516e14d195957163a2d5d97029c9e11a83ca71cf69e00ecc0bb2a8 dab2969f5ae6a15ec331c0152e7c116d1ee2c3d073b2d4da59ffbcb83404c65f -test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql 0cd439f61569ecf046e9548c458329647f331bfa034ae8b3d4f7628595881287 013a948607e1ac96100ea9a8cd3c8f357e378ac21baa015dcf4927022c2bdafb +test/extractor-tests/generated/FormatArgsExpr/Format.ql 25268dd7ad2a58b071c3a38164944c1b7389dfdda01c99ef2694a475596341b4 0a3f674d5a4f005835b9a5ba11a6e8bf58477829258f30ae7d8f76f8986f7b7f +test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql a521903c73f79e2616f7b8ef76790e11cbf432f8437825d52d117da232022b9e 4cb195d09ecb51e5bbd5c1c069ec1720f74fc074efc88b0f5c07cfc140167775 +test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.ql 7e1a7f902fb661660760d2a2f3f4cb6818a0c9f5b5061ede6ae80223774e4e09 8a50f64cba6f56320631206c801160201e3c98e74367bb035d689baaa9b4e411 +test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.ql 0e2f24388d516e14d195957163a2d5d97029c9e11a83ca71cf69e00ecc0bb2a8 dab2969f5ae6a15ec331c0152e7c116d1ee2c3d073b2d4da59ffbcb83404c65f +test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql 7b6f09b23d0dffa19b8dddf7f5cfe53068f8a8e5279e235c6d54e60616bd0822 47db74f035770ce708a00355acbfd4ae99152b7eb29cf28001985806a4efe5aa test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.ql 8f692486be1546b914b17abdff4a989dfbaa889bfa1fc44597f4357806c1a1dd da9fd237e31e9c8dd0ef0c3c968157815b87d3e8dcdfd74674c988ce2ab6d270 test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getAttr.ql 1f9bf1344f942e65c3a3591b6ae04d3f5a2a1a65459bce0d976698de7d8a5958 02acb861d8ab4d32cf144c589881a888c3da5e2ade27e8c85fec3ae45219bb3b +test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql 02d3fad540700966488b24c62dcf200548154a2f10f578ee2995d8c4ebe32287 cccfe779b9804c2bb968a2b1f54da8a72393805c2c8b31d7160e8538f2f335f2 test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.ql c912ac37275cbe7b3b29607bed1a3190c80779436422c14a475113e1bfd91a54 ef90f67a9b952a38ce557b1afbf0b5ce8551e83ddfaad8309a0c9523e40b5ea7 +test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql 7a7ee3a3322b4af8cb3b525cfed8cc9719d136ea80aa6b3fb30c7e16394dd93f 5aa8a77d7741b02f8ceb9e5991efa4c2c43c6f1624989218990e985108dae535 +test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql 7bd4ec3dde2ef0463585794101e6cc426c368b0e4ab95fbb1f24f8f0a76cf471 e7b01e8b21df5b22c51643e2c909c6fc4ca96fda41b3290c907ba228abe8669b +test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql 2793ba1ff52182dab992d82d3767a000928f6b2fbfdb621349cafc183f0d2480 c3777d03214f7feb9020de3ce45af6556129e39e9b30d083de605b70ab9a0a12 +test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql 26d592398a17795427b5b6b51ff4a013ee15c31443e732a000baca5f2e65acca 7940a864b84b89e84d7fb186599cb8b6bcbead7141c592b8ab0c59fcd380d5fb test/extractor-tests/generated/Function/Function.ql c1c2a9b68c35f839ccd2b5e62e87d1acd94dcc2a3dc4c307c269b84b2a0806e6 1c446f19d2f81dd139aa5a1578d1b165e13bddbaeab8cfee8f0430bced3a99ab test/extractor-tests/generated/Function/Function_getAbi.ql e5c9c97de036ddd51cae5d99d41847c35c6b2eabbbd145f4467cb501edc606d8 0b81511528bd0ef9e63b19edfc3cb638d8af43eb87d018fad69d6ef8f8221454 test/extractor-tests/generated/Function/Function_getAttr.ql 44067ee11bdec8e91774ff10de0704a8c5c1b60816d587378e86bf3d82e1f660 b4bebf9441bda1f2d1e34e9261e07a7468cbabf53cf8047384f3c8b11869f04e diff --git a/rust/ql/.gitattributes b/rust/ql/.gitattributes index 68b893ba9c78..5e2e30e2ffea 100644 --- a/rust/ql/.gitattributes +++ b/rust/ql/.gitattributes @@ -754,13 +754,19 @@ /test/extractor-tests/generated/ForType/ForType.ql linguist-generated /test/extractor-tests/generated/ForType/ForType_getGenericParamList.ql linguist-generated /test/extractor-tests/generated/ForType/ForType_getTy.ql linguist-generated -/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.ql linguist-generated -/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.ql linguist-generated -/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/Format.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.ql linguist-generated /test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql linguist-generated /test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.ql linguist-generated /test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getAttr.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql linguist-generated /test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql linguist-generated +/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql linguist-generated /test/extractor-tests/generated/Function/Function.ql linguist-generated /test/extractor-tests/generated/Function/Function_getAbi.ql linguist-generated /test/extractor-tests/generated/Function/Function_getAttr.ql linguist-generated 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 b42a00bf551f..2cbb9e9d3bd2 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll @@ -928,7 +928,11 @@ module MakeCfgNodes Input> { /** * A FormatArgsExpr. For example: * ```rust - * todo!() + * format_args!("no args"); + * format_args!("{} foo {:?}", 1, 2); + * format_args!("{b} foo {a:?}", a=1, b=2); + * let (x, y) = (1, 42); + * format_args!("{x}, {y}"); * ``` */ final class FormatArgsExprCfgNode extends CfgNodeFinal, ExprCfgNode { @@ -980,6 +984,21 @@ module MakeCfgNodes Input> { * Holds if `getTemplate()` exists. */ predicate hasTemplate() { exists(this.getTemplate()) } + + /** + * Gets the `index`th format of this format arguments expression (0-based). + */ + Format getFormat(int index) { result = node.getFormat(index) } + + /** + * Gets any of the formats of this format arguments expression. + */ + Format getAFormat() { result = this.getFormat(_) } + + /** + * Gets the number of formats of this format arguments expression. + */ + int getNumberOfFormats() { result = count(int i | exists(this.getFormat(i))) } } final private class ParentFormatTemplateVariableAccess extends ParentAstNode, diff --git a/rust/ql/lib/codeql/rust/elements/Format.qll b/rust/ql/lib/codeql/rust/elements/Format.qll index 0c8b5d1c5413..f8b705be4fdb 100644 --- a/rust/ql/lib/codeql/rust/elements/Format.qll +++ b/rust/ql/lib/codeql/rust/elements/Format.qll @@ -5,6 +5,7 @@ private import internal.FormatImpl import codeql.rust.elements.FormatArgsExpr +import codeql.rust.elements.FormatArgument import codeql.rust.elements.Locatable /** diff --git a/rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll b/rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll index 226b4d211aae..419a48a53351 100644 --- a/rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/FormatArgsExpr.qll @@ -6,12 +6,17 @@ private import internal.FormatArgsExprImpl import codeql.rust.elements.Attr import codeql.rust.elements.Expr +import codeql.rust.elements.Format import codeql.rust.elements.FormatArgsArg /** * A FormatArgsExpr. For example: * ```rust - * todo!() + * format_args!("no args"); + * format_args!("{} foo {:?}", 1, 2); + * format_args!("{b} foo {a:?}", a=1, b=2); + * let (x, y) = (1, 42); + * format_args!("{x}, {y}"); * ``` */ final class FormatArgsExpr = Impl::FormatArgsExpr; diff --git a/rust/ql/lib/codeql/rust/elements/FormatArgument.qll b/rust/ql/lib/codeql/rust/elements/FormatArgument.qll index 62313c523727..00e9007434bb 100644 --- a/rust/ql/lib/codeql/rust/elements/FormatArgument.qll +++ b/rust/ql/lib/codeql/rust/elements/FormatArgument.qll @@ -5,6 +5,7 @@ private import internal.FormatArgumentImpl import codeql.rust.elements.Format +import codeql.rust.elements.FormatTemplateVariableAccess import codeql.rust.elements.Locatable /** diff --git a/rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll index 667439777b1a..59e020fb9e48 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FormatArgsExprImpl.qll @@ -16,16 +16,16 @@ module Impl { /** * A FormatArgsExpr. For example: * ```rust - * todo!() + * format_args!("no args"); + * format_args!("{} foo {:?}", 1, 2); + * format_args!("{b} foo {a:?}", a=1, b=2); + * let (x, y) = (1, 42); + * format_args!("{x}, {y}"); * ``` */ class FormatArgsExpr extends Generated::FormatArgsExpr { - /** - * Gets the `index`th format of this `FormatArgsExpr`'s formatting template (0-based). - */ - Format getFormat(int index) { - result = - rank[index + 1](Format f, int i | f.getParent() = this and f.getIndex() = i | f order by i) + override Format getFormat(int index) { + result.getParent() = this and result.getIndex() = index + 1 } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/FormatArgumentImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FormatArgumentImpl.qll index 7370939716d4..6719d9d8cb3c 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FormatArgumentImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FormatArgumentImpl.qll @@ -39,6 +39,8 @@ module Impl { override string toString() { result = name } override Format getParent() { result = Synth::TFormat(parent, index, _, _) } + + override FormatTemplateVariableAccess getVariable() { result.getArgument() = this } } private class FormatSynthLocationImpl extends FormatArgument, LocatableImpl::SynthLocatable { diff --git a/rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll index 59c66768f05f..7cde91053e91 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/FormatImpl.qll @@ -38,6 +38,8 @@ module Impl { override int getIndex() { result = index } + override FormatArgument getArgument() { result.getParent() = this } + /** * Gets the name or position reference of this format, if any. For example `name` and `0` in: * ```rust diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll index f2ade708ffaa..41c748d7fde3 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Format.qll @@ -7,6 +7,7 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.internal.generated.Raw import codeql.rust.elements.FormatArgsExpr +import codeql.rust.elements.FormatArgument import codeql.rust.elements.internal.LocatableImpl::Impl as LocatableImpl /** @@ -34,5 +35,15 @@ module Generated { * Gets the index of this format. */ int getIndex() { none() } + + /** + * Gets the argument of this format, if it exists. + */ + FormatArgument getArgument() { none() } + + /** + * Holds if `getArgument()` exists. + */ + final predicate hasArgument() { exists(this.getArgument()) } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll index 7fe088e25411..38034779e053 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgsExpr.qll @@ -9,6 +9,7 @@ private import codeql.rust.elements.internal.generated.Raw import codeql.rust.elements.Attr import codeql.rust.elements.Expr import codeql.rust.elements.internal.ExprImpl::Impl as ExprImpl +import codeql.rust.elements.Format import codeql.rust.elements.FormatArgsArg /** @@ -19,7 +20,11 @@ module Generated { /** * A FormatArgsExpr. For example: * ```rust - * todo!() + * format_args!("no args"); + * format_args!("{} foo {:?}", 1, 2); + * format_args!("{b} foo {a:?}", a=1, b=2); + * let (x, y) = (1, 42); + * format_args!("{x}, {y}"); * ``` * INTERNAL: Do not reference the `Generated::FormatArgsExpr` class directly. * Use the subclass `FormatArgsExpr`, where the following predicates are available. @@ -81,5 +86,20 @@ module Generated { * Holds if `getTemplate()` exists. */ final predicate hasTemplate() { exists(this.getTemplate()) } + + /** + * Gets the `index`th format of this format arguments expression (0-based). + */ + Format getFormat(int index) { none() } + + /** + * Gets any of the formats of this format arguments expression. + */ + final Format getAFormat() { result = this.getFormat(_) } + + /** + * Gets the number of formats of this format arguments expression. + */ + final int getNumberOfFormats() { result = count(int i | exists(this.getFormat(i))) } } } diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgument.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgument.qll index 658d6b92e7a5..a1db224494b5 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgument.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/FormatArgument.qll @@ -7,6 +7,7 @@ private import codeql.rust.elements.internal.generated.Synth private import codeql.rust.elements.internal.generated.Raw import codeql.rust.elements.Format +import codeql.rust.elements.FormatTemplateVariableAccess import codeql.rust.elements.internal.LocatableImpl::Impl as LocatableImpl /** @@ -33,5 +34,15 @@ module Generated { * Gets the parent of this format argument. */ Format getParent() { none() } + + /** + * Gets the variable of this format argument, if it exists. + */ + FormatTemplateVariableAccess getVariable() { none() } + + /** + * Holds if `getVariable()` exists. + */ + final predicate hasVariable() { exists(this.getVariable()) } } } 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 470207683ae5..a396da834d41 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/ParentChild.qll @@ -52,14 +52,17 @@ private module Impl { } private Element getImmediateChildOfFormat(Format e, int index, string partialPredicateCall) { - exists(int b, int bLocatable, int n | + exists(int b, int bLocatable, int n, int nArgument | b = 0 and bLocatable = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocatable(e, i, _)) | i) and n = bLocatable and + nArgument = n + 1 and ( none() or result = getImmediateChildOfLocatable(e, index - b, partialPredicateCall) + or + index = n and result = e.getArgument() and partialPredicateCall = "Argument()" ) ) } @@ -67,14 +70,17 @@ private module Impl { private Element getImmediateChildOfFormatArgument( FormatArgument e, int index, string partialPredicateCall ) { - exists(int b, int bLocatable, int n | + exists(int b, int bLocatable, int n, int nVariable | b = 0 and bLocatable = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfLocatable(e, i, _)) | i) and n = bLocatable and + nVariable = n + 1 and ( none() or result = getImmediateChildOfLocatable(e, index - b, partialPredicateCall) + or + index = n and result = e.getVariable() and partialPredicateCall = "Variable()" ) ) } @@ -1761,13 +1767,14 @@ private module Impl { private Element getImmediateChildOfFormatArgsExpr( FormatArgsExpr e, int index, string partialPredicateCall ) { - exists(int b, int bExpr, int n, int nArg, int nAttr, int nTemplate | + exists(int b, int bExpr, int n, int nArg, int nAttr, int nTemplate, int nFormat | b = 0 and bExpr = b + 1 + max(int i | i = -1 or exists(getImmediateChildOfExpr(e, i, _)) | i) and n = bExpr and nArg = n + 1 + max(int i | i = -1 or exists(e.getArg(i)) | i) and nAttr = nArg + 1 + max(int i | i = -1 or exists(e.getAttr(i)) | i) and nTemplate = nAttr + 1 and + nFormat = nTemplate + 1 + max(int i | i = -1 or exists(e.getFormat(i)) | i) and ( none() or @@ -1780,6 +1787,9 @@ private module Impl { partialPredicateCall = "Attr(" + (index - nArg).toString() + ")" or index = nAttr and result = e.getTemplate() and partialPredicateCall = "Template()" + or + result = e.getFormat(index - nTemplate) and + partialPredicateCall = "Format(" + (index - nTemplate).toString() + ")" ) ) } 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 25af8ddac644..efcdd4818dce 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll @@ -1885,7 +1885,11 @@ module Raw { * INTERNAL: Do not use. * A FormatArgsExpr. For example: * ```rust - * todo!() + * format_args!("no args"); + * format_args!("{} foo {:?}", 1, 2); + * format_args!("{b} foo {a:?}", a=1, b=2); + * let (x, y) = (1, 42); + * format_args!("{x}, {y}"); * ``` */ class FormatArgsExpr extends @format_args_expr, Expr { diff --git a/rust/ql/test/extractor-tests/generated/.generated_tests.list b/rust/ql/test/extractor-tests/generated/.generated_tests.list index b60779ebd86a..bfbe339bcc86 100644 --- a/rust/ql/test/extractor-tests/generated/.generated_tests.list +++ b/rust/ql/test/extractor-tests/generated/.generated_tests.list @@ -31,8 +31,10 @@ FieldExpr/gen_field_expr.rs 9a70500d592e0a071b03d974a55558b3bc0df531ff11bce5898f FnPtrType/gen_fn_ptr_type.rs a7842d8c21636739d1be959e5ce5e0b23482d5ef6eab5c45b009895da8175932 a7842d8c21636739d1be959e5ce5e0b23482d5ef6eab5c45b009895da8175932 ForExpr/gen_for_expr.rs 67decf3073e1a9363d9df05a5a64a6059349e50b81356f480f7aeb352189136d 67decf3073e1a9363d9df05a5a64a6059349e50b81356f480f7aeb352189136d ForType/gen_for_type.rs 6cb447df02c61b192e283e019576c28225added02d167030d64ebd0bebb1b158 6cb447df02c61b192e283e019576c28225added02d167030d64ebd0bebb1b158 -FormatArgsArg/gen_format_args_arg.rs c466f2fc2c0f9592061a159a217a87551d67f1ccb0e4d8f7f56a463a2aa4a73a c466f2fc2c0f9592061a159a217a87551d67f1ccb0e4d8f7f56a463a2aa4a73a -FormatArgsExpr/gen_format_args_expr.rs 7184dbb8833f970676e59fca3a40ec51d14a68e3151d8a6d637896494f2b4454 7184dbb8833f970676e59fca3a40ec51d14a68e3151d8a6d637896494f2b4454 +FormatArgsExpr/gen_format.rs bd009cb152c35e2aacd147b5520a42be31e66e9a8715ec1d0fd57b8e97c743ed bd009cb152c35e2aacd147b5520a42be31e66e9a8715ec1d0fd57b8e97c743ed +FormatArgsExpr/gen_format_args_arg.rs c466f2fc2c0f9592061a159a217a87551d67f1ccb0e4d8f7f56a463a2aa4a73a c466f2fc2c0f9592061a159a217a87551d67f1ccb0e4d8f7f56a463a2aa4a73a +FormatArgsExpr/gen_format_args_expr.rs 72c806ed163e9dcce2d0c5c8664d409b2aa635c1022c91959f9e8ae084f05bf2 72c806ed163e9dcce2d0c5c8664d409b2aa635c1022c91959f9e8ae084f05bf2 +FormatArgsExpr/gen_format_argument.rs 350d370e6f1db03d756384a3dbdb294697d241ff7c28d159cf57748abe99cfe9 350d370e6f1db03d756384a3dbdb294697d241ff7c28d159cf57748abe99cfe9 Function/gen_function.rs ba6ecb9e0d89183295eb02f3c20ebbf5c209f89bd0172c73a3b4a6dacbf3a54c ba6ecb9e0d89183295eb02f3c20ebbf5c209f89bd0172c73a3b4a6dacbf3a54c GenericArgList/gen_generic_arg_list.rs cfb072d3b48f9dd568c23d4dfefba28766628678f66bbf9a436de9919ead35f5 cfb072d3b48f9dd568c23d4dfefba28766628678f66bbf9a436de9919ead35f5 GenericParamList/gen_generic_param_list.rs 4cc9b628f53e1a6c5781ad195b8648fa6dee0bb41b24007fbd986527374d3669 4cc9b628f53e1a6c5781ad195b8648fa6dee0bb41b24007fbd986527374d3669 diff --git a/rust/ql/test/extractor-tests/generated/.gitattributes b/rust/ql/test/extractor-tests/generated/.gitattributes index 8ea3a00a31f0..df5c0c5b60cb 100644 --- a/rust/ql/test/extractor-tests/generated/.gitattributes +++ b/rust/ql/test/extractor-tests/generated/.gitattributes @@ -33,8 +33,10 @@ /FnPtrType/gen_fn_ptr_type.rs linguist-generated /ForExpr/gen_for_expr.rs linguist-generated /ForType/gen_for_type.rs linguist-generated -/FormatArgsArg/gen_format_args_arg.rs linguist-generated +/FormatArgsExpr/gen_format.rs linguist-generated +/FormatArgsExpr/gen_format_args_arg.rs linguist-generated /FormatArgsExpr/gen_format_args_expr.rs linguist-generated +/FormatArgsExpr/gen_format_argument.rs linguist-generated /Function/gen_function.rs linguist-generated /GenericArgList/gen_generic_arg_list.rs linguist-generated /GenericParamList/gen_generic_param_list.rs linguist-generated diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.expected new file mode 100644 index 000000000000..312f5a3b0712 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.expected @@ -0,0 +1,9 @@ +| gen_format.rs:5:21:5:22 | {} | getParent: | gen_format.rs:5:14:5:32 | FormatArgsExpr | getIndex: | 1 | hasArgument: | no | +| gen_format_args_expr.rs:6:19:6:20 | {} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 1 | hasArgument: | no | +| gen_format_args_expr.rs:6:26:6:29 | {:?} | getParent: | gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getIndex: | 3 | hasArgument: | no | +| gen_format_args_expr.rs:7:19:7:21 | {b} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes | +| gen_format_args_expr.rs:7:27:7:31 | {a:?} | getParent: | gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getIndex: | 3 | hasArgument: | yes | +| gen_format_args_expr.rs:9:19:9:21 | {x} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes | +| gen_format_args_expr.rs:9:24:9:26 | {y} | getParent: | gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getIndex: | 3 | hasArgument: | yes | +| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | getParent: | gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes | +| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | getParent: | gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | getIndex: | 1 | hasArgument: | yes | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.ql new file mode 100644 index 000000000000..fa17b4294f7e --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format.ql @@ -0,0 +1,12 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from Format x, FormatArgsExpr getParent, int getIndex, string hasArgument +where + toBeTested(x) and + not x.isUnknown() and + getParent = x.getParent() and + getIndex = x.getIndex() and + if x.hasArgument() then hasArgument = "yes" else hasArgument = "no" +select x, "getParent:", getParent, "getIndex:", getIndex, "hasArgument:", hasArgument diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.expected new file mode 100644 index 000000000000..8e704471e02c --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.expected @@ -0,0 +1,8 @@ +| gen_format.rs:5:26:5:32 | FormatArgsArg | hasExpr: | yes | hasName: | no | +| gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg | hasExpr: | yes | hasName: | no | +| gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg | hasExpr: | yes | hasName: | no | +| gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | hasExpr: | yes | hasName: | yes | +| gen_format_args_expr.rs:7:40:7:42 | FormatArgsArg | hasExpr: | yes | hasName: | yes | +| gen_format_argument.rs:7:34:7:38 | FormatArgsArg | hasExpr: | yes | hasName: | no | +| gen_format_argument.rs:7:41:7:45 | FormatArgsArg | hasExpr: | yes | hasName: | no | +| gen_format_argument.rs:7:48:7:56 | FormatArgsArg | hasExpr: | yes | hasName: | no | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql similarity index 100% rename from rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.ql rename to rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg.ql diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.expected new file mode 100644 index 000000000000..90cf2cae221f --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.expected @@ -0,0 +1,8 @@ +| gen_format.rs:5:26:5:32 | FormatArgsArg | gen_format.rs:5:26:5:32 | "world" | +| gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg | gen_format_args_expr.rs:6:33:6:33 | 1 | +| gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg | gen_format_args_expr.rs:6:36:6:36 | 2 | +| gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | gen_format_args_expr.rs:7:37:7:37 | 1 | +| gen_format_args_expr.rs:7:40:7:42 | FormatArgsArg | gen_format_args_expr.rs:7:42:7:42 | 2 | +| gen_format_argument.rs:7:34:7:38 | FormatArgsArg | gen_format_argument.rs:7:34:7:38 | value | +| gen_format_argument.rs:7:41:7:45 | FormatArgsArg | gen_format_argument.rs:7:41:7:45 | width | +| gen_format_argument.rs:7:48:7:56 | FormatArgsArg | gen_format_argument.rs:7:48:7:56 | precision | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.ql similarity index 100% rename from rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.ql rename to rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getExpr.ql diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.expected new file mode 100644 index 000000000000..ad5d7ab4ab22 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.expected @@ -0,0 +1,2 @@ +| gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | gen_format_args_expr.rs:7:35:7:35 | a | +| gen_format_args_expr.rs:7:40:7:42 | FormatArgsArg | gen_format_args_expr.rs:7:40:7:40 | b | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.ql similarity index 100% rename from rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.ql rename to rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsArg_getName.ql diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.expected index e69de29bb2d1..bed19ed26d47 100644 --- a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.expected +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.expected @@ -0,0 +1,7 @@ +| gen_format.rs:5:14:5:32 | FormatArgsExpr | getNumberOfArgs: | 1 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 | +| gen_format_args_expr.rs:5:17:5:27 | FormatArgsExpr | getNumberOfArgs: | 0 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 0 | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | getNumberOfArgs: | 2 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 2 | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | getNumberOfArgs: | 2 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 2 | +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | getNumberOfArgs: | 0 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 2 | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | getNumberOfArgs: | 0 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | getNumberOfArgs: | 3 | getNumberOfAttrs: | 0 | hasTemplate: | yes | getNumberOfFormats: | 1 | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql index 4d5bcf051735..6a43bc1ea0a3 100644 --- a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr.ql @@ -2,12 +2,15 @@ import codeql.rust.elements import TestUtils -from FormatArgsExpr x, int getNumberOfArgs, int getNumberOfAttrs, string hasTemplate +from + FormatArgsExpr x, int getNumberOfArgs, int getNumberOfAttrs, string hasTemplate, + int getNumberOfFormats where toBeTested(x) and not x.isUnknown() and getNumberOfArgs = x.getNumberOfArgs() and getNumberOfAttrs = x.getNumberOfAttrs() and - if x.hasTemplate() then hasTemplate = "yes" else hasTemplate = "no" + (if x.hasTemplate() then hasTemplate = "yes" else hasTemplate = "no") and + getNumberOfFormats = x.getNumberOfFormats() select x, "getNumberOfArgs:", getNumberOfArgs, "getNumberOfAttrs:", getNumberOfAttrs, - "hasTemplate:", hasTemplate + "hasTemplate:", hasTemplate, "getNumberOfFormats:", getNumberOfFormats diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.expected index e69de29bb2d1..89fce13908fd 100644 --- a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.expected +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getArg.expected @@ -0,0 +1,8 @@ +| gen_format.rs:5:14:5:32 | FormatArgsExpr | 0 | gen_format.rs:5:26:5:32 | FormatArgsArg | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 0 | gen_format_args_expr.rs:6:33:6:33 | FormatArgsArg | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 1 | gen_format_args_expr.rs:6:36:6:36 | FormatArgsArg | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 0 | gen_format_args_expr.rs:7:35:7:37 | FormatArgsArg | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 1 | gen_format_args_expr.rs:7:40:7:42 | FormatArgsArg | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | 0 | gen_format_argument.rs:7:34:7:38 | FormatArgsArg | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | 1 | gen_format_argument.rs:7:41:7:45 | FormatArgsArg | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | 2 | gen_format_argument.rs:7:48:7:56 | FormatArgsArg | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.expected new file mode 100644 index 000000000000..acbe782a35d2 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.expected @@ -0,0 +1,9 @@ +| gen_format.rs:5:14:5:32 | FormatArgsExpr | 0 | gen_format.rs:5:21:5:22 | {} | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 0 | gen_format_args_expr.rs:6:19:6:20 | {} | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | 2 | gen_format_args_expr.rs:6:26:6:29 | {:?} | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 0 | gen_format_args_expr.rs:7:19:7:21 | {b} | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | 2 | gen_format_args_expr.rs:7:27:7:31 | {a:?} | +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | 0 | gen_format_args_expr.rs:9:19:9:21 | {x} | +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | 2 | gen_format_args_expr.rs:9:24:9:26 | {y} | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | 0 | gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | 0 | gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql new file mode 100644 index 000000000000..ca61ca2bebd9 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getFormat.ql @@ -0,0 +1,7 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from FormatArgsExpr x, int index +where toBeTested(x) and not x.isUnknown() +select x, index, x.getFormat(index) diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.expected index e69de29bb2d1..6c4f70308109 100644 --- a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.expected +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getTemplate.expected @@ -0,0 +1,7 @@ +| gen_format.rs:5:14:5:32 | FormatArgsExpr | gen_format.rs:5:14:5:23 | "Hello {}\\n" | +| gen_format_args_expr.rs:5:17:5:27 | FormatArgsExpr | gen_format_args_expr.rs:5:18:5:26 | "no args" | +| gen_format_args_expr.rs:6:17:6:37 | FormatArgsExpr | gen_format_args_expr.rs:6:18:6:30 | "{} foo {:?}" | +| gen_format_args_expr.rs:7:17:7:43 | FormatArgsExpr | gen_format_args_expr.rs:7:18:7:32 | "{b} foo {a:?}" | +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | gen_format_args_expr.rs:9:18:9:27 | "{x}, {y}" | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | gen_format_argument.rs:5:14:5:47 | "Value {value:#width$.precision$}\\n" | +| gen_format_argument.rs:7:14:7:56 | FormatArgsExpr | gen_format_argument.rs:7:14:7:31 | "Value {0:#1$.2$}\\n" | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getVariable.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getVariable.expected new file mode 100644 index 000000000000..dca240710f7d --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgsExpr_getVariable.expected @@ -0,0 +1,5 @@ +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | 1 | gen_format_args_expr.rs:9:20:9:20 | x | +| gen_format_args_expr.rs:9:17:9:28 | FormatArgsExpr | 3 | gen_format_args_expr.rs:9:25:9:25 | y | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | 1 | gen_format_argument.rs:5:22:5:26 | value | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | 1 | gen_format_argument.rs:5:29:5:33 | width | +| gen_format_argument.rs:5:14:5:47 | FormatArgsExpr | 1 | gen_format_argument.rs:5:36:5:44 | precision | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.expected new file mode 100644 index 000000000000..e63b4b6558fc --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.expected @@ -0,0 +1,10 @@ +| gen_format_args_expr.rs:7:20:7:20 | b | getParent: | gen_format_args_expr.rs:7:19:7:21 | {b} | hasVariable: | no | +| gen_format_args_expr.rs:7:28:7:28 | a | getParent: | gen_format_args_expr.rs:7:27:7:31 | {a:?} | hasVariable: | no | +| gen_format_args_expr.rs:9:20:9:20 | x | getParent: | gen_format_args_expr.rs:9:19:9:21 | {x} | hasVariable: | yes | +| gen_format_args_expr.rs:9:25:9:25 | y | getParent: | gen_format_args_expr.rs:9:24:9:26 | {y} | hasVariable: | yes | +| gen_format_argument.rs:5:22:5:26 | value | getParent: | gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | hasVariable: | yes | +| gen_format_argument.rs:5:29:5:33 | width | getParent: | gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | hasVariable: | yes | +| gen_format_argument.rs:5:36:5:44 | precision | getParent: | gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | hasVariable: | yes | +| gen_format_argument.rs:7:22:7:22 | 0 | getParent: | gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | hasVariable: | no | +| gen_format_argument.rs:7:25:7:25 | 1 | getParent: | gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | hasVariable: | no | +| gen_format_argument.rs:7:28:7:28 | 2 | getParent: | gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | hasVariable: | no | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql new file mode 100644 index 000000000000..ed57154f7e82 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument.ql @@ -0,0 +1,11 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from FormatArgument x, Format getParent, string hasVariable +where + toBeTested(x) and + not x.isUnknown() and + getParent = x.getParent() and + if x.hasVariable() then hasVariable = "yes" else hasVariable = "no" +select x, "getParent:", getParent, "hasVariable:", hasVariable diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.expected new file mode 100644 index 000000000000..11db93ec06dd --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.expected @@ -0,0 +1,5 @@ +| gen_format_args_expr.rs:9:20:9:20 | x | gen_format_args_expr.rs:9:20:9:20 | x | +| gen_format_args_expr.rs:9:25:9:25 | y | gen_format_args_expr.rs:9:25:9:25 | y | +| gen_format_argument.rs:5:22:5:26 | value | gen_format_argument.rs:5:22:5:26 | value | +| gen_format_argument.rs:5:29:5:33 | width | gen_format_argument.rs:5:29:5:33 | width | +| gen_format_argument.rs:5:36:5:44 | precision | gen_format_argument.rs:5:36:5:44 | precision | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql new file mode 100644 index 000000000000..5d303bc4b6c6 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatArgument_getVariable.ql @@ -0,0 +1,7 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from FormatArgument x +where toBeTested(x) and not x.isUnknown() +select x, x.getVariable() diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.expected new file mode 100644 index 000000000000..df4fdad5c911 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.expected @@ -0,0 +1,5 @@ +| gen_format_args_expr.rs:9:20:9:20 | x | +| gen_format_args_expr.rs:9:25:9:25 | y | +| gen_format_argument.rs:5:22:5:26 | value | +| gen_format_argument.rs:5:29:5:33 | width | +| gen_format_argument.rs:5:36:5:44 | precision | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql new file mode 100644 index 000000000000..4f43ca11870a --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/FormatTemplateVariableAccess.ql @@ -0,0 +1,7 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from FormatTemplateVariableAccess x +where toBeTested(x) and not x.isUnknown() +select x diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.expected b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.expected new file mode 100644 index 000000000000..af9dd77578ce --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.expected @@ -0,0 +1,10 @@ +| gen_format_args_expr.rs:7:19:7:21 | {b} | gen_format_args_expr.rs:7:20:7:20 | b | +| gen_format_args_expr.rs:7:27:7:31 | {a:?} | gen_format_args_expr.rs:7:28:7:28 | a | +| gen_format_args_expr.rs:9:19:9:21 | {x} | gen_format_args_expr.rs:9:20:9:20 | x | +| gen_format_args_expr.rs:9:24:9:26 | {y} | gen_format_args_expr.rs:9:25:9:25 | y | +| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:22:5:26 | value | +| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:29:5:33 | width | +| gen_format_argument.rs:5:21:5:46 | {value:#width$.precision$} | gen_format_argument.rs:5:36:5:44 | precision | +| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:22:7:22 | 0 | +| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:25:7:25 | 1 | +| gen_format_argument.rs:7:21:7:30 | {0:#1$.2$} | gen_format_argument.rs:7:28:7:28 | 2 | diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql new file mode 100644 index 000000000000..e131365770b6 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/Format_getArgument.ql @@ -0,0 +1,7 @@ +// generated by codegen, do not edit +import codeql.rust.elements +import TestUtils + +from Format x +where toBeTested(x) and not x.isUnknown() +select x, x.getArgument() diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format.rs b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format.rs new file mode 100644 index 000000000000..86b78256d403 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format.rs @@ -0,0 +1,6 @@ +// generated by codegen, do not edit + +fn test_format() -> () { + // A format element in a formatting template. For example the `{}` in: + println!("Hello {}", "world"); +} diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/gen_format_args_arg.rs b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_arg.rs similarity index 100% rename from rust/ql/test/extractor-tests/generated/FormatArgsArg/gen_format_args_arg.rs rename to rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_arg.rs diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_expr.rs b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_expr.rs index 7345a633ba5d..3c2acb387fc7 100644 --- a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_expr.rs +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_args_expr.rs @@ -2,5 +2,9 @@ fn test_format_args_expr() -> () { // A FormatArgsExpr. For example: - todo!() + format_args!("no args"); + format_args!("{} foo {:?}", 1, 2); + format_args!("{b} foo {a:?}", a=1, b=2); + let (x, y) = (1, 42); + format_args!("{x}, {y}"); } diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_argument.rs b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_argument.rs new file mode 100644 index 000000000000..32cb123f51d0 --- /dev/null +++ b/rust/ql/test/extractor-tests/generated/FormatArgsExpr/gen_format_argument.rs @@ -0,0 +1,8 @@ +// generated by codegen, do not edit + +fn test_format_argument() -> () { + // An argument in a format element in a formatting template. For example the `width`, `precision`, and `value` in: + println!("Value {value:#width$.precision$}"); + // or the `0`, `1` and `2` in: + println!("Value {0:#1$.2$}", value, width, precision); +} diff --git a/rust/schema/annotations.py b/rust/schema/annotations.py index ae94b0604e7e..60f67a710d84 100644 --- a/rust/schema/annotations.py +++ b/rust/schema/annotations.py @@ -1011,6 +1011,7 @@ class _: @annotate(FormatArgsArg) +@qltest.test_with(FormatArgsExpr) class _: """ A FormatArgsArg. For example: @@ -1025,9 +1026,14 @@ class _: """ A FormatArgsExpr. For example: ```rust - todo!() + format_args!("no args"); + format_args!("{} foo {:?}", 1, 2); + format_args!("{b} foo {a:?}", a=1, b=2); + let (x, y) = (1, 42); + format_args!("{x}, {y}"); ``` """ + formats: list["Format"] | child | synth @annotate(GenericArg) @@ -1766,14 +1772,15 @@ class _: attrs: drop -@qltest.skip @synth.on_arguments(parent="FormatArgsExpr", index=int, kind=int) +@qltest.test_with(FormatArgsExpr) class FormatTemplateVariableAccess(PathExprBase): pass -@qltest.skip @synth.on_arguments(parent=FormatArgsExpr, index=int, text=string, offset=int) +@qltest.test_with(FormatArgsExpr) + class Format(Locatable): """ A format element in a formatting template. For example the `{}` in: @@ -1783,10 +1790,11 @@ class Format(Locatable): """ parent: FormatArgsExpr index: int + argument: optional["FormatArgument"] | child -@qltest.skip @synth.on_arguments(parent=FormatArgsExpr, index=int, kind=int, name=string, positional=boolean, offset=int) +@qltest.test_with(FormatArgsExpr) class FormatArgument(Locatable): """ An argument in a format element in a formatting template. For example the `width`, `precision`, and `value` in: @@ -1799,6 +1807,7 @@ class FormatArgument(Locatable): ``` """ parent: Format + variable: optional[FormatTemplateVariableAccess] | child @annotate(Item) class _: From 9a07b3c3d4d76e618c0bee5f363778285ef2984e Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 22 Nov 2024 12:24:44 +0100 Subject: [PATCH 2/3] Rust: remove obsolete expected files --- .../generated/FormatArgsArg/FormatArgsArg.expected | 0 .../generated/FormatArgsArg/FormatArgsArg_getExpr.expected | 0 .../generated/FormatArgsArg/FormatArgsArg_getName.expected | 0 3 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.expected delete mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.expected delete mode 100644 rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.expected diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.expected b/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg.expected deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.expected b/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getExpr.expected deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.expected b/rust/ql/test/extractor-tests/generated/FormatArgsArg/FormatArgsArg_getName.expected deleted file mode 100644 index e69de29bb2d1..000000000000 From 2e90c80a6f85fb451467b66002e7949490115bd0 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Fri, 22 Nov 2024 13:45:00 +0100 Subject: [PATCH 3/3] Rust: accept test changes --- .../CONSISTENCY/DataFlowConsistency.expected | 4 --- .../CONSISTENCY/DataFlowConsistency.expected | 5 ---- .../formatstrings/FormatTemplate.expected | 30 +++++++++---------- .../CONSISTENCY/DataFlowConsistency.expected | 4 --- .../CONSISTENCY/DataFlowConsistency.expected | 5 ---- 5 files changed, 15 insertions(+), 33 deletions(-) delete mode 100644 rust/ql/test/library-tests/definitions/CONSISTENCY/DataFlowConsistency.expected delete mode 100644 rust/ql/test/library-tests/formatstrings/CONSISTENCY/DataFlowConsistency.expected delete mode 100644 rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected diff --git a/rust/ql/test/library-tests/definitions/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/library-tests/definitions/CONSISTENCY/DataFlowConsistency.expected deleted file mode 100644 index 8d729bb5fd93..000000000000 --- a/rust/ql/test/library-tests/definitions/CONSISTENCY/DataFlowConsistency.expected +++ /dev/null @@ -1,4 +0,0 @@ -uniqueEnclosingCallable -| main.rs:5:29:5:33 | width | Node should have one enclosing callable but has 0. | -| main.rs:5:36:5:44 | precision | Node should have one enclosing callable but has 0. | -| main.rs:9:22:9:27 | people | Node should have one enclosing callable but has 0. | diff --git a/rust/ql/test/library-tests/formatstrings/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/library-tests/formatstrings/CONSISTENCY/DataFlowConsistency.expected deleted file mode 100644 index 5bd870a72056..000000000000 --- a/rust/ql/test/library-tests/formatstrings/CONSISTENCY/DataFlowConsistency.expected +++ /dev/null @@ -1,5 +0,0 @@ -uniqueEnclosingCallable -| main.rs:5:29:5:33 | width | Node should have one enclosing callable but has 0. | -| main.rs:5:36:5:44 | precision | Node should have one enclosing callable but has 0. | -| main.rs:16:22:16:27 | people | Node should have one enclosing callable but has 0. | -| main.rs:27:23:27:27 | width | Node should have one enclosing callable but has 0. | diff --git a/rust/ql/test/library-tests/formatstrings/FormatTemplate.expected b/rust/ql/test/library-tests/formatstrings/FormatTemplate.expected index 6750a5dc5f03..b554f7e79207 100644 --- a/rust/ql/test/library-tests/formatstrings/FormatTemplate.expected +++ b/rust/ql/test/library-tests/formatstrings/FormatTemplate.expected @@ -2,20 +2,20 @@ getFormat | main.rs:5:14:5:61 | FormatArgsExpr | main.rs:5:21:5:46 | {value:#width$.precision$} | 0 | | main.rs:6:14:6:56 | FormatArgsExpr | main.rs:6:21:6:30 | {0:#1$.2$} | 0 | | main.rs:7:14:7:40 | FormatArgsExpr | main.rs:7:21:7:22 | {} | 0 | -| main.rs:7:14:7:40 | FormatArgsExpr | main.rs:7:24:7:25 | {} | 1 | +| main.rs:7:14:7:40 | FormatArgsExpr | main.rs:7:24:7:25 | {} | 2 | | main.rs:11:14:11:34 | FormatArgsExpr | main.rs:11:22:11:23 | {} | 0 | | main.rs:12:14:12:34 | FormatArgsExpr | main.rs:12:29:12:30 | {} | 0 | | main.rs:13:14:13:27 | FormatArgsExpr | main.rs:13:15:13:18 | {:?} | 0 | | main.rs:14:14:14:33 | FormatArgsExpr | main.rs:14:15:14:21 | {value} | 0 | | main.rs:16:14:16:30 | FormatArgsExpr | main.rs:16:21:16:28 | {people} | 0 | | main.rs:17:14:17:26 | FormatArgsExpr | main.rs:17:15:17:16 | {} | 0 | -| main.rs:17:14:17:26 | FormatArgsExpr | main.rs:17:18:17:19 | {} | 1 | +| main.rs:17:14:17:26 | FormatArgsExpr | main.rs:17:18:17:19 | {} | 2 | | main.rs:18:14:18:24 | FormatArgsExpr | main.rs:18:15:18:19 | {:04} | 0 | | main.rs:19:14:19:32 | FormatArgsExpr | main.rs:19:15:19:19 | {:#?} | 0 | | main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:15:21:17 | {1} | 0 | -| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:19:21:20 | {} | 1 | -| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:22:21:24 | {0} | 2 | -| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:26:21:27 | {} | 3 | +| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:19:21:20 | {} | 2 | +| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:22:21:24 | {0} | 4 | +| main.rs:21:14:21:34 | FormatArgsExpr | main.rs:21:26:21:27 | {} | 6 | | main.rs:22:14:22:31 | FormatArgsExpr | main.rs:22:21:22:24 | {:5} | 0 | | main.rs:23:14:23:35 | FormatArgsExpr | main.rs:23:21:23:25 | {:1$} | 0 | | main.rs:24:14:24:36 | FormatArgsExpr | main.rs:24:21:24:26 | {1:0$} | 0 | @@ -33,25 +33,25 @@ getFormat | main.rs:36:24:36:41 | FormatArgsExpr | main.rs:36:31:36:35 | {:05} | 0 | | main.rs:37:24:37:38 | FormatArgsExpr | main.rs:37:25:37:32 | {:#010x} | 0 | | main.rs:39:14:39:45 | FormatArgsExpr | main.rs:39:21:39:23 | {0} | 0 | -| main.rs:39:14:39:45 | FormatArgsExpr | main.rs:39:28:39:33 | {1:.5} | 1 | +| main.rs:39:14:39:45 | FormatArgsExpr | main.rs:39:28:39:33 | {1:.5} | 2 | | main.rs:41:14:41:49 | FormatArgsExpr | main.rs:41:21:41:23 | {1} | 0 | -| main.rs:41:14:41:49 | FormatArgsExpr | main.rs:41:28:41:34 | {2:.0$} | 1 | +| main.rs:41:14:41:49 | FormatArgsExpr | main.rs:41:28:41:34 | {2:.0$} | 2 | | main.rs:43:14:43:49 | FormatArgsExpr | main.rs:43:21:43:23 | {0} | 0 | -| main.rs:43:14:43:49 | FormatArgsExpr | main.rs:43:28:43:34 | {2:.1$} | 1 | +| main.rs:43:14:43:49 | FormatArgsExpr | main.rs:43:28:43:34 | {2:.1$} | 2 | | main.rs:45:14:45:46 | FormatArgsExpr | main.rs:45:21:45:22 | {} | 0 | -| main.rs:45:14:45:46 | FormatArgsExpr | main.rs:45:27:45:31 | {:.*} | 1 | +| main.rs:45:14:45:46 | FormatArgsExpr | main.rs:45:27:45:31 | {:.*} | 2 | | main.rs:47:14:47:48 | FormatArgsExpr | main.rs:47:21:47:23 | {1} | 0 | -| main.rs:47:14:47:48 | FormatArgsExpr | main.rs:47:28:47:33 | {2:.*} | 1 | +| main.rs:47:14:47:48 | FormatArgsExpr | main.rs:47:28:47:33 | {2:.*} | 2 | | main.rs:48:14:48:47 | FormatArgsExpr | main.rs:48:21:48:22 | {} | 0 | -| main.rs:48:14:48:47 | FormatArgsExpr | main.rs:48:27:48:32 | {2:.*} | 1 | +| main.rs:48:14:48:47 | FormatArgsExpr | main.rs:48:27:48:32 | {2:.*} | 2 | | main.rs:49:14:49:72 | FormatArgsExpr | main.rs:49:21:49:22 | {} | 0 | -| main.rs:49:14:49:72 | FormatArgsExpr | main.rs:49:27:49:41 | {number:.prec$} | 1 | +| main.rs:49:14:49:72 | FormatArgsExpr | main.rs:49:27:49:41 | {number:.prec$} | 2 | | main.rs:52:9:55:22 | FormatArgsExpr | main.rs:52:10:52:11 | {} | 0 | -| main.rs:52:9:55:22 | FormatArgsExpr | main.rs:52:15:52:23 | {name:.*} | 1 | +| main.rs:52:9:55:22 | FormatArgsExpr | main.rs:52:15:52:23 | {name:.*} | 2 | | main.rs:58:9:61:24 | FormatArgsExpr | main.rs:58:10:58:11 | {} | 0 | -| main.rs:58:9:61:24 | FormatArgsExpr | main.rs:58:15:58:23 | {name:.*} | 1 | +| main.rs:58:9:61:24 | FormatArgsExpr | main.rs:58:15:58:23 | {name:.*} | 2 | | main.rs:64:9:67:24 | FormatArgsExpr | main.rs:64:10:64:11 | {} | 0 | -| main.rs:64:9:67:24 | FormatArgsExpr | main.rs:64:15:64:25 | {name:>8.*} | 1 | +| main.rs:64:9:67:24 | FormatArgsExpr | main.rs:64:15:64:25 | {name:>8.*} | 2 | | main.rs:70:12:70:31 | FormatArgsExpr | main.rs:70:13:70:20 | {0:.1$e} | 0 | | main.rs:71:12:71:31 | FormatArgsExpr | main.rs:71:13:71:20 | {0:.1$e} | 0 | | main.rs:73:14:73:35 | FormatArgsExpr | main.rs:73:28:73:29 | {} | 0 | diff --git a/rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/DataFlowConsistency.expected index 6e35019c1cbf..d9a60435a6f9 100644 --- a/rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/DataFlowConsistency.expected +++ b/rust/ql/test/query-tests/security/CWE-089/CONSISTENCY/DataFlowConsistency.expected @@ -1,7 +1,3 @@ -uniqueEnclosingCallable -| sqlx.rs:52:72:52:84 | remote_number | Node should have one enclosing callable but has 0. | -| sqlx.rs:56:74:56:86 | remote_string | Node should have one enclosing callable but has 0. | -| sqlx.rs:199:32:199:44 | enable_remote | Node should have one enclosing callable but has 0. | uniqueNodeToString | sqlx.rs:154:13:154:81 | (no string representation) | Node should have one toString but has 0. | | sqlx.rs:156:17:156:86 | (no string representation) | Node should have one toString but has 0. | diff --git a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected b/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected deleted file mode 100644 index 0a61a151c204..000000000000 --- a/rust/ql/test/query-tests/unusedentities/CONSISTENCY/DataFlowConsistency.expected +++ /dev/null @@ -1,5 +0,0 @@ -uniqueEnclosingCallable -| main.rs:194:25:194:25 | x | Node should have one enclosing callable but has 0. | -| main.rs:198:28:198:28 | x | Node should have one enclosing callable but has 0. | -| main.rs:202:28:202:28 | x | Node should have one enclosing callable but has 0. | -| main.rs:206:28:206:28 | x | Node should have one enclosing callable but has 0. |