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

Unexpected node ForeignItem with extern generic #95665

Closed
ahrens opened this issue Apr 5, 2022 · 1 comment · Fixed by #98159
Closed

Unexpected node ForeignItem with extern generic #95665

ahrens opened this issue Apr 5, 2022 · 1 comment · Fixed by #98159
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. 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

@ahrens
Copy link

ahrens commented Apr 5, 2022

Code

pub trait Trait: {}

pub struct Struct<T: Trait> {
    member: T,
}

// uncomment and bug goes away
//impl Trait for u8 {}

extern "C" {
    static VAR: Struct<u8>;
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (76d770ac2 2022-04-02)
binary: rustc
commit-hash: 76d770ac21d9521db6a92a48c7b3d5b2cc535941
commit-date: 2022-04-02
host: aarch64-apple-darwin
release: 1.61.0-nightly
LLVM version: 14.0.0

Also reproduces on 1.58.0 and 1.59.0.

Error output

error: internal compiler error: compiler/rustc_typeck/src/hir_wf_check.rs:144:25: Unexpected node ForeignItem(ForeignItem { ident: VAR#0, kind: Static(Ty { hir_id: HirId { owner: DefId(0:8 ~ boom[15c8]::{extern#0}::VAR), local_id: 1 }, kind: Path(Resolved(None, Path { span: boom.rs:12:17: 12:27 (#0), res: Def(Struct, DefId(0:4 ~ boom[15c8]::Struct)), segments: [PathSegment { ident: Struct#0, hir_id: Some(HirId { owner: DefId(0:8 ~ boom[15c8]::{extern#0}::VAR), local_id: 4 }), res: Some(Err), args: Some(GenericArgs { args: [Type(Ty { hir_id: HirId { owner: DefId(0:8 ~ boom[15c8]::{extern#0}::VAR), local_id: 2 }, kind: Path(Resolved(None, Path { span: boom.rs:12:24: 12:26 (#0), res: PrimTy(Uint(U8)), segments: [PathSegment { ident: u8#0, hir_id: Some(HirId { owner: DefId(0:8 ~ boom[15c8]::{extern#0}::VAR), local_id: 3 }), res: Some(Err), args: None, infer_args: false }] })), span: boom.rs:12:24: 12:26 (#0) })], bindings: [], parenthesized: false, span_ext: boom.rs:12:23: 12:27 (#0) }), infer_args: false }] })), span: boom.rs:12:17: 12:27 (#0) }, Not), def_id: DefId(0:8 ~ boom[15c8]::{extern#0}::VAR), span: boom.rs:12:5: 12:28 (#0), vis: Spanned { node: Inherited, span: boom.rs:12:5: 12:5 (#0) } }) 

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1279:9

query stack during panic:
#0 [diagnostic_hir_wf_check] performing HIR wf-checking for predicate Binder(TraitPredicate(<u8 as Trait>, polarity:Positive), []) at item Ty(DefId(0:8 ~ boom[15c8]::{extern#0}::VAR))
#1 [check_item_well_formed] checking that `` is well-formed
#2 [analysis] running analysis passes on this crate
end of query stack

Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1279:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   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::<rustc_query_impl::queries::diagnostic_hir_wf_check, rustc_query_impl::plumbing::QueryCtxt>
   9: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::diagnostic_hir_wf_check
  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::FnCtxt>::select_all_obligations_or_error
  14: <rustc_infer::infer::InferCtxtBuilder>::enter::<(), <rustc_typeck::check::inherited::InheritedBuilder>::enter<<rustc_typeck::check::wfcheck::CheckWfFcxBuilder>::with_fcx<rustc_typeck::check::wfcheck::check_item_type::{closure#0}>::{closure#0}, ()>::{closure#0}>
  15: rustc_typeck::check::wfcheck::check_item_type
  16: rustc_typeck::check::wfcheck::check_item_well_formed
  17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, ()>>
  18: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::check_item_well_formed, rustc_query_impl::plumbing::QueryCtxt>
  19: <core::panic::unwind_safe::AssertUnwindSafe<rustc_data_structures::sync::par_for_each_in<&alloc::vec::Vec<rustc_hir::hir::MaybeOwner<&rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>::{closure#0}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
  20: rustc_data_structures::sync::par_for_each_in::<&alloc::vec::Vec<rustc_hir::hir::MaybeOwner<&rustc_hir::hir::OwnerInfo>>, <rustc_middle::hir::map::Map>::par_visit_all_item_likes<rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor>::{closure#0}>
  21: <rustc_session::session::Session>::track_errors::<rustc_typeck::check_crate::{closure#5}, ()>
  22: rustc_typeck::check_crate
  23: rustc_interface::passes::analysis
  24: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorGuaranteed>>>
  25: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  26: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  27: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorGuaranteed>>
  28: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  29: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
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.61.0-nightly (76d770ac2 2022-04-02) running on aarch64-apple-darwin

query stack during panic:
#0 [diagnostic_hir_wf_check] performing HIR wf-checking for predicate Binder(TraitPredicate(<u8 as Trait>, polarity:Positive), []) at item Ty(DefId(0:8 ~ boom[15c8]::{extern#0}::VAR))
#1 [check_item_well_formed] checking that `` is well-formed
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@ahrens ahrens 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 Apr 5, 2022
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 9, 2022
@cjgillot cjgillot added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. labels Jun 10, 2022
@PrestonFrom
Copy link
Contributor

@rustbot claim

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Jun 20, 2022
…nkov

Include ForeignItem when visiting types for WF check

Addresses Issue 95665 by including `hir::Node::ForeignItem` as a valid
type to visit in `diagnostic_hir_wf_check`.

Fixes rust-lang#95665
@bors bors closed this as completed in f725b97 Jun 20, 2022
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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. 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.

4 participants