rust icon indicating copy to clipboard operation
rust copied to clipboard

ICE in improper_ctypes lint for specialised associated type default

Open juntyr opened this issue 3 years ago • 2 comments

Code

#![feature(specialization)]

trait Foo {
    type Bar;
}

impl<T> Foo for T {
    default type Bar = u32;
}

impl Foo for i32 {
    type Bar = i32;
}

extern "C" {
    #[allow(unused)]
    // OK as Foo::Bar is explicitly defined for i32
    static OK: <i32 as Foo>::Bar;
    
    #[allow(unused)]
    // ICE in the improper_ctypes lint
    //  as Foo::Bar is only default implemented for ()
    static ICE: <() as Foo>::Bar;
}

Rust Playground: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d12c793a1779bb8d40110fe9ccf87ff5

Meta

rustc --version --verbose:

rustc 1.56.0-nightly (a49e38e67 2021-08-23)
binary: rustc
commit-hash: a49e38e672c60da788360e088f00ad12353e3913
commit-date: 2021-08-23
host: x86_64-unknown-linux-gnu
release: 1.56.0-nightly
LLVM version: 13.0.0

Error output

error: internal compiler error: compiler/rustc_lint/src/types.rs:1119:32: unexpected type in foreign function: <() as Foo>::Bar
Backtrace

   Compiling playground v0.0.1 (/playground)
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
 --> src/main.rs:1:12
  |
1 | #![feature(specialization)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default
  = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
  = help: consider using `min_specialization` instead, which is more stable and complete

error: internal compiler error: compiler/rustc_lint/src/types.rs:1119:32: unexpected type in foreign function: <() as Foo>::Bar

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1145: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_lint::types::ImproperCTypesVisitor::check_type_for_ffi
   8: rustc_lint::types::ImproperCTypesVisitor::check_type_for_ffi_and_report_errors
   9: <rustc_lint::types::ImproperCTypesDeclarations as rustc_lint::passes::LateLintPass>::check_foreign_item
  10: rustc_hir::intravisit::Visitor::visit_nested_foreign_item
  11: rustc_hir::intravisit::walk_item
  12: rustc_hir::intravisit::Visitor::visit_nested_item
  13: rustc_lint::late::late_lint_mod
  14: rustc_query_system::query::plumbing::get_query_impl
  15: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::lint_mod
  16: rustc_data_structures::sync::join
  17: <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  18: rustc_session::utils::<impl rustc_session::session::Session>::time
  19: rustc_interface::passes::analysis
  20: rustc_query_system::query::plumbing::get_query_impl
  21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  22: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  23: rustc_span::with_source_map
  24: 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 (a49e38e67 2021-08-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground`; 1 warning emitted

juntyr avatar Aug 24 '21 16:08 juntyr

Triage: Still reproduces in Playground.

Enselic avatar Sep 10 '23 11:09 Enselic

updated stacktrace

warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
 --> a.rs:1:12
  |
1 | #![feature(specialization)]
  |            ^^^^^^^^^^^^^^
  |
  = note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
  = help: consider using `min_specialization` instead, which is more stable and complete
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: compiler/rustc_lint/src/types.rs:1490:32: unexpected type in foreign function: Alias(Projection, AliasTy { args: [()], def_id: DefId(0:4 ~ a[f493]::Foo::Bar) })

thread 'rustc' panicked at compiler/rustc_lint/src/types.rs:1490:32:
Box<dyn Any>
stack backtrace:
   0:     0x72e5b3225cd5 - std::backtrace_rs::backtrace::libunwind::trace::h516a98be21ea1e9d
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x72e5b3225cd5 - std::backtrace_rs::backtrace::trace_unsynchronized::h0beee091dd45e212
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x72e5b3225cd5 - std::sys_common::backtrace::_print_fmt::hd6e747bb9d3f708b
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x72e5b3225cd5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h88bd8885dd8bc971
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x72e5b3274f9b - core::fmt::rt::Argument::fmt::h0a98b623e411d353
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/core/src/fmt/rt.rs:165:63
   5:     0x72e5b3274f9b - core::fmt::write::h05543e7a8f793da9
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/core/src/fmt/mod.rs:1157:21
   6:     0x72e5b321a85f - std::io::Write::write_fmt::h32fe40906746efba
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/io/mod.rs:1832:15
   7:     0x72e5b3225aae - std::sys_common::backtrace::_print::h18bd86a960ce0efd
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x72e5b3225aae - std::sys_common::backtrace::print::h46870d6ea993b433
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x72e5b3228429 - std::panicking::default_hook::{{closure}}::h1eb28bb3c5a81eb1
  10:     0x72e5b322816d - std::panicking::default_hook::h0776def55f4233d2
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/panicking.rs:291:9
  11:     0x72e5afa7f6ec - std[c749c752f96c7002]::panicking::update_hook::<alloc[6a3f043098cccec3]::boxed::Box<rustc_driver_impl[86e4e46edf7629a3]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x72e5b3228b2c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h40f3001d7823cc3a
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/alloc/src/boxed.rs:2032:9
  13:     0x72e5b3228b2c - std::panicking::rust_panic_with_hook::h7775800bf8e4e70f
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/panicking.rs:792:13
  14:     0x72e5afaaeed4 - std[c749c752f96c7002]::panicking::begin_panic::<rustc_errors[8ddcc8e87ede5729]::ExplicitBug>::{closure#0}
  15:     0x72e5afaabc46 - std[c749c752f96c7002]::sys_common::backtrace::__rust_end_short_backtrace::<std[c749c752f96c7002]::panicking::begin_panic<rustc_errors[8ddcc8e87ede5729]::ExplicitBug>::{closure#0}, !>
  16:     0x72e5afaab926 - std[c749c752f96c7002]::panicking::begin_panic::<rustc_errors[8ddcc8e87ede5729]::ExplicitBug>
  17:     0x72e5afab7f01 - <rustc_errors[8ddcc8e87ede5729]::diagnostic::BugAbort as rustc_errors[8ddcc8e87ede5729]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x72e5aff5e31c - rustc_middle[f173bc7e2a2ad92a]::util::bug::opt_span_bug_fmt::<rustc_span[aae7cfb8fdf78867]::span_encoding::Span>::{closure#0}
  19:     0x72e5aff45f9a - rustc_middle[f173bc7e2a2ad92a]::ty::context::tls::with_opt::<rustc_middle[f173bc7e2a2ad92a]::util::bug::opt_span_bug_fmt<rustc_span[aae7cfb8fdf78867]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x72e5aff45e3b - rustc_middle[f173bc7e2a2ad92a]::ty::context::tls::with_context_opt::<rustc_middle[f173bc7e2a2ad92a]::ty::context::tls::with_opt<rustc_middle[f173bc7e2a2ad92a]::util::bug::opt_span_bug_fmt<rustc_span[aae7cfb8fdf78867]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x72e5adb4c750 - rustc_middle[f173bc7e2a2ad92a]::util::bug::bug_fmt
  22:     0x72e5b232bb3a - <rustc_lint[9c0fc95c3b9bf5d1]::types::ImproperCTypesVisitor>::check_type_for_ffi.cold
  23:     0x72e5b13b99ce - <rustc_lint[9c0fc95c3b9bf5d1]::types::ImproperCTypesVisitor>::check_type_for_ffi_and_report_errors
  24:     0x72e5b232b5e6 - <rustc_lint[9c0fc95c3b9bf5d1]::types::ImproperCTypesDeclarations as rustc_lint[9c0fc95c3b9bf5d1]::passes::LateLintPass>::check_foreign_item.cold
  25:     0x72e5b0fa0c43 - <rustc_lint[9c0fc95c3b9bf5d1]::late::LateContextAndPass<rustc_lint[9c0fc95c3b9bf5d1]::BuiltinCombinedModuleLateLintPass> as rustc_hir[d3c3bf960b5b3c55]::intravisit::Visitor>::visit_nested_item
  26:     0x72e5b0f9fb31 - rustc_lint[9c0fc95c3b9bf5d1]::lint_mod
  27:     0x72e5b0f9f947 - rustc_query_impl[ee442aa8421a48b6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ee442aa8421a48b6]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f173bc7e2a2ad92a]::query::erase::Erased<[u8; 0usize]>>
  28:     0x72e5b18fce7d - rustc_query_system[1cb7ec193da8cd5e]::query::plumbing::try_execute_query::<rustc_query_impl[ee442aa8421a48b6]::DynamicConfig<rustc_query_system[1cb7ec193da8cd5e]::query::caches::DefaultCache<rustc_span[aae7cfb8fdf78867]::def_id::LocalModDefId, rustc_middle[f173bc7e2a2ad92a]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[ee442aa8421a48b6]::plumbing::QueryCtxt, false>
  29:     0x72e5b18fbaff - rustc_query_impl[ee442aa8421a48b6]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  30:     0x72e5b18fb6a1 - rustc_lint[9c0fc95c3b9bf5d1]::late::check_crate::{closure#1}
  31:     0x72e5b18fb0c0 - rustc_lint[9c0fc95c3b9bf5d1]::late::check_crate
  32:     0x72e5b1339303 - rustc_interface[bce89b6f210e4d53]::passes::analysis
  33:     0x72e5b1338807 - rustc_query_impl[ee442aa8421a48b6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ee442aa8421a48b6]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f173bc7e2a2ad92a]::query::erase::Erased<[u8; 1usize]>>
  34:     0x72e5b1c31b25 - rustc_query_system[1cb7ec193da8cd5e]::query::plumbing::try_execute_query::<rustc_query_impl[ee442aa8421a48b6]::DynamicConfig<rustc_query_system[1cb7ec193da8cd5e]::query::caches::SingleCache<rustc_middle[f173bc7e2a2ad92a]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[ee442aa8421a48b6]::plumbing::QueryCtxt, false>
  35:     0x72e5b1c31889 - rustc_query_impl[ee442aa8421a48b6]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  36:     0x72e5b19f8d53 - rustc_interface[bce89b6f210e4d53]::interface::run_compiler::<core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>, rustc_driver_impl[86e4e46edf7629a3]::run_compiler::{closure#0}>::{closure#0}
  37:     0x72e5b1bba61d - std[c749c752f96c7002]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bce89b6f210e4d53]::util::run_in_thread_with_globals<rustc_interface[bce89b6f210e4d53]::util::run_in_thread_pool_with_globals<rustc_interface[bce89b6f210e4d53]::interface::run_compiler<core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>, rustc_driver_impl[86e4e46edf7629a3]::run_compiler::{closure#0}>::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>
  38:     0x72e5b1bba42a - <<std[c749c752f96c7002]::thread::Builder>::spawn_unchecked_<rustc_interface[bce89b6f210e4d53]::util::run_in_thread_with_globals<rustc_interface[bce89b6f210e4d53]::util::run_in_thread_pool_with_globals<rustc_interface[bce89b6f210e4d53]::interface::run_compiler<core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>, rustc_driver_impl[86e4e46edf7629a3]::run_compiler::{closure#0}>::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[736ebc8723171d66]::result::Result<(), rustc_span[aae7cfb8fdf78867]::ErrorGuaranteed>>::{closure#2} as core[736ebc8723171d66]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x72e5b3232a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h5094758ec9661a91
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/alloc/src/boxed.rs:2018:9
  40:     0x72e5b3232a1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hcff27637da9ad77a
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/alloc/src/boxed.rs:2018:9
  41:     0x72e5b3232a1b - std::sys::pal::unix::thread::Thread::new::thread_start::h31fc9ec883ba717b
                               at /rustc/ccfcd950b333fed046275dd8d54fe736ca498aa7/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x72e5b2fd055a - <unknown>
  43:     0x72e5b304da3c - <unknown>
  44:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: please attach the file at `/tmp/rustc-ice-2024-04-16T19_13_53-2803773.txt` to your bug report

note: compiler flags: --crate-type lib

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error; 1 warning emitted

matthiaskrgr avatar Apr 16 '24 19:04 matthiaskrgr