Skip to content

Commit 4fa4bb5

Browse files
Rollup merge of rust-lang#53504 - ekse:suggestions-applicability-2, r=estebank
Set applicability for more suggestions. Converts a couple more calls to `span_suggestion_with_applicability` (rust-lang#50723). To be on the safe side, I marked suggestions that depend on the intent of the user or that are potentially lossy conversions as MaybeIncorrect. r? @estebank
2 parents 55d9823 + 5a23a0d commit 4fa4bb5

File tree

8 files changed

+217
-125
lines changed

8 files changed

+217
-125
lines changed

src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc::ty;
1717
use rustc_mir::util::borrowck_errors::{BorrowckErrors, Origin};
1818
use syntax::ast;
1919
use syntax_pos;
20-
use errors::DiagnosticBuilder;
20+
use errors::{DiagnosticBuilder, Applicability};
2121
use borrowck::gather_loans::gather_moves::PatternSource;
2222

2323
pub struct MoveErrorCollector<'tcx> {
@@ -80,9 +80,12 @@ fn report_move_errors<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, errors: &[MoveErr
8080
let initializer =
8181
e.init.as_ref().expect("should have an initializer to get an error");
8282
if let Ok(snippet) = bccx.tcx.sess.source_map().span_to_snippet(initializer.span) {
83-
err.span_suggestion(initializer.span,
84-
"consider using a reference instead",
85-
format!("&{}", snippet));
83+
err.span_suggestion_with_applicability(
84+
initializer.span,
85+
"consider using a reference instead",
86+
format!("&{}", snippet),
87+
Applicability::MaybeIncorrect // using a reference may not be the right fix
88+
);
8689
}
8790
}
8891
_ => {

src/librustc_passes/ast_validation.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use syntax::symbol::keywords;
2525
use syntax::visit::{self, Visitor};
2626
use syntax_pos::Span;
2727
use errors;
28+
use errors::Applicability;
2829

2930
struct AstValidator<'a> {
3031
session: &'a Session,
@@ -185,11 +186,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
185186
);
186187
match val.node {
187188
ExprKind::Lit(ref v) if v.node.is_numeric() => {
188-
err.span_suggestion(
189+
err.span_suggestion_with_applicability(
189190
place.span.between(val.span),
190191
"if you meant to write a comparison against a negative value, add a \
191192
space in between `<` and `-`",
192193
"< -".to_string(),
194+
Applicability::MaybeIncorrect
193195
);
194196
}
195197
_ => {}

src/librustc_resolve/macros.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ use syntax::symbol::{Symbol, keywords};
3838
use syntax::tokenstream::{TokenStream, TokenTree, Delimited};
3939
use syntax::util::lev_distance::find_best_match_for_name;
4040
use syntax_pos::{Span, DUMMY_SP};
41+
use errors::Applicability;
4142

4243
use std::cell::Cell;
4344
use std::mem;
@@ -938,9 +939,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
938939
if let Some(suggestion) = suggestion {
939940
if suggestion != name {
940941
if let MacroKind::Bang = kind {
941-
err.span_suggestion(span, "you could try the macro", suggestion.to_string());
942+
err.span_suggestion_with_applicability(
943+
span,
944+
"you could try the macro",
945+
suggestion.to_string(),
946+
Applicability::MaybeIncorrect
947+
);
942948
} else {
943-
err.span_suggestion(span, "try", suggestion.to_string());
949+
err.span_suggestion_with_applicability(
950+
span,
951+
"try",
952+
suggestion.to_string(),
953+
Applicability::MaybeIncorrect
954+
);
944955
}
945956
} else {
946957
err.help("have you added the `#[macro_use]` on the module/import?");
@@ -1065,10 +1076,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
10651076
if let Some(span) = span {
10661077
let found_use = if found_use { "" } else { "\n" };
10671078
self.session.struct_span_err(err.use_span, err.warn_msg)
1068-
.span_suggestion(
1079+
.span_suggestion_with_applicability(
10691080
span,
10701081
"instead, import the procedural macro like any other item",
10711082
format!("use {}::{};{}", err.crate_name, err.name, found_use),
1083+
Applicability::MachineApplicable
10721084
).emit();
10731085
} else {
10741086
self.session.struct_span_err(err.use_span, err.warn_msg)

src/librustc_typeck/check/callee.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rustc::ty::adjustment::{Adjustment, Adjust, AllowTwoPhase, AutoBorrow, AutoB
2020
use rustc_target::spec::abi;
2121
use syntax::ast::Ident;
2222
use syntax_pos::Span;
23+
use errors::Applicability;
2324

2425
use rustc::hir;
2526

@@ -234,10 +235,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
234235
err.span_label(call_expr.span, "not a function");
235236

236237
if let Some(ref path) = unit_variant {
237-
err.span_suggestion(call_expr.span,
238-
&format!("`{}` is a unit variant, you need to write it \
239-
without the parenthesis", path),
240-
path.to_string());
238+
err.span_suggestion_with_applicability(
239+
call_expr.span,
240+
&format!("`{}` is a unit variant, you need to write it \
241+
without the parenthesis", path),
242+
path.to_string(),
243+
Applicability::MachineApplicable
244+
);
241245
}
242246

243247
if let hir::ExprKind::Call(ref expr, _) = call_expr.node {

0 commit comments

Comments
 (0)