Auto merge of #46608 - estebank:resolve-return, r=nikomatsakis

Resolve type on return type suggestion

Partially address #45871.
This commit is contained in:
bors 2017-12-11 21:14:13 +00:00
commit 9fe7aa353f
8 changed files with 51 additions and 7 deletions

View File

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

View File

@ -4503,7 +4503,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(&hir::FunctionRetTy::DefaultReturn(span), true, true) => {
err.span_suggestion(span,
"try adding a return type",
format!("-> {} ", found));
format!("-> {} ",
self.resolve_type_vars_with_obligations(found)));
}
(&hir::FunctionRetTy::DefaultReturn(span), false, true) => {
err.span_label(span, "possibly return type missing here?");

View File

@ -8,7 +8,7 @@ error[E0308]: mismatched types
--> $DIR/tab.rs:18:2
|
17 | fn foo() {
| - help: try adding a return type: `-> &'static str `
| - help: try adding a return type: `-> &'static str`
18 | "bar boo" //~ ERROR mismatched types
| ^^^^^^^^^^^^^^^^^^^^ expected (), found reference
|

View File

@ -548,7 +548,7 @@ warning: function is marked #[no_mangle], but not exported
426 | #[no_mangle = "3500"] fn f() { }
| -^^^^^^^^^
| |
| help: try making it public: `pub `
| help: try making it public: `pub`
|
= note: #[warn(private_no_mangle_fns)] on by default

View File

@ -38,7 +38,7 @@ warning: static is marked #[no_mangle], but not exported
14 | #[no_mangle] static SHENZHOU: usize = 1; // should suggest `pub`
| -^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| help: try making it public: `pub `
| help: try making it public: `pub`
|
= note: #[warn(private_no_mangle_statics)] on by default
@ -68,7 +68,7 @@ warning: function is marked #[no_mangle], but not exported
24 | fn rio_grande() {} // should suggest `pub`
| -^^^^^^^^^^^^^^^^^
| |
| help: try making it public: `pub `
| help: try making it public: `pub`
|
= note: #[warn(private_no_mangle_fns)] on by default

View File

@ -2,7 +2,7 @@ error[E0308]: mismatched types
--> $DIR/issue-19109.rs:14:5
|
13 | fn function(t: &mut Trait) {
| - help: try adding a return type: `-> *mut Trait `
| - help: try adding a return type: `-> *mut Trait`
14 | t as *mut Trait
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|

View File

@ -0,0 +1,24 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
struct S<T> {
t: T,
}
fn foo<T>(x: T) -> S<T> {
S { t: x }
}
fn bar() {
foo(4 as usize)
//~^ ERROR mismatched types
}
fn main() {}

View File

@ -0,0 +1,19 @@
error[E0308]: mismatched types
--> $DIR/return-type.rs:20:5
|
20 | foo(4 as usize)
| ^^^^^^^^^^^^^^^ expected (), found struct `S`
|
= note: expected type `()`
found type `S<usize>`
help: try adding a semicolon
|
20 | foo(4 as usize);
| ^
help: try adding a return type
|
19 | fn bar() -> S<usize> {
| ^^^^^^^^^^^
error: aborting due to previous error