mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
Adjust new suggestions to the suggestion guidelines
This commit is contained in:
parent
d361efac26
commit
401ab612c2
@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
let suggestions = compatible_variants.iter()
|
let suggestions = compatible_variants.iter()
|
||||||
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
|
.map(|v| format!("{}({})", v, expr_text)).collect::<Vec<_>>();
|
||||||
err.span_suggestions(expr.span,
|
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);
|
suggestions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
// Add help to type error if this is an `if` condition with an assignment
|
||||||
match (expected, &expr.node) {
|
match (expected, &expr.node) {
|
||||||
(ExpectIfCondition, &hir::ExprAssign(ref lhs, ref rhs)) => {
|
(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)) = (
|
if let (Ok(left), Ok(right)) = (
|
||||||
self.tcx.sess.codemap().span_to_snippet(lhs.span),
|
self.tcx.sess.codemap().span_to_snippet(lhs.span),
|
||||||
self.tcx.sess.codemap().span_to_snippet(rhs.span))
|
self.tcx.sess.codemap().span_to_snippet(rhs.span))
|
||||||
@ -4270,7 +4270,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
hir::ExprBlock(..) => {
|
hir::ExprBlock(..) => {
|
||||||
let sp = cause_span.next_point();
|
let sp = cause_span.next_point();
|
||||||
err.span_suggestion(sp,
|
err.span_suggestion(sp,
|
||||||
"did you mean to add a semicolon here?",
|
"try adding a semicolon",
|
||||||
";".to_string());
|
";".to_string());
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
@ -4302,7 +4302,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
|||||||
} = fn_decl {
|
} = fn_decl {
|
||||||
if ty.is_suggestable() {
|
if ty.is_suggestable() {
|
||||||
err.span_suggestion(span,
|
err.span_suggestion(span,
|
||||||
"possibly return type missing here?",
|
"try adding a return type",
|
||||||
format!("-> {} ", ty));
|
format!("-> {} ", ty));
|
||||||
} else {
|
} else {
|
||||||
err.span_label(span, "possibly return type missing here?");
|
err.span_label(span, "possibly return type missing here?");
|
||||||
|
@ -2936,7 +2936,7 @@ impl<'a> Parser<'a> {
|
|||||||
let expr_str = self.sess.codemap().span_to_snippet(expr.span)
|
let expr_str = self.sess.codemap().span_to_snippet(expr.span)
|
||||||
.unwrap_or(pprust::expr_to_string(&expr));
|
.unwrap_or(pprust::expr_to_string(&expr));
|
||||||
err.span_suggestion(expr.span,
|
err.span_suggestion(expr.span,
|
||||||
"if you want to compare the casted value then write:",
|
"try comparing the casted value",
|
||||||
format!("({})", expr_str));
|
format!("({})", expr_str));
|
||||||
err.emit();
|
err.emit();
|
||||||
|
|
||||||
|
@ -6,11 +6,11 @@ error[E0308]: mismatched types
|
|||||||
|
|
|
|
||||||
= note: expected type `()`
|
= note: expected type `()`
|
||||||
found type `usize`
|
found type `usize`
|
||||||
help: did you mean to add a semicolon here?
|
help: try adding a semicolon
|
||||||
|
|
|
|
||||||
19 | foo();
|
19 | foo();
|
||||||
| ^
|
| ^
|
||||||
help: possibly return type missing here?
|
help: try adding a return type
|
||||||
|
|
|
|
||||||
18 | fn bar() -> usize {
|
18 | fn bar() -> usize {
|
||||||
| ^^^^^^^^
|
| ^^^^^^^^
|
||||||
|
@ -6,7 +6,7 @@ error[E0308]: mismatched types
|
|||||||
|
|
|
|
||||||
= note: expected type `DoubleOption<_>`
|
= note: expected type `DoubleOption<_>`
|
||||||
found type `usize`
|
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));
|
21 | this_function_expects_a_double_option(DoubleOption::FirstSome(n));
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
@ -2,66 +2,46 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
|
|||||||
--> $DIR/issue-22644.rs:16:31
|
--> $DIR/issue-22644.rs:16:31
|
||||||
|
|
|
|
||||||
16 | println!("{}", a as usize < long_name);
|
16 | println!("{}", a as usize < long_name);
|
||||||
| ^ --------- interpreted as generic arguments
|
| ---------- ^ --------- interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
|
| help: try comparing the casted value: `(a as usize)`
|
||||||
help: if you want to compare the casted value then write:
|
|
||||||
|
|
|
||||||
16 | println!("{}", (a as usize) < long_name);
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||||
--> $DIR/issue-22644.rs:17:33
|
--> $DIR/issue-22644.rs:17:33
|
||||||
|
|
|
|
||||||
17 | println!("{}{}", a as usize < long_name, long_name);
|
17 | println!("{}{}", a as usize < long_name, long_name);
|
||||||
| ^ -------------------- interpreted as generic arguments
|
| ---------- ^ -------------------- interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
|
| help: try comparing the casted value: `(a as usize)`
|
||||||
help: if you want to compare the casted value then write:
|
|
||||||
|
|
|
||||||
17 | println!("{}{}", (a as usize) < long_name, long_name);
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||||
--> $DIR/issue-22644.rs:18:31
|
--> $DIR/issue-22644.rs:18:31
|
||||||
|
|
|
|
||||||
18 | println!("{}", a as usize < 4);
|
18 | println!("{}", a as usize < 4);
|
||||||
| ^ - interpreted as generic arguments
|
| ---------- ^ - interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
|
| help: try comparing the casted value: `(a as usize)`
|
||||||
help: if you want to compare the casted value then write:
|
|
||||||
|
|
|
||||||
18 | println!("{}", (a as usize) < 4);
|
|
||||||
| ^^^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||||
--> $DIR/issue-22644.rs:20:31
|
--> $DIR/issue-22644.rs:20:31
|
||||||
|
|
|
|
||||||
20 | println!("{}{}", a: usize < long_name, long_name);
|
20 | println!("{}{}", a: usize < long_name, long_name);
|
||||||
| ^ -------------------- interpreted as generic arguments
|
| -------- ^ -------------------- interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
|
| help: try comparing the casted value: `(a: usize)`
|
||||||
help: if you want to compare the casted value then write:
|
|
||||||
|
|
|
||||||
20 | println!("{}{}", (a: usize) < long_name, long_name);
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||||
--> $DIR/issue-22644.rs:21:29
|
--> $DIR/issue-22644.rs:21:29
|
||||||
|
|
|
|
||||||
21 | println!("{}", a: usize < 4);
|
21 | println!("{}", a: usize < 4);
|
||||||
| ^ - interpreted as generic arguments
|
| -------- ^ - interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
|
| help: try comparing the casted value: `(a: usize)`
|
||||||
help: if you want to compare the casted value then write:
|
|
||||||
|
|
|
||||||
21 | println!("{}", (a: usize) < 4);
|
|
||||||
| ^^^^^^^^^^
|
|
||||||
|
|
||||||
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
error: `<` is interpreted as a start of generic arguments for `usize`, not a comparison
|
||||||
--> $DIR/issue-22644.rs:26:20
|
--> $DIR/issue-22644.rs:26:20
|
||||||
@ -71,7 +51,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
|
|||||||
27 | 4);
|
27 | 4);
|
||||||
| - interpreted as generic arguments
|
| - interpreted as generic arguments
|
||||||
|
|
|
|
||||||
help: if you want to compare the casted value then write:
|
help: try comparing the casted value
|
||||||
|
|
|
|
||||||
23 | println!("{}", (a
|
23 | println!("{}", (a
|
||||||
24 | as
|
24 | as
|
||||||
@ -86,7 +66,7 @@ error: `<` is interpreted as a start of generic arguments for `usize`, not a com
|
|||||||
36 | 5);
|
36 | 5);
|
||||||
| - interpreted as generic arguments
|
| - interpreted as generic arguments
|
||||||
|
|
|
|
||||||
help: if you want to compare the casted value then write:
|
help: try comparing the casted value
|
||||||
|
|
|
|
||||||
28 | println!("{}", (a
|
28 | println!("{}", (a
|
||||||
29 |
|
29 |
|
||||||
|
@ -2,17 +2,13 @@ error: `<` is interpreted as a start of generic arguments for `u32`, not a compa
|
|||||||
--> $DIR/issue-42954.rs:13:19
|
--> $DIR/issue-42954.rs:13:19
|
||||||
|
|
|
|
||||||
13 | $i as u32 < 0
|
13 | $i as u32 < 0
|
||||||
| ^ - interpreted as generic arguments
|
| --------- ^ - interpreted as generic arguments
|
||||||
| |
|
| | |
|
||||||
| not interpreted as comparison
|
| | not interpreted as comparison
|
||||||
|
| help: try comparing the casted value: `($i as u32)`
|
||||||
...
|
...
|
||||||
19 | is_plainly_printable!(c);
|
19 | is_plainly_printable!(c);
|
||||||
| ------------------------- in this macro invocation
|
| ------------------------- 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
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/issue-19109.rs:14:5
|
--> $DIR/issue-19109.rs:14:5
|
||||||
|
|
|
|
||||||
13 | fn function(t: &mut Trait) {
|
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
|
14 | t as *mut Trait
|
||||||
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|
||||||
|
|
|
|
||||||
|
@ -35,7 +35,7 @@ error[E0308]: mismatched types
|
|||||||
--> $DIR/token-error-correct-3.rs:25:13
|
--> $DIR/token-error-correct-3.rs:25:13
|
||||||
|
|
|
|
||||||
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
|
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`
|
| expected (), found enum `std::result::Result`
|
||||||
|
|
|
|
||||||
|
@ -5,7 +5,7 @@ error[E0308]: mismatched types
|
|||||||
| ^^^^^
|
| ^^^^^
|
||||||
| |
|
| |
|
||||||
| expected bool, found ()
|
| expected bool, found ()
|
||||||
| help: did you mean to compare equality?: `x == x`
|
| help: try comparing for equality: `x == x`
|
||||||
|
|
|
|
||||||
= note: expected type `bool`
|
= note: expected type `bool`
|
||||||
found type `()`
|
found type `()`
|
||||||
@ -17,7 +17,7 @@ error[E0308]: mismatched types
|
|||||||
| ^^^^^^^
|
| ^^^^^^^
|
||||||
| |
|
| |
|
||||||
| expected bool, found ()
|
| expected bool, found ()
|
||||||
| help: did you mean to compare equality?: `x == x`
|
| help: try comparing for equality: `x == x`
|
||||||
|
|
|
|
||||||
= note: expected type `bool`
|
= note: expected type `bool`
|
||||||
found type `()`
|
found type `()`
|
||||||
@ -29,7 +29,7 @@ error[E0308]: mismatched types
|
|||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
| |
|
| |
|
||||||
| expected bool, found ()
|
| 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`
|
= note: expected type `bool`
|
||||||
found type `()`
|
found type `()`
|
||||||
@ -41,7 +41,7 @@ error[E0308]: mismatched types
|
|||||||
| ^^^^^
|
| ^^^^^
|
||||||
| |
|
| |
|
||||||
| expected bool, found ()
|
| expected bool, found ()
|
||||||
| help: did you mean to compare equality?: `3 == x`
|
| help: try comparing for equality: `3 == x`
|
||||||
|
|
|
|
||||||
= note: expected type `bool`
|
= note: expected type `bool`
|
||||||
found type `()`
|
found type `()`
|
||||||
|
Loading…
Reference in New Issue
Block a user