Skip to content

bad type inferencing #231

@mcandre

Description

@mcandre

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions