mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-06 12:18:33 +00:00
Move a hint to an error message in cast_ref_to_mut lint
This matches mem::transmute::<&T, &mut T> lint in rustc.
This commit is contained in:
parent
1cab4d15a2
commit
6faf1330aa
@ -16,8 +16,8 @@ use crate::utils::paths;
|
|||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
clip, comparisons, differing_macro_contexts, higher, in_constant, in_macro, int_bits, last_path_segment,
|
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,
|
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,
|
snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
|
||||||
span_note_and_lint, unsext, AbsolutePathBuffer,
|
AbsolutePathBuffer,
|
||||||
};
|
};
|
||||||
use if_chain::if_chain;
|
use if_chain::if_chain;
|
||||||
use rustc::hir;
|
use rustc::hir;
|
||||||
@ -2291,13 +2291,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RefToMut {
|
|||||||
if let TyKind::Ptr(MutTy { mutbl: Mutability::MutImmutable, .. }) = t.node;
|
if let TyKind::Ptr(MutTy { mutbl: Mutability::MutImmutable, .. }) = t.node;
|
||||||
if let Ref(..) = cx.tables.node_id_to_type(e.hir_id).sty;
|
if let Ref(..) = cx.tables.node_id_to_type(e.hir_id).sty;
|
||||||
then {
|
then {
|
||||||
span_note_and_lint(
|
span_lint(
|
||||||
cx,
|
cx,
|
||||||
CAST_REF_TO_MUT,
|
CAST_REF_TO_MUT,
|
||||||
expr.span,
|
expr.span,
|
||||||
"casting immutable reference to a mutable reference",
|
"casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell",
|
||||||
expr.span,
|
|
||||||
"consider implementing `UnsafeCell` instead",
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,22 @@
|
|||||||
error: casting immutable reference to a mutable reference
|
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
|
||||||
--> $DIR/cast_ref_to_mut.rs:18:9
|
--> $DIR/cast_ref_to_mut.rs:18:9
|
||||||
|
|
|
|
||||||
LL | (*(a as *const _ as *mut String)).push_str(" world");
|
LL | (*(a as *const _ as *mut String)).push_str(" world");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
= note: `-D clippy::cast-ref-to-mut` implied by `-D warnings`
|
= note: `-D clippy::cast-ref-to-mut` implied by `-D warnings`
|
||||||
= note: consider implementing `UnsafeCell` instead
|
|
||||||
|
|
||||||
error: casting immutable reference to a mutable reference
|
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
|
||||||
--> $DIR/cast_ref_to_mut.rs:19:9
|
--> $DIR/cast_ref_to_mut.rs:19:9
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
LL | *(a as *const _ as *mut _) = String::from("Replaced");
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= note: consider implementing `UnsafeCell` instead
|
|
||||||
|
|
||||||
error: casting immutable reference to a mutable reference
|
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
|
||||||
--> $DIR/cast_ref_to_mut.rs:20:9
|
--> $DIR/cast_ref_to_mut.rs:20:9
|
||||||
|
|
|
|
||||||
LL | *(a as *const _ as *mut String) += " world";
|
LL | *(a as *const _ as *mut String) += " world";
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
||||||
= note: consider implementing `UnsafeCell` instead
|
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user