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: compiler/rustc_typeck/src/hir_wf_check.rs:133:29: Unexpected TraitItem #87495

Closed
chengniansun opened this issue Jul 26, 2021 · 1 comment · Fixed by #87524
Closed

ICE: compiler/rustc_typeck/src/hir_wf_check.rs:133:29: Unexpected TraitItem #87495

chengniansun opened this issue Jul 26, 2021 · 1 comment · Fixed by #87524
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chengniansun
Copy link

Code

trait u32 {
    const CONST: u32;
}

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (9c25eb7aa 2021-07-25)
binary: rustc
commit-hash: 9c25eb7aa3a71fb951564b0ddf131be59c2c951d
commit-date: 2021-07-25
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 12.0.1

Error output

warning: trait `u32` should have an upper camel case name
 --> mutant.rs:1:7
  |
1 | trait u32 {
  |       ^^^ help: convert the identifier to upper camel case (notice the capitalization): `U32`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: trait objects without an explicit `dyn` are deprecated
 --> mutant.rs:2:18
  |
2 |     const CONST: u32;
  |                  ^^^ help: use `dyn`: `dyn u32`
  |
  = note: `#[warn(bare_trait_objects)]` on by default
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>

error: associated item referring to unboxed trait object for its own trait
 --> mutant.rs:2:18
  |
1 | trait u32 {
  |       --- in this trait
2 |     const CONST: u32;
  |                  ^^^
  |
help: you might have meant to use `Self` to refer to the implementing type
  |
2 |     const CONST: Self;
  |                  ^^^^

error: internal compiler error: compiler/rustc_typeck/src/hir_wf_check.rs:133:29: Unexpected TraitItem Const(Ty { hir_id: HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 3 }, kind: TraitObject([PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: mutant.rs:2:18: 2:21 (#0), res: Def(Trait, DefId(0:3 ~ mutant[d0c6]::u32)), segments: [PathSegment { ident: u32#0, hir_id: Some(HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 2 }), res: Some(Def(Trait, DefId(0:3 ~ mutant[d0c6]::u32))), args: None, infer_args: false }] }, hir_ref_id: HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 1 } }, span: mutant.rs:2:18: 2:21 (#0) }], lifetime(HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 4 }: ), None), span: mutant.rs:2:18: 2:21 (#0) }, None)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.56.0-nightly (9c25eb7aa 2021-07-25) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [diagnostic_hir_wf_check] performing HIR wf-checking for predicate Binder(ObjectSafe(DefId(0:3 ~ mutant[d0c6]::u32)), []) at item Ty(DefId(0:4 ~ mutant[d0c6]::u32::CONST))
#1 [check_trait_item_well_formed] checking that `u32::CONST` is well-formed
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted
Backtrace

warning: trait `u32` should have an upper camel case name
 --> mutant.rs:1:7
  |
1 | trait u32 {
  |       ^^^ help: convert the identifier to upper camel case (notice the capitalization): `U32`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

warning: trait objects without an explicit `dyn` are deprecated
 --> mutant.rs:2:18
  |
2 |     const CONST: u32;
  |                  ^^^ help: use `dyn`: `dyn u32`
  |
  = note: `#[warn(bare_trait_objects)]` on by default
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see issue #80165 <https://github.com/rust-lang/rust/issues/80165>

error: associated item referring to unboxed trait object for its own trait
 --> mutant.rs:2:18
  |
1 | trait u32 {
  |       --- in this trait
2 |     const CONST: u32;
  |                  ^^^
  |
help: you might have meant to use `Self` to refer to the implementing type
  |
2 |     const CONST: Self;
  |                  ^^^^

error: internal compiler error: compiler/rustc_typeck/src/hir_wf_check.rs:133:29: Unexpected TraitItem Const(Ty { hir_id: HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 3 }, kind: TraitObject([PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: mutant.rs:2:18: 2:21 (#0), res: Def(Trait, DefId(0:3 ~ mutant[d0c6]::u32)), segments: [PathSegment { ident: u32#0, hir_id: Some(HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 2 }), res: Some(Def(Trait, DefId(0:3 ~ mutant[d0c6]::u32))), args: None, infer_args: false }] }, hir_ref_id: HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 1 } }, span: mutant.rs:2:18: 2:21 (#0) }], lifetime(HirId { owner: DefId(0:4 ~ mutant[d0c6]::u32::CONST), local_id: 4 }: ), None), span: mutant.rs:2:18: 2:21 (#0) }, None)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1034:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_typeck::hir_wf_check::diagnostic_hir_wf_check
   8: rustc_query_system::query::plumbing::get_query_impl
   9: rustc_query_system::query::plumbing::get_query
  10: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_selection_error
  11: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error
  12: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
  13: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::select_all_obligations_or_error
  14: rustc_infer::infer::InferCtxtBuilder::enter
  15: rustc_typeck::check::wfcheck::check_associated_item
  16: rustc_typeck::check::wfcheck::check_trait_item
  17: rustc_query_system::query::plumbing::get_query_impl
  18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_trait_item_well_formed
  19: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::intravisit::Visitor>::visit_trait_item
  20: std::panicking::try
  21: rustc_data_structures::sync::par_for_each_in
  22: rustc_session::session::Session::track_errors
  23: rustc_typeck::check_crate
  24: rustc_interface::passes::analysis
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  27: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  28: rustc_span::with_source_map
  29: rustc_interface::interface::create_compiler_and_run
  30: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.56.0-nightly (9c25eb7aa 2021-07-25) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type staticlib

query stack during panic:
#0 [diagnostic_hir_wf_check] performing HIR wf-checking for predicate Binder(ObjectSafe(DefId(0:3 ~ mutant[d0c6]::u32)), []) at item Ty(DefId(0:4 ~ mutant[d0c6]::u32::CONST))
#1 [check_trait_item_well_formed] checking that `u32::CONST` is well-formed
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

@chengniansun chengniansun 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, 2021
@hellow554
Copy link
Contributor

I used this to make some warnings/errors go away:

#[allow(non_camel_case_types)]
trait u32 {
    const CONST: Box<dyn u32>;
}

fn main() {}

Regressed in 7c89e38

cc #87265 @Aaron1011

@rustbot modify labels: regression-from-stable-to-nightly

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 27, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 28, 2021
Fix ICE in `diagnostic_hir_wf_check`

Fixes rust-lang#87495. The [documentation for `ObligationCauseCode::WellFormed`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_infer/traits/enum.ObligationCauseCode.html#variant.WellFormed) says that

> it is always correct [...] to specify `WellFormed(None)`

instead of `WellFormed(Some(...))`, which seems to have caused the issue here, as `diagnostic_hir_wf_check` does not expect to be called with an associated constant and will ICE:

https://github.com/rust-lang/rust/blob/fd853c00e255559255885aadff9e93a1760c8728/compiler/rustc_typeck/src/hir_wf_check.rs#L131-L134

Therefore, I have changed `check_associated_item()` to pass a `WellFormed(None)` for associated constants.

r? `@Aaron1011`
@bors bors closed this as completed in 7985e4c Jul 28, 2021
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 29, 2021
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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

4 participants