Skip to content

Commit fd3ab4d

Browse files
committed
fix invalid_ref lint and prepare for invalid_value lint
1 parent c55d38e commit fd3ab4d

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

Diff for: clippy_lints/src/invalid_ref.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ declare_clippy_lint! {
2121
"creation of invalid reference"
2222
}
2323

24-
const ZERO_REF_SUMMARY: &str = "reference to zeroed memory";
25-
const UNINIT_REF_SUMMARY: &str = "reference to uninitialized memory";
26-
const HELP: &str = "Creation of a null reference is undefined behavior; \
24+
const SUMMARY: &str = "invalid reference";
25+
const ZERO_REF_HELP: &str = "Creation of a null reference is undefined behavior; \
26+
see https://doc.rust-lang.org/reference/behavior-considered-undefined.html";
27+
const UNINIT_REF_HELP: &str = "Creation of an uninitialized reference is undefined behavior; \
2728
see https://doc.rust-lang.org/reference/behavior-considered-undefined.html";
2829

2930
declare_lint_pass!(InvalidRef => [INVALID_REF]);
@@ -37,18 +38,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidRef {
3738
if let ty::Ref(..) = cx.tables.expr_ty(expr).sty;
3839
if let Some(def_id) = cx.tables.qpath_res(qpath, path.hir_id).opt_def_id();
3940
then {
40-
let msg = if match_def_path(cx, def_id, &paths::MEM_ZEROED) |
41+
let help = if match_def_path(cx, def_id, &paths::MEM_ZEROED) |
4142
match_def_path(cx, def_id, &paths::INIT)
4243
{
43-
ZERO_REF_SUMMARY
44+
ZERO_REF_HELP
4445
} else if match_def_path(cx, def_id, &paths::MEM_UNINIT) |
4546
match_def_path(cx, def_id, &paths::UNINIT)
4647
{
47-
UNINIT_REF_SUMMARY
48+
UNINIT_REF_HELP
4849
} else {
4950
return;
5051
};
51-
span_help_and_lint(cx, INVALID_REF, expr.span, msg, HELP);
52+
span_help_and_lint(cx, INVALID_REF, expr.span, SUMMARY, help);
5253
}
5354
}
5455
}

Diff for: tests/ui/invalid_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(deprecated, unused)]
1+
#![allow(deprecated, unused, unknown_lints, invalid_value)]
22
#![feature(core_intrinsics)]
33

44
extern crate core;

Diff for: tests/ui/invalid_ref.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: reference to zeroed memory
1+
error: invalid reference
22
--> $DIR/invalid_ref.rs:23:24
33
|
44
LL | let ref_zero: &T = std::mem::zeroed(); // warning
@@ -7,37 +7,37 @@ LL | let ref_zero: &T = std::mem::zeroed(); // warning
77
= note: `#[deny(clippy::invalid_ref)]` on by default
88
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
99

10-
error: reference to zeroed memory
10+
error: invalid reference
1111
--> $DIR/invalid_ref.rs:27:24
1212
|
1313
LL | let ref_zero: &T = core::mem::zeroed(); // warning
1414
| ^^^^^^^^^^^^^^^^^^^
1515
|
1616
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1717

18-
error: reference to zeroed memory
18+
error: invalid reference
1919
--> $DIR/invalid_ref.rs:31:24
2020
|
2121
LL | let ref_zero: &T = std::intrinsics::init(); // warning
2222
| ^^^^^^^^^^^^^^^^^^^^^^^
2323
|
2424
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
2525

26-
error: reference to uninitialized memory
26+
error: invalid reference
2727
--> $DIR/invalid_ref.rs:35:26
2828
|
2929
LL | let ref_uninit: &T = std::mem::uninitialized(); // warning
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^
3131
|
32-
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
32+
= help: Creation of an uninitialized reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
3333

34-
error: reference to uninitialized memory
34+
error: invalid reference
3535
--> $DIR/invalid_ref.rs:39:26
3636
|
3737
LL | let ref_uninit: &T = core::mem::uninitialized(); // warning
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
3939
|
40-
= help: Creation of a null reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
40+
= help: Creation of an uninitialized reference is undefined behavior; see https://doc.rust-lang.org/reference/behavior-considered-undefined.html
4141

4242
error: aborting due to 5 previous errors
4343

0 commit comments

Comments
 (0)