提交 c13a913e 编写于 作者: E Esteban Küber

Don't naively point to return type on type error

上级 27d4b314
......@@ -1174,12 +1174,6 @@ fn coerce_inner<'a>(&mut self,
expected, found,
cause.span, blk_id);
}
ObligationCauseCode::ReturnType(ret_id) => {
db = fcx.report_mismatched_types(cause, expected, found, err);
if let Some((fn_decl, _)) = fcx.get_fn_decl(ret_id) {
fcx.point_to_type_requirement(&mut db, &fn_decl, expected);
}
}
_ => {
db = fcx.report_mismatched_types(cause, expected, found, err);
}
......
......@@ -4261,7 +4261,6 @@ pub fn suggest_mismatched_types_on_tail(&self,
self.suggest_missing_semicolon(err, expression, expected, cause_span);
if let Some((fn_decl, is_main)) = self.get_fn_decl(blk_id) {
self.point_to_type_requirement(err, &fn_decl, expected);
// `fn main()` must return `()`, do not suggest changing return type
if !is_main {
self.suggest_missing_return_type(err, &fn_decl, found);
......@@ -4269,27 +4268,6 @@ pub fn suggest_mismatched_types_on_tail(&self,
}
}
pub fn point_to_type_requirement(&self,
err: &mut DiagnosticBuilder<'tcx>,
fn_decl: &hir::FnDecl,
ty: Ty<'tcx>) {
let msg = if let &hir::FnDecl {
output: hir::FunctionRetTy::DefaultReturn(_), ..
} = fn_decl {
"default "
} else {
""
};
let ty = self.resolve_type_vars_if_possible(&ty);
if ty.to_string().len() < 10 {
err.span_label(fn_decl.output.span(),
format!("expected `{}` because of this {}return type", ty, msg));
} else {
err.span_label(fn_decl.output.span(),
format!("expected because of this {}return type", msg));
}
}
/// A common error is to forget to add a semicolon at the end of a block:
///
/// ```
......
error[E0308]: mismatched types
--> $DIR/issue-13624.rs:17:5
|
16 | pub fn get_enum_struct_variant() -> () {
| -- expected `()` because of this return type
17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
|
......
......@@ -2,10 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-20862.rs:12:5
|
11 | fn foo(x: i32) {
| -
| |
| possibly return type missing here?
| expected `()` because of this default return type
| - possibly return type missing here?
12 | |y| x + y
| ^^^^^^^^^ expected (), found closure
|
......
......@@ -11,9 +11,6 @@ error[E0277]: the trait bound `{integer}: Scalar` is not satisfied
error[E0308]: mismatched types
--> $DIR/issue-22645.rs:25:3
|
23 | fn main() {
| - expected `()` because of this default return type
24 | let b = Bob + 3.5;
25 | b + 3 //~ ERROR E0277
| ^^^^^ expected (), found struct `Bob`
|
......
......@@ -8,10 +8,7 @@ error[E0308]: mismatched types
--> $DIR/issue-3563.rs:13:9
|
12 | fn a(&self) {
| -
| |
| possibly return type missing here?
| expected `()` because of this default return type
| - possibly return type missing here?
13 | || self.b()
| ^^^^^^^^^^^ expected (), found closure
|
......
error[E0308]: mismatched types
--> $DIR/issue-5500.rs:12:5
|
11 | fn main() {
| - expected `()` because of this default return type
12 | &panic!()
| ^^^^^^^^^ expected (), found reference
|
......
error[E0308]: mismatched types
--> $DIR/unexpected-return-on-unit.rs:19:5
|
18 | fn bar() {
| - expected `()` because of this default return type
19 | foo()
| ^^^^^ expected (), found usize
|
......
error[E0308]: mismatched types
--> $DIR/equality.rs:25:5
|
21 | fn two(x: bool) -> impl Foo {
| -------- expected `i32` because of this return type
...
25 | 0_u32
| ^^^^^ expected i32, found u32
|
......
error[E0308]: mismatched types
--> $DIR/abridged.rs:26:5
|
25 | fn a() -> Foo {
| --- expected `Foo` because of this return type
26 | Some(Foo { bar: 1 })
| ^^^^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::option::Option`
|
......@@ -12,8 +10,6 @@ error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/abridged.rs:30:5
|
29 | fn a2() -> Foo {
| --- expected `Foo` because of this return type
30 | Ok(Foo { bar: 1})
| ^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::result::Result`
|
......@@ -23,8 +19,6 @@ error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/abridged.rs:34:5
|
33 | fn b() -> Option<Foo> {
| ----------- expected because of this return type
34 | Foo { bar: 1 }
| ^^^^^^^^^^^^^^ expected enum `std::option::Option`, found struct `Foo`
|
......@@ -34,8 +28,6 @@ error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/abridged.rs:38:5
|
37 | fn c() -> Result<Foo, Bar> {
| ---------------- expected because of this return type
38 | Foo { bar: 1 }
| ^^^^^^^^^^^^^^ expected enum `std::result::Result`, found struct `Foo`
|
......@@ -45,8 +37,6 @@ error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/abridged.rs:42:5
|
41 | fn d() -> X<X<String, String>, String> {
| ---------------------------- expected because of this return type
42 | / X {
43 | | x: X {
44 | | x: "".to_string(),
......@@ -62,8 +52,6 @@ error[E0308]: mismatched types
error[E0308]: mismatched types
--> $DIR/abridged.rs:52:5
|
51 | fn e() -> X<X<String, String>, String> {
| ---------------------------- expected because of this return type
52 | / X {
53 | | x: X {
54 | | x: "".to_string(),
......
......@@ -2,10 +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 `
| expected `()` because of this default return type
| - help: possibly return type missing here? `-> *mut Trait `
14 | t as *mut Trait
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|
......
......@@ -34,9 +34,6 @@ error[E0425]: cannot find function `is_directory` in this scope
error[E0308]: mismatched types
--> $DIR/token-error-correct-3.rs:25:13
|
20 | -> io::Result<bool> {
| ---------------- expected `()` because of this return type
...
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here? `;`
| |
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册