Skip to content

Unexpected node ForeignItem with extern generic #95665

Closed
@ahrens

Description

@ahrens

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

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions