Repository: rust
Issue: ICE in improper_ctypes lint for specialised associated type default
Labels: A-lints,I-ICE,T-compiler,C-bug,F-specialization,glacier,S-bug-has-test,requires-incomplete-features,L-improper_ctypes

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.

http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/

-->

### Code

```Rust
#![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
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`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
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
   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
```

</p>
</details>