From 4c4a8d76193504c5567323cb5aa84fa472308669 Mon Sep 17 00:00:00 2001 From: Paolo Tranquilli Date: Mon, 16 Dec 2024 14:12:13 +0100 Subject: [PATCH] Rust: extract `isRef` for `SelfParam` --- rust/ast-generator/src/main.rs | 8 ++++++++ rust/extractor/src/generated/.generated.list | 2 +- rust/extractor/src/generated/top.rs | 4 ++++ rust/extractor/src/translate/generated.rs | 2 ++ rust/ql/.generated.list | 14 +++++++------- .../controlflow/internal/generated/CfgNodes.qll | 14 ++++++++++++-- rust/ql/lib/codeql/rust/elements/SelfParam.qll | 9 +++++++-- .../rust/elements/internal/SelfParamImpl.qll | 9 +++++++-- .../rust/elements/internal/generated/Raw.qll | 14 ++++++++++++-- .../rust/elements/internal/generated/SelfParam.qll | 14 ++++++++++++-- rust/ql/lib/rust.dbscheme | 5 +++++ .../generated/.generated_tests.list | 2 +- .../generated/SelfParam/SelfParam.expected | 6 +++++- .../generated/SelfParam/SelfParam.ql | 9 +++++---- .../SelfParam/SelfParam_getLifetime.expected | 1 + .../generated/SelfParam/SelfParam_getName.expected | 6 +++++- .../generated/SelfParam/gen_self_param.rs | 13 ++++++++----- rust/schema/annotations.py | 10 ++++++++-- rust/schema/ast.py | 1 + 19 files changed, 111 insertions(+), 32 deletions(-) diff --git a/rust/ast-generator/src/main.rs b/rust/ast-generator/src/main.rs index 3fe918a4c3eb..c586342856f6 100644 --- a/rust/ast-generator/src/main.rs +++ b/rust/ast-generator/src/main.rs @@ -35,6 +35,7 @@ fn property_name(type_name: &str, field_name: &str) -> String { (_, "then_branch") => "then", (_, "else_branch") => "else_", ("ArrayType", "ty") => "element_type_repr", + ("SelfParam", "is_amp") => "is_ref", (_, "ty") => "type_repr", _ => field_name, }; @@ -363,6 +364,13 @@ fn get_fields(node: &AstNodeSrc) -> Vec { is_many: false, }); } + "SelfParam" => { + result.push(FieldInfo { + name: "is_amp".to_string(), + tp: "predicate".to_string(), + is_many: false, + }); + } _ => {} } diff --git a/rust/extractor/src/generated/.generated.list b/rust/extractor/src/generated/.generated.list index cbc2dd7c6573..d298aadd79fb 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 d09cf25daa06fc9bc802e438231e0f038443d2ede3972a0dd829f322b390c4e4 d09cf25daa06fc9bc802e438231e0f038443d2ede3972a0dd829f322b390c4e4 +top.rs d6c934b738b7f071df86303f6deb2a2d18bfc7545cd487446823e97702240582 d6c934b738b7f071df86303f6deb2a2d18bfc7545cd487446823e97702240582 diff --git a/rust/extractor/src/generated/top.rs b/rust/extractor/src/generated/top.rs index ee61282295da..b7b00a606082 100644 --- a/rust/extractor/src/generated/top.rs +++ b/rust/extractor/src/generated/top.rs @@ -6911,6 +6911,7 @@ pub struct SelfParam { pub id: trap::TrapId, pub attrs: Vec>, pub type_repr: Option>, + pub is_ref: bool, pub is_mut: bool, pub lifetime: Option>, pub name: Option>, @@ -6929,6 +6930,9 @@ impl trap::TrapEntry for SelfParam { if let Some(v) = self.type_repr { out.add_tuple("param_base_type_reprs", vec![id.into(), v.into()]); } + if self.is_ref { + out.add_tuple("self_param_is_ref", vec![id.into()]); + } if self.is_mut { out.add_tuple("self_param_is_mut", vec![id.into()]); } diff --git a/rust/extractor/src/translate/generated.rs b/rust/extractor/src/translate/generated.rs index a87f2d74caf4..a1c4865cf621 100644 --- a/rust/extractor/src/translate/generated.rs +++ b/rust/extractor/src/translate/generated.rs @@ -1812,6 +1812,7 @@ impl Translator<'_> { pub(crate) fn emit_self_param(&mut self, node: ast::SelfParam) -> Label { let attrs = node.attrs().map(|x| self.emit_attr(x)).collect(); + let is_ref = node.amp_token().is_some(); let is_mut = node.mut_token().is_some(); let lifetime = node.lifetime().map(|x| self.emit_lifetime(x)); let name = node.name().map(|x| self.emit_name(x)); @@ -1819,6 +1820,7 @@ impl Translator<'_> { let label = self.trap.emit(generated::SelfParam { id: TrapId::Star, attrs, + is_ref, is_mut, lifetime, name, diff --git a/rust/ql/.generated.list b/rust/ql/.generated.list index 264205ee9145..41a3264fae4f 100644 --- a/rust/ql/.generated.list +++ b/rust/ql/.generated.list @@ -1,4 +1,4 @@ -lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll 12a240e8392e4b0ad9ddb8067b25a1b5e4c1151886d9d64292a7a9ff29d11d97 fdbe7ca4f085d04371280299fd10a604ee5a059294d2c4c836f334d2b5f8926d +lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll 9e80eb4315a41fe2ce8649701f6306435861a048687d35de043c5a9feba195c2 8d4b43beaed489befb3ecbc2f0d52085fd157a67e3baeba78f6d312b51288b9c lib/codeql/rust/elements/Abi.qll 4c973d28b6d628f5959d1f1cc793704572fd0acaae9a97dfce82ff9d73f73476 250f68350180af080f904cd34cb2af481c5c688dc93edf7365fd0ae99855e893 lib/codeql/rust/elements/Addressable.qll 13011bfd2e1556694c3d440cc34af8527da4df49ad92b62f2939d3699ff2cea5 ddb25935f7553a1a384b1abe2e4b4fa90ab50b952dadec32fd867afcb054f4be lib/codeql/rust/elements/ArgList.qll 661f5100f5d3ef8351452d9058b663a2a5c720eea8cf11bedd628969741486a2 28e424aac01a90fb58cd6f9f83c7e4cf379eea39e636bc0ba07efc818be71c71 @@ -131,7 +131,7 @@ lib/codeql/rust/elements/RestPat.qll a898a2c396f974a52424efbc8168174416ac6ed30f9 lib/codeql/rust/elements/RetTypeRepr.qll a95a053e861a8d6e5e8eda531f29c611b00904d48ea2bb493138d94d39096ace ebde4f865d310351ba6ee71852428819627ea3909e341d6800ab268b1810c6fa lib/codeql/rust/elements/ReturnExpr.qll b87187cff55bc33c8c18558c9b88617179183d1341b322c1cab35ba07167bbdb 892f3a9df2187e745c869e67f33c228ee42754bc9e4f8f4c1718472eb8f8c80f lib/codeql/rust/elements/ReturnTypeSyntax.qll 0aa9125f5ea8864ecf1e4ff6e85f060f1b11fdd603448816145fea1b290f0232 3911819548ad1cf493199aac2ed15652c8e48b532a1e92153388b062191c1e6e -lib/codeql/rust/elements/SelfParam.qll 7d720c99097a340bc7bf6cc27ac6fe291a04af53e9bac23bf070b04b36e6e033 736488794a46ea702dcd3f603134052598207f3953acce3c9237bd6c6a038b23 +lib/codeql/rust/elements/SelfParam.qll e36b54cdc57529935910b321c336783e9e2662c762f3cd6af492d819373ff188 7a4735dbf532fc0c33ebdb0b5c1dfc4e5267e79ceff4ca8977065eb0ce54aaf5 lib/codeql/rust/elements/SlicePat.qll f48f13bb13378cc68f935d5b09175c316f3e81f50ef6a3ac5fdbfbfb473d6fc1 4c8df0b092274f37028e287a949f1a287f7505b7c2c36ee8d5f47fb8365d278a lib/codeql/rust/elements/SliceTypeRepr.qll 4f3fcb2b457ba95c76a1ff786e6fc217ad1a5f570dac68ec5da4b9a37c963186 b3f524d744d3fcef85a2e1e175b99a8e3acab36b2a717f107272ed92a48940c0 lib/codeql/rust/elements/SourceFile.qll 5916d550385d618bd3b3d4835fbd3040485822220af8ce52ee1adb649b3d8594 0b79766216649e948fa59de467d64fa752de4666c28e0e503e88740ae27a2aef @@ -347,7 +347,7 @@ lib/codeql/rust/elements/internal/ReturnExprConstructor.qll 57be5afbe20aa8db6e63 lib/codeql/rust/elements/internal/ReturnTypeSyntaxConstructor.qll 8994672e504d1674e5773157d0ad8a0dc3aad3d64ef295e7722e647e78e36c11 abe7df754721f4ff7f3e3bb22d275976b2e9a1ef51436a461fe52ebd2d29cff1 lib/codeql/rust/elements/internal/ReturnTypeSyntaxImpl.qll d47a3dcfcc2b02a6a9eaeefe9a7a4be2074ecd2019da129dda0f218bc3fbd94b 87198db7c0620ed49369da160f09287015e0cd1718784e1ba28ec3ec5a0bb4a8 lib/codeql/rust/elements/internal/SelfParamConstructor.qll a63af1d1ccde6013c09e0397f1247f5ab3efd97f3410dd1b6c15e1fb6cd96e54 0d8977653c074d5010c78144327f8b6c4da07f09d21e5cc3342082cd50107a81 -lib/codeql/rust/elements/internal/SelfParamImpl.qll def23beb8926f498fc81b7b44489001b35d704da1a2058c84c23b329e8bc2f49 c9be1e8fa2c4e23b314a4d0563be6cffcbab6f03d08b77a366f7638b28a09de4 +lib/codeql/rust/elements/internal/SelfParamImpl.qll 4112ffa718b95b3917ac3dfb45f4f4df56c1ee9cbbc61b91ec16628be57001c5 23f49c040a785ff5c9b09891d09007e9878fa78be086a68621d1f4d59d2e5d86 lib/codeql/rust/elements/internal/SlicePatConstructor.qll 19216ec9e87ca98784d78b29b8b06ea9ac428e2faa468f0717d1c0d0a8e7351c 458e5be76aa51aec579566be39486525ec9d4c73d248cb228da74892e2a56c08 lib/codeql/rust/elements/internal/SlicePatImpl.qll c6176095360e3b23382557242d2d3ff0b5e0f01f8b1c438452518e9c36ff3c70 644ab41a59a619947f69f75e2d0807245d4ddefc247efaeab63b99b4f08c1cc1 lib/codeql/rust/elements/internal/SliceTypeReprConstructor.qll 4576f203450767bfd142b1d6797b6482bb78f7700b6b410475b182d5067504ae 2b5aeaf91d5ea10e2370fa88b86bce7d0691d6d00f18ab8e1a1be917bb1619bb @@ -521,7 +521,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 876e28befd6a93666832de01342c6df403efb5cbea36d3c4b5d5cc2f34c54d6c 3448847608c25b100328bd68f70730a7e43b7d8b5ef8ab1ce40ae3f5a57c6bd2 +lib/codeql/rust/elements/internal/generated/ParentChild.qll 9064e1cbc32dd6f830ea9d96f7408ee864c79404cadda1f278c3782eeca7bd7f 3448847608c25b100328bd68f70730a7e43b7d8b5ef8ab1ce40ae3f5a57c6bd2 lib/codeql/rust/elements/internal/generated/Pat.qll 3605ac062be2f294ee73336e9669027b8b655f4ad55660e1eab35266275154ee 7f9400db2884d336dd1d21df2a8093759c2a110be9bf6482ce8e80ae0fd74ed4 lib/codeql/rust/elements/internal/generated/Path.qll bf6a86e7fcb7164624cc070dcce86d2bda50a2516b95115b87d0ebb5596e50a1 fd7a9ad4034cdebe8dfe495619c46f464630d38195313072e0bd904061b0fb00 lib/codeql/rust/elements/internal/generated/PathAstNode.qll e6d4d5bffd3c623baaaee46bc183eb31ce88795535f164f6a9b9b4d98bbd6101 168db515404933479ba6b150c72e012d28592cbc32366aefcb1bf9599dbcd183 @@ -535,7 +535,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 b295dd46979a2d4df840e1bef4ba12e3b4ff58aa886c8a1320281739d36c5a4f 2369cba6d70f0e853acb0e018dfb47e604ee01dca48af7094b484a7e18a46365 +lib/codeql/rust/elements/internal/generated/Raw.qll 71ebb4246cd4b34ef28e216ea3a2d494b3514ec011aa4106105f83accf781d98 4a58d85b93e6547565acea761221d7c69ef34fdb69ec8d7912d6e50569f5f48e lib/codeql/rust/elements/internal/generated/RecordExpr.qll 2131b2cb336caa76170082e69776011bf02576bbfdd34ba68ca84af24209250a 39a2e3ec32352b594c43cc1295e0e8b3f9808173322d3d73cb7d48ef969d5565 lib/codeql/rust/elements/internal/generated/RecordExprField.qll 7e9f8663d3b74ebbc9603b10c9912f082febba6bd73d344b100bbd3edf837802 fbe6b578e7fd5d5a6f21bbb8c388957ab7210a6a249ec71510a50fb35b319ea1 lib/codeql/rust/elements/internal/generated/RecordExprFieldList.qll 179a97211fe7aa6265085d4d54115cdbc0e1cd7c9b2135591e8f36d6432f13d3 dd44bbbc1e83a1ed3a587afb729d7debf7aeb7b63245de181726af13090e50c0 @@ -553,7 +553,7 @@ lib/codeql/rust/elements/internal/generated/RestPat.qll 234bbaa8aa37962c9138baf5 lib/codeql/rust/elements/internal/generated/RetTypeRepr.qll 173fd722308161f9405f929a13718134f8eaefe9fce1686048860b7c8f4c29f7 30bbaada842369dac5618ae573999f59979597c6a3315c6cce04e5bed0b38c87 lib/codeql/rust/elements/internal/generated/ReturnExpr.qll c9c05400d326cd8e0da11c3bfa524daa08b2579ecaee80e468076e5dd7911d56 e7694926727220f46a7617b6ca336767450e359c6fa3782e82b1e21d85d37268 lib/codeql/rust/elements/internal/generated/ReturnTypeSyntax.qll 34e32623d2c0e848c57ce1892c16f4bc81ccca7df22dc21dad5eb48969224465 ccb07c205468bce06392ff4a150136c0d8ebacfb15d1d96dd599ab020b353f47 -lib/codeql/rust/elements/internal/generated/SelfParam.qll e1d994dea58a406dbfca3ea0c724ac48be66ac4380e7270e4037ca2714eef722 90f8ebfac723eef259e13d3c8a7ef6b886c2831d4f436a742144b96db6b6fc92 +lib/codeql/rust/elements/internal/generated/SelfParam.qll 076c583f7f34e29aaaf3319e9d64565a34c64caa5a6dfca240c0cc7800e9a14c 375afed1772d193b71980d3825c4ac438e90b295cba0baf58319d29a3a8463a0 lib/codeql/rust/elements/internal/generated/SlicePat.qll 722b1bd47a980ac9c91d018133b251c65ee817682e06708ad130031fbd01379b 7e0ce13b9de2040d2ef9d0948aab3f39e5fdc28d38c40bfbee590e2125dbe41c lib/codeql/rust/elements/internal/generated/SliceTypeRepr.qll efd28e97936944ce56ab5f83aa16cf76cc1b42a39c123959d3a878ca13ceb84e 3435ea66d467f4234b9644ce63fa9072a7e9ac86e23d464ba18aea7802fc03a7 lib/codeql/rust/elements/internal/generated/SourceFile.qll 55d44c9f09c5ff28c4f715f779a0db74083e1180acaf0d410e63ca07b90d1cb5 78c0af48b0b64aa377413ea4799dfe977602a111208e1d25e4bdfa920dbd7238 @@ -995,7 +995,7 @@ test/extractor-tests/generated/ReturnExpr/ReturnExpr.ql 8e9eba0837a466255e8e249e test/extractor-tests/generated/ReturnExpr/ReturnExpr_getAttr.ql 9fb7e1c79798e4f42e18785f3af17ea75f901a36abf9beb47a1eede69c613ba9 9cdb7cc4a4742865f6c92357973f84cee9229f55ff28081e5d17b6d57d6d275f test/extractor-tests/generated/ReturnExpr/ReturnExpr_getExpr.ql 7d4562efb0d26d92d11f03a0ef80338eb7d5a0c073f1f09cbb8a826f0cef33de 523ebd51b97f957afaf497e5a4d27929eed18e1d276054e3d5a7c5cfe7285c6e test/extractor-tests/generated/ReturnTypeSyntax/ReturnTypeSyntax.ql 976ce33fe3fd34aae2028a11b4accdee122b6d82d07722488c3239f0d2c14609 906bf8c8e7769a1052196bc78947b655158dd3b2903fef2802e2031cffbc1d78 -test/extractor-tests/generated/SelfParam/SelfParam.ql 1a75aa4caf4342365c74811f566359053a1a1bbff7058840891f4e050433ee50 a173a91b4c9d8af2f82d8c774b674e06c54414e2bae845695d06f6d27e6ff40b +test/extractor-tests/generated/SelfParam/SelfParam.ql a5be8dc977d652c6fe8b27377a3dae3e34b4e034b76d2621d6c43ea9cf07128e 099fe28e1b17238c46c457593aed8d9fca6e6e6cf8f9c4ec5b14261035261c04 test/extractor-tests/generated/SelfParam/SelfParam_getAttr.ql 00dd5409c07e9a7b5dc51c1444e24b35d2ac3cab11320396ef70f531a3b65dc0 effbed79ad530a835e85b931389a0c8609a10ee035cb694f2e39b8539f8e54ba test/extractor-tests/generated/SelfParam/SelfParam_getLifetime.ql 0b7c243f609e005dd63fd1b3b9f0096fc13cb98fe113e6f3fefb0d5c414e9a5f f6e06de8bcddfc9bd978c058079e53174edbe7b39f18df3c0bd4e80486808eda test/extractor-tests/generated/SelfParam/SelfParam_getName.ql 69207a57b415ba590e50003d506a64fd1780b27b8832b14f9bd3c909bddb5593 56fa28ba1222f45893237052fa5a9421d960e14fbf1396b2d1049b440c2e5abe 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 78e78192b7c7..e4c1078b682e 100644 --- a/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll +++ b/rust/ql/lib/codeql/rust/controlflow/internal/generated/CfgNodes.qll @@ -2695,8 +2695,13 @@ module MakeCfgNodes Input> { /** * A `self` parameter. For example `self` in: * ```rust - * fn push(&mut self, value: T) { - * // ... + * struct X; + * impl X { + * fn one(&self) {} + * fn two(&mut self) {} + * fn three(self) {} + * fn four(mut self) {} + * fn five<'a>(&'a self) {} * } * ``` */ @@ -2708,6 +2713,11 @@ module MakeCfgNodes Input> { /** Gets the underlying `SelfParam`. */ SelfParam getSelfParam() { result = node } + /** + * Holds if this self parameter is reference. + */ + predicate isRef() { node.isRef() } + /** * Holds if this self parameter is mut. */ diff --git a/rust/ql/lib/codeql/rust/elements/SelfParam.qll b/rust/ql/lib/codeql/rust/elements/SelfParam.qll index 88c1a05d8371..35afdab562b9 100644 --- a/rust/ql/lib/codeql/rust/elements/SelfParam.qll +++ b/rust/ql/lib/codeql/rust/elements/SelfParam.qll @@ -11,8 +11,13 @@ import codeql.rust.elements.ParamBase /** * A `self` parameter. For example `self` in: * ```rust - * fn push(&mut self, value: T) { - * // ... + * struct X; + * impl X { + * fn one(&self) {} + * fn two(&mut self) {} + * fn three(self) {} + * fn four(mut self) {} + * fn five<'a>(&'a self) {} * } * ``` */ diff --git a/rust/ql/lib/codeql/rust/elements/internal/SelfParamImpl.qll b/rust/ql/lib/codeql/rust/elements/internal/SelfParamImpl.qll index 0d0d23a1e8c5..dad7b1d96fb2 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/SelfParamImpl.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/SelfParamImpl.qll @@ -15,8 +15,13 @@ module Impl { /** * A `self` parameter. For example `self` in: * ```rust - * fn push(&mut self, value: T) { - * // ... + * struct X; + * impl X { + * fn one(&self) {} + * fn two(&mut self) {} + * fn three(self) {} + * fn four(mut self) {} + * fn five<'a>(&'a self) {} * } * ``` */ 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 5a32a8623bc1..c6ee20a4dc4b 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/Raw.qll @@ -2631,14 +2631,24 @@ module Raw { * INTERNAL: Do not use. * A `self` parameter. For example `self` in: * ```rust - * fn push(&mut self, value: T) { - * // ... + * struct X; + * impl X { + * fn one(&self) {} + * fn two(&mut self) {} + * fn three(self) {} + * fn four(mut self) {} + * fn five<'a>(&'a self) {} * } * ``` */ class SelfParam extends @self_param, ParamBase { override string toString() { result = "SelfParam" } + /** + * Holds if this self parameter is reference. + */ + predicate isRef() { self_param_is_ref(this) } + /** * Holds if this self parameter is mut. */ diff --git a/rust/ql/lib/codeql/rust/elements/internal/generated/SelfParam.qll b/rust/ql/lib/codeql/rust/elements/internal/generated/SelfParam.qll index b2cc6e4b0c4a..1092de3cc08c 100644 --- a/rust/ql/lib/codeql/rust/elements/internal/generated/SelfParam.qll +++ b/rust/ql/lib/codeql/rust/elements/internal/generated/SelfParam.qll @@ -18,8 +18,13 @@ module Generated { /** * A `self` parameter. For example `self` in: * ```rust - * fn push(&mut self, value: T) { - * // ... + * struct X; + * impl X { + * fn one(&self) {} + * fn two(&mut self) {} + * fn three(self) {} + * fn four(mut self) {} + * fn five<'a>(&'a self) {} * } * ``` * INTERNAL: Do not reference the `Generated::SelfParam` class directly. @@ -28,6 +33,11 @@ module Generated { class SelfParam extends Synth::TSelfParam, ParamBaseImpl::ParamBase { override string getAPrimaryQlClass() { result = "SelfParam" } + /** + * Holds if this self parameter is reference. + */ + predicate isRef() { Synth::convertSelfParamToRaw(this).(Raw::SelfParam).isRef() } + /** * Holds if this self parameter is mut. */ diff --git a/rust/ql/lib/rust.dbscheme b/rust/ql/lib/rust.dbscheme index d706df19af4a..df89d1c2034f 100644 --- a/rust/ql/lib/rust.dbscheme +++ b/rust/ql/lib/rust.dbscheme @@ -2226,6 +2226,11 @@ self_params( unique int id: @self_param ); +#keyset[id] +self_param_is_ref( + int id: @self_param ref +); + #keyset[id] self_param_is_mut( int id: @self_param ref diff --git a/rust/ql/test/extractor-tests/generated/.generated_tests.list b/rust/ql/test/extractor-tests/generated/.generated_tests.list index 2410d9237d0c..78f9e0cfc778 100644 --- a/rust/ql/test/extractor-tests/generated/.generated_tests.list +++ b/rust/ql/test/extractor-tests/generated/.generated_tests.list @@ -105,7 +105,7 @@ RestPat/gen_rest_pat.rs e762bf7537225f97da751c5dca6a2cd3836ad7579b68c748b8c6cba6 RetTypeRepr/gen_ret_type_repr.rs 25edbd60ad63ab4266f6426ef50f1dd17e24132f5a24404d240a3f07daef6a31 25edbd60ad63ab4266f6426ef50f1dd17e24132f5a24404d240a3f07daef6a31 ReturnExpr/gen_return_expr.rs 4f6ef29d7b3c60d6d71d1a6034a0721671f517428ba21897361a92b01009d38f 4f6ef29d7b3c60d6d71d1a6034a0721671f517428ba21897361a92b01009d38f ReturnTypeSyntax/gen_return_type_syntax.rs 0b11a4cc400f9a2001996f99d61391bdb636e8aea036f587cf18ad6a957fe496 0b11a4cc400f9a2001996f99d61391bdb636e8aea036f587cf18ad6a957fe496 -SelfParam/gen_self_param.rs 9be528c454e2734292d54550f8850ae8e48e1558da46dcf7f06fc7a7a8c3e569 9be528c454e2734292d54550f8850ae8e48e1558da46dcf7f06fc7a7a8c3e569 +SelfParam/gen_self_param.rs 15491f86a32020c9ed3ecadc08c945ed01916b63683f95d2f5c1bedb4f3f01f2 15491f86a32020c9ed3ecadc08c945ed01916b63683f95d2f5c1bedb4f3f01f2 SlicePat/gen_slice_pat.rs df4a6692f5100aa11dd777561400ce71e37b85f2363b0638c21975a1771b15d5 df4a6692f5100aa11dd777561400ce71e37b85f2363b0638c21975a1771b15d5 SliceTypeRepr/gen_slice_type_repr.rs e50c142b7cf7bc3040ad64f351488557323d0b2fd5d004b41ed0fa8e522b5648 e50c142b7cf7bc3040ad64f351488557323d0b2fd5d004b41ed0fa8e522b5648 SourceFile/gen_source_file.rs a7a1d4fa77b53adb6fbc031bf7ab49cf7c8787728ba0a687c348b5eefbb5b9df a7a1d4fa77b53adb6fbc031bf7ab49cf7c8787728ba0a687c348b5eefbb5b9df diff --git a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.expected b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.expected index 6fd67c90f3ba..ba8ab1e624d6 100644 --- a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.expected +++ b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.expected @@ -1 +1,5 @@ -| gen_self_param.rs:5:13:5:21 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isMut: | yes | hasLifetime: | no | hasName: | yes | +| gen_self_param.rs:6:10:6:14 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | no | hasLifetime: | no | hasName: | yes | +| gen_self_param.rs:7:10:7:18 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | yes | hasLifetime: | no | hasName: | yes | +| gen_self_param.rs:8:12:8:15 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | no | isMut: | no | hasLifetime: | no | hasName: | yes | +| gen_self_param.rs:9:11:9:18 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | no | isMut: | yes | hasLifetime: | no | hasName: | yes | +| gen_self_param.rs:10:15:10:22 | SelfParam | getNumberOfAttrs: | 0 | hasTypeRepr: | no | isRef: | yes | isMut: | no | hasLifetime: | yes | hasName: | yes | diff --git a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.ql b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.ql index 2e8ef6d0bb61..3f09c3ece20b 100644 --- a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.ql +++ b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam.ql @@ -3,15 +3,16 @@ import codeql.rust.elements import TestUtils from - SelfParam x, int getNumberOfAttrs, string hasTypeRepr, string isMut, string hasLifetime, - string hasName + SelfParam x, int getNumberOfAttrs, string hasTypeRepr, string isRef, string isMut, + string hasLifetime, string hasName where toBeTested(x) and not x.isUnknown() and getNumberOfAttrs = x.getNumberOfAttrs() and (if x.hasTypeRepr() then hasTypeRepr = "yes" else hasTypeRepr = "no") and + (if x.isRef() then isRef = "yes" else isRef = "no") and (if x.isMut() then isMut = "yes" else isMut = "no") and (if x.hasLifetime() then hasLifetime = "yes" else hasLifetime = "no") and if x.hasName() then hasName = "yes" else hasName = "no" -select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasTypeRepr:", hasTypeRepr, "isMut:", isMut, - "hasLifetime:", hasLifetime, "hasName:", hasName +select x, "getNumberOfAttrs:", getNumberOfAttrs, "hasTypeRepr:", hasTypeRepr, "isRef:", isRef, + "isMut:", isMut, "hasLifetime:", hasLifetime, "hasName:", hasName diff --git a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getLifetime.expected b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getLifetime.expected index e69de29bb2d1..47e9eba10acc 100644 --- a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getLifetime.expected +++ b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getLifetime.expected @@ -0,0 +1 @@ +| gen_self_param.rs:10:15:10:22 | SelfParam | gen_self_param.rs:10:16:10:17 | ''a | diff --git a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getName.expected b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getName.expected index 70a9a4a06596..6b57cfe1570a 100644 --- a/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getName.expected +++ b/rust/ql/test/extractor-tests/generated/SelfParam/SelfParam_getName.expected @@ -1 +1,5 @@ -| gen_self_param.rs:5:13:5:21 | SelfParam | gen_self_param.rs:5:18:5:21 | self | +| gen_self_param.rs:6:10:6:14 | SelfParam | gen_self_param.rs:6:11:6:14 | self | +| gen_self_param.rs:7:10:7:18 | SelfParam | gen_self_param.rs:7:15:7:18 | self | +| gen_self_param.rs:8:12:8:15 | SelfParam | gen_self_param.rs:8:12:8:15 | self | +| gen_self_param.rs:9:11:9:18 | SelfParam | gen_self_param.rs:9:15:9:18 | self | +| gen_self_param.rs:10:15:10:22 | SelfParam | gen_self_param.rs:10:19:10:22 | self | diff --git a/rust/ql/test/extractor-tests/generated/SelfParam/gen_self_param.rs b/rust/ql/test/extractor-tests/generated/SelfParam/gen_self_param.rs index 6278147a8783..4c6da9bcc064 100644 --- a/rust/ql/test/extractor-tests/generated/SelfParam/gen_self_param.rs +++ b/rust/ql/test/extractor-tests/generated/SelfParam/gen_self_param.rs @@ -1,8 +1,11 @@ // generated by codegen, do not edit -fn test_self_param() -> () { - // A `self` parameter. For example `self` in: - fn push(&mut self, value: T) { - // ... - } +// A `self` parameter. For example `self` in: +struct X; +impl X { + fn one(&self) {} + fn two(&mut self) {} + fn three(self) {} + fn four(mut self) {} + fn five<'a>(&'a self) {} } diff --git a/rust/schema/annotations.py b/rust/schema/annotations.py index 33a837871043..b2ce365bc4cb 100644 --- a/rust/schema/annotations.py +++ b/rust/schema/annotations.py @@ -1546,12 +1546,18 @@ class _: @annotate(SelfParam, replace_bases={AstNode: ParamBase}, cfg = True) +@rust.doc_test_signature(None) class _: """ A `self` parameter. For example `self` in: ```rust - fn push(&mut self, value: T) { - // ... + struct X; + impl X { + fn one(&self) {} + fn two(&mut self) {} + fn three(self) {} + fn four(mut self) {} + fn five<'a>(&'a self) {} } ``` """ diff --git a/rust/schema/ast.py b/rust/schema/ast.py index 77d52977b4ec..cb302e093150 100644 --- a/rust/schema/ast.py +++ b/rust/schema/ast.py @@ -540,6 +540,7 @@ class ReturnTypeSyntax(AstNode): class SelfParam(AstNode): attrs: list["Attr"] | child + is_ref: predicate is_mut: predicate lifetime: optional["Lifetime"] | child name: optional["Name"] | child