about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2018-09-04 10:41:33 -0700
committerEsteban Küber <esteban@kuber.com.ar>2018-09-05 03:34:16 -0700
commitd7a74be09b3c3d5ad015be31c51208260aa85007 (patch)
tree12af8e4d4fe2287e58d8a3aa25071a4dbf4afb2e
parent1c2e17f4e3a2070a7f703f51e29c1c388ef703b6 (diff)
downloadrust-d7a74be09b3c3d5ad015be31c51208260aa85007.tar.gz
rust-d7a74be09b3c3d5ad015be31c51208260aa85007.zip
Fix incorrect outer function type parameter message
-rw-r--r--src/librustc_resolve/lib.rs9
-rw-r--r--src/test/ui/error-codes/E0401.stderr7
-rw-r--r--src/test/ui/issues/issue-12796.stderr7
-rw-r--r--src/test/ui/use-self-in-inner-fn.rs24
-rw-r--r--src/test/ui/use-self-in-inner-fn.stderr15
5 files changed, 55 insertions, 7 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 0f6a9742309..19a4fdae485 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -197,6 +197,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
             err.span_label(span, "use of type variable from outer function");
 
             let cm = resolver.session.source_map();
+            let mut is_self = false;
             match outer_def {
                 Def::SelfTy(_, maybe_impl_defid) => {
                     if let Some(impl_span) = maybe_impl_defid.map_or(None,
@@ -204,6 +205,7 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
                         err.span_label(reduce_impl_span_to_impl_keyword(cm, impl_span),
                                     "`Self` type implicitly declared here, on the `impl`");
                     }
+                    is_self = true;
                 },
                 Def::TyParam(typaram_defid) => {
                     if let Some(typaram_span) = resolver.definitions.opt_span(typaram_defid) {
@@ -219,7 +221,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
             // Try to retrieve the span of the function signature and generate a new message with
             // a local type parameter
             let sugg_msg = "try using a local type parameter instead";
-            if let Some((sugg_span, new_snippet)) = cm.generate_local_type_param_snippet(span) {
+            if is_self {
+                // Suggest using the actual type
+                err.span_label(span, "use a materialized type here instead");
+            } else if let Some(
+                (sugg_span, new_snippet),
+            ) = cm.generate_local_type_param_snippet(span) {
                 // Suggest the modification to the user
                 err.span_suggestion_with_applicability(
                     sugg_span,
diff --git a/src/test/ui/error-codes/E0401.stderr b/src/test/ui/error-codes/E0401.stderr
index b088e8330e9..90e8d2d2479 100644
--- a/src/test/ui/error-codes/E0401.stderr
+++ b/src/test/ui/error-codes/E0401.stderr
@@ -27,9 +27,10 @@ LL | impl<T> Iterator for A<T> {
    | ---- `Self` type implicitly declared here, on the `impl`
 ...
 LL |         fn helper(sel: &Self) -> u8 { //~ ERROR E0401
-   |            ------       ^^^^ use of type variable from outer function
-   |            |
-   |            help: try using a local type parameter instead: `helper<Self>`
+   |                         ^^^^
+   |                         |
+   |                         use of type variable from outer function
+   |                         use a materialized type here instead
 
 error: aborting due to 3 previous errors
 
diff --git a/src/test/ui/issues/issue-12796.stderr b/src/test/ui/issues/issue-12796.stderr
index c8bedd3853c..078c1db5de5 100644
--- a/src/test/ui/issues/issue-12796.stderr
+++ b/src/test/ui/issues/issue-12796.stderr
@@ -2,9 +2,10 @@ error[E0401]: can't use type parameters from outer function
   --> $DIR/issue-12796.rs:13:22
    |
 LL |         fn inner(_: &Self) {
-   |            -----     ^^^^ use of type variable from outer function
-   |            |
-   |            help: try using a local type parameter instead: `inner<Self>`
+   |                      ^^^^
+   |                      |
+   |                      use of type variable from outer function
+   |                      use a materialized type here instead
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/use-self-in-inner-fn.rs b/src/test/ui/use-self-in-inner-fn.rs
new file mode 100644
index 00000000000..a1183854eb5
--- /dev/null
+++ b/src/test/ui/use-self-in-inner-fn.rs
@@ -0,0 +1,24 @@
+// Copyright 2018 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 A;
+
+impl A {
+//~^ NOTE `Self` type implicitly declared here, on the `impl`
+    fn banana(&mut self) {
+        fn peach(this: &Self) {
+        //~^ ERROR can't use type parameters from outer function
+        //~| NOTE use of type variable from outer function
+        //~| NOTE use a materialized type here instead
+        }
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/use-self-in-inner-fn.stderr b/src/test/ui/use-self-in-inner-fn.stderr
new file mode 100644
index 00000000000..c14e4895d99
--- /dev/null
+++ b/src/test/ui/use-self-in-inner-fn.stderr
@@ -0,0 +1,15 @@
+error[E0401]: can't use type parameters from outer function
+  --> $DIR/use-self-in-inner-fn.rs:16:25
+   |
+LL | impl A {
+   | ---- `Self` type implicitly declared here, on the `impl`
+...
+LL |         fn peach(this: &Self) {
+   |                         ^^^^
+   |                         |
+   |                         use of type variable from outer function
+   |                         use a materialized type here instead
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0401`.