Skip to content

Commit 95a0458

Browse files
committed
Resolve type on return type suggestion
1 parent c7b6d82 commit 95a0458

File tree

8 files changed

+51
-7
lines changed

8 files changed

+51
-7
lines changed

src/librustc_errors/emitter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl Emitter for EmitterWriter {
4646
sugg.msg.split_whitespace().count() < 10 &&
4747
// don't display multiline suggestions as labels
4848
!sugg.substitutions[0].parts[0].snippet.contains('\n') {
49-
let substitution = &sugg.substitutions[0].parts[0].snippet;
49+
let substitution = &sugg.substitutions[0].parts[0].snippet.trim();
5050
let msg = if substitution.len() == 0 || !sugg.show_code_when_inline {
5151
// This substitution is only removal or we explicitly don't want to show the
5252
// code inline, don't show it

src/librustc_typeck/check/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4503,7 +4503,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
45034503
(&hir::FunctionRetTy::DefaultReturn(span), true, true) => {
45044504
err.span_suggestion(span,
45054505
"try adding a return type",
4506-
format!("-> {} ", found));
4506+
format!("-> {} ",
4507+
self.resolve_type_vars_with_obligations(found)));
45074508
}
45084509
(&hir::FunctionRetTy::DefaultReturn(span), false, true) => {
45094510
err.span_label(span, "possibly return type missing here?");

src/test/ui/codemap_tests/tab.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ error[E0308]: mismatched types
88
--> $DIR/tab.rs:18:2
99
|
1010
17 | fn foo() {
11-
| - help: try adding a return type: `-> &'static str `
11+
| - help: try adding a return type: `-> &'static str`
1212
18 | "bar boo" //~ ERROR mismatched types
1313
| ^^^^^^^^^^^^^^^^^^^^ expected (), found reference
1414
|

src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ warning: function is marked #[no_mangle], but not exported
548548
426 | #[no_mangle = "3500"] fn f() { }
549549
| -^^^^^^^^^
550550
| |
551-
| help: try making it public: `pub `
551+
| help: try making it public: `pub`
552552
|
553553
= note: #[warn(private_no_mangle_fns)] on by default
554554

src/test/ui/lint/suggestions.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ warning: static is marked #[no_mangle], but not exported
3838
14 | #[no_mangle] static SHENZHOU: usize = 1; // should suggest `pub`
3939
| -^^^^^^^^^^^^^^^^^^^^^^^^^^
4040
| |
41-
| help: try making it public: `pub `
41+
| help: try making it public: `pub`
4242
|
4343
= note: #[warn(private_no_mangle_statics)] on by default
4444

@@ -68,7 +68,7 @@ warning: function is marked #[no_mangle], but not exported
6868
24 | fn rio_grande() {} // should suggest `pub`
6969
| -^^^^^^^^^^^^^^^^^
7070
| |
71-
| help: try making it public: `pub `
71+
| help: try making it public: `pub`
7272
|
7373
= note: #[warn(private_no_mangle_fns)] on by default
7474

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: try adding a return type: `-> *mut Trait `
5+
| - help: try adding a return type: `-> *mut Trait`
66
14 | t as *mut Trait
77
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
88
|
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S<T> {
12+
t: T,
13+
}
14+
15+
fn foo<T>(x: T) -> S<T> {
16+
S { t: x }
17+
}
18+
19+
fn bar() {
20+
foo(4 as usize)
21+
//~^ ERROR mismatched types
22+
}
23+
24+
fn main() {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/return-type.rs:20:5
3+
|
4+
20 | foo(4 as usize)
5+
| ^^^^^^^^^^^^^^^ expected (), found struct `S`
6+
|
7+
= note: expected type `()`
8+
found type `S<usize>`
9+
help: try adding a semicolon
10+
|
11+
20 | foo(4 as usize);
12+
| ^
13+
help: try adding a return type
14+
|
15+
19 | fn bar() -> S<usize> {
16+
| ^^^^^^^^^^^
17+
18+
error: aborting due to previous error
19+

0 commit comments

Comments
 (0)