mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 16:54:01 +00:00
Add ambiguity errors for macros
This commit is contained in:
parent
6256bff7a3
commit
fbd2d16c3f
@ -884,9 +884,9 @@ fn ambiguity_error(cx: &DocContext, attrs: &Attributes,
|
|||||||
&format!("`{}` is both {} {} and {} {}",
|
&format!("`{}` is both {} {} and {} {}",
|
||||||
path_str, article1, kind1,
|
path_str, article1, kind1,
|
||||||
article2, kind2))
|
article2, kind2))
|
||||||
.help(&format!("try `{0}` if you want to select the {1}, \
|
.help(&format!("try `{}` if you want to select the {}, \
|
||||||
or `{2}@{3}` if you want to \
|
or `{}` if you want to \
|
||||||
select the {2}",
|
select the {}",
|
||||||
disambig1, kind1, disambig2,
|
disambig1, kind1, disambig2,
|
||||||
kind2))
|
kind2))
|
||||||
.emit();
|
.emit();
|
||||||
@ -920,8 +920,8 @@ impl Clean<Attributes> for [ast::Attribute] {
|
|||||||
link.trim_left_matches(prefix)
|
link.trim_left_matches(prefix)
|
||||||
} else if let Some(prefix) =
|
} else if let Some(prefix) =
|
||||||
["const@", "static@",
|
["const@", "static@",
|
||||||
"value@", "function@"].iter()
|
"value@", "function@", "mod@", "fn@", "module@"]
|
||||||
.find(|p| link.starts_with(**p)) {
|
.iter().find(|p| link.starts_with(**p)) {
|
||||||
kind = PathKind::Value;
|
kind = PathKind::Value;
|
||||||
link.trim_left_matches(prefix)
|
link.trim_left_matches(prefix)
|
||||||
} else if link.ends_with("()") {
|
} else if link.ends_with("()") {
|
||||||
@ -1007,28 +1007,44 @@ impl Clean<Attributes> for [ast::Attribute] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
PathKind::Unknown => {
|
PathKind::Unknown => {
|
||||||
// try both!
|
// try everything!
|
||||||
// It is imperative we search for not-a-value first
|
if let Some(macro_def) = macro_resolve() {
|
||||||
// Otherwise we will find struct ctors for when we are looking
|
if let Ok(type_path) = resolve(false) {
|
||||||
// for structs, and the link won't work.
|
let (type_kind, article, type_disambig)
|
||||||
if let Ok(path) = resolve(false) {
|
= 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 there is something in both namespaces
|
||||||
if let Ok(value_path) = resolve(true) {
|
if let Ok(value_path) = resolve(true) {
|
||||||
let kind = value_ns_kind(value_path.def, path_str);
|
let kind = value_ns_kind(value_path.def, path_str);
|
||||||
if let Some((value_kind, value_disambig)) = kind {
|
if let Some((value_kind, value_disambig)) = kind {
|
||||||
let (type_kind, article, type_disambig)
|
let (type_kind, article, type_disambig)
|
||||||
= type_ns_kind(path.def);
|
= type_ns_kind(type_path.def, path_str);
|
||||||
ambiguity_error(cx, &attrs,
|
ambiguity_error(cx, &attrs, path_str,
|
||||||
article, type_kind, type_disambig,
|
article, type_kind, &type_disambig,
|
||||||
"a", value_kind, value_disambig);
|
"a", value_kind, &value_disambig);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.def
|
type_path.def
|
||||||
} else if let Ok(path) = resolve(true) {
|
} else if let Ok(value_path) = resolve(true) {
|
||||||
path.def
|
value_path.def
|
||||||
} else if let Some(def) = macro_resolve() {
|
|
||||||
def
|
|
||||||
} else {
|
} else {
|
||||||
// this could just be a normal link
|
// this could just be a normal link
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user