Skip to content

Commit

Permalink
get_mut_span_in_struct_field uses span.between
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Dec 18, 2021
1 parent 97bf7b9 commit e573075
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Expand Up @@ -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,
);
}
Expand Down Expand Up @@ -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>,
Expand All @@ -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));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-38147-2.stderr
Expand Up @@ -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
Expand Down

0 comments on commit e573075

Please sign in to comment.