diff options
| author | Lucas Kent <rubickent@gmail.com> | 2021-12-18 12:57:55 +1100 |
|---|---|---|
| committer | Lucas Kent <rubickent@gmail.com> | 2021-12-18 13:00:08 +1100 |
| commit | e57307560e7ac522b18f79fc7e98a808664f4059 (patch) | |
| tree | 674d620ed8dde79551b4f15e8fb97307c487eb07 | |
| parent | 97bf7b934e740b8b94aaf0e75a17f995444e44b6 (diff) | |
| download | rust-e57307560e7ac522b18f79fc7e98a808664f4059.tar.gz rust-e57307560e7ac522b18f79fc7e98a808664f4059.zip | |
get_mut_span_in_struct_field uses span.between
| -rw-r--r-- | compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs | 14 | ||||
| -rw-r--r-- | src/test/ui/did_you_mean/issue-38147-2.stderr | 2 |
2 files changed, 7 insertions, 9 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs index 86e577fdf1d..b5dad5ccdea 100644 --- a/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs @@ -237,7 +237,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { err.span_suggestion_verbose( span, "consider changing this to be mutable", - "mut ".into(), + " mut ".into(), Applicability::MaybeIncorrect, ); } @@ -1059,12 +1059,12 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool { ty.is_closure() || ty.is_generator() } -/// Given a field that needs to be mutuable, returns a span where the mut could go. +/// Given a field that needs to be mutable, returns a span where the " mut " could go. /// This function expects the local to be a reference to a struct in order to produce a span. /// /// ```text -/// LL | s: &'a String -/// | ^ returns a span pointing here +/// LL | s: &'a String +/// | ^^^ returns a span taking up the space here /// ``` fn get_mut_span_in_struct_field<'tcx>( tcx: TyCtxt<'tcx>, @@ -1081,12 +1081,10 @@ fn get_mut_span_in_struct_field<'tcx>( // Now we're dealing with the actual struct that we're going to suggest a change to, // we can expect a field that is an immutable reference to a type. if let hir::Node::Field(field) = node { - if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, .. }) = + if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) = field.ty.kind { - return Some( - lifetime.span.with_hi(lifetime.span.hi() + BytePos(1)).shrink_to_hi(), - ); + return Some(lifetime.span.between(ty.span)); } } } diff --git a/src/test/ui/did_you_mean/issue-38147-2.stderr b/src/test/ui/did_you_mean/issue-38147-2.stderr index 5ff97eacc23..7c287a7dbfa 100644 --- a/src/test/ui/did_you_mean/issue-38147-2.stderr +++ b/src/test/ui/did_you_mean/issue-38147-2.stderr @@ -17,7 +17,7 @@ LL | self.longer_name.push(13); | help: consider changing this to be mutable | -LL | longer_name: & 'a mut Vec<u8> +LL | longer_name: & 'a mut Vec<u8> | +++ error: aborting due to 2 previous errors |
