Skip to content

ICE with type_alias_impl_trait: ty_is_local invoked on unexpected type #66580

Closed
@WaffleLapkin

Description

@WaffleLapkin

This code:

#![feature(type_alias_impl_trait)]

fn main() {
    let mut lazy = Wrap::default();
    let a: bool = lazy.call();
    assert_eq!(a, false);
}

type Closure<T> = impl FnOnce() -> T;

fn closure<T: Default>() -> Closure<T> {
    || T::default()
}

struct Wrap<T, F>(F, std::marker::PhantomData<dyn Fn() -> T>);

impl<T> Wrap<T, Closure<T>> {
    fn default() -> Self
    where
        T: Default,
    {
        Self(closure::<T>(), std::marker::PhantomData)
    }
}

impl<T, F> Wrap<T, F> {
    fn call(self) -> T 
    where
        F: FnOnce() -> T,
    {
        self.0()
    }
}

(playground)

Causes an ICE.

backtrace
   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc/traits/coherence.rs:534: ty_is_local invoked on unexpected type: [closure@src/main.rs:12:5: 12:20]

thread 'rustc' panicked at 'Box', src/librustc_errors/lib.rs:892:9
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/backtrace.rs:84
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/backtrace.rs:61
4: core::fmt::write
at src/libcore/fmt/mod.rs:1030
5: std::io::Write::write_fmt
at src/libstd/io/mod.rs:1412
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:65
7: std::sys_common::backtrace::print
at src/libstd/sys_common/backtrace.rs:50
8: std::panicking::default_hook::{{closure}}
at src/libstd/panicking.rs:188
9: std::panicking::default_hook
at src/libstd/panicking.rs:205
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:468
12: std::panicking::begin_panic
13: rustc_errors::HandlerInner::bug
14: rustc_errors::Handler::bug
15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
16: rustc::ty::context::tls::with_opt::{{closure}}
17: rustc::ty::context::tls::with_context_opt
18: rustc::ty::context::tls::with_opt
19: rustc::util::bug::opt_span_bug_fmt
20: rustc::util::bug::bug_fmt
21: rustc::traits::coherence::ty_is_non_local_constructor
22: rustc::traits::coherence::ty_is_non_local
23: rustc::traits::coherence::orphan_check_trait_ref
24: rustc::traits::coherence::trait_ref_is_knowable
25: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
26: rustc::dep_graph::graph::DepGraph::with_anon_task
27: rustc::traits::select::SelectionContext::candidate_from_obligation
28: rustc::traits::select::SelectionContext::evaluate_stack
29: rustc::dep_graph::graph::DepGraph::with_anon_task
30: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
31: rustc::infer::InferCtxt::probe
32: core::ops::function::impls::<impl core::ops::function::FnMut for &mut F>::call_mut
33: <core::iter::adapters::chain::Chain<A,B> as core::iter::traits::iterator::Iterator>::try_fold
34: rustc::traits::coherence::overlap_within_probe
35: rustc::infer::InferCtxt::probe
36: rustc::traits::coherence::overlap
37: rustc::ty::context::GlobalCtxt::enter_local
38: rustc::traits::coherence::overlapping_impls
39: <rustc_typeck::coherence::inherent_impls_overlap::InherentOverlapChecker as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
40: rustc::hir::Crate::visit_all_item_likes
41: rustc_typeck::coherence::inherent_impls_overlap::crate_inherent_impls_overlap_check
42: rustc::ty::query::__query_compute::crate_inherent_impls_overlap_check
43: rustc::dep_graph::graph::DepGraph::with_task_impl
44: rustc::ty::query::plumbing::::get_query
45: rustc_typeck::check_crate::{{closure}}::{{closure}}
46: rustc::util::common::time
47: rustc_typeck::check_crate
48: rustc_interface::passes::analysis
49: rustc::ty::query::__query_compute::analysis
50: rustc::dep_graph::graph::DepGraph::with_task_impl
51: rustc::ty::query::plumbing::::get_query
52: rustc::ty::context::tls::enter_global
53: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
54: rustc_interface::passes::create_global_ctxt::{{closure}}
55: rustc_interface::passes::BoxedGlobalCtxt::enter
56: rustc_interface::interface::run_compiler_in_existing_thread_pool
57: std::thread::local::LocalKey::with
58: syntax::with_globals
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.41.0-nightly (618b01f9f 2019-11-19) running on x86_64-unknown-linux-gnu

note: compiler flags: -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 [crate_inherent_impls_overlap_check] check for overlap between inherent impls defined in this crate
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile playground.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions