Description
In a project of mine I just got confronted with the following mouthful diagnostic:
error: type `for<'a, 'b> fn(&'a Query<EngineKind, std::result::Result<std::string::String, ()>>, for<'a> fn(EngineKind, context::Context<'a>) -> std::result::Result<std::string::String, ()>, EngineKind, context::Context<'b>) -> std::result::Result<std::string::String, ()> {invoke::<EngineKind, std::result::Result<std::string::String, ()>>}` is private
--> src/context.rs:73:5
|
73 | invoke(&$cx.store().$query, $query, $input, $cx)
| ^^^^^^ private type
|
::: src/build.rs:746:9
|
746 | crate::context::invoke!(cx.query_engine_path(self))
| --------------------------------------------------- in this macro invocation
|
= note: this error originates in the macro `crate::context::invoke` (in Nightly builds, run with -Z macro-backtrace for more info)
The underlying user error is the fact that the expansion of macro invoke
contains a function (invoke
) that isn't public enough at the usage site.
While rustc nicely highlights the private function, instead of talking about a private function, it talks about the visibility of the corresponding function type. That's technically correct but slightly confusing. Moreover, it blasts out the entire function type into the primary message (that I find most problematic)!
Primary messages should generally not contain things whose textual representation can easily grow arbitrarily large like types (I thought I once read about this in the diagnostic output style guide but apparently I'm misremembering).
In my case, I encountered this diagnostic as an "end-of-line diagnostic" in my editor (shown alongside the source code) and thus the only thing I basically saw was type `for<'a, 'b> fn(XYZXYZXZY...
.
Here's an MCVE:
#![feature(decl_macro)]
mod chamber {
pub(crate) macro invoke { () => { invoke() } }
fn invoke() {}
}
fn main() { chamber::invoke!(); }
error: type `fn() {invoke}` is private
--> src/main.rs:4:39
|
4 | pub(crate) macro invoke { () => { invoke() } }
| ^^^^^^ private type
...
8 | fn main() { chamber::invoke!(); }
| ------------------ in this macro invocation
|
= note: this error originates in the macro `chamber::invoke` (in Nightly builds, run with -Z macro-backtrace for more info)