Skip to content

Commit 6146ed0

Browse files
authored
Unrolled build for rust-lang#127675
Rollup merge of rust-lang#127675 - chenyukang:yukang-fix-127562-addr, r=petrochenkov Remove invalid help diagnostics for const pointer Partially addresses rust-lang#127562
2 parents da93539 + 7ff71e5 commit 6146ed0

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+21-12
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11461146
}
11471147
// don't create labels for compiler-generated spans
11481148
Some(_) => None,
1149+
// don't create labels for the span not from user's code
1150+
None if opt_assignment_rhs_span
1151+
.is_some_and(|span| self.infcx.tcx.sess.source_map().is_imported(span)) =>
1152+
{
1153+
None
1154+
}
11491155
None => {
11501156
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
11511157
suggest_ampmut(
@@ -1198,18 +1204,21 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
11981204
sugg.push(s);
11991205
}
12001206

1201-
err.multipart_suggestion_verbose(
1202-
format!(
1203-
"consider changing this to be a mutable {pointer_desc}{}",
1204-
if is_trait_sig {
1205-
" in the `impl` method and the `trait` definition"
1206-
} else {
1207-
""
1208-
}
1209-
),
1210-
sugg,
1211-
Applicability::MachineApplicable,
1212-
);
1207+
if sugg.iter().all(|(span, _)| !self.infcx.tcx.sess.source_map().is_imported(*span))
1208+
{
1209+
err.multipart_suggestion_verbose(
1210+
format!(
1211+
"consider changing this to be a mutable {pointer_desc}{}",
1212+
if is_trait_sig {
1213+
" in the `impl` method and the `trait` definition"
1214+
} else {
1215+
""
1216+
}
1217+
),
1218+
sugg,
1219+
Applicability::MachineApplicable,
1220+
);
1221+
}
12131222
}
12141223
Some((false, err_label_span, message, _)) => {
12151224
let def_id = self.body.source.def_id();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let val = 2;
3+
let ptr = std::ptr::addr_of!(val);
4+
unsafe {
5+
*ptr = 3; //~ ERROR cannot assign to `*ptr`, which is behind a `*const` pointer
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
2+
--> $DIR/dont_suggest_raw_pointer_syntax-issue-127562.rs:5:9
3+
|
4+
LL | *ptr = 3;
5+
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0594`.

0 commit comments

Comments
 (0)