var_subdiag refinement
trim old
This commit is contained in:
parent
a0cee0ab90
commit
abf259cc54
@ -715,22 +715,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
borrow_span,
|
borrow_span,
|
||||||
&self.describe_any_place(borrow.borrowed_place.as_ref()),
|
&self.describe_any_place(borrow.borrowed_place.as_ref()),
|
||||||
);
|
);
|
||||||
borrow_spans.var_subdiag(
|
borrow_spans.var_subdiag(&mut err, Some(borrow.kind), |kind, var_span| {
|
||||||
&mut err,
|
|
||||||
|var_span| {
|
|
||||||
use crate::session_diagnostics::CaptureVarCause::*;
|
use crate::session_diagnostics::CaptureVarCause::*;
|
||||||
let place = &borrow.borrowed_place;
|
let place = &borrow.borrowed_place;
|
||||||
let desc_place = self.describe_any_place(place.as_ref());
|
let desc_place = self.describe_any_place(place.as_ref());
|
||||||
match borrow_spans {
|
match kind {
|
||||||
UseSpans::ClosureUse { generator_kind, .. } => match generator_kind {
|
|
||||||
Some(_) => BorrowUsePlaceGenerator { place: desc_place, var_span },
|
Some(_) => BorrowUsePlaceGenerator { place: desc_place, var_span },
|
||||||
None => BorrowUsePlaceClosure { place: desc_place, var_span },
|
None => BorrowUsePlaceClosure { place: desc_place, var_span },
|
||||||
},
|
|
||||||
_ => BorrowUsePlace { place: desc_place, var_span },
|
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
"mutable",
|
|
||||||
);
|
|
||||||
|
|
||||||
self.explain_why_borrow_contains_point(location, borrow, None)
|
self.explain_why_borrow_contains_point(location, borrow, None)
|
||||||
.add_explanation_to_diagnostic(
|
.add_explanation_to_diagnostic(
|
||||||
|
@ -650,19 +650,28 @@ impl UseSpans<'_> {
|
|||||||
pub(super) fn var_subdiag(
|
pub(super) fn var_subdiag(
|
||||||
self,
|
self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
f: impl Fn(Span) -> crate::session_diagnostics::CaptureVarCause,
|
kind: Option<rustc_middle::mir::BorrowKind>,
|
||||||
kind_desc: impl Into<String>,
|
f: impl Fn(Option<GeneratorKind>, Span) -> crate::session_diagnostics::CaptureVarCause,
|
||||||
) {
|
) {
|
||||||
if let UseSpans::ClosureUse { capture_kind_span, path_span, .. } = self {
|
use crate::session_diagnostics::CaptureVarKind::*;
|
||||||
if capture_kind_span == path_span {
|
if let UseSpans::ClosureUse { generator_kind, capture_kind_span, path_span, .. } = self {
|
||||||
err.subdiagnostic(f(capture_kind_span));
|
if capture_kind_span != path_span {
|
||||||
} else {
|
err.subdiagnostic(match kind {
|
||||||
err.subdiagnostic(crate::session_diagnostics::CaptureVarKind {
|
Some(kd) => match kd {
|
||||||
kind_desc: kind_desc.into(),
|
rustc_middle::mir::BorrowKind::Shared
|
||||||
kind_span: capture_kind_span,
|
| rustc_middle::mir::BorrowKind::Shallow
|
||||||
});
|
| rustc_middle::mir::BorrowKind::Unique => {
|
||||||
err.subdiagnostic(f(path_span));
|
Immute { kind_span: capture_kind_span }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rustc_middle::mir::BorrowKind::Mut { .. } => {
|
||||||
|
Mut { kind_span: capture_kind_span }
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None => Move { kind_span: capture_kind_span },
|
||||||
|
});
|
||||||
|
};
|
||||||
|
err.subdiagnostic(f(generator_kind, path_span));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,36 +149,6 @@ pub(crate) enum RequireStaticErr {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
|
||||||
#[label(borrowck_capture_kind_label)]
|
|
||||||
pub(crate) struct CaptureVarKind {
|
|
||||||
pub kind_desc: String,
|
|
||||||
#[primary_span]
|
|
||||||
pub kind_span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
|
||||||
pub(crate) enum CaptureVarCause {
|
|
||||||
#[label(borrowck_var_borrow_by_use_place)]
|
|
||||||
BorrowUsePlace {
|
|
||||||
place: String,
|
|
||||||
#[primary_span]
|
|
||||||
var_span: Span,
|
|
||||||
},
|
|
||||||
#[label(borrowck_var_borrow_by_use_place_in_generator)]
|
|
||||||
BorrowUsePlaceGenerator {
|
|
||||||
place: String,
|
|
||||||
#[primary_span]
|
|
||||||
var_span: Span,
|
|
||||||
},
|
|
||||||
#[label(borrowck_var_borrow_by_use_place_in_closure)]
|
|
||||||
BorrowUsePlaceClosure {
|
|
||||||
place: String,
|
|
||||||
#[primary_span]
|
|
||||||
var_span: Span,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Subdiagnostic)]
|
#[derive(Subdiagnostic)]
|
||||||
pub(crate) enum CaptureVarPathUseCause {
|
pub(crate) enum CaptureVarPathUseCause {
|
||||||
#[label(borrowck_borrow_due_to_use_generator)]
|
#[label(borrowck_borrow_due_to_use_generator)]
|
||||||
@ -222,3 +192,38 @@ pub(crate) enum CaptureVarPathUseCause {
|
|||||||
path_span: Span,
|
path_span: Span,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub(crate) enum CaptureVarKind {
|
||||||
|
#[label(borrowck_capture_immute)]
|
||||||
|
Immute {
|
||||||
|
#[primary_span]
|
||||||
|
kind_span: Span,
|
||||||
|
},
|
||||||
|
#[label(borrowck_capture_mut)]
|
||||||
|
Mut {
|
||||||
|
#[primary_span]
|
||||||
|
kind_span: Span,
|
||||||
|
},
|
||||||
|
#[label(borrowck_capture_move)]
|
||||||
|
Move {
|
||||||
|
#[primary_span]
|
||||||
|
kind_span: Span,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subdiagnostic)]
|
||||||
|
pub(crate) enum CaptureVarCause {
|
||||||
|
#[label(borrowck_var_borrow_by_use_place_in_generator)]
|
||||||
|
BorrowUsePlaceGenerator {
|
||||||
|
place: String,
|
||||||
|
#[primary_span]
|
||||||
|
var_span: Span,
|
||||||
|
},
|
||||||
|
#[label(borrowck_var_borrow_by_use_place_in_closure)]
|
||||||
|
BorrowUsePlaceClosure {
|
||||||
|
place: String,
|
||||||
|
#[primary_span]
|
||||||
|
var_span: Span,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
@ -94,3 +94,18 @@ borrowck_assign_due_to_use_closure =
|
|||||||
|
|
||||||
borrowck_assign_part_due_to_use_closure =
|
borrowck_assign_part_due_to_use_closure =
|
||||||
assign to part occurs due to use in closure
|
assign to part occurs due to use in closure
|
||||||
|
|
||||||
|
borrowck_capture_immute =
|
||||||
|
capture is immutable because of use here
|
||||||
|
|
||||||
|
borrowck_capture_mut =
|
||||||
|
capture is mutable because of use here
|
||||||
|
|
||||||
|
borrowck_capture_move =
|
||||||
|
capture is moved because of use here
|
||||||
|
|
||||||
|
borrowck_var_move_by_use_place_in_generator =
|
||||||
|
move occurs due to use of {$place} in generator
|
||||||
|
|
||||||
|
borrowck_var_move_by_use_place_in_closure =
|
||||||
|
move occurs due to use of {$place} in closure
|
||||||
|
@ -1898,6 +1898,7 @@ impl BorrowKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: won't be used after diagnostic migration
|
||||||
pub fn describe_mutability(&self) -> &str {
|
pub fn describe_mutability(&self) -> &str {
|
||||||
match *self {
|
match *self {
|
||||||
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => "immutable",
|
BorrowKind::Shared | BorrowKind::Shallow | BorrowKind::Unique => "immutable",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user