dtolnay / inventory

Typed distributed plugin registration
Apache License 2.0
948 stars 43 forks source link

Look into hiding "consider wrapping this expression in Lazy::new" rustc suggestion #51

Closed dtolnay closed 9 months ago

dtolnay commented 1 year ago

The most recent nightly (nightly-2022-08-21) started producing the following suggestion:

 error[E0015]: cannot call non-const fn `Thing::new` in statics
   --> tests/ui/submit-nonconst.rs:11:20
    |
 11 | inventory::submit!(Thing::new());
    |                    ^^^^^^^^^^^^
    |
    = note: calls in statics are limited to constant functions, tuple structs and tuple variants
+   = note: consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell

This is basically never going to be helpful in using inventory::submit!. Maybe there is something we can do with spans to make it not emit this.

jpmckinney commented 1 year ago

Is there a way around this error?

(The issue title is about hiding the suggestion, but right now I'm facing the problem of how to avoid the error.)