Skip to content

Commit

Permalink
Auto merge of #46608 - estebank:resolve-return, r=nikomatsakis
Browse files Browse the repository at this point in the history
Resolve type on return type suggestion

Partially address #45871.
  • Loading branch information
bors committed Dec 11, 2017
2 parents ddbb27a + 95a0458 commit 9fe7aa3
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/codemap_tests/tab.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/lint/suggestions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/mismatched_types/issue-19109.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/suggestions/return-type.rs
Original file line number Diff line number Diff line change
@@ -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() {}
19 changes: 19 additions & 0 deletions src/test/ui/suggestions/return-type.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9fe7aa3

Please sign in to comment.