about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-06-02 18:10:37 -0700
committerbors <bors@rust-lang.org>2016-06-02 18:10:37 -0700
commit0646e8ae6ee2d6697b828a6512357c135f834633 (patch)
treec18800fd602e7f1bfb5078b7016dcc3825b53fc5
parent915b003e32ca169c5c9b907a5457bc03582d5f67 (diff)
parentf4e6f3c186ebe18c34acb1afc37d8fd1878f76de (diff)
downloadrust-0646e8ae6ee2d6697b828a6512357c135f834633.tar.gz
rust-0646e8ae6ee2d6697b828a6512357c135f834633.zip
Auto merge of #33878 - GuillaumeGomez:improve_helps, r=jonathandturner
Improve help messages for E0425

Fixes #33876.

r? @Manishearth

cc @steveklabnik
cc @jonathandturner
-rw-r--r--src/librustc_resolve/lib.rs22
-rw-r--r--src/test/compile-fail/issue-2356.rs2
-rw-r--r--src/test/compile-fail/issue-33876.rs26
-rw-r--r--src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs18
4 files changed, 51 insertions, 17 deletions
diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs
index 36053d3c4ff..4941f867f06 100644
--- a/src/librustc_resolve/lib.rs
+++ b/src/librustc_resolve/lib.rs
@@ -153,7 +153,8 @@ enum ResolutionError<'a> {
         message: &'a str,
         context: UnresolvedNameContext<'a>,
         is_static_method: bool,
-        is_field: bool
+        is_field: bool,
+        def: Def,
     },
     /// error E0426: use of undeclared label
     UndeclaredLabel(&'a str),
@@ -413,7 +414,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
                              argument is missing?")
         }
         ResolutionError::UnresolvedName { path, message: msg, context, is_static_method,
-                                          is_field } => {
+                                          is_field, def } => {
             let mut err = struct_span_err!(resolver.session,
                                            span,
                                            E0425,
@@ -430,19 +431,20 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
                 UnresolvedNameContext::PathIsMod(parent) => {
                     err.help(&match parent.map(|parent| &parent.node) {
                         Some(&ExprKind::Field(_, ident)) => {
-                            format!("To reference an item from the `{module}` module, \
+                            format!("to reference an item from the `{module}` module, \
                                      use `{module}::{ident}`",
                                     module = path,
                                     ident = ident.node)
                         }
                         Some(&ExprKind::MethodCall(ident, _, _)) => {
-                            format!("To call a function from the `{module}` module, \
+                            format!("to call a function from the `{module}` module, \
                                      use `{module}::{ident}(..)`",
                                     module = path,
                                     ident = ident.node)
                         }
                         _ => {
-                            format!("Module `{module}` cannot be used as an expression",
+                            format!("{def} `{module}` cannot be used as an expression",
+                                    def = def.kind_name(),
                                     module = path)
                         }
                     });
@@ -1113,7 +1115,8 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
                         message: "",
                         context: UnresolvedNameContext::Other,
                         is_static_method: false,
-                        is_field: false
+                        is_field: false,
+                        def: Def::Err,
                     };
                 resolve_error(self, path.span, error);
                 Def::Err
@@ -3063,6 +3066,7 @@ impl<'a> Resolver<'a> {
                                 };
 
                                 let mut context =  UnresolvedNameContext::Other;
+                                let mut def = Def::Err;
                                 if !msg.is_empty() {
                                     msg = format!(". Did you mean {}?", msg);
                                 } else {
@@ -3075,7 +3079,10 @@ impl<'a> Resolver<'a> {
                                     match self.resolve_module_path(&name_path[..],
                                                                    UseLexicalScope,
                                                                    expr.span) {
-                                        Success(_) => {
+                                        Success(e) => {
+                                            if let Some(def_type) = e.def {
+                                                def = def_type;
+                                            }
                                             context = UnresolvedNameContext::PathIsMod(parent);
                                         },
                                         _ => {},
@@ -3090,6 +3097,7 @@ impl<'a> Resolver<'a> {
                                                   context: context,
                                                   is_static_method: method_scope && is_static,
                                                   is_field: is_field,
+                                                  def: def,
                                               });
                             }
                         }
diff --git a/src/test/compile-fail/issue-2356.rs b/src/test/compile-fail/issue-2356.rs
index 5e816bcfa61..d7ec1ed6739 100644
--- a/src/test/compile-fail/issue-2356.rs
+++ b/src/test/compile-fail/issue-2356.rs
@@ -88,6 +88,6 @@ impl cat {
 fn main() {
     self += 1;
     //~^ ERROR: unresolved name `self`
-    //~| HELP: Module
+    //~| HELP: module `self`
     // it's a bug if this suggests a missing `self` as we're not in a method
 }
diff --git a/src/test/compile-fail/issue-33876.rs b/src/test/compile-fail/issue-33876.rs
new file mode 100644
index 00000000000..d95890730a0
--- /dev/null
+++ b/src/test/compile-fail/issue-33876.rs
@@ -0,0 +1,26 @@
+// Copyright 2016 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.
+
+#![feature(reflect_marker)]
+
+use std::marker::Reflect;
+use std::any::Any;
+
+struct Foo;
+
+trait Bar {}
+
+impl Bar for Foo {}
+
+fn main() {
+    let any: &Any = &Bar; //~ ERROR E0425
+                          //~| HELP trait `Bar`
+    if any.is::<u32>() { println!("u32"); }
+}
diff --git a/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs b/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs
index 412c90fd214..4a816ea7572 100644
--- a/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs
+++ b/src/test/compile-fail/suggest-path-instead-of-mod-dot-item.rs
@@ -26,51 +26,51 @@ pub mod a {
 fn h1() -> i32 {
     a.I
         //~^ ERROR E0425
-        //~| HELP To reference an item from the `a` module, use `a::I`
+        //~| HELP to reference an item from the `a` module, use `a::I`
 }
 
 fn h2() -> i32 {
     a.g()
         //~^ ERROR E0425
-        //~| HELP To call a function from the `a` module, use `a::g(..)`
+        //~| HELP to call a function from the `a` module, use `a::g(..)`
 }
 
 fn h3() -> i32 {
     a.b.J
         //~^ ERROR E0425
-        //~| HELP To reference an item from the `a` module, use `a::b`
+        //~| HELP to reference an item from the `a` module, use `a::b`
 }
 
 fn h4() -> i32 {
     a::b.J
         //~^ ERROR E0425
-        //~| HELP To reference an item from the `a::b` module, use `a::b::J`
+        //~| HELP to reference an item from the `a::b` module, use `a::b::J`
 }
 
 fn h5() {
     a.b.f();
         //~^ ERROR E0425
-        //~| HELP To reference an item from the `a` module, use `a::b`
+        //~| HELP to reference an item from the `a` module, use `a::b`
     let v = Vec::new();
     v.push(a::b);
         //~^ ERROR E0425
-        //~| HELP Module `a::b` cannot be used as an expression
+        //~| HELP module `a::b` cannot be used as an expression
 }
 
 fn h6() -> i32 {
     a::b.f()
         //~^ ERROR E0425
-        //~| HELP To call a function from the `a::b` module, use `a::b::f(..)`
+        //~| HELP to call a function from the `a::b` module, use `a::b::f(..)`
 }
 
 fn h7() {
     a::b
         //~^ ERROR E0425
-        //~| HELP Module `a::b` cannot be used as an expression
+        //~| HELP module `a::b` cannot be used as an expression
 }
 
 fn h8() -> i32 {
     a::b()
         //~^ ERROR E0425
-        //~| HELP Module `a::b` cannot be used as an expression
+        //~| HELP module `a::b` cannot be used as an expression
 }