Title: Incorrect substitutions for rules using `Ptr` parameters · Issue #220 · Cpp2Rust/cpp2rust · GitHub
Open Graph Title: Incorrect substitutions for rules using `Ptr` parameters · Issue #220 · Cpp2Rust/cpp2rust
X Title: Incorrect substitutions for rules using `Ptr` parameters · Issue #220 · Cpp2Rust/cpp2rust
Description: Using the following rules for std::vector: // src.cpp template
Open Graph Description: Using the following rules for std::vector: // src.cpp template X Description: Using the following rules for std::vector: // src.cpp template <typename T1> using t1 = std::vector<T1>; template <typename T1> std::vector<T1> f1(const std::vector<T1>...
Opengraph URL: https://github.com/Cpp2Rust/cpp2rust/issues/220
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect substitutions for rules using `Ptr` parameters","articleBody":"Using the following rules for `std::vector`:\n```cpp\n// src.cpp\ntemplate \u003ctypename T1\u003e using t1 = std::vector\u003cT1\u003e;\n\ntemplate \u003ctypename T1\u003e std::vector\u003cT1\u003e f1(const std::vector\u003cT1\u003e \u0026a0) {\n return std::vector\u003cT1\u003e(a0);\n}\n\ntemplate \u003ctypename T1\u003e std::vector\u003cT1\u003e f2(std::vector\u003cT1\u003e \u0026\u0026a0) {\n return std::vector\u003cT1\u003e(std::move(a0));\n}\n\ntemplate \u003ctypename T1\u003e\nstd::vector\u003cT1\u003e \u0026f3(std::vector\u003cT1\u003e \u0026a0, std::vector\u003cT1\u003e \u0026\u0026a1) {\n return a0.operator=(std::move(a1));\n}\n```\n```rust\n// tgt_refcount.rs\nfn t1\u003cT1\u003e() -\u003e Vec\u003cT1\u003e {\n Vec::new()\n}\n\nfn f1\u003cT1: Clone\u003e(a0: Ptr\u003cVec\u003cT1\u003e\u003e) -\u003e Vec\u003cT1\u003e {\n a0.to_strong().borrow().clone()\n}\n\nfn f2\u003cT1\u003e(a0: Ptr\u003cVec\u003cT1\u003e\u003e) -\u003e Vec\u003cT1\u003e {\n std::mem::take(\u0026mut *a0.to_strong().borrow_mut())\n}\n\nfn f3\u003cT1: ByteRepr\u003e(a0: Ptr\u003cVec\u003cT1\u003e\u003e, a1: Ptr\u003cVec\u003cT1\u003e\u003e) -\u003e Ptr\u003cVec\u003cT1\u003e\u003e {\n let moved = a1.with_mut(|v| std::mem::take(v));\n a0.with_mut(|dst| *dst = moved);\n a0\n}\n```\n\nThe following translation is generated:\n```cpp\nint main() {\n std::vector\u003cint\u003e vec1;\n std::vector\u003cint\u003e vec2(std::move(vec1));\n std::vector\u003cint\u003e vec3(vec2);\n vec3 = std::move(vec2);\n\n return 0;\n}\n```\n```rust\nfn main_0() -\u003e i32 {\n let vec1: Value\u003cVec\u003ci32\u003e\u003e = Rc::new(RefCell::new(Vec::new()));\n let vec2: Value\u003cVec\u003ci32\u003e\u003e = Rc::new(RefCell::new(std::mem::take(\n \u0026mut *(*vec1.borrow_mut()).to_strong().borrow_mut(), // (*vec1.borrow_mut()) should be (vec1.as_pointer() as Ptr\u003c...\u003e)\n )));\n let vec3: Value\u003cVec\u003ci32\u003e\u003e =\n Rc::new(RefCell::new(vec2.as_pointer().to_strong().borrow().clone())); // vec2.as_pointer should be (vec2.as_pointer() as Ptr\u003c...\u003e)\n {\n let moved = (*vec2.borrow_mut()).with_mut(|v| std::mem::take(v)); // (*vec2.borrow_mut()) should be (vec2.as_pointer() as Ptr\u003c...\u003e)\n (vec3.as_pointer() as Ptr\u003cVec\u003ci32\u003e\u003e).with_mut(|dst| *dst = moved);\n (vec3.as_pointer() as Ptr\u003cVec\u003ci32\u003e\u003e)\n };\n return 0;\n}\n```\n\nThe generated `ir_refcount.json` appears to be correct. All `Ptr` parameters are marked as `is_refcount_pointer`:\n```json\n// f1\n\"params\": {\n \"a0\": {\n \"type\": \"Ptr\u003cVec\u003cT1\u003e\u003e\",\n \"is_refcount_pointer\": true\n }\n},\n\n// f2\n\"params\": {\n \"a0\": {\n \"type\": \"Ptr\u003cVec\u003cT1\u003e\u003e\",\n \"is_refcount_pointer\": true\n }\n},\n\n// f3\n\"params\": {\n \"a0\": {\n \"type\": \"Ptr\u003cVec\u003cT1\u003e\u003e\",\n \"is_refcount_pointer\": true\n },\n \"a1\": {\n \"type\": \"Ptr\u003cVec\u003cT1\u003e\u003e\",\n \"is_refcount_pointer\": true\n }\n},\n```","author":{"url":"https://github.com/joaotgouveia","@type":"Person","name":"joaotgouveia"},"datePublished":"2026-07-01T12:04:35.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/220/cpp2rust/issues/220"}
route-pattern /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) route-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:d696285a-5b4f-9af9-8fe7-9821872f6419 current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id A22E:1960E9:D1FA7:119D04:6A4D8278 html-safe-nonce adea91c8a1e4a94a9dc71ded1dd8a1106388ef7fb104a7a6e9049386fe8db3ef visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjJFOjE5NjBFOTpEMUZBNzoxMTlEMDQ6NkE0RDgyNzgiLCJ2aXNpdG9yX2lkIjoiNzM1OTI1MzgxODY3OTA2NzI1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac 2b792b8ad3b82aa575903bc61dd1f22dddd2021e4666a8829bd580da8d672081 hovercard-subject-tag issue:4785340612 github-keyboard-shortcuts repository,issues,copilot google-site-verification Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I octolytics-url https://collector.github.com/github/collect analytics-location / fb:app_id 1401488693436528 apple-itunes-app app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/Cpp2Rust/cpp2rust/220/issue_layout twitter:image https://opengraph.githubassets.com/492043dc508f8342d5090a1fb7a71b54a8a1e6b360d60aa7bdad2385d1ecbada/Cpp2Rust/cpp2rust/issues/220 twitter:card summary_large_image og:image https://opengraph.githubassets.com/492043dc508f8342d5090a1fb7a71b54a8a1e6b360d60aa7bdad2385d1ecbada/Cpp2Rust/cpp2rust/issues/220 og:image:alt Using the following rules for std::vector: // src.cpp template og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username joaotgouveia hostname github.com expected-hostname github.com None c6bf61c909482ec3072ef5d7a5a28f2a9d214788c9a44793eca1960048cb05ae turbo-cache-control no-preview go-import github.com/Cpp2Rust/cpp2rust git https://github.com/Cpp2Rust/cpp2rust.git octolytics-dimension-user_id 197474191 octolytics-dimension-user_login Cpp2Rust octolytics-dimension-repository_id 1183095779 octolytics-dimension-repository_nwo Cpp2Rust/cpp2rust octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 1183095779 octolytics-dimension-repository_network_root_nwo Cpp2Rust/cpp2rust turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release 6702a58b419a792226bd21ef0fb1bcb318bbcaa3 ui-target full theme-color #1e2327 color-scheme light dark
URLs of crawlers that visited me.