Skip to content

Commit b6fea32

Browse files
committed
Remove usages of span_suggestion without Applicability
Use Applicability::Unspecified for all of them instead.
1 parent d3cba9b commit b6fea32

File tree

18 files changed

+107
-50
lines changed

18 files changed

+107
-50
lines changed

src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use infer::error_reporting::nice_region_error::NiceRegionError;
1414
use ty;
1515
use util::common::ErrorReported;
16+
use errors::Applicability;
1617

1718
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1819
/// When given a `ConcreteFailure` for a function with arguments containing a named region and
@@ -111,10 +112,11 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
111112
E0621,
112113
"explicit lifetime required in {}",
113114
error_var
114-
).span_suggestion(
115+
).span_suggestion_with_applicability(
115116
new_ty_span,
116117
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
117-
new_ty.to_string()
118+
new_ty.to_string(),
119+
Applicability::Unspecified,
118120
)
119121
.span_label(span, format!("lifetime `{}` required", named))
120122
.emit();

src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use infer::error_reporting::nice_region_error::NiceRegionError;
1414
use infer::lexical_region_resolve::RegionResolutionError;
1515
use ty::{BoundRegion, FreeRegion, RegionKind};
1616
use util::common::ErrorReported;
17+
use errors::Applicability;
1718

1819
impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
1920
/// Print the error message for lifetime errors when the return type is a static impl Trait.
@@ -61,14 +62,15 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
6162
_ => "'_".to_owned(),
6263
};
6364
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(return_sp) {
64-
err.span_suggestion(
65+
err.span_suggestion_with_applicability(
6566
return_sp,
6667
&format!(
6768
"you can add a constraint to the return type to make it last \
6869
less than `'static` and match {}",
6970
lifetime,
7071
),
7172
format!("{} + {}", snippet, lifetime_name),
73+
Applicability::Unspecified,
7274
);
7375
}
7476
err.emit();

src/librustc/session/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_data_structures::base_n;
2828
use rustc_data_structures::sync::{self, Lrc, Lock, LockCell, OneThread, Once, RwLock};
2929

3030
use syntax::ast::NodeId;
31-
use errors::{self, DiagnosticBuilder, DiagnosticId};
31+
use errors::{self, DiagnosticBuilder, DiagnosticId, Applicability};
3232
use errors::emitter::{Emitter, EmitterWriter};
3333
use syntax::edition::Edition;
3434
use syntax::json::JsonEmitter;
@@ -431,8 +431,9 @@ impl Session {
431431
diag_builder.span_note(span, message);
432432
}
433433
DiagnosticBuilderMethod::SpanSuggestion(suggestion) => {
434-
let span = span_maybe.expect("span_suggestion needs a span");
435-
diag_builder.span_suggestion(span, message, suggestion);
434+
let span = span_maybe.expect("span_suggestion_* needs a span");
435+
diag_builder.span_suggestion_with_applicability(span, message, suggestion,
436+
Applicability::Unspecified);
436437
}
437438
}
438439
}

src/librustc_borrowck/borrowck/mod.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ use rustc_data_structures::sync::Lrc;
4545
use std::hash::{Hash, Hasher};
4646
use syntax::ast;
4747
use syntax_pos::{MultiSpan, Span};
48-
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
48+
use errors::{Applicability, DiagnosticBuilder, DiagnosticId, Applicability};
4949

5050
use rustc::hir;
5151
use rustc::hir::intravisit::{self, Visitor};
@@ -867,10 +867,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
867867
}) = cmt.cat {
868868
db.note(fn_closure_msg);
869869
} else {
870-
db.span_suggestion(sp, msg, suggestion);
870+
db.span_suggestion_with_applicability(
871+
sp, msg, suggestion, Applicability::Unspecified);
871872
}
872873
} else {
873-
db.span_suggestion(sp, msg, suggestion);
874+
db.span_suggestion_with_applicability(
875+
sp, msg, suggestion, Applicability::Unspecified);
874876
}
875877
}
876878
_ => {
@@ -1236,10 +1238,11 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12361238
let let_span = self.tcx.hir.span(node_id);
12371239
let suggestion = suggest_ref_mut(self.tcx, let_span);
12381240
if let Some(replace_str) = suggestion {
1239-
db.span_suggestion(
1241+
db.span_suggestion_with_applicability(
12401242
let_span,
12411243
"use a mutable reference instead",
12421244
replace_str,
1245+
Applicability::Unspecified,
12431246
);
12441247
}
12451248
}
@@ -1292,11 +1295,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
12921295
)) = ty.map(|t| &t.node)
12931296
{
12941297
let borrow_expr_id = self.tcx.hir.get_parent_node(borrowed_node_id);
1295-
db.span_suggestion(
1298+
db.span_suggestion_with_applicability(
12961299
self.tcx.hir.span(borrow_expr_id),
12971300
"consider removing the `&mut`, as it is an \
12981301
immutable binding to a mutable reference",
1299-
snippet
1302+
snippet,
1303+
Applicability::Unspecified,
13001304
);
13011305
} else {
13021306
db.span_suggestion_with_applicability(
@@ -1326,12 +1330,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
13261330
&cmt_path_or_string,
13271331
capture_span,
13281332
Origin::Ast)
1329-
.span_suggestion(err.span,
1333+
.span_suggestion_with_applicability(err.span,
13301334
&format!("to force the closure to take ownership of {} \
13311335
(and any other referenced variables), \
13321336
use the `move` keyword",
13331337
cmt_path_or_string),
1334-
suggestion)
1338+
suggestion,
1339+
Applicability::Unspecified,
1340+
)
13351341
.emit();
13361342
self.signal_error();
13371343
}

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use core::unicode::property::Pattern_White_Space;
1212
use rustc::mir::*;
1313
use rustc::ty;
14-
use rustc_errors::DiagnosticBuilder;
14+
use rustc_errors::{DiagnosticBuilder,Applicability};
1515
use syntax_pos::Span;
1616

1717
use borrow_check::MirBorrowckCtxt;
@@ -350,16 +350,18 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
350350
// expressions `a[b]`, which roughly desugar to
351351
// `*Index::index(&a, b)` or
352352
// `*IndexMut::index_mut(&mut a, b)`.
353-
err.span_suggestion(
353+
err.span_suggestion_with_applicability(
354354
span,
355355
"consider removing the `*`",
356356
snippet[1..].to_owned(),
357+
Applicability::Unspecified,
357358
);
358359
} else {
359-
err.span_suggestion(
360+
err.span_suggestion_with_applicability(
360361
span,
361362
"consider borrowing here",
362363
format!("&{}", snippet),
364+
Applicability::Unspecified,
363365
);
364366
}
365367

@@ -420,10 +422,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
420422
suggestions.sort_unstable_by_key(|&(span, _, _)| span);
421423
suggestions.dedup_by_key(|&mut (span, _, _)| span);
422424
for (span, to_remove, suggestion) in suggestions {
423-
err.span_suggestion(
425+
err.span_suggestion_with_applicability(
424426
span,
425427
&format!("consider removing the `{}`", to_remove),
426-
suggestion
428+
suggestion,
429+
Applicability::Unspecified,
427430
);
428431
}
429432
}

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use borrow_check::MirBorrowckCtxt;
2222
use util::borrowck_errors::{BorrowckErrors, Origin};
2323
use util::collect_writes::FindAssignments;
2424
use util::suggest_ref_mut;
25+
use rustc_errors::Applicability;
2526

2627
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2728
pub(super) enum AccessKind {
@@ -227,10 +228,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
227228
assert_eq!(local_decl.mutability, Mutability::Not);
228229

229230
err.span_label(span, format!("cannot {ACT}", ACT = act));
230-
err.span_suggestion(
231+
err.span_suggestion_with_applicability(
231232
local_decl.source_info.span,
232233
"consider changing this to be mutable",
233234
format!("mut {}", local_decl.name.unwrap()),
235+
Applicability::Unspecified,
234236
);
235237
}
236238

@@ -257,10 +259,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
257259
_,
258260
) = pat.node
259261
{
260-
err.span_suggestion(
262+
err.span_suggestion_with_applicability(
261263
upvar_ident.span,
262264
"consider changing this to be mutable",
263265
format!("mut {}", upvar_ident.name),
266+
Applicability::Unspecified,
264267
);
265268
}
266269
}
@@ -351,10 +354,11 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
351354
};
352355

353356
if let Some((err_help_span, suggested_code)) = suggestion {
354-
err.span_suggestion(
357+
err.span_suggestion_with_applicability(
355358
err_help_span,
356359
&format!("consider changing this to be a mutable {}", pointer_desc),
357360
suggested_code,
361+
Applicability::Unspecified,
358362
);
359363
}
360364

src/librustc_passes/ast_validation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,9 @@ impl<'a> AstValidator<'a> {
182182
);
183183

184184
if let Ok(snippet) = self.session.source_map().span_to_snippet(span) {
185-
err.span_suggestion(
185+
err.span_suggestion_with_applicability(
186186
span, "consider adding parentheses", format!("({})", snippet),
187+
Applicability::Unspecified,
187188
);
188189
}
189190

src/librustc_passes/loops.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::hir::intravisit::{self, Visitor, NestedVisitorMap};
1616
use rustc::hir::{self, Node, Destination};
1717
use syntax::ast;
1818
use syntax_pos::Span;
19+
use errors::Applicability;
1920

2021
#[derive(Clone, Copy, Debug, PartialEq)]
2122
enum LoopKind {
@@ -140,11 +141,13 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
140141
.span_label(e.span,
141142
"can only break with a value inside \
142143
`loop` or breakable block")
143-
.span_suggestion(e.span,
144+
.span_suggestion_with_applicability(e.span,
144145
&format!("instead, use `break` on its own \
145146
without a value inside this `{}` loop",
146147
kind.name()),
147-
"break".to_string())
148+
"break".to_string(),
149+
Applicability::Unspecified,
150+
)
148151
.emit();
149152
}
150153
}

src/librustc_resolve/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,9 +3299,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
32993299
err.span_label(base_span,
33003300
"expecting a type here because of type ascription");
33013301
if line_sp != line_base_sp {
3302-
err.span_suggestion_short(sp,
3302+
err.span_suggestion_short_with_applicability(sp,
33033303
"did you mean to use `;` here instead?",
3304-
";".to_string());
3304+
";".to_string(),
3305+
Applicability::Unspecified,
3306+
);
33053307
}
33063308
break;
33073309
} else if snippet.trim().len() != 0 {
@@ -4826,7 +4828,8 @@ fn show_candidates(err: &mut DiagnosticBuilder,
48264828
*candidate = format!("use {};\n{}", candidate, additional_newline);
48274829
}
48284830

4829-
err.span_suggestions(span, &msg, path_strings);
4831+
err.span_suggestions_with_applicability(span, &msg, path_strings,
4832+
Applicability::Unspecified);
48304833
} else {
48314834
let mut msg = msg;
48324835
msg.push(':');

src/librustc_typeck/check/cast.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
4141
use super::FnCtxt;
4242

43-
use errors::DiagnosticBuilder;
43+
use errors::{DiagnosticBuilder,Applicability};
4444
use hir::def_id::DefId;
4545
use lint;
4646
use rustc::hir;
@@ -299,9 +299,11 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
299299
err.note("The type information given here is insufficient to check whether \
300300
the pointer cast is valid");
301301
if unknown_cast_to {
302-
err.span_suggestion_short(self.cast_span,
302+
err.span_suggestion_short_with_applicability(self.cast_span,
303303
"consider giving more type information",
304-
String::new());
304+
String::new(),
305+
Applicability::Unspecified,
306+
);
305307
}
306308
err.emit();
307309
}
@@ -327,9 +329,11 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
327329
if self.cast_ty.is_trait() {
328330
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
329331
Ok(s) => {
330-
err.span_suggestion(self.cast_span,
332+
err.span_suggestion_with_applicability(self.cast_span,
331333
"try casting to a reference instead",
332-
format!("&{}{}", mtstr, s));
334+
format!("&{}{}", mtstr, s),
335+
Applicability::Unspecified,
336+
);
333337
}
334338
Err(_) => {
335339
span_help!(err, self.cast_span, "did you mean `&{}{}`?", mtstr, tstr)
@@ -346,9 +350,11 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
346350
ty::Adt(def, ..) if def.is_box() => {
347351
match fcx.tcx.sess.source_map().span_to_snippet(self.cast_span) {
348352
Ok(s) => {
349-
err.span_suggestion(self.cast_span,
353+
err.span_suggestion_with_applicability(self.cast_span,
350354
"try casting to a `Box` instead",
351-
format!("Box<{}>", s));
355+
format!("Box<{}>", s),
356+
Applicability::Unspecified,
357+
);
352358
}
353359
Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr),
354360
}

src/librustc_typeck/check/compare_method.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal};
1616
use rustc::ty::error::{ExpectedFound, TypeError};
1717
use rustc::ty::subst::{Subst, Substs};
1818
use rustc::util::common::ErrorReported;
19+
use errors::Applicability;
1920

2021
use syntax_pos::Span;
2122

@@ -321,10 +322,11 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
321322
if let Some(trait_err_span) = trait_err_span {
322323
if let Ok(trait_err_str) = tcx.sess.source_map().
323324
span_to_snippet(trait_err_span) {
324-
diag.span_suggestion(
325+
diag.span_suggestion_with_applicability(
325326
impl_err_span,
326327
"consider change the type to match the mutability in trait",
327328
format!("{}", trait_err_str),
329+
Applicability::Unspecified,
328330
);
329331
}
330332
}

src/librustc_typeck/check/method/probe.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
10641064
"a method with this name may be added to the standard library in the future",
10651065
);
10661066

1067-
// FIXME: This should be a `span_suggestion` instead of `help`. However `self.span` only
1067+
// FIXME: This should be a `span_suggestion_with_applicability` instead of `help`
1068+
// However `self.span` only
10681069
// highlights the method name, so we can't use it. Also consider reusing the code from
10691070
// `report_method_error()`.
10701071
diag.help(&format!(

0 commit comments

Comments
 (0)