Improve proc macro errors a bit

Distinguish between
 - there is no build data (for some reason?)
 - there is build data, but the cargo package didn't build a proc macro dylib
 - there is a proc macro dylib, but it didn't contain the proc macro we expected
 - the name did not resolve to any macro (this is now an
 unresolved_macro_call even for attributes)

I changed the handling of disabled attribute macro expansion to
immediately ignore the macro and report an unresolved_proc_macro,
because otherwise they would now result in loud unresolved_macro_call
errors. I hope this doesn't break anything.

Also try to improve error ranges for unresolved_macro_call / macro_error
by reusing the code for unresolved_proc_macro. It's not perfect but
probably better than before.
This commit is contained in:
Florian Diebold 2022-06-24 13:03:13 +02:00
parent 32b40ded0f
commit c80c34867f
10 changed files with 164 additions and 163 deletions

View file

@ -459,7 +459,7 @@ fn project_json_to_crate_graph(
krate.display_name.as_ref().map(|it| it.canonical_name()).unwrap_or(""),
&it,
),
None => Ok(Vec::new()),
None => Err("no proc macro dylib present".into()),
};
let target_cfgs = match krate.target.as_deref() {
@ -870,9 +870,10 @@ fn add_target_crate_root(
}
}
let proc_macro = match build_data.as_ref().and_then(|it| it.proc_macro_dylib_path.as_ref()) {
Some(it) => load_proc_macro(it),
None => Ok(Vec::new()),
let proc_macro = match build_data.as_ref().map(|it| it.proc_macro_dylib_path.as_ref()) {
Some(Some(it)) => load_proc_macro(it),
Some(None) => Err("no proc macro dylib present".into()),
None => Err("no build data".into()),
};
let display_name = CrateDisplayName::from_canonical_name(cargo_name.to_string());