Skip to content

Commit a9d9a4a

Browse files
committed
Change some helps to suggestions
1 parent 4a28663 commit a9d9a4a

26 files changed

+139
-159
lines changed

src/librustc_borrowck/borrowck/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
991991
.span_suggestion(err.span,
992992
&format!("to force the closure to take ownership of {} \
993993
(and any other referenced variables), \
994-
use the `move` keyword, as shown:",
994+
use the `move` keyword",
995995
cmt_path_or_string),
996996
suggestion)
997997
.emit();

src/librustc_errors/diagnostic.rs

+12
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,18 @@ impl Diagnostic {
211211

212212
/// Prints out a message with a suggested edit of the code.
213213
///
214+
/// In case of short messages and a simple suggestion,
215+
/// rustc displays it as a label like
216+
///
217+
/// "try adding parentheses: `(tup.0).1`"
218+
///
219+
/// The message
220+
/// * should not end in any punctuation (a `:` is added automatically)
221+
/// * should not be a question
222+
/// * should not contain any parts like "the following", "as shown"
223+
/// * may look like "to do xyz, use" or "to do xyz, use abc"
224+
/// * may contain a name of a function, variable or type, but not whole expressions
225+
///
214226
/// See `diagnostic::CodeSuggestion` for more information.
215227
pub fn span_suggestion(&mut self, sp: Span, msg: &str, suggestion: String) -> &mut Self {
216228
self.suggestions.push(CodeSuggestion {

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Emitter for EmitterWriter {
5151
// This substitution is only removal, don't show it
5252
format!("help: {}", sugg.msg)
5353
} else {
54-
format!("help: {} `{}`", sugg.msg, substitution)
54+
format!("help: {}: `{}`", sugg.msg, substitution)
5555
};
5656
primary_span.push_span_label(sugg.substitution_spans().next().unwrap(), msg);
5757
} else {

src/librustc_resolve/lib.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -2409,13 +2409,15 @@ impl<'a> Resolver<'a> {
24092409
.map(|suggestion| import_candidate_to_paths(&suggestion)).collect::<Vec<_>>();
24102410
enum_candidates.sort();
24112411
for (sp, variant_path, enum_path) in enum_candidates {
2412-
let msg = format!("there is an enum variant `{}`, did you mean to use `{}`?",
2413-
variant_path,
2414-
enum_path);
24152412
if sp == DUMMY_SP {
2413+
let msg = format!("there is an enum variant `{}`, \
2414+
try using `{}`?",
2415+
variant_path,
2416+
enum_path);
24162417
err.help(&msg);
24172418
} else {
2418-
err.span_help(sp, &msg);
2419+
err.span_suggestion(span, "you can try using the variant's enum",
2420+
enum_path);
24192421
}
24202422
}
24212423
}
@@ -2424,18 +2426,20 @@ impl<'a> Resolver<'a> {
24242426
let self_is_available = this.self_value_is_available(path[0].ctxt, span);
24252427
match candidate {
24262428
AssocSuggestion::Field => {
2427-
err.span_label(span, format!("did you mean `self.{}`?", path_str));
2429+
err.span_suggestion(span, "try",
2430+
format!("self.{}", path_str));
24282431
if !self_is_available {
24292432
err.span_label(span, format!("`self` value is only available in \
24302433
methods with `self` parameter"));
24312434
}
24322435
}
24332436
AssocSuggestion::MethodWithSelf if self_is_available => {
2434-
err.span_label(span, format!("did you mean `self.{}(...)`?",
2435-
path_str));
2437+
err.span_suggestion(span, "try",
2438+
format!("self.{}", path_str));
24362439
}
24372440
AssocSuggestion::MethodWithSelf | AssocSuggestion::AssocItem => {
2438-
err.span_label(span, format!("did you mean `Self::{}`?", path_str));
2441+
err.span_suggestion(span, "try",
2442+
format!("Self::{}", path_str));
24392443
}
24402444
}
24412445
return err;

src/librustc_resolve/macros.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -658,9 +658,10 @@ impl<'a> Resolver<'a> {
658658
if let Some(suggestion) = suggestion {
659659
if suggestion != name {
660660
if let MacroKind::Bang = kind {
661-
err.help(&format!("did you mean `{}!`?", suggestion));
661+
err.span_suggestion(span, "you could try the macro",
662+
format!("{}!", suggestion));
662663
} else {
663-
err.help(&format!("did you mean `{}`?", suggestion));
664+
err.span_suggestion(span, "try", suggestion.to_string());
664665
}
665666
} else {
666667
err.help("have you added the `#[macro_use]` on the module/import?");

src/librustc_typeck/check/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
253253
match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) {
254254
Ok(s) => {
255255
err.span_suggestion(self.cast_span,
256-
"try casting to a reference instead:",
256+
"try casting to a reference instead",
257257
format!("&{}{}", mtstr, s));
258258
}
259259
Err(_) => {
@@ -272,7 +272,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> {
272272
match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) {
273273
Ok(s) => {
274274
err.span_suggestion(self.cast_span,
275-
"try casting to a `Box` instead:",
275+
"try casting to a `Box` instead",
276276
format!("Box<{}>", s));
277277
}
278278
Err(_) => span_help!(err, self.cast_span, "did you mean `Box<{}>`?", tstr),

src/librustc_typeck/check/op.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
320320
from a string reference. String concatenation \
321321
appends the string on the right to the string \
322322
on the left and may require reallocation. This \
323-
requires ownership of the string on the left."), suggestion);
323+
requires ownership of the string on the left"), suggestion);
324324
is_string_addition = true;
325325
}
326326

src/libsyntax/parse/parser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1490,7 +1490,7 @@ impl<'a> Parser<'a> {
14901490
s.print_bounds(" +", &bounds)?;
14911491
s.pclose()
14921492
});
1493-
err.span_suggestion(sum_span, "try adding parentheses:", sum_with_parens);
1493+
err.span_suggestion(sum_span, "try adding parentheses", sum_with_parens);
14941494
}
14951495
TyKind::Ptr(..) | TyKind::BareFn(..) => {
14961496
err.span_label(sum_span, "perhaps you forgot parentheses?");
@@ -5280,7 +5280,7 @@ impl<'a> Parser<'a> {
52805280
`pub(in path::to::module)`: visible only on the specified path"##;
52815281
let path = self.parse_path(PathStyle::Mod)?;
52825282
let path_span = self.prev_span;
5283-
let help_msg = format!("make this visible only to module `{}` with `in`:", path);
5283+
let help_msg = format!("make this visible only to module `{}` with `in`", path);
52845284
self.expect(&token::CloseDelim(token::Paren))?; // `)`
52855285
let mut err = self.span_fatal_help(path_span, msg, suggestion);
52865286
err.span_suggestion(path_span, &help_msg, format!("in {}", path));
+27-41
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,62 @@
11
error: cannot find derive macro `FooWithLongNan` in this scope
2-
--> $DIR/resolve-error.rs:36:10
2+
--> $DIR/resolve-error.rs:37:10
33
|
4-
36 | #[derive(FooWithLongNan)]
5-
| ^^^^^^^^^^^^^^
6-
|
7-
= help: did you mean `FooWithLongName`?
4+
37 | #[derive(FooWithLongNan)]
5+
| ^^^^^^^^^^^^^^ help: try: `FooWithLongName`
86

97
error: cannot find attribute macro `attr_proc_macra` in this scope
10-
--> $DIR/resolve-error.rs:39:3
11-
|
12-
39 | #[attr_proc_macra]
13-
| ^^^^^^^^^^^^^^^
8+
--> $DIR/resolve-error.rs:40:3
149
|
15-
= help: did you mean `attr_proc_macro`?
10+
40 | #[attr_proc_macra]
11+
| ^^^^^^^^^^^^^^^ help: try: `attr_proc_macro`
1612

1713
error: cannot find attribute macro `FooWithLongNan` in this scope
18-
--> $DIR/resolve-error.rs:42:3
14+
--> $DIR/resolve-error.rs:43:3
1915
|
20-
42 | #[FooWithLongNan]
16+
43 | #[FooWithLongNan]
2117
| ^^^^^^^^^^^^^^
2218

2319
error: cannot find derive macro `Dlone` in this scope
24-
--> $DIR/resolve-error.rs:45:10
20+
--> $DIR/resolve-error.rs:46:10
2521
|
26-
45 | #[derive(Dlone)]
27-
| ^^^^^
28-
|
29-
= help: did you mean `Clone`?
22+
46 | #[derive(Dlone)]
23+
| ^^^^^ help: try: `Clone`
3024

3125
error: cannot find derive macro `Dlona` in this scope
32-
--> $DIR/resolve-error.rs:48:10
33-
|
34-
48 | #[derive(Dlona)]
35-
| ^^^^^
26+
--> $DIR/resolve-error.rs:49:10
3627
|
37-
= help: did you mean `Clona`?
28+
49 | #[derive(Dlona)]
29+
| ^^^^^ help: try: `Clona`
3830

3931
error: cannot find derive macro `attr_proc_macra` in this scope
40-
--> $DIR/resolve-error.rs:51:10
32+
--> $DIR/resolve-error.rs:52:10
4133
|
42-
51 | #[derive(attr_proc_macra)]
34+
52 | #[derive(attr_proc_macra)]
4335
| ^^^^^^^^^^^^^^^
4436

4537
error: cannot find macro `FooWithLongNama!` in this scope
46-
--> $DIR/resolve-error.rs:55:5
38+
--> $DIR/resolve-error.rs:56:5
4739
|
48-
55 | FooWithLongNama!();
49-
| ^^^^^^^^^^^^^^^
50-
|
51-
= help: did you mean `FooWithLongNam!`?
40+
56 | FooWithLongNama!();
41+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `FooWithLongNam!`
5242

5343
error: cannot find macro `attr_proc_macra!` in this scope
54-
--> $DIR/resolve-error.rs:57:5
55-
|
56-
57 | attr_proc_macra!();
57-
| ^^^^^^^^^^^^^^^
44+
--> $DIR/resolve-error.rs:58:5
5845
|
59-
= help: did you mean `attr_proc_mac!`?
46+
58 | attr_proc_macra!();
47+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `attr_proc_mac!`
6048

6149
error: cannot find macro `Dlona!` in this scope
62-
--> $DIR/resolve-error.rs:59:5
50+
--> $DIR/resolve-error.rs:60:5
6351
|
64-
59 | Dlona!();
52+
60 | Dlona!();
6553
| ^^^^^
6654

6755
error: cannot find macro `bang_proc_macrp!` in this scope
68-
--> $DIR/resolve-error.rs:61:5
69-
|
70-
61 | bang_proc_macrp!();
71-
| ^^^^^^^^^^^^^^^
56+
--> $DIR/resolve-error.rs:62:5
7257
|
73-
= help: did you mean `bang_proc_macro!`?
58+
62 | bang_proc_macrp!();
59+
| ^^^^^^^^^^^^^^^ help: you could try the macro: `bang_proc_macro!`
7460

7561
error: aborting due to 10 previous errors
7662

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
error: cast to unsized type: `&{integer}` as `std::marker::Send`
1+
error[E0620]: cast to unsized type: `&{integer}` as `std::marker::Send`
22
--> $DIR/cast-to-unsized-trait-object-suggestion.rs:12:5
33
|
44
12 | &1 as Send;
55
| ^^^^^^----
66
| |
77
| help: try casting to a reference instead: `&Send`
88

9-
error: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send`
9+
error[E0620]: cast to unsized type: `std::boxed::Box<{integer}>` as `std::marker::Send`
1010
--> $DIR/cast-to-unsized-trait-object-suggestion.rs:13:5
1111
|
1212
13 | Box::new(1) as Send;
1313
| ^^^^^^^^^^^^^^^----
1414
| |
1515
| help: try casting to a `Box` instead: `Box<Send>`
1616

17-
error: aborting due to previous error(s)
17+
error: aborting due to 2 previous errors
1818

src/test/ui/issue-35675.stderr

+23-28
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ error[E0412]: cannot find type `Apple` in this scope
22
--> $DIR/issue-35675.rs:20:29
33
|
44
20 | fn should_return_fruit() -> Apple {
5-
| ^^^^^ not found in this scope
6-
|
7-
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
8-
--> $DIR/issue-35675.rs:14:5
9-
|
10-
14 | Apple(i64),
11-
| ^^^^^^^^^^
5+
| ^^^^^
6+
| |
7+
| not found in this scope
8+
| help: you can try using the variant's enum: `Fruit`
129

1310
error[E0425]: cannot find function `Apple` in this scope
1411
--> $DIR/issue-35675.rs:23:5
@@ -17,19 +14,18 @@ error[E0425]: cannot find function `Apple` in this scope
1714
| ^^^^^ not found in this scope
1815
|
1916
help: possible candidate is found in another module, you can import it into scope
20-
| use Fruit::Apple;
17+
|
18+
12 | use Fruit::Apple;
19+
|
2120

2221
error[E0573]: expected type, found variant `Fruit::Apple`
2322
--> $DIR/issue-35675.rs:28:33
2423
|
2524
28 | fn should_return_fruit_too() -> Fruit::Apple {
26-
| ^^^^^^^^^^^^ not a type
27-
|
28-
help: there is an enum variant `Fruit::Apple`, did you mean to use `Fruit`?
29-
--> $DIR/issue-35675.rs:14:5
30-
|
31-
14 | Apple(i64),
32-
| ^^^^^^^^^^
25+
| ^^^^^^^^^^^^
26+
| |
27+
| not a type
28+
| help: you can try using the variant's enum: `Fruit`
3329

3430
error[E0425]: cannot find function `Apple` in this scope
3531
--> $DIR/issue-35675.rs:31:5
@@ -38,37 +34,36 @@ error[E0425]: cannot find function `Apple` in this scope
3834
| ^^^^^ not found in this scope
3935
|
4036
help: possible candidate is found in another module, you can import it into scope
41-
| use Fruit::Apple;
37+
|
38+
12 | use Fruit::Apple;
39+
|
4240

4341
error[E0573]: expected type, found variant `Ok`
4442
--> $DIR/issue-35675.rs:36:13
4543
|
4644
36 | fn foo() -> Ok {
4745
| ^^ not a type
4846
|
49-
= help: there is an enum variant `std::prelude::v1::Ok`, did you mean to use `std::prelude::v1`?
50-
= help: there is an enum variant `std::prelude::v1::Result::Ok`, did you mean to use `std::prelude::v1::Result`?
47+
= help: there is an enum variant `std::prelude::v1::Ok`, try using `std::prelude::v1`?
48+
= help: there is an enum variant `std::result::Result::Ok`, try using `std::result::Result`?
5149

5250
error[E0412]: cannot find type `Variant3` in this scope
5351
--> $DIR/issue-35675.rs:44:13
5452
|
5553
44 | fn bar() -> Variant3 {
56-
| ^^^^^^^^ not found in this scope
57-
|
58-
help: there is an enum variant `x::Enum::Variant3`, did you mean to use `x::Enum`?
59-
--> $DIR/issue-35675.rs:63:9
60-
|
61-
63 | Variant3(usize),
62-
| ^^^^^^^^^^^^^^^
54+
| ^^^^^^^^
55+
| |
56+
| not found in this scope
57+
| help: you can try using the variant's enum: `x::Enum`
6358

6459
error[E0573]: expected type, found variant `Some`
6560
--> $DIR/issue-35675.rs:49:13
6661
|
6762
49 | fn qux() -> Some {
6863
| ^^^^ not a type
6964
|
70-
= help: there is an enum variant `std::option::Option::Some`, did you mean to use `std::option::Option`?
71-
= help: there is an enum variant `std::prelude::v1::Some`, did you mean to use `std::prelude::v1`?
65+
= help: there is an enum variant `std::option::Option::Some`, try using `std::option::Option`?
66+
= help: there is an enum variant `std::prelude::v1::Some`, try using `std::prelude::v1`?
7267

73-
error: aborting due to previous error(s)
68+
error: aborting due to 7 previous errors
7469

src/test/ui/issue-40402-ref-hints/issue-40402-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0507]: cannot move out of indexed content
44
19 | let e = f.v[0];
55
| ^^^^^^
66
| |
7-
| help: consider using a reference instead `&f.v[0]`
7+
| help: consider using a reference instead: `&f.v[0]`
88
| cannot move out of indexed content
99

1010
error: aborting due to previous error

src/test/ui/macros/macro-name-typo.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ error: cannot find macro `printlx!` in this scope
22
--> $DIR/macro-name-typo.rs:12:5
33
|
44
12 | printlx!("oh noes!");
5-
| ^^^^^^^
6-
|
7-
= help: did you mean `println!`?
5+
| ^^^^^^^ help: you could try the macro: `println!`
86

9-
error: aborting due to previous error(s)
7+
error: aborting due to previous error
108

src/test/ui/macros/macro_undefined.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ error: cannot find macro `k!` in this scope
1010
--> $DIR/macro_undefined.rs:21:5
1111
|
1212
21 | k!();
13-
| ^
14-
|
15-
= help: did you mean `kl!`?
13+
| ^ help: you could try the macro: `kl!`
1614

17-
error: aborting due to previous error(s)
15+
error: aborting due to 2 previous errors
1816

0 commit comments

Comments
 (0)