Skip to content

Commit fbd2d16

Browse files
committed
Add ambiguity errors for macros
1 parent 6256bff commit fbd2d16

File tree

1 file changed

+35
-19
lines changed

1 file changed

+35
-19
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,9 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
884884
&format!("`{}` is both {} {} and {} {}",
885885
path_str, article1, kind1,
886886
article2, kind2))
887-
.help(&format!("try `{0}` if you want to select the {1}, \
888-
or `{2}@{3}` if you want to \
889-
select the {2}",
887+
.help(&format!("try `{}` if you want to select the {}, \
888+
or `{}` if you want to \
889+
select the {}",
890890
disambig1, kind1, disambig2,
891891
kind2))
892892
.emit();
@@ -920,8 +920,8 @@ impl Clean<Attributes> for [ast::Attribute] {
920920
link.trim_left_matches(prefix)
921921
} else if let Some(prefix) =
922922
["const@", "static@",
923-
"value@", "function@"].iter()
924-
.find(|p| link.starts_with(**p)) {
923+
"value@", "function@", "mod@", "fn@", "module@"]
924+
.iter().find(|p| link.starts_with(**p)) {
925925
kind = PathKind::Value;
926926
link.trim_left_matches(prefix)
927927
} else if link.ends_with("()") {
@@ -1007,28 +1007,44 @@ impl Clean<Attributes> for [ast::Attribute] {
10071007
}
10081008
}
10091009
PathKind::Unknown => {
1010-
// try both!
1011-
// It is imperative we search for not-a-value first
1012-
// Otherwise we will find struct ctors for when we are looking
1013-
// for structs, and the link won't work.
1014-
if let Ok(path) = resolve(false) {
1010+
// try everything!
1011+
if let Some(macro_def) = macro_resolve() {
1012+
if let Ok(type_path) = resolve(false) {
1013+
let (type_kind, article, type_disambig)
1014+
= type_ns_kind(type_path.def, path_str);
1015+
ambiguity_error(cx, &attrs, path_str,
1016+
article, type_kind, &type_disambig,
1017+
"a", "macro", &format!("macro@{}", path_str));
1018+
continue;
1019+
} else if let Ok(value_path) = resolve(true) {
1020+
let (value_kind, value_disambig)
1021+
= value_ns_kind(value_path.def, path_str)
1022+
.expect("struct and mod cases should have been \
1023+
caught in previous branch");
1024+
ambiguity_error(cx, &attrs, path_str,
1025+
"a", value_kind, &value_disambig,
1026+
"a", "macro", &format!("macro@{}", path_str));
1027+
}
1028+
macro_def
1029+
} else if let Ok(type_path) = resolve(false) {
1030+
// It is imperative we search for not-a-value first
1031+
// Otherwise we will find struct ctors for when we are looking
1032+
// for structs, and the link won't work.
10151033
// if there is something in both namespaces
10161034
if let Ok(value_path) = resolve(true) {
10171035
let kind = value_ns_kind(value_path.def, path_str);
10181036
if let Some((value_kind, value_disambig)) = kind {
10191037
let (type_kind, article, type_disambig)
1020-
= type_ns_kind(path.def);
1021-
ambiguity_error(cx, &attrs,
1022-
article, type_kind, type_disambig,
1023-
"a", value_kind, value_disambig);
1038+
= type_ns_kind(type_path.def, path_str);
1039+
ambiguity_error(cx, &attrs, path_str,
1040+
article, type_kind, &type_disambig,
1041+
"a", value_kind, &value_disambig);
10241042
continue;
10251043
}
10261044
}
1027-
path.def
1028-
} else if let Ok(path) = resolve(true) {
1029-
path.def
1030-
} else if let Some(def) = macro_resolve() {
1031-
def
1045+
type_path.def
1046+
} else if let Ok(value_path) = resolve(true) {
1047+
value_path.def
10321048
} else {
10331049
// this could just be a normal link
10341050
continue;

0 commit comments

Comments
 (0)