rust/compiler/rustc_lint/src
bors 7537b20626 Auto merge of #83948 - ABouttefeux:lint-nullprt-deref, r=RalfJung
add lint deref_nullptr detecting when a null ptr is dereferenced

fixes #83856
changelog: add lint that detect code like
```rust
unsafe {
      &*core::ptr::null::<i32>()
 };
unsafe {
     addr_of!(std::ptr::null::<i32>())
};
let x: i32 = unsafe {*core::ptr::null()};
let x: i32 = unsafe {*core::ptr::null_mut()};
unsafe {*(0 as *const i32)};
unsafe {*(core::ptr::null() as *const i32)};
```
```
warning: Dereferencing a null pointer causes undefined behavior
 --> src\main.rs:5:26
  |
5 |     let x: i32 = unsafe {*core::ptr::null()};
  |                          ^^^^^^^^^^^^^^^^^^
  |                          |
  |                          a null pointer is dereferenced
  |                          this code causes undefined behavior when executed
  |
  = note: `#[warn(deref_nullptr)]` on by default
```

Limitation:
It does not detect code like
```rust
const ZERO: usize = 0;
unsafe {*(ZERO as *const i32)};
```
or code where `0` is not directly a literal
2021-04-14 18:04:22 +00:00
..
nonstandard_style
array_into_iter.rs Implement rustc side of report-future-incompat 2020-10-30 20:02:14 -04:00
builtin.rs Auto merge of #83948 - ABouttefeux:lint-nullprt-deref, r=RalfJung 2021-04-14 18:04:22 +00:00
context.rs add OR_PATTERNS_BACK_COMPAT lint 2021-04-01 23:14:14 +08:00
early.rs ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
internal.rs Remove hir::Item::attrs. 2021-03-09 19:27:50 +01:00
late.rs ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
levels.rs Fix bug where rustc_lint would not apply renamed tool lints 2021-04-05 04:13:36 -04:00
lib.rs add lint deref_nullptr 2021-04-06 22:01:00 +02:00
methods.rs Fix doctest 2020-10-26 18:19:49 -04:00
non_ascii_idents.rs Auto merge of #76541 - matthiaskrgr:unstable_sort, r=davidtwco 2020-09-14 21:43:17 +00:00
non_fmt_panic.rs Rollup merge of #82456 - klensy:or-else, r=estebank 2021-02-26 15:52:31 +01:00
nonstandard_style.rs Remove hir::Item::attrs. 2021-03-09 19:27:50 +01:00
noop_method_call.rs Warn in doc test 2021-03-03 11:23:33 +01:00
passes.rs ast/hir: Rename field-related structures 2021-03-16 11:41:24 +03:00
redundant_semicolon.rs Lint on redundant trailing semicolon after item 2020-12-29 16:30:02 -05:00
traits.rs Only store a LocalDefId in hir::Item. 2021-02-15 19:32:10 +01:00
types.rs Use iter::zip in compiler/ 2021-03-26 09:32:31 -07:00
unused.rs Visit attributes in one go. 2021-03-09 19:09:34 +01:00