]> git.lizzy.rs Git - rust.git/commitdiff
Better error message
authorManish Goregaokar <manishsmail@gmail.com>
Tue, 9 Jan 2018 05:20:52 +0000 (10:50 +0530)
committerManish Goregaokar <manishsmail@gmail.com>
Mon, 22 Jan 2018 09:54:31 +0000 (15:24 +0530)
src/librustdoc/clean/mod.rs

index 5e8d6301acb544bc9c5483ba7b78ae352745416a..4bc7b81b3f6eae05a925d99d25740815f3fb453b 100644 (file)
@@ -926,12 +926,19 @@ fn clean(&self, cx: &DocContext) -> Attributes {
                             // for structs, etc, and the link won't work.
                             if let Ok(path) = resolve(false) {
                                 path.def
-                            } else if let Ok(_path) = resolve(true) {
+                            } else if let Ok(path) = resolve(true) {
+                                let kind = match path.def {
+                                    Def::Variant(..) | Def::VariantCtor(..) => ("variant", format!("{}()", path_str)),
+                                    Def::Fn(..) => ("function", format!("{}()", path_str)),
+                                    Def::Method(..) => ("method", format!("{}()", path_str)),
+                                    Def::Const(..) => ("const", format!("const@{}", path_str)),
+                                    Def::Static(..) => ("static", format!("static@{}", path_str)),
+                                    _ => ("value", format!("static@{}", path_str)),
+                                };
                                 let sp = attrs.doc_strings.first().map_or(DUMMY_SP, |a| a.span());
-                                cx.sess().struct_span_err(sp, &format!("could not resolve `{}`",
-                                                                       path_str))
-                                         .help(&format!("try `{0}()`, `static@{0}`, or `const@{0}`",
-                                                        path_str))
+                                cx.sess().struct_span_err(sp, &format!("could not resolve `{}` as a type, it is a {}",
+                                                                       path_str, kind.0))
+                                         .help(&format!("try `{}`", kind.1))
                                          .emit();
                                 continue;
                             } else {