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() {

src/librustc_typeck/check/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,8 +3348,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
33483348
let base = self.tcx.hir.node_to_pretty_string(base.id);
33493349
let msg = format!("`{}` is a native pointer; try dereferencing it", base);
33503350
let suggestion = format!("(*{}).{}", base, field);
3351-
err.span_suggestion_with_applicability(field.span, &msg, suggestion,
3352-
Applicability::Unspecified);
3351+
err.span_suggestion_with_applicability(
3352+
field.span,
3353+
&msg,
3354+
suggestion,
3355+
Applicability::MaybeIncorrect,
3356+
);
33533357
}
33543358
_ => {}
33553359
}
@@ -4717,8 +4721,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47174721
found: Ty<'tcx>,
47184722
) {
47194723
if let Some((sp, msg, suggestion)) = self.check_ref(expr, found, expected) {
4720-
err.span_suggestion_with_applicability(sp, msg, suggestion,
4721-
Applicability::Unspecified);
4724+
err.span_suggestion_with_applicability(
4725+
sp,
4726+
msg,
4727+
suggestion,
4728+
Applicability::MachineApplicable,
4729+
);
47224730
} else if !self.check_for_cast(err, expr, found, expected) {
47234731
let methods = self.get_conversion_methods(expr.span, expected, found);
47244732
if let Ok(expr_text) = self.sess().source_map().span_to_snippet(expr.span) {
@@ -4748,10 +4756,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
47484756
}
47494757
}) .collect::<Vec<_>>();
47504758
if !suggestions.is_empty() {
4751-
err.span_suggestions_with_applicability(expr.span,
4759+
err.span_suggestions_with_applicability(
4760+
expr.span,
47524761
"try using a conversion method",
47534762
suggestions,
4754-
Applicability::Unspecified,
4763+
Applicability::MaybeIncorrect,
47554764
);
47564765
}
47574766
}

src/librustc_typeck/check/op.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,10 +444,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
444444
err.span_label(expr.span,
445445
"`+` can't be used to concatenate two `&str` strings");
446446
match source_map.span_to_snippet(lhs_expr.span) {
447-
Ok(lstring) => err.span_suggestion_with_applicability(lhs_expr.span,
447+
Ok(lstring) => err.span_suggestion_with_applicability(
448+
lhs_expr.span,
448449
msg,
449450
format!("{}.to_owned()", lstring),
450-
Applicability::Unspecified,
451+
Applicability::MachineApplicable,
451452
),
452453
_ => err.help(msg),
453454
};
@@ -464,11 +465,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
464465
is_assign,
465466
) {
466467
(Ok(l), Ok(r), false) => {
467-
err.multipart_suggestion_with_applicability(msg, vec![
468-
(lhs_expr.span, format!("{}.to_owned()", l)),
469-
(rhs_expr.span, format!("&{}", r)),
470-
],
471-
Applicability::Unspecified,
468+
err.multipart_suggestion_with_applicability(
469+
msg,
470+
vec![
471+
(lhs_expr.span, format!("{}.to_owned()", l)),
472+
(rhs_expr.span, format!("&{}", r)),
473+
],
474+
Applicability::MachineApplicable,
472475
);
473476
}
474477
_ => {

src/libsyntax/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ impl<'a> StripUnconfigured<'a> {
124124
let error = |span, msg, suggestion: &str| {
125125
let mut err = self.sess.span_diagnostic.struct_span_err(span, msg);
126126
if !suggestion.is_empty() {
127-
err.span_suggestion_with_applicability(span,
127+
err.span_suggestion_with_applicability(
128+
span,
128129
"expected syntax is",
129130
suggestion.into(),
130-
Applicability::Unspecified,
131+
Applicability::MaybeIncorrect,
131132
);
132133
}
133134
err.emit();

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,10 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
189189
err.note("you might be missing a comma");
190190
} else {
191191
err.span_suggestion_short_with_applicability(
192-
comma_span,
193-
"missing comma here",
194-
", ".to_string(),
195-
Applicability::Unspecified,
192+
comma_span,
193+
"missing comma here",
194+
", ".to_string(),
195+
Applicability::MachineApplicable,
196196
);
197197
}
198198
}

src/libsyntax/parse/parser.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3882,11 +3882,12 @@ impl<'a> Parser<'a> {
38823882
if self.token == token::CloseDelim(token::Brace) {
38833883
// If the struct looks otherwise well formed, recover and continue.
38843884
if let Some(sp) = comma_sp {
3885-
err.span_suggestion_short_with_applicability(sp,
3886-
"remove this comma",
3887-
String::new(),
3888-
Applicability::Unspecified,
3889-
);
3885+
err.span_suggestion_short_with_applicability(
3886+
sp,
3887+
"remove this comma",
3888+
String::new(),
3889+
Applicability::MachineApplicable,
3890+
);
38903891
}
38913892
err.emit();
38923893
break;

src/libsyntax_ext/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt,
997997
}
998998
if suggestions.len() > 0 {
999999
diag.multipart_suggestion_with_applicability(
1000-
"format specifiers use curly braces",
1001-
suggestions,
1002-
Applicability::Unspecified,
1000+
"format specifiers use curly braces",
1001+
suggestions,
1002+
Applicability::MachineApplicable,
10031003
);
10041004
}
10051005
}};

0 commit comments

Comments
 (0)