You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pubstructSomeStruct{_p:()}#[cfg(target_os = "linux")]constTARGET_STORAGE_SIZE:usize = 128;#[cfg(not(target_os = "linux"))]constTARGET_STORAGE_SIZE:usize = 256;implSomeStruct{/// How much storage to allocate for a call to/// [`some_method`](Self::some_method).pubconstSTORAGE_SIZE:usize = TARGET_STORAGE_SIZE;/// The user is expected to call this with an array of size/// `SomeStruct::STORAGE_SIZE`, whatever that happens to be.pubfnsome_method(&self,storage:&mut[u8;SomeStruct::STORAGE_SIZE],){}}
Unfortunately, the rustdoc output is confusing because it evaluates the constant when formatting the function signature:
If a user were to copy-paste from the rustdoc'd function signature when writing the call site, they would write code like this, which would fail to compile on some platforms:
This strongly relates to the ongoing discussion around the formatting of constant values and expressions in rustdoc. I am in the process of writing an RFC (I've finally found time to start working on it). Your issue would fit in the drawbacks / alternatives section.
I won't assign myself to this issue since I am already assigned to too many issues related to this topic and no decisions have been reached yet and everything is very much in flux, hence the planned RFC.
Current rustdoc behavior
Given the following code:
The user would be expected to call it like this:
Unfortunately, the rustdoc output is confusing because it evaluates the constant when formatting the function signature:
If a user were to copy-paste from the rustdoc'd function signature when writing the call site, they would write code like this, which would fail to compile on some platforms:
Proposed new behavior
A better way to format this function signature would be to use the constant's name, if the constant is public:
An even niftier formatting would let the constant become a link:
The text was updated successfully, but these errors were encountered: