Remove invalid help diagnostics for const pointer
This commit is contained in:
parent
03c2100ded
commit
7ff71e5fb4
@ -1146,6 +1146,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
|||||||
}
|
}
|
||||||
// don't create labels for compiler-generated spans
|
// don't create labels for compiler-generated spans
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
|
// don't create labels for the span not from user's code
|
||||||
|
None if opt_assignment_rhs_span
|
||||||
|
.is_some_and(|span| self.infcx.tcx.sess.source_map().is_imported(span)) =>
|
||||||
|
{
|
||||||
|
None
|
||||||
|
}
|
||||||
None => {
|
None => {
|
||||||
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
|
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
|
||||||
suggest_ampmut(
|
suggest_ampmut(
|
||||||
@ -1198,6 +1204,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
|||||||
sugg.push(s);
|
sugg.push(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sugg.iter().all(|(span, _)| !self.infcx.tcx.sess.source_map().is_imported(*span))
|
||||||
|
{
|
||||||
err.multipart_suggestion_verbose(
|
err.multipart_suggestion_verbose(
|
||||||
format!(
|
format!(
|
||||||
"consider changing this to be a mutable {pointer_desc}{}",
|
"consider changing this to be a mutable {pointer_desc}{}",
|
||||||
@ -1211,6 +1219,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
|
|||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Some((false, err_label_span, message, _)) => {
|
Some((false, err_label_span, message, _)) => {
|
||||||
let def_id = self.body.source.def_id();
|
let def_id = self.body.source.def_id();
|
||||||
let hir_id = if let Some(local_def_id) = def_id.as_local()
|
let hir_id = if let Some(local_def_id) = def_id.as_local()
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
fn main() {
|
||||||
|
let val = 2;
|
||||||
|
let ptr = std::ptr::addr_of!(val);
|
||||||
|
unsafe {
|
||||||
|
*ptr = 3; //~ ERROR cannot assign to `*ptr`, which is behind a `*const` pointer
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
|
||||||
|
--> $DIR/dont_suggest_raw_pointer_syntax-issue-127562.rs:5:9
|
||||||
|
|
|
||||||
|
LL | *ptr = 3;
|
||||||
|
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0594`.
|
Loading…
x
Reference in New Issue
Block a user