Skip to content

Make the BUG_REPORT_URL configurable for tools #109486

Closed

Description

@jyn514

Right now, install_ice_hook hard-codes the bug report url to "https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md":

report_ice(info, BUG_REPORT_URL);

For tools, this is not correct; rustdoc at least wants T-rustdoc instead of T-compiler, and other tools want different repositories altogether. I'm opening this bug here because it's relevant to all tools, even though the original context was for clippy.

Fixing this seems a little tricky since DEFAULT_HOOK can't take an argument and doesn't have access to TyCtxt, but maybe we can solve this with thread-locals or something similar?

cc @rust-lang/rustdoc @rust-lang/clippy @rust-lang/miri @rust-lang/rustfmt
_Originally posted by @ingomancer in rust-lang/rust-clippy#10529

Activity

  1. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.
    E-help-wantedCall for participation: Help is requested to fix this issue.
    E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.
    on Mar 22, 2023
  2. flip1995 commented on Mar 22, 2023

    @flip1995
    Member

    Clippy already sets its own URL, so that is already possible. However Clippy needs to do a lot to do that:

    const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
    type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static;
    static ICE_HOOK: LazyLock<Box<PanicCallback>> = LazyLock::new(|| {
    let hook = panic::take_hook();
    panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
    hook
    });
    fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
    // Invoke our ICE handler, which prints the actual panic message and optionally a backtrace
    (*ICE_HOOK)(info);
    // Separate the output with an empty line
    eprintln!();
    let fallback_bundle = rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
    let emitter = Box::new(rustc_errors::emitter::EmitterWriter::stderr(
    rustc_errors::ColorConfig::Auto,
    None,
    None,
    fallback_bundle,
    false,
    false,
    None,
    false,
    false,
    rustc_errors::TerminalUrl::No,
    ));
    let handler = rustc_errors::Handler::with_emitter(true, None, emitter);
    // a .span_bug or .bug call has already printed what
    // it wants to print.
    if !info.payload().is::<rustc_errors::ExplicitBug>() {
    let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
    handler.emit_diagnostic(&mut d);
    }
    let version_info = rustc_tools_util::get_version_info!();
    let xs: Vec<Cow<'static, str>> = vec![
    "the compiler unexpectedly panicked. this is a bug.".into(),
    format!("we would appreciate a bug report: {bug_report_url}").into(),
    format!("Clippy version: {version_info}").into(),
    ];
    for note in &xs {
    handler.note_without_error(note.as_ref());
    }
    // If backtraces are enabled, also print the query stack
    let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
    let num_frames = if backtrace { None } else { Some(2) };
    interface::try_print_query_stack(&handler, num_frames);
    }

    Definitely worth improving the situation here.

  3. jyn514 commented on Mar 22, 2023

    @jyn514
    MemberAuthor

    Clippy already sets its own URL, so that is already possible. However Clippy needs to do a lot to do that:

    Ah hmm, looks like the original problem was a bug in rustfix:

    after fixes were automatically applied the compiler reported errors within these files:
    
      * src/main.rs
    
    This likely indicates a bug in either rustc or cargo itself,
    and we would appreciate a bug report! You're likely to see
    a number of compiler warnings after this message which cargo
    attempted to fix but failed. If you could open an issue at
    https://github.com/rust-lang/rust/issues
    quoting the full output of this command we'd be very appreciative!
    

    I'll open a separate issue there.

  4. self-assigned this
    on Apr 29, 2023
  5. jyn514 commented on Apr 29, 2023

    @jyn514
    MemberAuthor

    @rust-lang/miri the way I'm implementing this requires a change to the miri subtree in rust-lang/rust. What URL would you prefer for the bug report, just https://github.com/rust-lang/miri/issues/new ?

  6. jyn514 commented on Apr 29, 2023

    @jyn514
    MemberAuthor

    #110989 - looks like rustfmt isn't using install_ice_hook today? Happy to add it, but I'll make the PR to the rust-lang/rustfmt repo instead of doing it here.

  7. saethlin commented on Apr 29, 2023

    @saethlin
    Member

    In my experience, ICEs in Miri are just as often rustc bugs. I don't care if users report them in either place.

  8. calebcartwright commented on Apr 29, 2023

    @calebcartwright
    Member

    #110989 - looks like rustfmt isn't using install_ice_hook today? Happy to add it, but I'll make the PR to the rust-lang/rustfmt repo instead of doing it here.

    Do you have a ballpark feel for the size of the change? FWIW I'd be okay with making the rustfmt update in tree if it's reasonably small and logically part of a batch of related in-tree changes

  9. jyn514 commented on Apr 29, 2023

    @jyn514
    MemberAuthor

    about 3 lines of code :) most of which will be the URL itself

  10. calebcartwright commented on Apr 29, 2023

    @calebcartwright
    Member

    about 3 lines of code :) most of which will be the URL itself

    sgtm, feel free to go ahead 👍

  11. added a commit that references this issue on May 4, 2023
  12. added 3 commits that reference this issue on May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-help-wantedCall for participation: Help is requested to fix this issue.E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-dev-toolsRelevant to the dev-tools subteam, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions