Skip to content

Commit 5a23a0d

Browse files
committed
Set applicability for more suggestions.
1 parent d2048b6 commit 5a23a0d

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;
@@ -1000,9 +1001,19 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
10001001
if let Some(suggestion) = suggestion {
10011002
if suggestion != name {
10021003
if let MacroKind::Bang = kind {
1003-
err.span_suggestion(span, "you could try the macro", suggestion.to_string());
1004+
err.span_suggestion_with_applicability(
1005+
span,
1006+
"you could try the macro",
1007+
suggestion.to_string(),
1008+
Applicability::MaybeIncorrect
1009+
);
10041010
} else {
1005-
err.span_suggestion(span, "try", suggestion.to_string());
1011+
err.span_suggestion_with_applicability(
1012+
span,
1013+
"try",
1014+
suggestion.to_string(),
1015+
Applicability::MaybeIncorrect
1016+
);
10061017
}
10071018
} else {
10081019
err.help("have you added the `#[macro_use]` on the module/import?");
@@ -1123,10 +1134,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
11231134
if let Some(span) = span {
11241135
let found_use = if found_use { "" } else { "\n" };
11251136
self.session.struct_span_err(err.use_span, err.warn_msg)
1126-
.span_suggestion(
1137+
.span_suggestion_with_applicability(
11271138
span,
11281139
"instead, import the procedural macro like any other item",
11291140
format!("use {}::{};{}", err.crate_name, err.name, found_use),
1141+
Applicability::MachineApplicable
11301142
).emit();
11311143
} else {
11321144
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)