Skip to content

Diagnostic talks about and prints entire function *type* on private function in expansion of macro 2.0 #143455

Open
@fmease

Description

@fmease

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)A-diagnosticsArea: Messages for errors, warnings, and lintsA-visibilityArea: Visibility / privacyD-confusingDiagnostics: Confusing error or lint that should be reworked.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.F-decl_macro`#![feature(decl_macro)]`P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions