rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.43k stars 1.54k forks source link

ICE escaping late-bound region during canonicalization #6139

Closed Luminoth closed 4 years ago

Luminoth commented 4 years ago

Code

Unfortunately I don't have a minimal example for this, I honestly have no idea what's triggering it so I'm not sure what would be safe to remove or not. The repo that's doing it however is here: https://github.com/Luminoth/amethyst-hello and it's occurring at the very end of the clippy process, after checking all of the dependencies.

Meta

Error output

Running `/home/shane/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/clippy-driver rustc --crate-name amethyst_hello --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=3a312d09f1529110 -C extra-filename=-3a312d09f1529110 --out-dir /home/shane/Documents/github/amethyst-hello/target/debug/deps -C incremental=/home/shane/Documents/github/amethyst-hello/target/debug/incremental -L dependency=/home/shane/Documents/github/amethyst-hello/target/debug/deps --extern amethyst=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libamethyst-b118053152fc9a34.rmeta --extern amethyst_imgui=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libamethyst_imgui-d8ea62be2af49777.rmeta --extern derivative=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libderivative-16ebe84343a5b852.so --extern log=/home/shane/Documents/github/amethyst-hello/target/debug/deps/liblog-a3b06cbacbb73880.rmeta --extern serde=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libserde-cb3da048b32ba2a2.rmeta -L native=/usr/lib/x86_64-linux-gnu -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/minimp3-sys-36ee35f0ca87717d/out -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/servo-fontconfig-sys-60da3f9484a8b744/out -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/imgui-sys-a9af0915e5280dfd/out`
error: internal compiler error: src/librustc_infer/infer/canonical/canonicalizer.rs:310:21: escaping late-bound region during canonicalization

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy/issues/new

note: Clippy version: clippy 0.0.212 (18bf6b4 2020-10-07)

error: aborting due to previous error

error: could not compile `amethyst-hello`.

Caused by:
  process didn't exit successfully: `/home/shane/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/bin/clippy-driver rustc --crate-name amethyst_hello --edition=2018 src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,metadata -C embed-bitcode=no -C debuginfo=2 -C metadata=3a312d09f1529110 -C extra-filename=-3a312d09f1529110 --out-dir /home/shane/Documents/github/amethyst-hello/target/debug/deps -C incremental=/home/shane/Documents/github/amethyst-hello/target/debug/incremental -L dependency=/home/shane/Documents/github/amethyst-hello/target/debug/deps --extern amethyst=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libamethyst-b118053152fc9a34.rmeta --extern amethyst_imgui=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libamethyst_imgui-d8ea62be2af49777.rmeta --extern derivative=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libderivative-16ebe84343a5b852.so --extern log=/home/shane/Documents/github/amethyst-hello/target/debug/deps/liblog-a3b06cbacbb73880.rmeta --extern serde=/home/shane/Documents/github/amethyst-hello/target/debug/deps/libserde-cb3da048b32ba2a2.rmeta -L native=/usr/lib/x86_64-linux-gnu -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/minimp3-sys-36ee35f0ca87717d/out -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/servo-fontconfig-sys-60da3f9484a8b744/out -L native=/usr/lib/x86_64-linux-gnu -L native=/home/shane/Documents/github/amethyst-hello/target/debug/build/imgui-sys-a9af0915e5280dfd/out` (exit code: 101)

Backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:918:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_middle::ty::fold::TypeFolder>::fold_region
   9: rustc_middle::ty::fold::TypeFoldable::fold_with
  10: rustc_middle::ty::fold::TypeFoldable::fold_with
  11: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_fold_with
  12: <rustc_infer::infer::canonical::canonicalizer::Canonicalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  13: rustc_middle::ty::fold::TypeFoldable::fold_with
  14: rustc_middle::ty::fold::TypeFoldable::fold_with
  15: rustc_middle::ty::fold::TypeFoldable::fold_with
  16: rustc_infer::infer::canonical::canonicalizer::Canonicalizer::canonicalize
  17: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  18: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  19: rustc_trait_selection::traits::type_known_to_meet_bound_modulo_regions
  20: rustc_infer::infer::InferCtxtBuilder::enter
  21: rustc_ty::common_traits::is_sized_raw
  22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::is_sized_raw>::compute
  23: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_middle::ty::util::<impl rustc_middle::ty::TyS>::is_sized
  28: clippy_lints::types::Types::check_ty
  29: <clippy_lints::types::Types as rustc_lint::passes::LateLintPass>::check_fn
  30: <rustc_lint::late::LateLintPassObjects as rustc_lint::passes::LateLintPass>::check_fn
  31: rustc_hir::intravisit::walk_item
  32: rustc_hir::intravisit::Visitor::visit_nested_item
  33: rustc_hir::intravisit::walk_item
  34: rustc_hir::intravisit::Visitor::visit_nested_item
  35: rustc_hir::intravisit::walk_crate
  36: rustc_lint::late::late_lint_pass_crate
  37: rustc_lint::late::late_lint_crate
  38: rustc_data_structures::sync::join
  39: rustc_session::utils::<impl rustc_session::session::Session>::time
  40: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  41: rustc_session::utils::<impl rustc_session::session::Session>::time
  42: rustc_interface::passes::analysis
  43: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  44: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  45: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  46: rustc_data_structures::stack::ensure_sufficient_stack
  47: rustc_query_system::query::plumbing::get_query_impl
  48: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  49: rustc_span::with_source_map
  50: rustc_interface::interface::create_compiler_and_run
  51: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
flip1995 commented 4 years ago

I reduced it to

use amethyst::core::deferred_dispatcher_operation::DispatcherOperation;

fn foo<'a, 'b>(
    _bar: Vec<Box<dyn DispatcherOperation<'a, 'b>>>,
) {}

I will try to reduce it more to not depend on amethyst later.

flip1995 commented 4 years ago

Minimal example:

trait T<'a> {}

fn foo(
    _: Vec<Box<dyn T<'_>>>,
    //              ^^^^ removing this LT prevents the ICE
) {}

fn main() {
    foo(vec![]);
}

Playground

flip1995 commented 4 years ago

The ICE is caused by this is_sized call:https://github.com/rust-lang/rust-clippy/blob/fcf22d90bb9087f03e60c03ccccdc2f95668bf88/clippy_lints/src/types.rs#L543-L544

boxed_ty is dyn T<'_> + 'static (after the conversion to ty::Ty)