rust-lang-nursery / lazy-static.rs

A small macro for defining lazy evaluated static variables in Rust.
Apache License 2.0
1.91k stars 111 forks source link

Clippy complains about use of 0 as *const _ #75

Closed Apanatshka closed 6 years ago

Apanatshka commented 7 years ago

When I use lazy_static, for every static ref I create I get a clippy warning:

warning: `0 as *const _` detected. Consider using `ptr::null()`
  --> src/a.rs:b:9
   |
b |         lazy_static! {
   |         ^
   |
   = note: #[warn(zero_ptr)] on by default
   = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#zero_ptr
   = note: this error originates in a macro outside of the current crate
Kimundi commented 7 years ago

Not sure how to best address this, since the warning is about a line of code that runs as a constexpr.

Apanatshka commented 7 years ago

ah... so you can't use ptr::null() because it's not const? 😞

EDIT: actually, it is const, so maybe you can use it?

Kimundi commented 7 years ago

The problem is that calling a const is a unstable feature.

Apanatshka commented 7 years ago

Oh, right. Well, then this issue is blocked until calling const functions is stabilised.

dtolnay commented 6 years ago

This lint is no longer triggering as of Rust 1.29.0-nightly and Clippy 0.0.212.

#![cfg_attr(feature = "cargo-clippy", deny(zero_ptr))]

#[macro_use]
extern crate lazy_static;

lazy_static! {
    static ref S: u8 = 0;
}

fn main() {}