diff options
| author | Giacomo Pasini <giacomo@status.im> | 2023-02-16 23:14:04 +0100 |
|---|---|---|
| committer | Giacomo Pasini <giacomo@status.im> | 2023-03-03 16:33:11 +0100 |
| commit | 9cf0ff26f82937a20d60a115cfb331e3f7a8c2d3 (patch) | |
| tree | 1d8377a3eb94a6ee91231f674cf5017a8b860deb /compiler/rustc_borrowck/src/diagnostics | |
| parent | b3a47d9b6b26adebe9ce0e24c7efb26c6380d50a (diff) | |
| download | rust-9cf0ff26f82937a20d60a115cfb331e3f7a8c2d3.tar.gz rust-9cf0ff26f82937a20d60a115cfb331e3f7a8c2d3.zip | |
use helper function for error reporting
Diffstat (limited to 'compiler/rustc_borrowck/src/diagnostics')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index cb97699d7d2..a622a215a2e 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1467,6 +1467,32 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// Reports StorageDeadOrDrop of `place` conflicts with `borrow`. /// + /// Depending on the origin of the StorageDeadOrDrop, this may be + /// reported as either a drop or an illegal mutation of a borrowed value. + /// The latter is preferred when the this is a drop triggered by a + /// reassignment, as it's more user friendly to report a problem with the + /// explicit assignment than the implicit drop. + #[instrument(level = "debug", skip(self))] + pub(crate) fn report_storage_dead_or_drop_of_borrowed( + &mut self, + location: Location, + place_span: (Place<'tcx>, Span), + borrow: &BorrowData<'tcx>, + ) { + // It's sufficient to check the last desugaring as Replace is the last + // one to be applied. + if let Some(DesugaringKind::Replace) = place_span.1.desugaring_kind() { + self.report_illegal_mutation_of_borrowed(location, place_span, borrow) + } else { + self.report_borrowed_value_does_not_live_long_enough( + location, + borrow, + place_span, + Some(WriteKind::StorageDeadOrDrop), + ) + } + } + /// This means that some data referenced by `borrow` needs to live /// past the point where the StorageDeadOrDrop of `place` occurs. /// This is usually interpreted as meaning that `place` has too |
