Skip to content

Commit

Permalink
Auto merge of #43386 - oli-obk:suggestions, r=nikomatsakis
Browse files Browse the repository at this point in the history
  • Loading branch information
bors committed Jul 23, 2017
2 parents 6270257 + 401ab61 commit f3e26a0
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let suggestions = compatible_variants.iter()
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
err.span_suggestions(expr.span,
"perhaps you meant to use a variant of the expected type",
"try using a variant of the expected type",
suggestions);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2654,7 +2654,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// Add help to type error if this is an `if` condition with an assignment
match (expected, &expr.node) {
(ExpectIfCondition, &hir::ExprAssign(ref lhs, ref rhs)) => {
let msg = "did you mean to compare equality?";
let msg = "try comparing for equality";
if let (Ok(left), Ok(right)) = (
self.tcx.sess.codemap().span_to_snippet(lhs.span),
self.tcx.sess.codemap().span_to_snippet(rhs.span))
Expand Down Expand Up @@ -4270,7 +4270,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
hir::ExprBlock(..) => {
let sp = cause_span.next_point();
err.span_suggestion(sp,
"did you mean to add a semicolon here?",
"try adding a semicolon",
";".to_string());
}
_ => (),
Expand Down Expand Up @@ -4302,7 +4302,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
} = fn_decl {
if ty.is_suggestable() {
err.span_suggestion(span,
"possibly return type missing here?",
"try adding a return type",
format!("-> {} ", ty));
} else {
err.span_label(span, "possibly return type missing here?");
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2936,7 +2936,7 @@ impl<'a> Parser<'a> {
let expr_str = self.sess.codemap().span_to_snippet(expr.span)
.unwrap_or(pprust::expr_to_string(&expr));
err.span_suggestion(expr.span,
"if you want to compare the casted value then write:",
"try comparing the casted value",
format!("({})", expr_str));
err.emit();

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/block-result/unexpected-return-on-unit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ error[E0308]: mismatched types
|
= note: expected type `()`
found type `usize`
help: did you mean to add a semicolon here?
help: try adding a semicolon
|
19 | foo();
| ^
help: possibly return type missing here?
help: try adding a return type
|
18 | fn bar() -> usize {
| ^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/did_you_mean/issue-42764.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ error[E0308]: mismatched types
|
= note: expected type `DoubleOption<_>`
found type `usize`
help: perhaps you meant to use a variant of the expected type
help: try using a variant of the expected type
|
21 | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
64 changes: 22 additions & 42 deletions src/test/ui/issue-22644.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,46 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
--> $DIR/issue-22644.rs:16:31
|
16 | println!("{}", a as usize < long_name);
| ^ --------- interpreted as generic arguments
| |
| not interpreted as comparison
|
help: if you want to compare the casted value then write:
|
16 | println!("{}", (a as usize) < long_name);
| ^^^^^^^^^^^^
| ---------- ^ --------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`

error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:17:33
|
17 | println!("{}{}", a as usize < long_name, long_name);
| ^ -------------------- interpreted as generic arguments
| |
| not interpreted as comparison
|
help: if you want to compare the casted value then write:
|
17 | println!("{}{}", (a as usize) < long_name, long_name);
| ^^^^^^^^^^^^
| ---------- ^ -------------------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`

error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:18:31
|
18 | println!("{}", a as usize < 4);
| ^ - interpreted as generic arguments
| |
| not interpreted as comparison
|
help: if you want to compare the casted value then write:
|
18 | println!("{}", (a as usize) < 4);
| ^^^^^^^^^^^^
| ---------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a as usize)`

error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:20:31
|
20 | println!("{}{}", a: usize < long_name, long_name);
| ^ -------------------- interpreted as generic arguments
| |
| not interpreted as comparison
|
help: if you want to compare the casted value then write:
|
20 | println!("{}{}", (a: usize) < long_name, long_name);
| ^^^^^^^^^^
| -------- ^ -------------------- interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a: usize)`

error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:21:29
|
21 | println!("{}", a: usize < 4);
| ^ - interpreted as generic arguments
| |
| not interpreted as comparison
|
help: if you want to compare the casted value then write:
|
21 | println!("{}", (a: usize) < 4);
| ^^^^^^^^^^
| -------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `(a: usize)`

error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
--> $DIR/issue-22644.rs:26:20
Expand All @@ -71,7 +51,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
27 | 4);
| - interpreted as generic arguments
|
help: if you want to compare the casted value then write:
help: try comparing the casted value
|
23 | println!("{}", (a
24 | as
Expand All @@ -86,7 +66,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
36 | 5);
| - interpreted as generic arguments
|
help: if you want to compare the casted value then write:
help: try comparing the casted value
|
28 | println!("{}", (a
29 |
Expand Down
12 changes: 4 additions & 8 deletions src/test/ui/issue-42954.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a compa
--> $DIR/issue-42954.rs:13:19
|
13 | $i as u32 < 0
| ^ - interpreted as generic arguments
| |
| not interpreted as comparison
| --------- ^ - interpreted as generic arguments
| | |
| | not interpreted as comparison
| help: try comparing the casted value: `($i as u32)`
...
19 | is_plainly_printable!(c);
| ------------------------- in this macro invocation
|
help: if you want to compare the casted value then write:
|
13 | ($i as u32) < 0
| ^^^^^^^^^^^

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/issue-19109.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-19109.rs:14:5
|
13 | fn function(t: &mut Trait) {
| - help: possibly return type missing here?: `-> *mut Trait `
| - help: try adding a return type: `-> *mut Trait `
14 | t as *mut Trait
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/token-error-correct-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ error[E0308]: mismatched types
--> $DIR/token-error-correct-3.rs:25:13
|
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here?: `;`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: try adding a semicolon: `;`
| |
| expected (), found enum `std::result::Result`
|
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/type-check/assignment-in-if.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error[E0308]: mismatched types
| ^^^^^
| |
| expected bool, found ()
| help: did you mean to compare equality?: `x == x`
| help: try comparing for equality: `x == x`
|
= note: expected type `bool`
found type `()`
Expand All @@ -17,7 +17,7 @@ error[E0308]: mismatched types
| ^^^^^^^
| |
| expected bool, found ()
| help: did you mean to compare equality?: `x == x`
| help: try comparing for equality: `x == x`
|
= note: expected type `bool`
found type `()`
Expand All @@ -29,7 +29,7 @@ error[E0308]: mismatched types
| ^^^^^^^^^^^^^^^^^^^^
| |
| expected bool, found ()
| help: did you mean to compare equality?: `y == (Foo { foo: x })`
| help: try comparing for equality: `y == (Foo { foo: x })`
|
= note: expected type `bool`
found type `()`
Expand All @@ -41,7 +41,7 @@ error[E0308]: mismatched types
| ^^^^^
| |
| expected bool, found ()
| help: did you mean to compare equality?: `3 == x`
| help: try comparing for equality: `3 == x`
|
= note: expected type `bool`
found type `()`
Expand Down

0 comments on commit f3e26a0

Please sign in to comment.