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 when using the doc alias attribute on expr or local #99777

Closed
spideynn opened this issue Jul 26, 2022 · 2 comments · Fixed by #100029
Closed

ICE when using the doc alias attribute on expr or local #99777

spideynn opened this issue Jul 26, 2022 · 2 comments · Fixed by #100029
Assignees
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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@spideynn
Copy link

spideynn commented Jul 26, 2022

Code

pub fn test() {
    #[doc(alias = "test")]
    {
        println!("Hello, world!");
    }
}
pub fn test() {
    #[doc(alias = "test")]
    let num_flags = 0;
}

Meta

Stable rustc --version --verbose:

rustc 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-unknown-linux-gnu
release: 1.62.1
LLVM version: 14.0.5

Nightly rustc --version --verbose:

rustc 1.64.0-nightly (6dbae3ad1 2022-07-25)
binary: rustc
commit-hash: 6dbae3ad19309bb541d9e76638e6aa4b5449f29a
commit-date: 2022-07-25
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6

Error output

Compiling ice-repro v0.1.0 (/home/spideynn/CLionProjects/testing)
warning: unused doc comment
 --> src/lib.rs:2:5
  |
2 |     #[doc(alias = "test")]
  |     ^^^^^^^^^^^^^^^^^^^^^^
3 |     let num_flags = 0;
  |     ---------------------- rustdoc does not generate documentation for statements
  |
  = note: `#[warn(unused_doc_comments)]` on by default
  = help: use `//` for a plain comment

error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:944:21: no name for local let mut num_flags = 0; (hir_id=HirId { owner: DefId(0:3 ~ ice_repro[e526]::test), local_id: 3 })
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/compiler/rustc_errors/src/lib.rs:1335:9
stack backtrace:
   0:     0x7f61c8f3cfbd - std::backtrace_rs::backtrace::libunwind::trace::h8e036432725b1c57
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f61c8f3cfbd - std::backtrace_rs::backtrace::trace_unsynchronized::h4f83092254c85869
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f61c8f3cfbd - std::sys_common::backtrace::_print_fmt::h9728b5e056a3ece3
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f61c8f3cfbd - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h48bb4bd2928827d2
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f61c8f98c4c - core::fmt::write::h909e69a2c24f44cc
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/core/src/fmt/mod.rs:1196:17
   5:     0x7f61c8f2e731 - std::io::Write::write_fmt::h7f4b8ab8af89e9ef
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/io/mod.rs:1654:15
   6:     0x7f61c8f3fcd5 - std::sys_common::backtrace::_print::hff4838ebf14a2171
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f61c8f3fcd5 - std::sys_common::backtrace::print::h2499280374189ad9
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f61c8f3fcd5 - std::panicking::default_hook::{{closure}}::h8b270fc55eeb284e
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:295:22
   9:     0x7f61c8f3f949 - std::panicking::default_hook::h3217e229d6e9d13c
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:314:9
  10:     0x7f61c9704571 - rustc_driver[b4654d3c4d4292dd]::DEFAULT_HOOK::{closure#0}::{closure#0}
  11:     0x7f61c8f404a6 - std::panicking::rust_panic_with_hook::h9acb8048b738d2e0
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/panicking.rs:702:17
  12:     0x7f61ca77faf1 - std[8996aeeb2a45fe64]::panicking::begin_panic::<rustc_errors[4633ef6e4608f9c1]::ExplicitBug>::{closure#0}
  13:     0x7f61ca77a0d6 - std[8996aeeb2a45fe64]::sys_common::backtrace::__rust_end_short_backtrace::<std[8996aeeb2a45fe64]::panicking::begin_panic<rustc_errors[4633ef6e4608f9c1]::ExplicitBug>::{closure#0}, !>
  14:     0x7f61ca70f2f6 - std[8996aeeb2a45fe64]::panicking::begin_panic::<rustc_errors[4633ef6e4608f9c1]::ExplicitBug>
  15:     0x7f61ca6c3816 - std[8996aeeb2a45fe64]::panic::panic_any::<rustc_errors[4633ef6e4608f9c1]::ExplicitBug>
  16:     0x7f61ca6bfa85 - <rustc_errors[4633ef6e4608f9c1]::HandlerInner>::bug::<&alloc[9c8de9aaaf44fea]::string::String>
  17:     0x7f61ca6bf420 - <rustc_errors[4633ef6e4608f9c1]::Handler>::bug::<&alloc[9c8de9aaaf44fea]::string::String>
  18:     0x7f61ca7884ad - rustc_middle[74ddc95a19f9493f]::ty::context::tls::with_opt::<rustc_middle[74ddc95a19f9493f]::util::bug::opt_span_bug_fmt<rustc_span[1d0b4d44d1f53955]::span_encoding::Span>::{closure#0}, ()>
  19:     0x7f61ca788826 - rustc_middle[74ddc95a19f9493f]::util::bug::opt_span_bug_fmt::<rustc_span[1d0b4d44d1f53955]::span_encoding::Span>
  20:     0x7f61ca7887a3 - rustc_middle[74ddc95a19f9493f]::util::bug::bug_fmt
  21:     0x7f61cb69f8f3 - <rustc_middle[74ddc95a19f9493f]::hir::map::Map>::name
  22:     0x7f61cbae1b06 - <rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor>::check_doc_alias_value
  23:     0x7f61cadfc774 - <rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor>::check_attributes
  24:     0x7f61cae01817 - <rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor as rustc_hir[597a1a56ef61745a]::intravisit::Visitor>::visit_expr
  25:     0x7f61cadf9b3f - <rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor as rustc_hir[597a1a56ef61745a]::intravisit::Visitor>::visit_fn
  26:     0x7f61cae518b5 - rustc_hir[597a1a56ef61745a]::intravisit::walk_item::<rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor>
  27:     0x7f61cae26f25 - <rustc_middle[74ddc95a19f9493f]::hir::map::Map>::visit_item_likes_in_module::<rustc_hir[597a1a56ef61745a]::intravisit::DeepVisitor<rustc_passes[60f27083e5f41e00]::check_attr::CheckAttrVisitor>>
  28:     0x7f61cbae2a31 - rustc_passes[60f27083e5f41e00]::check_attr::check_mod_attrs
  29:     0x7f61cb1d0bc0 - rustc_query_system[b4bd2ce220f7e42d]::query::plumbing::try_execute_query::<rustc_query_impl[4e222bcb6a32466d]::plumbing::QueryCtxt, rustc_query_system[b4bd2ce220f7e42d]::query::caches::DefaultCache<rustc_span[1d0b4d44d1f53955]::def_id::LocalDefId, ()>>
  30:     0x7f61cbd1fef3 - rustc_query_system[b4bd2ce220f7e42d]::query::plumbing::get_query::<rustc_query_impl[4e222bcb6a32466d]::queries::check_mod_attrs, rustc_query_impl[4e222bcb6a32466d]::plumbing::QueryCtxt>
  31:     0x7f61cb7bdbbd - <core[dbea6f494faa966e]::panic::unwind_safe::AssertUnwindSafe<rustc_interface[9f664daa3237129]::passes::analysis::{closure#0}::{closure#1}> as core[dbea6f494faa966e]::ops::function::FnOnce<()>>::call_once
  32:     0x7f61cb7a72f7 - <rustc_session[a2f3190f51a45935]::session::Session>::time::<(), rustc_interface[9f664daa3237129]::passes::analysis::{closure#0}>
  33:     0x7f61cb7a1f7e - rustc_interface[9f664daa3237129]::passes::analysis
  34:     0x7f61cbcf3334 - rustc_query_system[b4bd2ce220f7e42d]::query::plumbing::try_execute_query::<rustc_query_impl[4e222bcb6a32466d]::plumbing::QueryCtxt, rustc_query_system[b4bd2ce220f7e42d]::query::caches::DefaultCache<(), core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>>
  35:     0x7f61cbd348ce - rustc_query_system[b4bd2ce220f7e42d]::query::plumbing::get_query::<rustc_query_impl[4e222bcb6a32466d]::queries::analysis, rustc_query_impl[4e222bcb6a32466d]::plumbing::QueryCtxt>
  36:     0x7f61cb782777 - <rustc_interface[9f664daa3237129]::passes::QueryContext>::enter::<rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>
  37:     0x7f61cb76d708 - <rustc_interface[9f664daa3237129]::interface::Compiler>::enter::<rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}::{closure#2}, core[dbea6f494faa966e]::result::Result<core[dbea6f494faa966e]::option::Option<rustc_interface[9f664daa3237129]::queries::Linker>, rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>
  38:     0x7f61cb79609f - rustc_span[1d0b4d44d1f53955]::with_source_map::<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_interface[9f664daa3237129]::interface::create_compiler_and_run<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}>::{closure#1}>
  39:     0x7f61cb76e374 - rustc_interface[9f664daa3237129]::interface::create_compiler_and_run::<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}>
  40:     0x7f61cb76bc12 - <scoped_tls[ab1554bfb6e7ab15]::ScopedKey<rustc_span[1d0b4d44d1f53955]::SessionGlobals>>::set::<rustc_interface[9f664daa3237129]::interface::run_compiler<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}>::{closure#0}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>
  41:     0x7f61cb782dff - std[8996aeeb2a45fe64]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[9f664daa3237129]::util::run_in_thread_pool_with_globals<rustc_interface[9f664daa3237129]::interface::run_compiler<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}>::{closure#0}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>::{closure#0}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>
  42:     0x7f61cb782f39 - <<std[8996aeeb2a45fe64]::thread::Builder>::spawn_unchecked_<rustc_interface[9f664daa3237129]::util::run_in_thread_pool_with_globals<rustc_interface[9f664daa3237129]::interface::run_compiler<core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>, rustc_driver[b4654d3c4d4292dd]::run_compiler::{closure#1}>::{closure#0}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>::{closure#0}, core[dbea6f494faa966e]::result::Result<(), rustc_errors[4633ef6e4608f9c1]::ErrorGuaranteed>>::{closure#1} as core[dbea6f494faa966e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x7f61c8f4a3c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h191d5c5ea3edb31d
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc/src/boxed.rs:1872:9
  44:     0x7f61c8f4a3c3 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h42ef7cb2ae640a31
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/alloc/src/boxed.rs:1872:9
  45:     0x7f61c8f4a3c3 - std::sys::unix::thread::Thread::new::thread_start::he47f7169665dab60
                               at /rustc/e092d0b6b43f2de967af0887873151bb1c0b18d3/library/std/src/sys/unix/thread.rs:108:17
  46:     0x7f61c8e7a609 - start_thread
  47:     0x7f61c8d93133 - clone
  48:                0x0 - <unknown>

@spideynn spideynn 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 Jul 26, 2022
@hdelc
Copy link
Contributor

hdelc commented Jul 26, 2022

@rustbot claim

@hdelc
Copy link
Contributor

hdelc commented Jul 27, 2022

Hi, so I've realized that this issue is extremely similar to #86239, and the fix is basically fully templated by that issue's closing pull request. The issue seems to come from this check_doc_alias_value function, which has a Target blacklist, followed by a call to rustc_middle::hir::map::Map::name, which fails with an ICE for any HirId without an associated Symbol:

if let Some(location) = match target {
Target::Impl => Some("implementation block"),
Target::ForeignMod => Some("extern block"),
Target::AssocTy => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
if Target::from_item(containing_item) == Target::Impl {
Some("type alias in implementation block")
} else {
None
}
}
Target::AssocConst => {
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
// We can't link to trait impl's consts.
let err = "associated constant in trait implementation block";
match containing_item.kind {
ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }) => Some(err),
_ => None,
}
}
// we check the validity of params elsewhere
Target::Param => return false,
_ => None,
} {
tcx.sess.emit_err(errors::DocAliasBadLocation { span, attr_str, location });
return false;
}
let item_name = self.tcx.hir().name(hir_id);

The blacklist seems out of place and error prone, considering all the other check_{attr} functions use Target whitelists. Just by looking at possible Targets not covered by the blacklist, I came up with another related ICE by aliasing a match arm:

fn main() {
  match () {
    #[doc(alias = "foo")]
    _ => {}
  }
}

Is there a specific reason this needs to be a blacklist? This is my first time contributing here, so I'm not too familiar with all the necessary considerations.

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) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants