From 1cab4d15a2e95223ad8d812e5f0932e31242f665 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Sun, 30 Dec 2018 13:06:37 +0100 Subject: [PATCH] Add a note to cast_ref_to_mut lint --- clippy_lints/src/types.rs | 10 ++++++---- tests/ui/cast_ref_to_mut.stderr | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clippy_lints/src/types.rs b/clippy_lints/src/types.rs index 43603c287..097ff1fec 100644 --- a/clippy_lints/src/types.rs +++ b/clippy_lints/src/types.rs @@ -16,8 +16,8 @@ use crate::utils::paths; use crate::utils::{ clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment, match_def_path, match_path, multispan_sugg, opt_def_id, same_tys, sext, snippet, snippet_opt, - snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext, - AbsolutePathBuffer, + snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, + span_note_and_lint, unsext, AbsolutePathBuffer, }; use if_chain::if_chain; use rustc::hir; @@ -2291,11 +2291,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut { if let TyKind::Ptr(MutTy { mutbl: Mutability::MutImmutable, .. }) = t.node; if let Ref(..) = cx.tables.node_id_to_type(e.hir_id).sty; then { - span_lint( + span_note_and_lint( cx, CAST_REF_TO_MUT, expr.span, - "casting immutable reference to a mutable reference" + "casting immutable reference to a mutable reference", + expr.span, + "consider implementing `UnsafeCell` instead", ); } } diff --git a/tests/ui/cast_ref_to_mut.stderr b/tests/ui/cast_ref_to_mut.stderr index a3e4fc541..23f03f011 100644 --- a/tests/ui/cast_ref_to_mut.stderr +++ b/tests/ui/cast_ref_to_mut.stderr @@ -5,18 +5,23 @@ LL | (*(a as *const _ as *mut String)).push_str(" world"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D clippy::cast-ref-to-mut` implied by `-D warnings` + = note: consider implementing `UnsafeCell` instead error: casting immutable reference to a mutable reference --> $DIR/cast_ref_to_mut.rs:19:9 | LL | *(a as *const _ as *mut _) = String::from("Replaced"); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: consider implementing `UnsafeCell` instead error: casting immutable reference to a mutable reference --> $DIR/cast_ref_to_mut.rs:20:9 | LL | *(a as *const _ as *mut String) += " world"; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: consider implementing `UnsafeCell` instead error: aborting due to 3 previous errors