3 ms·
It need new annotations. (see the paragraph under "Comment-Based Syntax")
by j16sdiz 10mo ago
It need new annotations. (see the paragraph under "Comment-Based Syntax")
- hmry 10mo agoThe article doesn't show any function lifetime annotations, only @safe and @unsafe. Functions need annotations like "return value lives as long as argument 1" or "return value lives as long as both arguments are alive"
- aw1621107 10mo ago> The article doesn't show any function lifetime annotations, only @safe and @unsafe. It does, but it's under the "External Annotations" section: // External annotations go in a header file // @external: { // strlen: [safe, (const char* str) -> owned] // strcpy: [unsafe, (char* dest, const char* src) -> char*] // strchr: [safe, (const char* str, int c) -> const char* where str: 'a, return: 'a] // // // Third-party libraries work the same way // sqlite3_column_text: [safe, (sqlite3_stmt* stmt, int col) -> const char* where stmt: 'a, return: 'a] // nlohmann::json::parse: [safe, (const string& s) -> owned json] // } > The where clause specifies lifetime relationships—like where stmt: 'a, return: 'a means the returned pointer lives as long as the statement handle. This lets the analyzer catch dangling pointers from external APIs. The GitHub repo also has an annotations guide with some more info [0]. The general syntax appears to be: // @lifetime: (parameters) -> return_type where constraints [0]: https://github.com/shuaimu/rusty-cpp/blob/main/docs/annotations.md#lifetime-annotations https://github.com/shuaimu/rusty-cpp/blob/main/docs/annotati...
- SkiFire13 10mo ago`@lifetime` seem to be what I was referring to, strange though it wasn't mentioned at all in the article. The ones in `@external` seem to be limited to C++ definitions outside the user control.
- aw1621107 10mo agoI had assumed the lifetime syntax with the `where` clauses would not be specific to @external blocks, to be fair.
- hmry 10mo agoAh, I see! Thank you!