]> git.lizzy.rs Git - rust.git/commitdiff
Resolve type on return type suggestion
authorEsteban Küber <esteban@kuber.com.ar>
Sat, 9 Dec 2017 21:04:27 +0000 (13:04 -0800)
committerEsteban Küber <esteban@kuber.com.ar>
Sat, 9 Dec 2017 23:19:39 +0000 (15:19 -0800)
src/librustc_errors/emitter.rs
src/librustc_typeck/check/mod.rs
src/test/ui/codemap_tests/tab.stderr
src/test/ui/feature-gate/issue-43106-gating-of-builtin-attrs.stderr
src/test/ui/lint/suggestions.stderr
src/test/ui/mismatched_types/issue-19109.stderr
src/test/ui/suggestions/return-type.rs [new file with mode: 0644]
src/test/ui/suggestions/return-type.stderr [new file with mode: 0644]

index 16bbd755b886934b8ca790ea5ecd118d4d8abf82..439ded40ec1c77e16af41d7ad1158852907b5a01 100644 (file)
@@ -46,7 +46,7 @@ fn emit(&mut self, db: &DiagnosticBuilder) {
                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
index efcf498b72c1433376448627b9c47b4d74905194..be595c712649603573d39776eae0b0fd0921c5f5 100644 (file)
@@ -4503,7 +4503,8 @@ fn suggest_missing_return_type(&self,
             (&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?");
index e95078f25474aed374fae6fe79e9643002a7d45c..c887821c6d11af63de111ba460583efedc5d5355 100644 (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
    |
index 0e72442143b0747a6ad2ea3690ec64015ddd4ec2..be340b1ab9aee14f1e3c6e1e16a922543b887b09 100644 (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
 
index 7b84cc1f4b4909d24e61c4140589275220323e55..44cfb1a82a244516822dcad0f7c99ba8c6511416 100644 (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
 
index 714d1b397334ff366ae4102583a581fc93829950..2942619f64936fee3a84a593cc25e2c1a372f531 100644 (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
    |
diff --git a/src/test/ui/suggestions/return-type.rs b/src/test/ui/suggestions/return-type.rs
new file mode 100644 (file)
index 0000000..e637879
--- /dev/null
@@ -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 (file)
index 0000000..19c5d72
--- /dev/null
@@ -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
+