Skip to content

Commit e573075

Browse files
committed
get_mut_span_in_struct_field uses span.between
1 parent 97bf7b9 commit e573075

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
237237
err.span_suggestion_verbose(
238238
span,
239239
"consider changing this to be mutable",
240-
"mut ".into(),
240+
" mut ".into(),
241241
Applicability::MaybeIncorrect,
242242
);
243243
}
@@ -1059,12 +1059,12 @@ fn is_closure_or_generator(ty: Ty<'_>) -> bool {
10591059
ty.is_closure() || ty.is_generator()
10601060
}
10611061

1062-
/// Given a field that needs to be mutuable, returns a span where the mut could go.
1062+
/// Given a field that needs to be mutable, returns a span where the " mut " could go.
10631063
/// This function expects the local to be a reference to a struct in order to produce a span.
10641064
///
10651065
/// ```text
1066-
/// LL | s: &'a String
1067-
/// | ^ returns a span pointing here
1066+
/// LL | s: &'a String
1067+
/// | ^^^ returns a span taking up the space here
10681068
/// ```
10691069
fn get_mut_span_in_struct_field<'tcx>(
10701070
tcx: TyCtxt<'tcx>,
@@ -1081,12 +1081,10 @@ fn get_mut_span_in_struct_field<'tcx>(
10811081
// Now we're dealing with the actual struct that we're going to suggest a change to,
10821082
// we can expect a field that is an immutable reference to a type.
10831083
if let hir::Node::Field(field) = node {
1084-
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, .. }) =
1084+
if let hir::TyKind::Rptr(lifetime, hir::MutTy { mutbl: hir::Mutability::Not, ty }) =
10851085
field.ty.kind
10861086
{
1087-
return Some(
1088-
lifetime.span.with_hi(lifetime.span.hi() + BytePos(1)).shrink_to_hi(),
1089-
);
1087+
return Some(lifetime.span.between(ty.span));
10901088
}
10911089
}
10921090
}

src/test/ui/did_you_mean/issue-38147-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | self.longer_name.push(13);
1717
|
1818
help: consider changing this to be mutable
1919
|
20-
LL | longer_name: & 'a mut Vec<u8>
20+
LL | longer_name: & 'a mut Vec<u8>
2121
| +++
2222

2323
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)