Add a note to cast_ref_to_mut lint

This commit is contained in:
Konrad Borowski 2018-12-30 13:06:37 +01:00
parent fd57874106
commit 1cab4d15a2
2 changed files with 11 additions and 4 deletions

View file

@ -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",
);
}
}

View file

@ -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