Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit da1d099

Browse files
committedJul 12, 2023
Auto merge of #112945 - compiler-errors:tighten-span-of-adjustment-error, r=oli-obk
(re-)tighten sourceinfo span of adjustments in MIR Diagnostics rely on the spans of MIR statements being (approximately) correct in order to give suggestions relative to that span (i.e. `shrink_to_hi` and `shrink_to_lo`). I discovered that we're *intentionally* lowering THIR exprs with their parent expr's span if they come from adjustments that are due to a parent expression. While I understand why that may be desirable to demonstrate the relationship of an adjustment and the expression that requires it, it leads to 1. very verbose borrowck output 2. incorrect spans for suggestions Some diagnostics get around that by giving suggestions relative to other spans we've collected during MIR lowering, such as the span of the method's identifier (e.g. `name` in `.name()`), but this doesn't work too well when things come from desugaring. I assume it also has lead to numerous tweaks and complications to diagnostics code down the road, which this PR doesn't necessarily aim to fix but may open the gates to fixing later... The last three commits are simplifications due to the fact that we can assume that the move span actually points to what is being moved (and a test). This regressed in #89110, which was debated somewhat in #90286. cc `@Aaron1011` who originally made this change. r? diagnostics Fixes #113547 Fixes #111016
2 parents 136dab6 + a74db1a commit da1d099

File tree

172 files changed

+426
-452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+426
-452
lines changed
 

‎compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11211121
err.eager_subdiagnostic(
11221122
&self.infcx.tcx.sess.parse_sess.span_diagnostic,
11231123
CaptureReasonSuggest::FreshReborrow {
1124-
span: fn_call_span.shrink_to_lo(),
1124+
span: move_span.shrink_to_hi(),
11251125
});
11261126
}
11271127
if let Some(clone_trait) = tcx.lang_items().clone_trait()
@@ -1135,10 +1135,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11351135
&& self.infcx.predicate_must_hold_modulo_regions(&o)
11361136
{
11371137
err.span_suggestion_verbose(
1138-
fn_call_span.shrink_to_lo(),
1138+
move_span.shrink_to_hi(),
11391139
"you can `clone` the value and consume it, but this might not be \
11401140
your desired behavior",
1141-
"clone().".to_string(),
1141+
".clone()".to_string(),
11421142
Applicability::MaybeIncorrect,
11431143
);
11441144
}

‎compiler/rustc_borrowck/src/session_diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ pub(crate) enum CaptureReasonSuggest<'tcx> {
398398
#[suggestion(
399399
borrowck_suggest_create_freash_reborrow,
400400
applicability = "maybe-incorrect",
401-
code = "as_mut().",
401+
code = ".as_mut()",
402402
style = "verbose"
403403
)]
404404
FreshReborrow {

0 commit comments

Comments
 (0)
Please sign in to comment.