-
Notifications
You must be signed in to change notification settings - Fork 125
Description
lazy_static variables fail to register their types properly in Rust API docs. They end up as struct <name> { /* private fields */ }
, which isn't very helpful for downstream users.
lazy_static variables interact poorly with the Rust compiler. When attempting to assign either one lazy_static constant or the other at runtime based on a boolean, then the compiler throws a fit:
Compiling kirill v0.0.4 (/Users/andrew/go/src/github.com/mcandre/kirill)
error[E0308]: `if` and `else` have incompatible types
--> src/lib.rs:180:13
|
177 | let pattern = if exclude_json5 {
| _______________________-
178 | | DEFAULT_JSON5_FILE_PATTERNS
| | --------------------------- expected because of this
179 | | } else {
180 | | DEFAULT_JSON_FILE_PATTERNS
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `DEFAULT_JSON5_FILE_PATTERNS`, found `DEFAULT_JSON_FILE_PATTERNS`
181 | | };
| |_________- `if` and `else` have incompatible types
Both variables have the exact same type, explicitly written ... : regex::Regex =
... in the variable declarations. Neither the Rust docs nor the compiler should get confused about the types of these variables.
I recognize these glitches reach deep into the heart of how lazy_static is implemented. Looking forward to enhancements, so that we can benefit from const expr
style code with less friction in the future.