Skip to content

Commit

Permalink
remove error suggestion because of span issue of compiletest
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jul 15, 2024
1 parent b44a484 commit 578578d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 12 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
}
// don't create labels for compiler-generated spans
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 => {
let (has_sugg, decl_span, sugg) = if name != kw::SelfLower {
suggest_ampmut(
Expand Down Expand Up @@ -1335,7 +1341,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
};
err.span_suggestion_verbose(
span,
format!("consider {changing} this binding's type"),
format!("consider {changing} this binding's type xxx"),
sugg,
Applicability::HasPlaceholders,
);
Expand Down Expand Up @@ -1449,6 +1455,11 @@ fn suggest_ampmut<'tcx>(
// let x: &i32 = &'a 5;
// ^^ lifetime annotation not allowed
//
eprintln!("opt_assignment_rhs_span: {:?}", opt_assignment_rhs_span);
eprintln!(
"code result: {:?}",
tcx.sess.source_map().span_to_snippet(opt_assignment_rhs_span.unwrap())
);
if let Some(assignment_rhs_span) = opt_assignment_rhs_span
&& let Ok(src) = tcx.sess.source_map().span_to_snippet(assignment_rhs_span)
&& let Some(stripped) = src.strip_prefix('&')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ error[E0594]: cannot assign to `*ptr`, which is behind a `*const` pointer
|
LL | *ptr = 3;
| ^^^^^^^^ `ptr` is a `*const` pointer, so the data it refers to cannot be written
|
help: consider specifying this binding's type
|
LL | let ptr: *mut i32 = std::ptr::addr_of!(val);
| ++++++++++

error: aborting due to 1 previous error

Expand Down

0 comments on commit 578578d

Please sign in to comment.