Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE: rustdoc on issue-43106-gating-of-proc_macro_derive.rs: proc-macro derives require a name #79496

Closed
matthiaskrgr opened this issue Nov 28, 2020 · 7 comments
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

code from ./src/test/ui/feature-gate/issue-43106-gating-of-proc_macro_derive.rs

// At time of authorship, #[proc_macro_derive = "2500"] will emit an
// error when it occurs on a mod (apart from crate-level), but will
// not descend further into the mod for other occurrences of the same
// error.
//
// This file sits on its own because the "weird" occurrences here
// signal errors, making it incompatible with the "warnings only"
// nature of issue-43106-gating-of-builtin-attrs.rs

#[proc_macro_derive()]
//~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
mod proc_macro_derive1 {
    mod inner { #![proc_macro_derive()] }
    // (no error issued here if there was one on outer module)
}

mod proc_macro_derive2 {
    mod inner { #![proc_macro_derive()] }
    //~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions

    #[proc_macro_derive()] fn f() { }
    //~^ ERROR the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro`

    #[proc_macro_derive()] struct S;
    //~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions

    #[proc_macro_derive()] type T = S;
    //~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions

    #[proc_macro_derive()] impl S { }
    //~^ ERROR the `#[proc_macro_derive]` attribute may only be used on bare functions
}

fn main() {}

Meta

rustc --version --verbose:

rustdoc 1.50.0-nightly (1c389ffef 2020-11-24)
binary: rustdoc
commit-hash: 1c389ffeff814726dec325f0f2b0c99107df2673
commit-date: 2020-11-24
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly

Error output

warning: Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
  |
  = warning: The generated documentation may be incorrect

thread 'rustc' panicked at 'proc-macro derives require a name', src/librustdoc/clean/mod.rs:896:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (1c389ffef 2020-11-24) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
warning: 1 warning emitted

Backtrace

warning: Trying to document proc macro crate without passing '--crate-type proc-macro to rustdoc
  |
  = warning: The generated documentation may be incorrect

thread 'rustc' panicked at 'proc-macro derives require a name', src/librustdoc/clean/mod.rs:896:22
stack backtrace:
   0:     0x7f430fecee30 - std::backtrace_rs::backtrace::libunwind::trace::h746c3e9529d524bc
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x7f430fecee30 - std::backtrace_rs::backtrace::trace_unsynchronized::h86340908ff889faa
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f430fecee30 - std::sys_common::backtrace::_print_fmt::h43f85f9b18230404
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f430fecee30 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hc132ae1a5b5aa7cd
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x7f430ff41c4c - core::fmt::write::hdf023a0036d2a25f
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/fmt/mod.rs:1078:17
   5:     0x7f430fec09a2 - std::io::Write::write_fmt::h8580846154bcb66a
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/io/mod.rs:1519:15
   6:     0x7f430fed2a95 - std::sys_common::backtrace::_print::h7ee55fed88d107a3
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x7f430fed2a95 - std::sys_common::backtrace::print::h54a7d3e52a524177
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x7f430fed2a95 - std::panicking::default_hook::{{closure}}::h60921e857bf55a40
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:208:50
   9:     0x7f430fed25ea - std::panicking::default_hook::hf0f9afb1017317fc
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:225:9
  10:     0x7f431075fbb8 - rustc_driver::report_ice::ha25ae86a5858acc3
  11:     0x7f430fed3396 - std::panicking::rust_panic_with_hook::h8d66bf42b407aaea
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:595:17
  12:     0x7f430fed2eb7 - std::panicking::begin_panic_handler::{{closure}}::hde71edcd925d0c5e
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:497:13
  13:     0x7f430fecf2ec - std::sys_common::backtrace::__rust_end_short_backtrace::h8a3c7d6cea578919
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys_common/backtrace.rs:141:18
  14:     0x7f430fed2e19 - rust_begin_unwind
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
  15:     0x7f430ff3e031 - core::panicking::panic_fmt::h20225113c4a2f8fd
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:92:14
  16:     0x7f430ff3dc13 - core::option::expect_failed::h8be1ca96ca0d69ca
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/option.rs:1260:5
  17:     0x55a546696a67 - <(&rustc_hir::hir::Item,core::option::Option<rustc_span::symbol::Ident>) as rustdoc::clean::Clean<alloc::vec::Vec<rustdoc::clean::types::Item>>>::clean::h6efe2622d62f0879
  18:     0x55a5467a101f - <alloc::vec::Vec<T,A> as alloc::vec::SpecExtend<T,I>>::spec_extend::hbf27f2437fec8031
  19:     0x55a54671dde8 - <rustdoc::doctree::Module as rustdoc::clean::Clean<rustdoc::clean::types::Item>>::clean::hee8955bac14e83bc
  20:     0x55a54671dd50 - <rustdoc::doctree::Module as rustdoc::clean::Clean<rustdoc::clean::types::Item>>::clean::hee8955bac14e83bc
  21:     0x55a546717153 - rustdoc::clean::utils::krate::h68bb50ab032123ce
  22:     0x55a546492b3b - rustdoc::core::run_global_ctxt::h7cf39be6ea65128e
  23:     0x55a54650cece - rustc_interface::passes::QueryContext::enter::hedb615e17429b641
  24:     0x55a546602917 - rustc_interface::interface::create_compiler_and_run::h25fa5935e40978f2
  25:     0x55a5464a90d3 - rustdoc::main_options::h8a5cda9c1c8c625b
  26:     0x55a5465f3a68 - rustc_span::with_session_globals::h7a83fbbd64fb6823
  27:     0x55a5464da30e - std::sys_common::backtrace::__rust_begin_short_backtrace::h50722f4a01515f7b
  28:     0x55a54660c03a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h22276985fb540191
  29:     0x7f430fee265a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hea1090dbdcecbf5a
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/alloc/src/boxed.rs:1318:9
  30:     0x7f430fee265a - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8d5723d3912bd325
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/alloc/src/boxed.rs:1318:9
  31:     0x7f430fee265a - std::sys::unix::thread::Thread::new::thread_start::hc17a425ca2995724
                               at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/sys/unix/thread.rs:71:17
  32:     0x7f430fdbe3e9 - start_thread
  33:     0x7f430fba4293 - __GI___clone
  34:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (1c389ffef 2020-11-24) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
warning: 1 warning emitted

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2020
@matthiaskrgr
Copy link
Member Author

@rustbot label -T-compiler +T-rustdoc

@rustbot rustbot added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 28, 2020
@fanninpm
Copy link

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

MCVE:

#![crate_type="proc-macro"]

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_derive()]
pub fn some_derive(_: TokenStream) -> TokenStream {
    TokenStream::new()
}

Rustc gives the correct error:

error: attribute must have either one or two arguments
 --> proc_macro.rs:6:1
  |
6 | #[proc_macro_derive()]
  | ^^^^^^^^^^^^^^^^^^^^^^

which is emitted from here:

self.handler.span_err(attr.span, "attribute must have either one or two arguments");

So for some reason that pass isn't getting run by rustdoc (probably because of the hackery in

rust/src/librustdoc/core.rs

Lines 457 to 473 in 0c11b93

// Certain queries assume that some checks were run elsewhere
// (see https://github.com/rust-lang/rust/pull/73566#issuecomment-656954425),
// so type-check everything other than function bodies in this crate before running lints.
// NOTE: this does not call `tcx.analysis()` so that we won't
// typeck function bodies or run the default rustc lints.
// (see `override_queries` in the `config`)
// HACK(jynelson) this calls an _extremely_ limited subset of `typeck`
// and might break if queries change their assumptions in the future.
// NOTE: This is copy/pasted from typeck/lib.rs and should be kept in sync with those changes.
tcx.sess.time("item_types_checking", || {
for &module in tcx.hir().krate().modules.keys() {
tcx.ensure().check_mod_item_types(tcx.hir().local_def_id(module));
}
});
). The fix is to run that pass.

@jyn514
Copy link
Member

jyn514 commented Dec 20, 2020

Marking as P-low since there are many places where rustdoc assumes its inputs are valid (e.g. all of https://doc.rust-lang.org/nightly/rustdoc/advanced-features.html#interactions-between-platform-specific-docs) and I don't think it's particularly important to handle invalid input, since people learn by running rustc, not rustdoc*.


*with the caveat that this only applies to features that are common to rustc and rustdoc; it's very important for rustdoc to handle invalid intra-doc links for example.

@matthiaskrgr
Copy link
Member Author

This no longer crashes as of

rustdoc 1.69.0-nightly (70fd01243 2023-02-26)
binary: rustdoc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.69.0-nightly
LLVM version: 15.0.7

but I now get an error

error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
 --> c.rs:6:1
  |
6 | #[proc_macro_derive()]
  | ^^^^^^^^^^^^^^^^^^^^^^

which is interesting because the file [1] actually has #![crate_type="proc-macro"]

[1] #79496 (comment)

@jyn514
Copy link
Member

jyn514 commented Feb 26, 2023

@matthiaskrgr probably #107291, the MCVE needs to use --crate-type proc-macro instead of an attribute

@JohnTitor
Copy link
Member

Triage: the error now says with --crate-type proc-macro:

error: attribute must have either one or two arguments
 --> out.rs:4:1
  |
4 | #[proc_macro_derive()]
  | ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

So I guess it has been fixed by another PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants