Skip to content

Commit f3e26a0

Browse files
committed
Auto merge of #43386 - oli-obk:suggestions, r=nikomatsakis
Adjust new suggestions to the suggestion guidelines Addresses #42033 (comment) guidelines are https://github.com/rust-lang/rust/blob/master//src/librustc_errors/diagnostic.rs#L212-L224
2 parents 6270257 + 401ab61 commit f3e26a0

File tree

10 files changed

+40
-64
lines changed

10 files changed

+40
-64
lines changed

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
118118
let suggestions = compatible_variants.iter()
119119
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
120120
err.span_suggestions(expr.span,
121-
"perhaps you meant to use a variant of the expected type",
121+
"try using a variant of the expected type",
122122
suggestions);
123123
}
124124
}

src/librustc_typeck/check/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2654,7 +2654,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
26542654
// Add help to type error if this is an `if` condition with an assignment
26552655
match (expected, &expr.node) {
26562656
(ExpectIfCondition, &hir::ExprAssign(ref lhs, ref rhs)) => {
2657-
let msg = "did you mean to compare equality?";
2657+
let msg = "try comparing for equality";
26582658
if let (Ok(left), Ok(right)) = (
26592659
self.tcx.sess.codemap().span_to_snippet(lhs.span),
26602660
self.tcx.sess.codemap().span_to_snippet(rhs.span))
@@ -4270,7 +4270,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
42704270
hir::ExprBlock(..) => {
42714271
let sp = cause_span.next_point();
42724272
err.span_suggestion(sp,
4273-
"did you mean to add a semicolon here?",
4273+
"try adding a semicolon",
42744274
";".to_string());
42754275
}
42764276
_ => (),
@@ -4302,7 +4302,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43024302
} = fn_decl {
43034303
if ty.is_suggestable() {
43044304
err.span_suggestion(span,
4305-
"possibly return type missing here?",
4305+
"try adding a return type",
43064306
format!("-> {} ", ty));
43074307
} else {
43084308
err.span_label(span, "possibly return type missing here?");

src/libsyntax/parse/parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ impl<'a> Parser<'a> {
29362936
let expr_str = self.sess.codemap().span_to_snippet(expr.span)
29372937
.unwrap_or(pprust::expr_to_string(&expr));
29382938
err.span_suggestion(expr.span,
2939-
"if you want to compare the casted value then write:",
2939+
"try comparing the casted value",
29402940
format!("({})", expr_str));
29412941
err.emit();
29422942

src/test/ui/block-result/unexpected-return-on-unit.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ error[E0308]: mismatched types
66
|
77
= note: expected type `()`
88
found type `usize`
9-
help: did you mean to add a semicolon here?
9+
help: try adding a semicolon
1010
|
1111
19 | foo();
1212
| ^
13-
help: possibly return type missing here?
13+
help: try adding a return type
1414
|
1515
18 | fn bar() -> usize {
1616
| ^^^^^^^^

src/test/ui/did_you_mean/issue-42764.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ error[E0308]: mismatched types
66
|
77
= note: expected type `DoubleOption<_>`
88
found type `usize`
9-
help: perhaps you meant to use a variant of the expected type
9+
help: try using a variant of the expected type
1010
|
1111
21 | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
1212
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

src/test/ui/issue-22644.stderr

+22-42
Original file line numberDiff line numberDiff line change
@@ -2,66 +2,46 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
22
--> $DIR/issue-22644.rs:16:31
33
|
44
16 | println!("{}", a as usize < long_name);
5-
| ^ --------- interpreted as generic arguments
6-
| |
7-
| not interpreted as comparison
8-
|
9-
help: if you want to compare the casted value then write:
10-
|
11-
16 | println!("{}", (a as usize) < long_name);
12-
| ^^^^^^^^^^^^
5+
| ---------- ^ --------- interpreted as generic arguments
6+
| | |
7+
| | not interpreted as comparison
8+
| help: try comparing the casted value: `(a as usize)`
139

1410
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
1511
--> $DIR/issue-22644.rs:17:33
1612
|
1713
17 | println!("{}{}", a as usize < long_name, long_name);
18-
| ^ -------------------- interpreted as generic arguments
19-
| |
20-
| not interpreted as comparison
21-
|
22-
help: if you want to compare the casted value then write:
23-
|
24-
17 | println!("{}{}", (a as usize) < long_name, long_name);
25-
| ^^^^^^^^^^^^
14+
| ---------- ^ -------------------- interpreted as generic arguments
15+
| | |
16+
| | not interpreted as comparison
17+
| help: try comparing the casted value: `(a as usize)`
2618

2719
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
2820
--> $DIR/issue-22644.rs:18:31
2921
|
3022
18 | println!("{}", a as usize < 4);
31-
| ^ - interpreted as generic arguments
32-
| |
33-
| not interpreted as comparison
34-
|
35-
help: if you want to compare the casted value then write:
36-
|
37-
18 | println!("{}", (a as usize) < 4);
38-
| ^^^^^^^^^^^^
23+
| ---------- ^ - interpreted as generic arguments
24+
| | |
25+
| | not interpreted as comparison
26+
| help: try comparing the casted value: `(a as usize)`
3927

4028
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
4129
--> $DIR/issue-22644.rs:20:31
4230
|
4331
20 | println!("{}{}", a: usize < long_name, long_name);
44-
| ^ -------------------- interpreted as generic arguments
45-
| |
46-
| not interpreted as comparison
47-
|
48-
help: if you want to compare the casted value then write:
49-
|
50-
20 | println!("{}{}", (a: usize) < long_name, long_name);
51-
| ^^^^^^^^^^
32+
| -------- ^ -------------------- interpreted as generic arguments
33+
| | |
34+
| | not interpreted as comparison
35+
| help: try comparing the casted value: `(a: usize)`
5236

5337
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
5438
--> $DIR/issue-22644.rs:21:29
5539
|
5640
21 | println!("{}", a: usize < 4);
57-
| ^ - interpreted as generic arguments
58-
| |
59-
| not interpreted as comparison
60-
|
61-
help: if you want to compare the casted value then write:
62-
|
63-
21 | println!("{}", (a: usize) < 4);
64-
| ^^^^^^^^^^
41+
| -------- ^ - interpreted as generic arguments
42+
| | |
43+
| | not interpreted as comparison
44+
| help: try comparing the casted value: `(a: usize)`
6545

6646
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
6747
--> $DIR/issue-22644.rs:26:20
@@ -71,7 +51,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
7151
27 | 4);
7252
| - interpreted as generic arguments
7353
|
74-
help: if you want to compare the casted value then write:
54+
help: try comparing the casted value
7555
|
7656
23 | println!("{}", (a
7757
24 | as
@@ -86,7 +66,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
8666
36 | 5);
8767
| - interpreted as generic arguments
8868
|
89-
help: if you want to compare the casted value then write:
69+
help: try comparing the casted value
9070
|
9171
28 | println!("{}", (a
9272
29 |

src/test/ui/issue-42954.stderr

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a compa
22
--> $DIR/issue-42954.rs:13:19
33
|
44
13 | $i as u32 < 0
5-
| ^ - interpreted as generic arguments
6-
| |
7-
| not interpreted as comparison
5+
| --------- ^ - interpreted as generic arguments
6+
| | |
7+
| | not interpreted as comparison
8+
| help: try comparing the casted value: `($i as u32)`
89
...
910
19 | is_plainly_printable!(c);
1011
| ------------------------- in this macro invocation
11-
|
12-
help: if you want to compare the casted value then write:
13-
|
14-
13 | ($i as u32) < 0
15-
| ^^^^^^^^^^^
1612

1713
error: aborting due to previous error
1814

src/test/ui/mismatched_types/issue-19109.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-19109.rs:14:5
33
|
44
13 | fn function(t: &mut Trait) {
5-
| - help: possibly return type missing here?: `-> *mut Trait `
5+
| - help: try adding a return type: `-> *mut Trait `
66
14 | t as *mut Trait
77
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
88
|

src/test/ui/resolve/token-error-correct-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ error[E0308]: mismatched types
3535
--> $DIR/token-error-correct-3.rs:25:13
3636
|
3737
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
38-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here?: `;`
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
3939
| |
4040
| expected (), found enum `std::result::Result`
4141
|

src/test/ui/type-check/assignment-in-if.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ error[E0308]: mismatched types
55
| ^^^^^
66
| |
77
| expected bool, found ()
8-
| help: did you mean to compare equality?: `x == x`
8+
| help: try comparing for equality: `x == x`
99
|
1010
= note: expected type `bool`
1111
found type `()`
@@ -17,7 +17,7 @@ error[E0308]: mismatched types
1717
| ^^^^^^^
1818
| |
1919
| expected bool, found ()
20-
| help: did you mean to compare equality?: `x == x`
20+
| help: try comparing for equality: `x == x`
2121
|
2222
= note: expected type `bool`
2323
found type `()`
@@ -29,7 +29,7 @@ error[E0308]: mismatched types
2929
| ^^^^^^^^^^^^^^^^^^^^
3030
| |
3131
| expected bool, found ()
32-
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
32+
| help: try comparing for equality: `y == (Foo { foo: x })`
3333
|
3434
= note: expected type `bool`
3535
found type `()`
@@ -41,7 +41,7 @@ error[E0308]: mismatched types
4141
| ^^^^^
4242
| |
4343
| expected bool, found ()
44-
| help: did you mean to compare equality?: `3 == x`
44+
| help: try comparing for equality: `3 == x`
4545
|
4646
= note: expected type `bool`
4747
found type `()`

0 commit comments

Comments
 (0)