From fbd2d16c3f9a4ce04547fa30aa60e8cb0362fdc7 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Fri, 19 Jan 2018 17:43:08 +0530 Subject: [PATCH] Add ambiguity errors for macros --- src/librustdoc/clean/mod.rs | 54 ++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index adc2390e93d..4e86827bf2f 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -884,9 +884,9 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes, &format!("`{}` is both {} {} and {} {}", path_str, article1, kind1, article2, kind2)) - .help(&format!("try `{0}` if you want to select the {1}, \ - or `{2}@{3}` if you want to \ - select the {2}", + .help(&format!("try `{}` if you want to select the {}, \ + or `{}` if you want to \ + select the {}", disambig1, kind1, disambig2, kind2)) .emit(); @@ -920,8 +920,8 @@ impl Clean for [ast::Attribute] { link.trim_left_matches(prefix) } else if let Some(prefix) = ["const@", "static@", - "value@", "function@"].iter() - .find(|p| link.starts_with(**p)) { + "value@", "function@", "mod@", "fn@", "module@"] + .iter().find(|p| link.starts_with(**p)) { kind = PathKind::Value; link.trim_left_matches(prefix) } else if link.ends_with("()") { @@ -1007,28 +1007,44 @@ impl Clean for [ast::Attribute] { } } PathKind::Unknown => { - // try both! - // It is imperative we search for not-a-value first - // Otherwise we will find struct ctors for when we are looking - // for structs, and the link won't work. - if let Ok(path) = resolve(false) { + // try everything! + if let Some(macro_def) = macro_resolve() { + if let Ok(type_path) = resolve(false) { + let (type_kind, article, type_disambig) + = type_ns_kind(type_path.def, path_str); + ambiguity_error(cx, &attrs, path_str, + article, type_kind, &type_disambig, + "a", "macro", &format!("macro@{}", path_str)); + continue; + } else if let Ok(value_path) = resolve(true) { + let (value_kind, value_disambig) + = value_ns_kind(value_path.def, path_str) + .expect("struct and mod cases should have been \ + caught in previous branch"); + ambiguity_error(cx, &attrs, path_str, + "a", value_kind, &value_disambig, + "a", "macro", &format!("macro@{}", path_str)); + } + macro_def + } else if let Ok(type_path) = resolve(false) { + // It is imperative we search for not-a-value first + // Otherwise we will find struct ctors for when we are looking + // for structs, and the link won't work. // if there is something in both namespaces if let Ok(value_path) = resolve(true) { let kind = value_ns_kind(value_path.def, path_str); if let Some((value_kind, value_disambig)) = kind { let (type_kind, article, type_disambig) - = type_ns_kind(path.def); - ambiguity_error(cx, &attrs, - article, type_kind, type_disambig, - "a", value_kind, value_disambig); + = type_ns_kind(type_path.def, path_str); + ambiguity_error(cx, &attrs, path_str, + article, type_kind, &type_disambig, + "a", value_kind, &value_disambig); continue; } } - path.def - } else if let Ok(path) = resolve(true) { - path.def - } else if let Some(def) = macro_resolve() { - def + type_path.def + } else if let Ok(value_path) = resolve(true) { + value_path.def } else { // this could just be a normal link continue;