Skip to content

Commit 2b77760

Browse files
committed
Fill in suggestions Applicability according to @estebank
Also fix some formatting along the way.
1 parent c61f4a7 commit 2b77760

File tree

16 files changed

+69
-46
lines changed

16 files changed

+69
-46
lines changed

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12501250
let_span,
12511251
"use a mutable reference instead",
12521252
replace_str,
1253+
// I believe this can be machine applicable,
1254+
// but if there are multiple attempted uses of an immutable
1255+
// reference, I don't know how rustfix handles it, it might
1256+
// attempt fixing them multiple times.
1257+
// @estebank
12531258
Applicability::Unspecified,
12541259
);
12551260
}
@@ -1308,7 +1313,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
13081313
"consider removing the `&mut`, as it is an \
13091314
immutable binding to a mutable reference",
13101315
snippet,
1311-
Applicability::Unspecified,
1316+
Applicability::MachineApplicable,
13121317
);
13131318
} else {
13141319
db.span_suggestion_with_applicability(
@@ -1345,7 +1350,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
13451350
use the `move` keyword",
13461351
cmt_path_or_string),
13471352
suggestion,
1348-
Applicability::Unspecified,
1353+
Applicability::MachineApplicable,
13491354
)
13501355
.emit();
13511356
self.signal_error();

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
426426
span,
427427
&format!("consider removing the `{}`", to_remove),
428428
suggestion,
429-
Applicability::Unspecified,
429+
Applicability::MachineApplicable,
430430
);
431431
}
432432
}

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
232232
local_decl.source_info.span,
233233
"consider changing this to be mutable",
234234
format!("mut {}", local_decl.name.unwrap()),
235-
Applicability::Unspecified,
235+
Applicability::MachineApplicable,
236236
);
237237
}
238238

@@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
263263
upvar_ident.span,
264264
"consider changing this to be mutable",
265265
format!("mut {}", upvar_ident.name),
266-
Applicability::Unspecified,
266+
Applicability::MachineApplicable,
267267
);
268268
}
269269
}
@@ -358,7 +358,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
358358
err_help_span,
359359
&format!("consider changing this to be a mutable {}", pointer_desc),
360360
suggested_code,
361-
Applicability::Unspecified,
361+
Applicability::MachineApplicable,
362362
);
363363
}
364364

src/librustc_passes/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'a> AstValidator<'a> {
184184
if let Ok(snippet) = self.session.source_map().span_to_snippet(span) {
185185
err.span_suggestion_with_applicability(
186186
span, "consider adding parentheses", format!("({})", snippet),
187-
Applicability::Unspecified,
187+
Applicability::MachineApplicable,
188188
);
189189
}
190190

src/librustc_passes/loops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
147147
without a value inside this `{}` loop",
148148
kind.name()),
149149
"break".to_string(),
150-
Applicability::Unspecified,
150+
Applicability::MaybeIncorrect,
151151
)
152152
.emit();
153153
}

src/librustc_resolve/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
33033303
sp,
33043304
"did you mean to use `;` here instead?",
33053305
";".to_string(),
3306-
Applicability::Unspecified,
3306+
Applicability::MaybeIncorrect,
33073307
);
33083308
}
33093309
break;

src/librustc_typeck/check/cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
332332
err.span_suggestion_with_applicability(self.cast_span,
333333
"try casting to a reference instead",
334334
format!("&{}{}", mtstr, s),
335-
Applicability::Unspecified,
335+
Applicability::MachineApplicable,
336336
);
337337
}
338338
Err(_) => {
@@ -353,7 +353,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
353353
err.span_suggestion_with_applicability(self.cast_span,
354354
"try casting to a `Box` instead",
355355
format!("Box<{}>", s),
356-
Applicability::Unspecified,
356+
Applicability::MachineApplicable,
357357
);
358358
}
359359
Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr),

src/librustc_typeck/check/compare_method.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
326326
impl_err_span,
327327
"consider change the type to match the mutability in trait",
328328
format!("{}", trait_err_str),
329-
Applicability::Unspecified,
329+
Applicability::MachineApplicable,
330330
);
331331
}
332332
}
@@ -811,7 +811,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
811811
// of the generics, but it works for the common case
812812
(generics_span, new_generics),
813813
],
814-
Applicability::Unspecified,
814+
Applicability::MaybeIncorrect,
815815
);
816816
Some(())
817817
})();
@@ -881,7 +881,7 @@ fn compare_synthetic_generics<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
881881
// replace param usage with `impl Trait`
882882
(span, format!("impl {}", bounds)),
883883
],
884-
Applicability::Unspecified,
884+
Applicability::MaybeIncorrect,
885885
);
886886
Some(())
887887
})();

src/librustc_typeck/check/demand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
135135
err.span_suggestions_with_applicability(expr.span,
136136
"try using a variant of the expected type",
137137
suggestions,
138-
Applicability::Unspecified,
138+
Applicability::MaybeIncorrect,
139139
);
140140
}
141141
}

src/librustc_typeck/check/method/suggest.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
258258
format!("{}_{}",
259259
snippet,
260260
concrete_type),
261-
Applicability::Unspecified,
261+
Applicability::MaybeIncorrect,
262262
);
263263
}
264264
hir::ExprKind::Path(ref qpath) => { // local binding
@@ -290,7 +290,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
290290
.unwrap_or(span)),
291291
&msg,
292292
format!("{}: {}", snippet, concrete_type),
293-
Applicability::Unspecified,
293+
Applicability::MaybeIncorrect,
294294
);
295295
}
296296
_ => {
@@ -519,8 +519,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
519519
format!("use {};\n{}", self.tcx.item_path_str(*did), additional_newline)
520520
}).collect();
521521

522-
err.span_suggestions_with_applicability(span, &msg, path_strings,
523-
Applicability::Unspecified);
522+
err.span_suggestions_with_applicability(
523+
span,
524+
&msg,
525+
path_strings,
526+
Applicability::MaybeIncorrect,
527+
);
524528
} else {
525529
let limit = if candidates.len() == 5 { 5 } else { 4 };
526530
for (i, trait_did) in candidates.iter().take(limit).enumerate() {

0 commit comments

Comments
 (0)