Skip to content

Commit 64581cf

Browse files
committed
Change span_help calls to fileline_help where appropriate
1 parent 880fb89 commit 64581cf

File tree

23 files changed

+76
-50
lines changed

23 files changed

+76
-50
lines changed

Diff for: src/librustc/lint/builtin.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1895,7 +1895,8 @@ impl LintPass for UnconditionalRecursion {
18951895
for call in &self_call_spans {
18961896
sess.span_note(*call, "recursive call site")
18971897
}
1898-
sess.span_help(sp, "a `loop` may express intention better if this is on purpose")
1898+
sess.fileline_help(sp, "a `loop` may express intention \
1899+
better if this is on purpose")
18991900
}
19001901
}
19011902

Diff for: src/librustc/metadata/loader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ impl<'a> Context<'a> {
353353
}
354354
}
355355
if self.rejected_via_kind.len() > 0 {
356-
self.sess.span_help(self.span, "please recompile this crate using \
356+
self.sess.fileline_help(self.span, "please recompile this crate using \
357357
--crate-type lib");
358358
let mismatches = self.rejected_via_kind.iter();
359359
for (i, &CrateMismatch { ref path, .. }) in mismatches.enumerate() {

Diff for: src/librustc/metadata/macro_import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<'a, 'v> Visitor<'v> for MacroLoader<'a> {
8484
}
8585
"plugin" => {
8686
self.sess.span_err(attr.span, "#[plugin] on `extern crate` is deprecated");
87-
self.sess.span_help(attr.span, &format!("use a crate attribute instead, \
87+
self.sess.fileline_help(attr.span, &format!("use a crate attribute instead, \
8888
i.e. #![plugin({})]",
8989
item.ident.as_str()));
9090
}

Diff for: src/librustc/middle/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ fn check_for_bindings_named_the_same_as_variants(cx: &MatchCheckCtxt, pat: &Pat)
252252
"pattern binding `{}` is named the same as one \
253253
of the variants of the type `{}`",
254254
&token::get_ident(ident.node), ty_to_string(cx.tcx, pat_ty));
255-
span_help!(cx.tcx.sess, p.span,
255+
fileline_help!(cx.tcx.sess, p.span,
256256
"if you meant to match on a variant, \
257257
consider making the path in the pattern qualified: `{}::{}`",
258258
ty_to_string(cx.tcx, pat_ty), &token::get_ident(ident.node));

Diff for: src/librustc/middle/infer/error_reporting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
444444
// Does the required lifetime have a nice name we can print?
445445
span_err!(self.tcx.sess, origin.span(), E0309,
446446
"{} may not live long enough", labeled_user_string);
447-
self.tcx.sess.span_help(
447+
self.tcx.sess.fileline_help(
448448
origin.span(),
449449
&format!(
450450
"consider adding an explicit lifetime bound `{}: {}`...",
@@ -456,7 +456,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
456456
// Does the required lifetime have a nice name we can print?
457457
span_err!(self.tcx.sess, origin.span(), E0310,
458458
"{} may not live long enough", labeled_user_string);
459-
self.tcx.sess.span_help(
459+
self.tcx.sess.fileline_help(
460460
origin.span(),
461461
&format!(
462462
"consider adding an explicit lifetime bound `{}: 'static`...",
@@ -468,7 +468,7 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> {
468468
span_err!(self.tcx.sess, origin.span(), E0311,
469469
"{} may not live long enough",
470470
labeled_user_string);
471-
self.tcx.sess.span_help(
471+
self.tcx.sess.fileline_help(
472472
origin.span(),
473473
&format!(
474474
"consider adding an explicit lifetime bound for `{}`",

Diff for: src/librustc_borrowck/borrowck/gather_loans/move_error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn note_move_destination(bccx: &BorrowckCtxt,
165165
bccx.span_note(
166166
move_to_span,
167167
"attempting to move value to here");
168-
bccx.span_help(
168+
bccx.fileline_help(
169169
move_to_span,
170170
&format!("to prevent the move, \
171171
use `ref {0}` or `ref mut {0}` to capture value by \

Diff for: src/librustc_borrowck/borrowck/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
643643
ol,
644644
moved_lp_msg,
645645
pat_ty.user_string(self.tcx)));
646-
self.tcx.sess.span_help(span,
646+
self.tcx.sess.fileline_help(span,
647647
"use `ref` to override");
648648
}
649649

@@ -675,7 +675,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
675675
moved_lp_msg,
676676
expr_ty.user_string(self.tcx),
677677
suggestion));
678-
self.tcx.sess.span_help(expr_span, help);
678+
self.tcx.sess.fileline_help(expr_span, help);
679679
}
680680
}
681681

@@ -741,6 +741,10 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
741741
self.tcx.sess.span_help(s, m);
742742
}
743743

744+
pub fn fileline_help(&self, s: Span, m: &str) {
745+
self.tcx.sess.fileline_help(s, m);
746+
}
747+
744748
pub fn bckerr_to_string(&self, err: &BckError<'tcx>) -> String {
745749
match err.code {
746750
err_mutbl => {
@@ -870,7 +874,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
870874
}
871875

872876
if is_closure {
873-
self.tcx.sess.span_help(
877+
self.tcx.sess.fileline_help(
874878
span,
875879
"closures behind references must be called via `&mut`");
876880
}

Diff for: src/librustc_resolve/lib.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -4115,10 +4115,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
41154115
uses it like a function name",
41164116
path_name));
41174117

4118-
self.session.span_help(expr.span,
4119-
&format!("Did you mean to write: \
4120-
`{} {{ /* fields */ }}`?",
4121-
path_name));
4118+
let msg = format!("Did you mean to write: \
4119+
`{} {{ /* fields */ }}`?",
4120+
path_name);
4121+
if self.emit_errors {
4122+
self.session.fileline_help(expr.span, &msg);
4123+
} else {
4124+
self.session.span_help(expr.span, &msg);
4125+
}
41224126
} else {
41234127
// Write the result into the def map.
41244128
debug!("(resolving expr) resolved `{}`",
@@ -4146,18 +4150,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
41464150
match type_res.map(|r| r.base_def) {
41474151
Some(DefTy(struct_id, _))
41484152
if self.structs.contains_key(&struct_id) => {
4149-
self.resolve_error(expr.span,
4153+
self.resolve_error(expr.span,
41504154
&format!("`{}` is a structure name, but \
41514155
this expression \
41524156
uses it like a function name",
41534157
path_name));
41544158

4155-
self.session.span_help(expr.span,
4156-
&format!("Did you mean to write: \
4157-
`{} {{ /* fields */ }}`?",
4158-
path_name));
4159-
4160-
}
4159+
let msg = format!("Did you mean to write: \
4160+
`{} {{ /* fields */ }}`?",
4161+
path_name);
4162+
if self.emit_errors {
4163+
self.session.fileline_help(expr.span, &msg);
4164+
} else {
4165+
self.session.span_help(expr.span, &msg);
4166+
}
4167+
}
41614168
_ => {
41624169
// Keep reporting some errors even if they're ignored above.
41634170
self.resolve_path(expr.id, path, 0, ValueNS, true);

Diff for: src/librustc_trans/trans/foreign.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ fn gate_simd_ffi(tcx: &ty::ctxt, decl: &ast::FnDecl, ty: &ty::BareFnTy) {
440440
&format!("use of SIMD type `{}` in FFI is highly experimental and \
441441
may result in invalid code",
442442
pprust::ty_to_string(ast_ty)));
443-
tcx.sess.span_help(ast_ty.span,
443+
tcx.sess.fileline_help(ast_ty.span,
444444
"add #![feature(simd_ffi)] to the crate attributes to enable");
445445
}
446446
};

Diff for: src/librustc_typeck/astconv.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -212,18 +212,18 @@ pub fn opt_ast_region_to_region<'tcx>(
212212
}
213213
}
214214
if len == 1 {
215-
span_help!(this.tcx().sess, default_span,
215+
fileline_help!(this.tcx().sess, default_span,
216216
"this function's return type contains a borrowed value, but \
217217
the signature does not say which {} it is borrowed from",
218218
m);
219219
} else if len == 0 {
220-
span_help!(this.tcx().sess, default_span,
220+
fileline_help!(this.tcx().sess, default_span,
221221
"this function's return type contains a borrowed value, but \
222222
there is no value for it to be borrowed from");
223-
span_help!(this.tcx().sess, default_span,
223+
fileline_help!(this.tcx().sess, default_span,
224224
"consider giving it a 'static lifetime");
225225
} else {
226-
span_help!(this.tcx().sess, default_span,
226+
fileline_help!(this.tcx().sess, default_span,
227227
"this function's return type contains a borrowed value, but \
228228
the signature does not say whether it is borrowed from {}",
229229
m);
@@ -705,7 +705,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
705705
span_err!(this.tcx().sess, span, E0215,
706706
"angle-bracket notation is not stable when \
707707
used with the `Fn` family of traits, use parentheses");
708-
span_help!(this.tcx().sess, span,
708+
fileline_help!(this.tcx().sess, span,
709709
"add `#![feature(unboxed_closures)]` to \
710710
the crate attributes to enable");
711711
}
@@ -719,7 +719,7 @@ fn ast_path_to_trait_ref<'a,'tcx>(
719719
span_err!(this.tcx().sess, span, E0216,
720720
"parenthetical notation is only stable when \
721721
used with the `Fn` family of traits");
722-
span_help!(this.tcx().sess, span,
722+
fileline_help!(this.tcx().sess, span,
723723
"add `#![feature(unboxed_closures)]` to \
724724
the crate attributes to enable");
725725
}
@@ -944,14 +944,14 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
944944
pprust::ty_to_string(ty));
945945
match ty.node {
946946
ast::TyRptr(None, ref mut_ty) => {
947-
span_help!(this.tcx().sess, ty.span,
947+
fileline_help!(this.tcx().sess, ty.span,
948948
"perhaps you meant `&{}({} +{})`? (per RFC 438)",
949949
ppaux::mutability_to_string(mut_ty.mutbl),
950950
pprust::ty_to_string(&*mut_ty.ty),
951951
pprust::bounds_to_string(bounds));
952952
}
953953
ast::TyRptr(Some(ref lt), ref mut_ty) => {
954-
span_help!(this.tcx().sess, ty.span,
954+
fileline_help!(this.tcx().sess, ty.span,
955955
"perhaps you meant `&{} {}({} +{})`? (per RFC 438)",
956956
pprust::lifetime_to_string(lt),
957957
ppaux::mutability_to_string(mut_ty.mutbl),
@@ -960,7 +960,7 @@ fn ast_ty_to_trait_ref<'tcx>(this: &AstConv<'tcx>,
960960
}
961961

962962
_ => {
963-
span_help!(this.tcx().sess, ty.span,
963+
fileline_help!(this.tcx().sess, ty.span,
964964
"perhaps you forgot parentheses? (per RFC 438)");
965965
}
966966
}

Diff for: src/librustc_typeck/check/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id:
6363
span_err!(tcx.sess, span, E0174,
6464
"explicit use of unboxed closure method `{}` is experimental",
6565
method);
66-
span_help!(tcx.sess, span,
66+
fileline_help!(tcx.sess, span,
6767
"add `#![feature(unboxed_closures)]` to the crate attributes to enable");
6868
}
6969
}

Diff for: src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3098,7 +3098,7 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
30983098
},
30993099
expr_t, None);
31003100

3101-
tcx.sess.span_help(field.span,
3101+
tcx.sess.fileline_help(field.span,
31023102
"maybe a `()` to call it is missing? \
31033103
If not, try an anonymous function");
31043104
} else {
@@ -4480,7 +4480,7 @@ pub fn check_instantiable(tcx: &ty::ctxt,
44804480
span_err!(tcx.sess, sp, E0073,
44814481
"this type cannot be instantiated without an \
44824482
instance of itself");
4483-
span_help!(tcx.sess, sp, "consider using `Option<{}>`",
4483+
fileline_help!(tcx.sess, sp, "consider using `Option<{}>`",
44844484
ppaux::ty_to_string(tcx, item_ty));
44854485
false
44864486
} else {

Diff for: src/librustc_typeck/check/wf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
400400

401401
match suggested_marker_id {
402402
Some(def_id) => {
403-
self.tcx().sess.span_help(
403+
self.tcx().sess.fileline_help(
404404
span,
405405
format!("consider removing `{}` or using a marker such as `{}`",
406406
param_name.user_string(self.tcx()),

Diff for: src/librustc_typeck/coherence/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id:
524524
return // everything OK
525525
};
526526
span_err!(tcx.sess, sp, E0183, "manual implementations of `{}` are experimental", trait_name);
527-
span_help!(tcx.sess, sp,
527+
fileline_help!(tcx.sess, sp,
528528
"add `#![feature(unboxed_closures)]` to the crate attributes to enable");
529529
}
530530

Diff for: src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ fn trait_def_of_item<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
12171217
it.span,
12181218
"the `#[rustc_paren_sugar]` attribute is a temporary means of controlling \
12191219
which traits can use parenthetical notation");
1220-
span_help!(ccx.tcx.sess, it.span,
1220+
fileline_help!(ccx.tcx.sess, it.span,
12211221
"add `#![feature(unboxed_closures)]` to \
12221222
the crate attributes to use it");
12231223
}

Diff for: src/libsyntax/diagnostics/macros.rs

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ macro_rules! span_help {
5252
})
5353
}
5454

55+
#[macro_export]
56+
macro_rules! fileline_help {
57+
($session:expr, $span:expr, $($message:tt)*) => ({
58+
($session).fileline_help($span, &format!($($message)*))
59+
})
60+
}
61+
5562
#[macro_export]
5663
macro_rules! register_diagnostics {
5764
($($code:tt),*) => (

Diff for: src/libsyntax/ext/base.rs

+4
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,10 @@ impl<'a> ExtCtxt<'a> {
725725
self.print_backtrace();
726726
self.parse_sess.span_diagnostic.span_help(sp, msg);
727727
}
728+
pub fn fileline_help(&self, sp: Span, msg: &str) {
729+
self.print_backtrace();
730+
self.parse_sess.span_diagnostic.fileline_help(sp, msg);
731+
}
728732
pub fn bug(&self, msg: &str) -> ! {
729733
self.print_backtrace();
730734
self.parse_sess.span_diagnostic.handler().bug(msg);

Diff for: src/libsyntax/ext/expand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool
571571
fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use");
572572
is_use = true;
573573
if let ast::AttrInner = attr.node.style {
574-
fld.cx.span_help(attr.span, "consider an outer attribute, \
574+
fld.cx.fileline_help(attr.span, "consider an outer attribute, \
575575
#[macro_use] mod ...");
576576
}
577577
};

Diff for: src/libsyntax/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -354,15 +354,15 @@ impl<'a> Context<'a> {
354354

355355
pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
356356
diag.span_err(span, explain);
357-
diag.span_help(span, &format!("add #![feature({})] to the \
357+
diag.fileline_help(span, &format!("add #![feature({})] to the \
358358
crate attributes to enable",
359359
feature));
360360
}
361361

362362
pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
363363
diag.span_warn(span, explain);
364364
if diag.handler.can_emit_warnings {
365-
diag.span_help(span, &format!("add #![feature({})] to the \
365+
diag.fileline_help(span, &format!("add #![feature({})] to the \
366366
crate attributes to silence this warning",
367367
feature));
368368
}

Diff for: src/libsyntax/parse/attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a> ParserAttr for Parser<'a> {
7777
self.span_err(span,
7878
"an inner attribute is not permitted in \
7979
this context");
80-
self.span_help(span,
80+
self.fileline_help(span,
8181
"place inner attribute at the top of the module or block");
8282
}
8383
ast::AttrInner

Diff for: src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ impl<'a> StringReader<'a> {
772772
self.span_diagnostic
773773
.span_warn(sp, "\\U00ABCD12 and \\uABCD escapes are deprecated");
774774
self.span_diagnostic
775-
.span_help(sp, "use \\u{ABCD12} escapes instead");
775+
.fileline_help(sp, "use \\u{ABCD12} escapes instead");
776776
}
777777

778778
/// Scan for a single (possibly escaped) byte or char

Diff for: src/libsyntax/parse/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,7 @@ pub fn integer_lit(s: &str, suffix: Option<&str>, sd: &SpanHandler, sp: Span) ->
722722
&suf[1..]));
723723
} else {
724724
sd.span_err(sp, &*format!("illegal suffix `{}` for numeric literal", suf));
725-
sd.span_help(sp, "the suffix must be one of the integral types \
725+
sd.fileline_help(sp, "the suffix must be one of the integral types \
726726
(`u32`, `isize`, etc)");
727727
}
728728

0 commit comments

Comments
 (0)