diff options
| author | bors <bors@rust-lang.org> | 2017-12-11 21:14:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-11 21:14:13 +0000 |
| commit | 9fe7aa353fac5084d0a44d6a15970310e9be67f4 (patch) | |
| tree | f36ba36d4a32f6eb675b28ab061f377ff3db4a15 | |
| parent | ddbb27a2414db79bef0a5858b440b04b545c80fa (diff) | |
| parent | 95a045835882e0f9590115ad992b650b71e8197c (diff) | |
| download | rust-9fe7aa353fac5084d0a44d6a15970310e9be67f4.tar.gz rust-9fe7aa353fac5084d0a44d6a15970310e9be67f4.zip | |
Auto merge of #46608 - estebank:resolve-return, r=nikomatsakis
Resolve type on return type suggestion Partially address #45871.
| -rw-r--r-- | src/librustc_errors/emitter.rs | 2 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 3 | ||||
| -rw-r--r-- | src/test/ui/codemap_tests/tab.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/suggestions.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/mismatched_types/issue-19109.stderr | 2 | ||||
| -rw-r--r-- | src/test/ui/suggestions/return-type.rs | 24 | ||||
| -rw-r--r-- | src/test/ui/suggestions/return-type.stderr | 19 |
8 files changed, 51 insertions, 7 deletions
diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 16bbd755b88..439ded40ec1 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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 diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 24ffc0ca542..0139e9b3cd7 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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?"); diff --git a/src/test/ui/codemap_tests/tab.stderr b/src/test/ui/codemap_tests/tab.stderr index e95078f2547..c887821c6d1 100644 --- a/src/test/ui/codemap_tests/tab.stderr +++ b/src/test/ui/codemap_tests/tab.stderr @@ -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 | diff --git a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr index 0e72442143b..be340b1ab9a 100644 --- a/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr +++ b/src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr @@ -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 diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr index 7b84cc1f4b4..44cfb1a82a2 100644 --- a/src/test/ui/lint/suggestions.stderr +++ b/src/test/ui/lint/suggestions.stderr @@ -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 diff --git a/src/test/ui/mismatched_types/issue-19109.stderr b/src/test/ui/mismatched_types/issue-19109.stderr index 714d1b39733..2942619f649 100644 --- a/src/test/ui/mismatched_types/issue-19109.stderr +++ b/src/test/ui/mismatched_types/issue-19109.stderr @@ -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 | diff --git a/src/test/ui/suggestions/return-type.rs b/src/test/ui/suggestions/return-type.rs new file mode 100644 index 00000000000..e63787949a4 --- /dev/null +++ b/src/test/ui/suggestions/return-type.rs @@ -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() {} diff --git a/src/test/ui/suggestions/return-type.stderr b/src/test/ui/suggestions/return-type.stderr new file mode 100644 index 00000000000..19c5d72dd7b --- /dev/null +++ b/src/test/ui/suggestions/return-type.stderr @@ -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 + |
