]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_const_eval/src/transform/check_consts/ops.rs
suggest lazy-static for non-const statics
[rust.git] / compiler / rustc_const_eval / src / transform / check_consts / ops.rs
index 3380226164460c74254966bf27dc14c15a564887..c9cfc1f3f469c8f3ce3d5598a14e97f61cbea19f 100644 (file)
@@ -1,6 +1,7 @@
 //! Concrete error types for all operations which may be invalid in a certain const context.
 
 use hir::def_id::LocalDefId;
+use hir::ConstContext;
 use rustc_errors::{
     error_code, struct_span_err, Applicability, DiagnosticBuilder, ErrorGuaranteed,
 };
@@ -331,6 +332,10 @@ macro_rules! error {
             ccx.const_kind(),
         ));
 
+        if let ConstContext::Static(_) = ccx.const_kind() {
+            err.note("consider wrapping this expression in `Lazy::new(|| ...)` from the `once_cell` crate: https://crates.io/crates/once_cell");
+        }
+
         err
     }
 }