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

ICE with type_alias_impl_trait: ty_is_local invoked on unexpected type #66580

WaffleLapkin opened this issue Nov 20, 2019 · 5 comments

ICE with type_alias_impl_trait: ty_is_local invoked on unexpected type #66580

WaffleLapkin opened this issue Nov 20, 2019 · 5 comments
A-impl-trait C-bug F-type_alias_impl_trait glacier I-ICE T-compiler


Copy link

@WaffleLapkin WaffleLapkin commented Nov 20, 2019

This code:


fn main() {
    let mut lazy = Wrap::default();
    let a: bool =;
    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
        T: Default,
        Self(closure::<T>(), std::marker::PhantomData)

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


Causes an ICE.

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

thread 'rustc' panicked at 'Box', src/librustc_errors/
stack backtrace:
0: backtrace::backtrace::libunwind::trace
at /cargo/registry/src/
1: backtrace::backtrace::trace_unsynchronized
at /cargo/registry/src/
2: std::sys_common::backtrace::_print_fmt
at src/libstd/sys_common/
3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
at src/libstd/sys_common/
4: core::fmt::write
at src/libcore/fmt/
5: std::io::Write::write_fmt
at src/libstd/io/
6: std::sys_common::backtrace::_print
at src/libstd/sys_common/
7: std::sys_common::backtrace::print
at src/libstd/sys_common/
8: std::panicking::default_hook::{{closure}}
at src/libstd/
9: std::panicking::default_hook
at src/libstd/
10: rustc_driver::report_ice
11: std::panicking::rust_panic_with_hook
at src/libstd/
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:

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.

@jonas-schievink jonas-schievink added A-impl-trait C-bug F-type_alias_impl_trait I-crash requires-nightly T-compiler labels Nov 20, 2019
@Centril Centril added the I-ICE label Nov 20, 2019
Copy link

@Centril Centril commented Nov 20, 2019

Initial reduction (I cannot reduce more):


type Closure = impl FnOnce();

fn closure() -> Closure {
    || {}

struct Wrap<T> { f: T }

impl Wrap<Closure> {}

impl<T> Wrap<T> {}

@jonas-schievink jonas-schievink removed the I-crash label Nov 20, 2019
Copy link

@Centril Centril commented Nov 20, 2019

cc @Aaron1011 @nikomatsakis (suggested by git blame)

Copy link

@Aaron1011 Aaron1011 commented Nov 20, 2019

Something appears to have gone horribly wrong with PR #63934.

In my initial commit to the PR, I make coherence checking for opaque types check the underlying type to determine whether the opaque type is local or not.

After some feedback from @nikomatsakis, I changed the PR to always treat opaque types as foreign. This is what was supposed to get merged.

I then added some additional tests, force-pushing due to (I think) a rebase. However, I appear to have accidentally switched back to the orignal version of the PR. It's hard to tell from looking at the first push, because I added a new commit (adding the tests). However, the parent of 4eb3d8d is not a commit with the always-foreign behavior - instead, it's a commit with the content of the original PR.

Effectively, an earlier version of the PR got merged, along with some tests intended to go along with the later version of the PR (but which also happened.

I sincerely apologize for this mistake. I'm opening a PR with the proper, approved fix.

Copy link

@Aaron1011 Aaron1011 commented Nov 20, 2019

I've opened #66590

Copy link

@hellow554 hellow554 commented Nov 21, 2019

@rustbot modify labels: -requires-nightly

ICE also appears on stable (also on 1.38) and beta without feature flag. Backport worthy?

@rustbot rustbot removed the requires-nightly label Nov 21, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier label Nov 26, 2019
0dvictor pushed a commit to 0dvictor/rust that referenced this issue Dec 1, 2019
While working on PR rust-lang#63934, I accidentally reverted to an older version
of the PR while working on a rebase. The PR was then merged, not with
the later, approved changes, but with earlier, unapproved changes.

This PR applies the changes that were *suppoesd* to be mereged in
PR rust-lang#63934. All of the proper tests appear to have been merged
in PR rust-lang#63934, so this PR adds no new tests

Fixes rust-lang#66580
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
A-impl-trait C-bug F-type_alias_impl_trait glacier I-ICE T-compiler
None yet

No branches or pull requests

7 participants