Skip to content

Commit eafbca9

Browse files
committed
take care when there is no args in method call
1 parent c825459 commit eafbca9

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
use crate::diagnostics::mutability_errors::mut_borrow_of_mutable_ref;
21
use either::Either;
3-
use hir::Closure;
42
use rustc_const_eval::util::CallKind;
53
use rustc_data_structures::captures::Captures;
64
use rustc_data_structures::fx::FxHashSet;
75
use rustc_errors::{
86
struct_span_err, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan,
97
};
108
use rustc_hir as hir;
9+
use rustc_hir::def::Res;
1110
use rustc_hir::intravisit::{walk_block, walk_expr, Visitor};
1211
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, LangItem};
1312
use rustc_infer::infer::TyCtxtInferExt;
@@ -31,6 +30,7 @@ use crate::borrowck_errors;
3130

3231
use crate::diagnostics::conflict_errors::StorageDeadOrDrop::LocalStorageDead;
3332
use crate::diagnostics::find_all_local_uses;
33+
use crate::diagnostics::mutability_errors::mut_borrow_of_mutable_ref;
3434
use crate::{
3535
borrow_set::BorrowData, diagnostics::Instance, prefixes::IsPrefixOf,
3636
InitializationRequiringAction, MirBorrowckCtxt, PrefixSet, WriteKind,
@@ -41,8 +41,6 @@ use super::{
4141
DescribePlaceOpt, RegionName, RegionNameSource, UseSpans,
4242
};
4343

44-
use rustc_hir::def::Res;
45-
4644
#[derive(Debug)]
4745
struct MoveSite {
4846
/// Index of the "move out" that we found. The `MoveData` can
@@ -1280,7 +1278,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
12801278
impl<'hir> Visitor<'hir> for ExpressionFinder<'hir> {
12811279
fn visit_expr(&mut self, e: &'hir hir::Expr<'hir>) {
12821280
if e.span.contains(self.capture_span) {
1283-
if let hir::ExprKind::Closure(&Closure {
1281+
if let hir::ExprKind::Closure(&hir::Closure {
12841282
movability: None,
12851283
body,
12861284
fn_arg_span,
@@ -1311,7 +1309,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13111309
if let hir::Pat { kind: hir::PatKind::Binding(_, hir_id, _ident, _), .. } = local.pat &&
13121310
let Some(init) = local.init
13131311
{
1314-
if let hir::Expr { kind: hir::ExprKind::Closure(&Closure {
1312+
if let hir::Expr { kind: hir::ExprKind::Closure(&hir::Closure {
13151313
movability: None,
13161314
..
13171315
}), .. } = init &&
@@ -1328,11 +1326,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13281326
let hir::QPath::Resolved(_, hir::Path { segments: [seg], ..}) = path &&
13291327
let Res::Local(hir_id) = seg.res &&
13301328
Some(hir_id) == self.closure_local_id {
1331-
let mut arg_str = "self".to_string();
1332-
if args.len() > 0 {
1333-
arg_str.push_str(", ");
1334-
}
1335-
self.closure_call_changes.push((seg.ident.span, arg_str));
1329+
let (span, arg_str) = if args.len() > 0 {
1330+
(args[0].span.shrink_to_lo(), "self, ".to_string())
1331+
} else {
1332+
let span = e.span.trim_start(seg.ident.span).unwrap_or(e.span);
1333+
(span, "(self)".to_string())
1334+
};
1335+
self.closure_call_changes.push((span, arg_str));
13361336
}
13371337
hir::intravisit::walk_stmt(self, s);
13381338
}
@@ -1369,9 +1369,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
13691369
}
13701370

13711371
for (span, suggest) in finder.closure_call_changes {
1372-
if let Ok(span) = sm.span_extend_while(span, |c| c != '(') {
1373-
sugg.push((sm.next_point(span).shrink_to_hi(), suggest));
1374-
}
1372+
sugg.push((span, suggest));
13751373
}
13761374

13771375
err.multipart_suggestion_verbose(

0 commit comments

Comments
 (0)