Skip to content

Commit 6faf133

Browse files
committed
Move a hint to an error message in cast_ref_to_mut lint
This matches mem::transmute::<&T, &mut T> lint in rustc.
1 parent 1cab4d1 commit 6faf133

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

clippy_lints/src/types.rs

+4-6
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,
20-
span_note_and_lint, unsext, AbsolutePathBuffer,
19+
snippet_with_applicability, span_help_and_lint, span_lint, span_lint_and_sugg, span_lint_and_then, unsext,
20+
AbsolutePathBuffer,
2121
};
2222
use if_chain::if_chain;
2323
use rustc::hir;
@@ -2291,13 +2291,11 @@ 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_note_and_lint(
2294+
span_lint(
22952295
cx,
22962296
CAST_REF_TO_MUT,
22972297
expr.span,
2298-
"casting immutable reference to a mutable reference",
2299-
expr.span,
2300-
"consider implementing `UnsafeCell` instead",
2298+
"casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell",
23012299
);
23022300
}
23032301
}

tests/ui/cast_ref_to_mut.stderr

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
1-
error: casting immutable reference to a mutable reference
1+
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
22
--> $DIR/cast_ref_to_mut.rs:18:9
33
|
44
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
98

10-
error: casting immutable reference to a mutable reference
9+
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
1110
--> $DIR/cast_ref_to_mut.rs:19:9
1211
|
1312
LL | *(a as *const _ as *mut _) = String::from("Replaced");
1413
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
15-
|
16-
= note: consider implementing `UnsafeCell` instead
1714

18-
error: casting immutable reference to a mutable reference
15+
error: casting &T to &mut T may cause undefined behaviour, consider instead using an UnsafeCell
1916
--> $DIR/cast_ref_to_mut.rs:20:9
2017
|
2118
LL | *(a as *const _ as *mut String) += " world";
2219
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
23-
|
24-
= note: consider implementing `UnsafeCell` instead
2520

2621
error: aborting due to 3 previous errors
2722

0 commit comments

Comments
 (0)