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

Impossible case reached #2831

Closed
mrcnski opened this issue Jun 5, 2018 · 11 comments · Fixed by #3248
Closed

Impossible case reached #2831

mrcnski opened this issue Jun 5, 2018 · 11 comments · Fixed by #3248
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@mrcnski
Copy link
Contributor

mrcnski commented Jun 5, 2018

Hi there,

We're seeing the following error when running clippy. I pasted the relevant excerpt below, and the full Travis job is here. The usual workaround of running cargo check first seems to work for now.

Let me know what additional information would be useful in debugging this. Running clippy 0.0.206 on this repo should be enough to reproduce the issue locally.

error: internal compiler error: librustc/ty/relate.rs:700: impossible case reached
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:554:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:467
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::bug_fmt
  14: rustc::ty::relate::TypeRelation::relate
  15: <&'a mut I as core::iter::iterator::Iterator>::next
  16: <core::result::Result<T, E> as rustc::ty::context::InternIteratorElement<T, R>>::intern_with
  17: <rustc::ty::sty::TraitRef<'tcx> as rustc::ty::relate::Relate<'tcx>>::relate
  18: rustc::infer::InferCtxt::commit_if_ok
  19: rustc::traits::select::SelectionContext::match_impl
  20: rustc::infer::InferCtxt::probe
  21: rustc::ty::trait_def::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::for_each_relevant_impl
  22: rustc::traits::select::SelectionContext::assemble_candidates
  23: rustc::traits::select::SelectionContext::candidate_from_obligation_no_cache
  24: rustc::dep_graph::graph::DepGraph::with_anon_task
  25: rustc::traits::select::SelectionContext::candidate_from_obligation
  26: rustc::traits::select::SelectionContext::evaluate_stack
  27: rustc::dep_graph::graph::DepGraph::with_anon_task
  28: rustc::traits::select::SelectionContext::evaluate_predicate_recursively
  29: rustc::traits::select::SelectionContext::evaluate_obligation_recursively
  30: rustc::ty::context::tls::with_related_context
  31: rustc::infer::InferCtxtBuilder::enter
  32: rustc_traits::evaluate_obligation::evaluate_obligation
  33: rustc::ty::maps::__query_compute::evaluate_obligation
  34: rustc::ty::maps::<impl rustc::ty::maps::config::QueryConfig<'tcx> for rustc::ty::maps::queries::evaluate_obligation<'tcx>>::compute
  35: rustc::dep_graph::graph::DepGraph::with_task_impl
  36: rustc::ty::context::tls::with_related_context
  37: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  38: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  39: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt<'cx, 'gcx, 'tcx>>::evaluate_obligation
  40: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt<'cx, 'gcx, 'tcx>>::predicate_must_hold
  41: rustc::ty::context::GlobalCtxt::enter_local
  42: clippy_lints::utils::implements_trait
  43: core::iter::iterator::Iterator::try_for_each::{{closure}}
  44: <clippy_lints::needless_pass_by_value::NeedlessPassByValue as rustc::lint::LateLintPass<'a, 'tcx>>::check_fn
  45: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
  46: rustc::hir::intravisit::walk_impl_item
  47: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_impl_item
  48: rustc::hir::intravisit::walk_impl_item_ref
  49: rustc::hir::intravisit::walk_item
  50: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  51: rustc::hir::intravisit::walk_mod
  52: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  53: rustc::hir::intravisit::walk_item
  54: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  55: rustc::hir::intravisit::walk_mod
  56: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  57: rustc::hir::intravisit::walk_item
  58: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  59: rustc::hir::intravisit::walk_mod
  60: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  61: rustc::lint::context::check_crate
  62: rustc::util::common::time
  63: rustc::ty::context::tls::enter_context
  64: <std::thread::local::LocalKey<T>>::with
  65: rustc::ty::context::TyCtxt::create_and_enter
  66: rustc_driver::driver::compile_input
  67: rustc_driver::run_compiler_with_pool
  68: syntax::with_globals
  69: rustc_driver::run_compiler
  70: std::panicking::try::do_call
  71: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  72: rustc_driver::run
  73: clippy_driver::main
  74: std::rt::lang_start::{{closure}}
  75: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  76: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  77: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:374
             at libstd/rt.rs:58
  78: main
  79: __libc_start_main
  80: <unknown>
query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `&T: wrapper::descriptors::desc::Desc<wrapper::objects::jclass::JClass<'_>>`
end of query stack
error: aborting due to previous error
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.28.0-nightly (5bf68db6e 2018-05-28) running on x86_64-unknown-linux-gnu
note: compiler flags: -C opt-level=3 -C opt-level=2 -C codegen-units=8 --crate-type lib
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `jni`.
Caused by:
  process didn't exit successfully: `/home/travis/.cargo/bin/clippy-driver rustc --crate-name jni /home/travis/.cargo/registry/src/github.com-1ecc6299db9ec823/jni-0.10.1/src/lib.rs --crate-type lib --emit=dep-info,metadata -C opt-level=3 --cfg feature="backtrace" --cfg feature="default" --cfg feature="error-chain" -C metadata=443a1eeac29cab09 -C extra-filename=-443a1eeac29cab09 --out-dir /home/travis/build/maidsafe/safe_client_libs/target/release/deps -L dependency=/home/travis/build/maidsafe/safe_client_libs/target/release/deps --extern cesu8=/home/travis/build/maidsafe/safe_client_libs/target/release/deps/libcesu8-990ed369d5ed2c20.rmeta --extern combine=/home/travis/build/maidsafe/safe_client_libs/target/release/deps/libcombine-a36df1c2285c6c57.rmeta --extern error_chain=/home/travis/build/maidsafe/safe_client_libs/target/release/deps/liberror_chain-c1d1b45c6be1ead8.rmeta --extern jni_sys=/home/travis/build/maidsafe/safe_client_libs/target/release/deps/libjni_sys-62be6b1159a364d5.rmeta --extern log=/home/travis/build/maidsafe/safe_client_libs/target/release/deps/liblog-0b6386fffb4fba18.rmeta --cap-lints allow -C opt-level=2 -C codegen-units=8 -L native=/home/travis/build/maidsafe/safe_client_libs/target/release/build/backtrace-sys-c7e1721ee38cd86b/out/.libs` (exit code: 101)
@phansch phansch added C-bug Category: Clippy is not doing the correct thing I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ and removed C-bug Category: Clippy is not doing the correct thing labels Jun 6, 2018
@mati865
Copy link
Contributor

mati865 commented Jun 6, 2018

Crash happens somewhere in this file and you can simply run clippy in jni-rs repo to trigger it.
Cannot help with it.

edit:
Apparently clippy wasn't crashing one week ago for jni: CI log, PR

@phansch
Copy link
Member

phansch commented Jun 12, 2018

Going to take a look at this crash next

@alexander-irbis
Copy link

@phansch I cleaned up the clippy warnings here, if it helps.

@alexander-irbis
Copy link

alexander-irbis commented Jun 19, 2018

Apparently clippy wasn't crashing one week ago for jni: CI log, PR

There was a "too many errors" message, so maybe clippy just did not reach the place where the error occurs. On a local fork clippy crashed there.

@idubrov
Copy link

idubrov commented Aug 1, 2018

This is the test case that crashes for us, with a similar backtrace:

trait Trait<'a, A> {}

impl<T> Trait<'static, T> for T {}

fn func<S: Trait<'static, ()>>(item: S) {}

P.S. I run on nightly-2018-07-31 with clippy installed via rustup.
P.P.S. Playground

@Marwes
Copy link

Marwes commented Sep 14, 2018

Seeing this when running clippy on https://github.com/gluon-lang/gluon (specifically the gluon_base crate which prevents clippy from running on the rest of the project).

Marwes added a commit to Marwes/gluon that referenced this issue Sep 14, 2018
Marwes added a commit to Marwes/gluon that referenced this issue Sep 14, 2018
bors bot added a commit to gluon-lang/gluon that referenced this issue Sep 14, 2018
628: style: Fix clippy warnings in gluon_base r=Marwes a=Marwes

Further fixes are blocked on
rust-lang/rust-clippy#2831

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
@phansch
Copy link
Member

phansch commented Sep 15, 2018

Thank you for the minimal repro @idubrov. This is at the top of my todo list again now.

bors bot added a commit to gluon-lang/gluon that referenced this issue Sep 15, 2018
628: style: Fix clippy warnings in gluon_base r=Marwes a=Marwes

Further fixes are blocked on
rust-lang/rust-clippy#2831

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
@phansch
Copy link
Member

phansch commented Sep 26, 2018

Quick update: It's difficult but I'm going to dig deeper. Unfortunately I don't know enough yet, about the Rusts trait system implementation to fix it right away.

Here are the things I know.

This is the minimal repro:

trait Bar<'a, A> {}

impl<'b, T> Bar<'b, T> for T {}

fn funk<'b, S: Bar<'b, ()>>(_item: S) {} // this line causes the crash

The crash originates from Clippy's needless_pass_by_value lint. Indeed, it should trigger for this function, because we never use S anywhere in the function body and S is passed by value.

The code for needless_pass_by_value calls utils::implements_trait which creates an inference context and calls InfCtxt::predicate_must_hold for that context.

The crash happens when predicate_must_hold is called. Specifically it's emitted from a branch in librustc/ty/relate.rs#705.

I added some debug statements inside Clippy's implements_trait and the output is:

cx.param_env: ParamEnv { caller_bounds: [Binder(TraitPredicate(<S as Bar<'b, ()>>)), Binder(TraitPredicate(<S as std::marker::Sized>))], reveal: Us
erFacing }
ty: &S
obligation: Obligation(predicate=Binder(TraitPredicate(<&S as Bar<()>>)),depth=0)
ty_params: [()]

Next I want to:

  • check why ty and the obligation's TraitPredicate are &S instead of S
  • trace up the call stack from where the crash is emitted in rustc and figure out why that branch is hit.

@arielb1
Copy link

arielb1 commented Sep 30, 2018

Bar<()>

This looks like you are creating the Bar trait without its 'a lifetime parameter (it should be Bar<'something, ()>). That would cause your error.

@arielb1
Copy link

arielb1 commented Sep 30, 2018

In that case, I suspect this call:
https://github.com/rust-lang-nursery/rust-clippy/blob/cdde22c2cc01c62474b2b73a93e6ad4a4498e230/clippy_lints/src/needless_pass_by_value.rs#L175-L186

It calls input_types, which drops the lifetime parameters out of Bar, turning an OK <S as Bar<'b, ()>> trait-ref into a not-OK <&S as Bar<()>> trait ref. The not OK trait-ref has its indexes wrong because it's missing a lifetime - at index 0, it should have a lifetime, not a type. So you get an ICE.

@arielb1
Copy link

arielb1 commented Sep 30, 2018

I think you just want to remove the input_types() and the .map(|ty| ty.into()) lines. In that case your code should work.

kennytm added a commit to kennytm/rust that referenced this issue Oct 1, 2018
…hewjasper

Improve bug! message for impossible case in Relate

Hitting this branch [in Clippy][clippy_issue] and I think it makes sense to print
both values here in case other people hit this branch, too.

(still have to figure out why this branch is hit)

[clippy_issue]: rust-lang/rust-clippy#2831 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants