Skip to content

Commit ec28b4a

Browse files
committed
auto merge of #18132 : P1start/rust/more-help, r=jakub-
Closes #18126. At the moment this mostly only changes notes that are particularly help-oriented or directly suggest the user to do something to help messages, and does not change messages that simply explain an error message further. If it is decided that those messages should also be help messages, I can add them to this PR, but for now I’m excluding them as I believe that changing those messages might leave very few places where notes would be appropriate.
2 parents 0a5e7f3 + 5bf9ef2 commit ec28b4a

26 files changed

+123
-80
lines changed

src/doc/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ fn add_one(x: int) -> int {
777777
x + 1;
778778
}
779779
780-
note: consider removing this semicolon:
780+
help: consider removing this semicolon:
781781
x + 1;
782782
^
783783
```

src/librustc/middle/borrowck/check_loans.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
789789
assignment_span,
790790
format!("cannot assign to {}",
791791
self.bccx.cmt_to_string(&*assignee_cmt)).as_slice());
792-
self.bccx.span_note(
792+
self.bccx.span_help(
793793
self.tcx().map.span(upvar_id.closure_expr_id),
794794
"consider changing this closure to take self by mutable reference");
795795
} else {

src/librustc/middle/borrowck/gather_loans/move_error.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,12 @@ fn note_move_destination(bccx: &BorrowckCtxt,
148148
if is_first_note {
149149
bccx.span_note(
150150
move_to_span,
151-
format!("attempting to move value to here (to prevent the move, \
151+
"attempting to move value to here");
152+
bccx.span_help(
153+
move_to_span,
154+
format!("to prevent the move, \
152155
use `ref {0}` or `ref mut {0}` to capture value by \
153-
reference)",
156+
reference",
154157
pat_name).as_slice());
155158
} else {
156159
bccx.span_note(move_to_span,

src/librustc/middle/borrowck/mod.rs

+30-21
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,8 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
527527
r).as_slice())
528528
}
529529
};
530-
let suggestion = move_suggestion(self.tcx, expr_ty,
531-
"moved by default (use `copy` to override)");
530+
let (suggestion, _) = move_suggestion(self.tcx, expr_ty,
531+
("moved by default", ""));
532532
self.tcx.sess.span_note(
533533
expr_span,
534534
format!("`{}` moved here{} because it has type `{}`, which is {}",
@@ -540,13 +540,15 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
540540

541541
move_data::MovePat => {
542542
let pat_ty = ty::node_id_to_type(self.tcx, the_move.id);
543-
self.tcx.sess.span_note(self.tcx.map.span(the_move.id),
543+
let span = self.tcx.map.span(the_move.id);
544+
self.tcx.sess.span_note(span,
544545
format!("`{}` moved here{} because it has type `{}`, \
545-
which is moved by default (use `ref` to \
546-
override)",
546+
which is moved by default",
547547
ol,
548548
moved_lp_msg,
549549
pat_ty.user_string(self.tcx)).as_slice());
550+
self.tcx.sess.span_help(span,
551+
"use `ref` to override");
550552
}
551553

552554
move_data::Captured => {
@@ -563,9 +565,9 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
563565
r).as_slice())
564566
}
565567
};
566-
let suggestion = move_suggestion(self.tcx, expr_ty,
567-
"moved by default (make a copy and \
568-
capture that instead to override)");
568+
let (suggestion, help) = move_suggestion(self.tcx, expr_ty,
569+
("moved by default", "make a copy and \
570+
capture that instead to override"));
569571
self.tcx.sess.span_note(
570572
expr_span,
571573
format!("`{}` moved into closure environment here{} because it \
@@ -574,21 +576,23 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
574576
moved_lp_msg,
575577
expr_ty.user_string(self.tcx),
576578
suggestion).as_slice());
579+
self.tcx.sess.span_help(expr_span, help);
577580
}
578581
}
579582

580-
fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msg: &'static str)
581-
-> &'static str {
583+
fn move_suggestion(tcx: &ty::ctxt, ty: ty::t, default_msgs: (&'static str, &'static str))
584+
-> (&'static str, &'static str) {
582585
match ty::get(ty).sty {
583586
ty::ty_closure(box ty::ClosureTy {
584587
store: ty::RegionTraitStore(..),
585588
..
586589
}) =>
587-
"a non-copyable stack closure (capture it in a new closure, \
588-
e.g. `|x| f(x)`, to override)",
590+
("a non-copyable stack closure",
591+
"capture it in a new closure, e.g. `|x| f(x)`, to override"),
589592
_ if ty::type_moves_by_default(tcx, ty) =>
590-
"non-copyable (perhaps you meant to use clone()?)",
591-
_ => default_msg,
593+
("non-copyable",
594+
"perhaps you meant to use `clone()`?"),
595+
_ => default_msgs,
592596
}
593597
}
594598
}
@@ -733,7 +737,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
733737
self.tcx.sess.span_err(span,
734738
format!("{} in a captured outer \
735739
variable in an `Fn` closure", prefix).as_slice());
736-
span_note!(self.tcx.sess, self.tcx.map.span(id),
740+
span_help!(self.tcx.sess, self.tcx.map.span(id),
737741
"consider changing this closure to take self by mutable reference");
738742
}
739743
mc::AliasableStatic(..) |
@@ -750,7 +754,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
750754
}
751755

752756
if is_closure {
753-
self.tcx.sess.span_note(
757+
self.tcx.sess.span_help(
754758
span,
755759
"closures behind references must be called via `&mut`");
756760
}
@@ -770,7 +774,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
770774
_ => unreachable!()
771775
};
772776
if kind == ty::FnUnboxedClosureKind {
773-
self.tcx.sess.span_note(
777+
self.tcx.sess.span_help(
774778
self.tcx.map.span(upvar_id.closure_expr_id),
775779
"consider changing this closure to take \
776780
self by mutable reference");
@@ -787,15 +791,20 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
787791
sub_scope,
788792
"...");
789793
let suggestion = if is_statement_scope(self.tcx, super_scope) {
790-
"; consider using a `let` binding to increase its lifetime"
794+
Some("consider using a `let` binding to increase its lifetime")
791795
} else {
792-
""
796+
None
793797
};
794-
note_and_explain_region(
798+
let span = note_and_explain_region(
795799
self.tcx,
796800
"...but borrowed value is only valid for ",
797801
super_scope,
798-
suggestion);
802+
"");
803+
match (span, suggestion) {
804+
(_, None) => {},
805+
(Some(span), Some(msg)) => self.tcx.sess.span_help(span, msg),
806+
(None, Some(msg)) => self.tcx.sess.help(msg),
807+
}
799808
}
800809

801810
err_borrowed_pointer_too_short(loan_scope, ptr_scope) => {

src/librustc/middle/dependency_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn add_library(sess: &session::Session,
213213
sess.err(format!("cannot satisfy dependencies so `{}` only \
214214
shows up once",
215215
data.name).as_slice());
216-
sess.note("having upstream crates all available in one format \
216+
sess.help("having upstream crates all available in one format \
217217
will likely make this go away");
218218
}
219219
}

src/librustc/middle/liveness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
15681568
hi: original_span.hi,
15691569
expn_id: original_span.expn_id
15701570
};
1571-
self.ir.tcx.sess.span_note(
1571+
self.ir.tcx.sess.span_help(
15721572
span_semicolon, "consider removing this semicolon:");
15731573
}
15741574
}

src/librustc/middle/resolve.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5868,7 +5868,7 @@ impl<'a> Resolver<'a> {
58685868
uses it like a function name",
58695869
wrong_name).as_slice());
58705870

5871-
self.session.span_note(expr.span,
5871+
self.session.span_help(expr.span,
58725872
format!("Did you mean to write: \
58735873
`{} {{ /* fields */ }}`?",
58745874
wrong_name).as_slice());

src/librustc/middle/typeck/astconv.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,18 @@ pub fn opt_ast_region_to_region<'tcx, AC: AstConv<'tcx>, RS: RegionScope>(
172172
}
173173
}
174174
if len == 1 {
175-
span_note!(this.tcx().sess, default_span,
175+
span_help!(this.tcx().sess, default_span,
176176
"this function's return type contains a borrowed value, but \
177177
the signature does not say which {} it is borrowed from",
178178
m);
179179
} else if len == 0 {
180-
span_note!(this.tcx().sess, default_span,
180+
span_help!(this.tcx().sess, default_span,
181181
"this function's return type contains a borrowed value, but \
182182
there is no value for it to be borrowed from");
183-
span_note!(this.tcx().sess, default_span,
183+
span_help!(this.tcx().sess, default_span,
184184
"consider giving it a 'static lifetime");
185185
} else {
186-
span_note!(this.tcx().sess, default_span,
186+
span_help!(this.tcx().sess, default_span,
187187
"this function's return type contains a borrowed value, but \
188188
the signature does not say whether it is borrowed from {}",
189189
m);
@@ -302,7 +302,7 @@ fn ast_path_substs<'tcx,AC,RS>(
302302
&& !this.tcx().sess.features.borrow().default_type_params {
303303
span_err!(this.tcx().sess, path.span, E0108,
304304
"default type parameters are experimental and possibly buggy");
305-
span_note!(this.tcx().sess, path.span,
305+
span_help!(this.tcx().sess, path.span,
306306
"add #![feature(default_type_params)] to the crate attributes to enable");
307307
}
308308

@@ -1168,6 +1168,7 @@ fn ty_of_method_or_bare_fn<'tcx, AC: AstConv<'tcx>>(
11681168

11691169
let param_lifetimes: Vec<(String, uint)> = lifetimes_for_params.into_iter()
11701170
.map(|(n, v)| (n, v.len()))
1171+
.filter(|&(_, l)| l != 0)
11711172
.collect();
11721173

11731174
let output_ty = match decl.output.node {

src/librustc/middle/typeck/check/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1355,18 +1355,18 @@ fn check_cast(fcx: &FnCtxt,
13551355
ast::MutImmutable => ""
13561356
};
13571357
if ty::type_is_trait(t_1) {
1358-
span_note!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr);
1358+
span_help!(fcx.tcx().sess, t.span, "did you mean `&{}{}`?", mtstr, tstr);
13591359
} else {
1360-
span_note!(fcx.tcx().sess, span,
1360+
span_help!(fcx.tcx().sess, span,
13611361
"consider using an implicit coercion to `&{}{}` instead",
13621362
mtstr, tstr);
13631363
}
13641364
}
13651365
ty::ty_uniq(..) => {
1366-
span_note!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr);
1366+
span_help!(fcx.tcx().sess, t.span, "did you mean `Box<{}>`?", tstr);
13671367
}
13681368
_ => {
1369-
span_note!(fcx.tcx().sess, e.span,
1369+
span_help!(fcx.tcx().sess, e.span,
13701370
"consider using a box or reference as appropriate");
13711371
}
13721372
}
@@ -2142,7 +2142,7 @@ fn try_overloaded_call<'a>(fcx: &FnCtxt,
21422142
if !fcx.tcx().sess.features.borrow().overloaded_calls {
21432143
span_err!(fcx.tcx().sess, call_expression.span, E0056,
21442144
"overloaded calls are experimental");
2145-
span_note!(fcx.tcx().sess, call_expression.span,
2145+
span_help!(fcx.tcx().sess, call_expression.span,
21462146
"add `#![feature(overloaded_calls)]` to \
21472147
the crate attributes to enable");
21482148
}
@@ -3479,8 +3479,9 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
34793479
},
34803480
expr_t, None);
34813481

3482-
tcx.sess.span_note(field.span,
3483-
"maybe a missing `()` to call it? If not, try an anonymous function.");
3482+
tcx.sess.span_help(field.span,
3483+
"maybe a `()` to call it is missing? \
3484+
If not, try an anonymous function");
34843485
}
34853486

34863487
Err(_) => {
@@ -4787,7 +4788,8 @@ pub fn check_instantiable(tcx: &ty::ctxt,
47874788
if !ty::is_instantiable(tcx, item_ty) {
47884789
span_err!(tcx.sess, sp, E0073,
47894790
"this type cannot be instantiated without an \
4790-
instance of itself; consider using `Option<{}>`",
4791+
instance of itself");
4792+
span_help!(tcx.sess, sp, "consider using `Option<{}>`",
47914793
ppaux::ty_to_string(tcx, item_ty));
47924794
false
47934795
} else {

src/librustc/middle/typeck/check/vtable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ fn note_obligation_cause(fcx: &FnCtxt,
525525
span_note!(tcx.sess, obligation.cause.span,
526526
"cannot implement a destructor on a \
527527
structure or enumeration that does not satisfy Send");
528-
span_note!(tcx.sess, obligation.cause.span,
528+
span_help!(tcx.sess, obligation.cause.span,
529529
"use \"#[unsafe_destructor]\" on the implementation \
530530
to force the compiler to allow this");
531531
}

src/librustc/middle/typeck/infer/error_reporting.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
438438
self.tcx.sess.span_err(
439439
origin.span(),
440440
format!(
441-
"the parameter type `{}` may not live long enough; \
442-
consider adding an explicit lifetime bound `{}:{}`...",
443-
param_ty.user_string(self.tcx),
441+
"the parameter type `{}` may not live long enough",
442+
param_ty.user_string(self.tcx)).as_slice());
443+
self.tcx.sess.span_help(
444+
origin.span(),
445+
format!(
446+
"consider adding an explicit lifetime bound `{}: {}`...",
444447
param_ty.user_string(self.tcx),
445448
sub.user_string(self.tcx)).as_slice());
446449
}
@@ -450,9 +453,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
450453
self.tcx.sess.span_err(
451454
origin.span(),
452455
format!(
453-
"the parameter type `{}` may not live long enough; \
454-
consider adding an explicit lifetime bound `{}:'static`...",
455-
param_ty.user_string(self.tcx),
456+
"the parameter type `{}` may not live long enough",
457+
param_ty.user_string(self.tcx)).as_slice());
458+
self.tcx.sess.span_help(
459+
origin.span(),
460+
format!(
461+
"consider adding an explicit lifetime bound `{}: 'static`...",
456462
param_ty.user_string(self.tcx)).as_slice());
457463
}
458464

@@ -461,9 +467,12 @@ impl<'a, 'tcx> ErrorReporting for InferCtxt<'a, 'tcx> {
461467
self.tcx.sess.span_err(
462468
origin.span(),
463469
format!(
464-
"the parameter type `{}` may not live long enough; \
465-
consider adding an explicit lifetime bound to `{}`",
466-
param_ty.user_string(self.tcx),
470+
"the parameter type `{}` may not live long enough",
471+
param_ty.user_string(self.tcx)).as_slice());
472+
self.tcx.sess.span_help(
473+
origin.span(),
474+
format!(
475+
"consider adding an explicit lifetime bound to `{}`",
467476
param_ty.user_string(self.tcx)).as_slice());
468477
note_and_explain_region(
469478
self.tcx,

src/librustc/util/ppaux.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,18 @@ pub trait UserString {
4848
pub fn note_and_explain_region(cx: &ctxt,
4949
prefix: &str,
5050
region: ty::Region,
51-
suffix: &str) {
51+
suffix: &str) -> Option<Span> {
5252
match explain_region_and_span(cx, region) {
5353
(ref str, Some(span)) => {
5454
cx.sess.span_note(
5555
span,
5656
format!("{}{}{}", prefix, *str, suffix).as_slice());
57+
Some(span)
5758
}
5859
(ref str, None) => {
5960
cx.sess.note(
6061
format!("{}{}{}", prefix, *str, suffix).as_slice());
62+
None
6163
}
6264
}
6365
}

src/libsyntax/ext/bytes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt,
2222
tts: &[ast::TokenTree])
2323
-> Box<base::MacResult+'cx> {
2424
cx.span_warn(sp, "`bytes!` is deprecated, use `b\"foo\"` literals instead");
25-
cx.parse_sess.span_diagnostic.span_note(sp,
25+
cx.parse_sess.span_diagnostic.span_help(sp,
2626
"see http://doc.rust-lang.org/reference.html#byte-and-byte-string-literals \
2727
for documentation");
28-
cx.parse_sess.span_diagnostic.span_note(sp,
28+
cx.parse_sess.span_diagnostic.span_help(sp,
2929
"see https://github.com/rust-lang/rust/blob/master/src/etc/2014-06-rewrite-bytes-macros.py \
3030
for an automated migration");
3131

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'a> Context<'a> {
131131
fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
132132
if !self.has_feature(feature) {
133133
self.span_handler.span_err(span, explain);
134-
self.span_handler.span_note(span, format!("add #![feature({})] to the \
134+
self.span_handler.span_help(span, format!("add #![feature({})] to the \
135135
crate attributes to enable",
136136
feature).as_slice());
137137
}

0 commit comments

Comments
 (0)