Skip to content

Commit 1cab4d1

Browse files
committed
Add a note to cast_ref_to_mut lint
1 parent fd57874 commit 1cab4d1

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

clippy_lints/src/types.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::utils::paths;
1616
use crate::utils::{
1717
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
1818
match_def_path, match_path, multispan_sugg, opt_def_id, same_tys, sext, snippet, snippet_opt,
19-
snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
20-
AbsolutePathBuffer,
19+
snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then,
20+
span_note_and_lint, unsext, AbsolutePathBuffer,
2121
};
2222
use if_chain::if_chain;
2323
use rustc::hir;
@@ -2291,11 +2291,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
22912291
if let TyKind::Ptr(MutTy { mutbl: Mutability::MutImmutable, .. }) = t.node;
22922292
if let Ref(..) = cx.tables.node_id_to_type(e.hir_id).sty;
22932293
then {
2294-
span_lint(
2294+
span_note_and_lint(
22952295
cx,
22962296
CAST_REF_TO_MUT,
22972297
expr.span,
2298-
"casting immutable reference to a mutable reference"
2298+
"casting immutable reference to a mutable reference",
2299+
expr.span,
2300+
"consider implementing `UnsafeCell` instead",
22992301
);
23002302
}
23012303
}

tests/ui/cast_ref_to_mut.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,23 @@ LL | (*(a as *const _ as *mut String)).push_str(" world");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::cast-ref-to-mut` implied by `-D warnings`
8+
= note: consider implementing `UnsafeCell` instead
89

910
error: casting immutable reference to a mutable reference
1011
--> $DIR/cast_ref_to_mut.rs:19:9
1112
|
1213
LL | *(a as *const _ as *mut _) = String::from("Replaced");
1314
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: consider implementing `UnsafeCell` instead
1417

1518
error: casting immutable reference to a mutable reference
1619
--> $DIR/cast_ref_to_mut.rs:20:9
1720
|
1821
LL | *(a as *const _ as *mut String) += " world";
1922
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23+
|
24+
= note: consider implementing `UnsafeCell` instead
2025

2126
error: aborting due to 3 previous errors
2227

0 commit comments

Comments
 (0)