Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero_ptr lint detected for any lazy_static code #1580

Closed
vitiral opened this issue Feb 27, 2017 · 9 comments · Fixed by #1610
Closed

zero_ptr lint detected for any lazy_static code #1580

vitiral opened this issue Feb 27, 2017 · 9 comments · Fixed by #1610
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types

Comments

@vitiral
Copy link

vitiral commented Feb 27, 2017

I'm running clippy v0.0.115

This code

pub const ART_VALID_STR: &'static str = "(REQ|SPC|RSK|TST)(-[A-Z0-9_-]*[A-Z0-9_])?";

lazy_static!{
    // must start with artifact type, followed by "-", followed by at least 1 valid character
    // cannot end with "-"
    pub static ref ART_VALID: Regex = Regex::new(
        &format!("^{}$", ART_VALID_STR)).unwrap();
    pub static ref PARENT_PATH: PathBuf = PathBuf::from("PARENT");
    pub static ref INCREMENTING_ID: AtomicUsize = AtomicUsize::new(0);
}

Is generating this error repeatedely:

warning: `0 as *const _` detected. Consider using `ptr::null()`
  --> src/core/types.rs:26:1
   |
26 |   lazy_static!{
   |  _^ starting here...
27 | |     // must start with artifact type, followed by "-", followed by at least 1 valid character
28 | |     // cannot end with "-"
29 | |     pub static ref ART_VALID: Regex = Regex::new(
30 | |         &format!("^{}$", ART_VALID_STR)).unwrap();
31 | |     pub static ref PARENT_PATH: PathBuf = PathBuf::from("PARENT");
32 | |     pub static ref INCREMENTING_ID: AtomicUsize = AtomicUsize::new(0);
33 | | }
   | |_^ ...ending here
   |
   = 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

This never happened before. All I did was update clippy to the latest version.

@vitiral
Copy link
Author

vitiral commented Feb 27, 2017

I also can't seem to silence the lint with #![allow(zero_ptr)] put at the top of the file

@vitiral
Copy link
Author

vitiral commented Feb 27, 2017

nevermind, the allow flag works -- it was just that I needed to enable it for my whole library since I use lazy_static! everywhere

@vitiral vitiral changed the title zero_ptr lint detected for lazy_static code zero_ptr lint detected for any lazy_static code Feb 27, 2017
@Arnavion
Copy link
Contributor

Unfortunately, just changing lazy_static to use ptr::null() doesn't work since it would require const functions support.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 28, 2017

I don't see any reason why ptr::null() couldn't be const fn. But we should probably not lint zero_ptr inside macro invocations.

@oli-obk oli-obk added good-first-issue These issues are a good way to get started with Clippy C-bug Category: Clippy is not doing the correct thing T-middle Type: Probably requires verifiying types labels Feb 28, 2017
@Arnavion
Copy link
Contributor

It is a const fn already. The issue is that using const fns requires opting in to the feature.

@aldanor
Copy link

aldanor commented Mar 6, 2017

I don't see any reason why ptr::null() couldn't be const fn. But we should probably not lint zero_ptr inside macro invocations

Disabling inside macro invocations sounds like a hack; could constexpr context be detected? At least this case (which is what causes false positives in lazy_static):

(static|static mut) <var>: <ty> = /* disable zero_ptr for RHS of the assignment */;

@oli-obk
Copy link
Contributor

oli-obk commented Mar 6, 2017

yea, but you also have [T; N] and the bodies of const fn. And

static FOO: fn() -> *const i32 = {
    fn f() -> *const i32 {
        0 as *const i32
    }
    f
};

Should not lint, ...

I'm working on trying to fully fix this instead of going for a partial fix. The same issues apply to other lints like cmp_nan, too.

@mcarton
Copy link
Member

mcarton commented Mar 7, 2017

Automatically closed but reopening as long as it's not fully fixed (see #1610).

frewsxcv referenced this issue in frewsxcv/rust Mar 9, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
alexcrichton referenced this issue in alexcrichton/rust Mar 10, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
alexcrichton referenced this issue in arielb1/rust Mar 10, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
alexcrichton referenced this issue in alexcrichton/rust Mar 10, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
arielb1 referenced this issue in arielb1/rust Mar 10, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
arielb1 referenced this issue in arielb1/rust Mar 10, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
arielb1 referenced this issue in arielb1/rust Mar 11, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
arielb1 referenced this issue in arielb1/rust Mar 11, 2017
Allow lints to check Bodys directly

r? @eddyb

babysteps towards fixing https://github.com/Manishearth/rust-clippy/issues/1580 (disable certain lints in const environments, since they make no sense there (yet))
@phansch phansch added the I-false-positive Issue: The lint was triggered on code it shouldn't have label Dec 21, 2020
@Jarcho
Copy link
Contributor

Jarcho commented Jan 6, 2022

I assume this is fixed now as all the relevant PR's are merged.

@oli-obk oli-obk closed this as completed Jan 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing good-first-issue These issues are a good way to get started with Clippy I-false-positive Issue: The lint was triggered on code it shouldn't have T-middle Type: Probably requires verifiying types
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants