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

Closed
WaffleLapkin opened this issue Nov 20, 2019 · 5 comments
Closed
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

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:/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.

@jonas-schievink jonas-schievink added A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 20, 2019
@Centril Centril added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Nov 20, 2019
@Centril
Copy link
Contributor

Centril commented Nov 20, 2019

Initial reduction (I cannot reduce more):

#![feature(type_alias_impl_trait)]

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 Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. label Nov 20, 2019
@Centril
Copy link
Contributor

Centril commented Nov 20, 2019

cc @Aaron1011 @nikomatsakis (suggested by git blame)

@Aaron1011
Copy link
Member

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.

@Aaron1011
Copy link
Member

I've opened #66590

@hellow554
Copy link
Contributor

@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 This issue requires a nightly compiler in some way. label Nov 21, 2019
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Nov 26, 2019
@bors bors closed this as completed in 79fcaf8 Nov 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-impl-trait Area: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

No branches or pull requests

7 participants