Skip to content

Commit c13a913

Browse files
committed
Don't naively point to return type on type error
1 parent 27d4b31 commit c13a913

12 files changed

+3
-67
lines changed

src/librustc_typeck/check/coercion.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1174,12 +1174,6 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E>
11741174
expected, found,
11751175
cause.span, blk_id);
11761176
}
1177-
ObligationCauseCode::ReturnType(ret_id) => {
1178-
db = fcx.report_mismatched_types(cause, expected, found, err);
1179-
if let Some((fn_decl, _)) = fcx.get_fn_decl(ret_id) {
1180-
fcx.point_to_type_requirement(&mut db, &fn_decl, expected);
1181-
}
1182-
}
11831177
_ => {
11841178
db = fcx.report_mismatched_types(cause, expected, found, err);
11851179
}

src/librustc_typeck/check/mod.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4261,35 +4261,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
42614261
self.suggest_missing_semicolon(err, expression, expected, cause_span);
42624262

42634263
if let Some((fn_decl, is_main)) = self.get_fn_decl(blk_id) {
4264-
self.point_to_type_requirement(err, &fn_decl, expected);
42654264
// `fn main()` must return `()`, do not suggest changing return type
42664265
if !is_main {
42674266
self.suggest_missing_return_type(err, &fn_decl, found);
42684267
}
42694268
}
42704269
}
42714270

4272-
pub fn point_to_type_requirement(&self,
4273-
err: &mut DiagnosticBuilder<'tcx>,
4274-
fn_decl: &hir::FnDecl,
4275-
ty: Ty<'tcx>) {
4276-
let msg = if let &hir::FnDecl {
4277-
output: hir::FunctionRetTy::DefaultReturn(_), ..
4278-
} = fn_decl {
4279-
"default "
4280-
} else {
4281-
""
4282-
};
4283-
let ty = self.resolve_type_vars_if_possible(&ty);
4284-
if ty.to_string().len() < 10 {
4285-
err.span_label(fn_decl.output.span(),
4286-
format!("expected `{}` because of this {}return type", ty, msg));
4287-
} else {
4288-
err.span_label(fn_decl.output.span(),
4289-
format!("expected because of this {}return type", msg));
4290-
}
4291-
}
4292-
42934271
/// A common error is to forget to add a semicolon at the end of a block:
42944272
///
42954273
/// ```

src/test/ui/block-result/issue-13624.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-13624.rs:17:5
33
|
4-
16 | pub fn get_enum_struct_variant() -> () {
5-
| -- expected `()` because of this return type
64
17 | Enum::EnumStructVariant { x: 1, y: 2, z: 3 }
75
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `a::Enum`
86
|

src/test/ui/block-result/issue-20862.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-20862.rs:12:5
33
|
44
11 | fn foo(x: i32) {
5-
| -
6-
| |
7-
| possibly return type missing here?
8-
| expected `()` because of this default return type
5+
| - possibly return type missing here?
96
12 | |y| x + y
107
| ^^^^^^^^^ expected (), found closure
118
|

src/test/ui/block-result/issue-22645.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ error[E0277]: the trait bound `{integer}: Scalar` is not satisfied
1111
error[E0308]: mismatched types
1212
--> $DIR/issue-22645.rs:25:3
1313
|
14-
23 | fn main() {
15-
| - expected `()` because of this default return type
16-
24 | let b = Bob + 3.5;
1714
25 | b + 3 //~ ERROR E0277
1815
| ^^^^^ expected (), found struct `Bob`
1916
|

src/test/ui/block-result/issue-3563.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ error[E0308]: mismatched types
88
--> $DIR/issue-3563.rs:13:9
99
|
1010
12 | fn a(&self) {
11-
| -
12-
| |
13-
| possibly return type missing here?
14-
| expected `()` because of this default return type
11+
| - possibly return type missing here?
1512
13 | || self.b()
1613
| ^^^^^^^^^^^ expected (), found closure
1714
|

src/test/ui/block-result/issue-5500.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/issue-5500.rs:12:5
33
|
4-
11 | fn main() {
5-
| - expected `()` because of this default return type
64
12 | &panic!()
75
| ^^^^^^^^^ expected (), found reference
86
|

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/unexpected-return-on-unit.rs:19:5
33
|
4-
18 | fn bar() {
5-
| - expected `()` because of this default return type
64
19 | foo()
75
| ^^^^^ expected (), found usize
86
|

src/test/ui/impl-trait/equality.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/equality.rs:25:5
33
|
4-
21 | fn two(x: bool) -> impl Foo {
5-
| -------- expected `i32` because of this return type
6-
...
74
25 | 0_u32
85
| ^^^^^ expected i32, found u32
96
|

src/test/ui/mismatched_types/abridged.stderr

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
error[E0308]: mismatched types
22
--> $DIR/abridged.rs:26:5
33
|
4-
25 | fn a() -> Foo {
5-
| --- expected `Foo` because of this return type
64
26 | Some(Foo { bar: 1 })
75
| ^^^^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::option::Option`
86
|
@@ -12,8 +10,6 @@ error[E0308]: mismatched types
1210
error[E0308]: mismatched types
1311
--> $DIR/abridged.rs:30:5
1412
|
15-
29 | fn a2() -> Foo {
16-
| --- expected `Foo` because of this return type
1713
30 | Ok(Foo { bar: 1})
1814
| ^^^^^^^^^^^^^^^^^ expected struct `Foo`, found enum `std::result::Result`
1915
|
@@ -23,8 +19,6 @@ error[E0308]: mismatched types
2319
error[E0308]: mismatched types
2420
--> $DIR/abridged.rs:34:5
2521
|
26-
33 | fn b() -> Option<Foo> {
27-
| ----------- expected because of this return type
2822
34 | Foo { bar: 1 }
2923
| ^^^^^^^^^^^^^^ expected enum `std::option::Option`, found struct `Foo`
3024
|
@@ -34,8 +28,6 @@ error[E0308]: mismatched types
3428
error[E0308]: mismatched types
3529
--> $DIR/abridged.rs:38:5
3630
|
37-
37 | fn c() -> Result<Foo, Bar> {
38-
| ---------------- expected because of this return type
3931
38 | Foo { bar: 1 }
4032
| ^^^^^^^^^^^^^^ expected enum `std::result::Result`, found struct `Foo`
4133
|
@@ -45,8 +37,6 @@ error[E0308]: mismatched types
4537
error[E0308]: mismatched types
4638
--> $DIR/abridged.rs:42:5
4739
|
48-
41 | fn d() -> X<X<String, String>, String> {
49-
| ---------------------------- expected because of this return type
5040
42 | / X {
5141
43 | | x: X {
5242
44 | | x: "".to_string(),
@@ -62,8 +52,6 @@ error[E0308]: mismatched types
6252
error[E0308]: mismatched types
6353
--> $DIR/abridged.rs:52:5
6454
|
65-
51 | fn e() -> X<X<String, String>, String> {
66-
| ---------------------------- expected because of this return type
6755
52 | / X {
6856
53 | | x: X {
6957
54 | | x: "".to_string(),

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0308]: mismatched types
22
--> $DIR/issue-19109.rs:14:5
33
|
44
13 | fn function(t: &mut Trait) {
5-
| -
6-
| |
7-
| help: possibly return type missing here? `-> *mut Trait `
8-
| expected `()` because of this default return type
5+
| - help: possibly return type missing here? `-> *mut Trait `
96
14 | t as *mut Trait
107
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
118
|

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ error[E0425]: cannot find function `is_directory` in this scope
3434
error[E0308]: mismatched types
3535
--> $DIR/token-error-correct-3.rs:25:13
3636
|
37-
20 | -> io::Result<bool> {
38-
| ---------------- expected `()` because of this return type
39-
...
4037
25 | fs::create_dir_all(path.as_ref()).map(|()| true) //~ ERROR: mismatched types
4138
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- help: did you mean to add a semicolon here? `;`
4239
| |

0 commit comments

Comments
 (0)