diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2022-12-09 13:01:41 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2022-12-13 10:06:15 -0800 |
| commit | cf0b6b93373509f6aa9f5828f700669653c60425 (patch) | |
| tree | 72eccf5c84e2d689acb11afe05f4449dce1c1065 /compiler/rustc_borrowck/src | |
| parent | b8bd1d0826b8f792eccb97a6560d002832bff562 (diff) | |
| download | rust-cf0b6b93373509f6aa9f5828f700669653c60425.tar.gz rust-cf0b6b93373509f6aa9f5828f700669653c60425.zip | |
Account for dereference expressions
Diffstat (limited to 'compiler/rustc_borrowck/src')
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/move_errors.rs | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 033e4283645..6db3c858ae7 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -410,13 +410,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diagnostic, span: Span) { match error { GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { - err.span_suggestion_verbose( - span.shrink_to_lo(), - "consider borrowing here", - "&".to_string(), - Applicability::Unspecified, - ); - + self.add_borrow_suggestions(err, span); if binds_to.is_empty() { let place_ty = move_from.ty(self.body, self.infcx.tcx).ty; let place_desc = match self.describe_place(move_from.as_ref()) { @@ -459,6 +453,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { } } + fn add_borrow_suggestions(&self, err: &mut Diagnostic, span: Span) { + match self.infcx.tcx.sess.source_map().span_to_snippet(span) { + Ok(snippet) if snippet.starts_with('*') => { + err.span_suggestion_verbose( + span.with_hi(span.lo() + BytePos(1)), + "consider removing the dereference here", + String::new(), + Applicability::MaybeIncorrect, + ); + } + _ => { + err.span_suggestion_verbose( + span.shrink_to_lo(), + "consider borrowing here", + "&".to_string(), + Applicability::MaybeIncorrect, + ); + } + } + } + fn add_move_error_suggestions(&self, err: &mut Diagnostic, binds_to: &[Local]) { let mut suggestions: Vec<(Span, String, String)> = Vec::new(); for local in binds_to { |
