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

Panic at computing function signature of closure with trait object #78262

Closed
nvksv opened this issue Oct 23, 2020 · 4 comments · Fixed by #78268
Closed

Panic at computing function signature of closure with trait object #78262

nvksv opened this issue Oct 23, 2020 · 4 comments · Fixed by #78268
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nvksv
Copy link

nvksv commented Oct 23, 2020

Code

trait TT {}

impl dyn TT {
    fn func(&self) {}
}

fn main() {
    let f = |x: &dyn TT| x.func();
}

Meta

rustc --version --verbose:

rustc 1.47.0 (18bf6b4f0 2020-10-07)
binary: rustc
commit-hash: 18bf6b4f01a6feaf7259ba7cdae58031af1b7b39
commit-date: 2020-10-07
host: x86_64-pc-windows-gnu
release: 1.47.0
LLVM version: 11.0

This bug also exists at Rust Playground.

Error output

error: internal compiler error: src\librustc_typeck\collect.rs:1587:13: to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.47.0 (18bf6b4f0 2020-10-07) running on x86_64-pc-windows-gnu

error: aborting due to previous error
Backtrace

error: internal compiler error: src\librustc_typeck\collect.rs:1587:13: to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`

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_typeck::collect::fn_sig
   9: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::fn_sig>::compute
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_query_system::query::plumbing::get_query_impl
  13: rustc_infer::infer::error_reporting::nice_region_error::util::<impl rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError>::find_param_with_region
  14: rustc_infer::infer::error_reporting::nice_region_error::static_impl_trait::<impl rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError>::try_report_static_impl_trait
  15: rustc_infer::infer::error_reporting::nice_region_error::NiceRegionError::try_report
  16: rustc_infer::infer::error_reporting::<impl rustc_infer::infer::InferCtxt>::report_region_errors
  17: rustc_infer::infer::InferCtxt::resolve_regions_and_report_errors
  18: rustc_typeck::check::regionck::<impl rustc_typeck::check::FnCtxt>::regionck_fn
  19: rustc_infer::infer::InferCtxtBuilder::enter
  20: rustc_typeck::check::typeck
  21: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::get_query_impl
  25: rustc_query_system::query::plumbing::ensure_query_impl
  26: rustc_typeck::check::typeck_item_bodies
  27: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::get_query_impl
  31: rustc_typeck::check_crate
  32: rustc_interface::passes::analysis
  33: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  35: rustc_data_structures::stack::ensure_sufficient_stack
  36: rustc_query_system::query::plumbing::get_query_impl
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  38: rustc_span::with_source_map
  39: rustc_interface::interface::create_compiler_and_run
  40: scoped_tls::ScopedKey<T>::set
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.47.0 (18bf6b4f0 2020-10-07) running on x86_64-pc-windows-gnu

query stack during panic:
#0 [fn_sig] computing function signature of `main::{{closure}}#0`
#1 [typeck] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@nvksv nvksv added C-bug Category: This is a bug. 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. labels Oct 23, 2020
@SNCPlay42
Copy link
Contributor

Output on 1.46:

error[E0308]: mismatched types
 --> <source>:8:28
  |
8 |     let f = |x: &dyn TT| x.func();
  |                            ^^^^ lifetime mismatch
  |
  = note: expected reference `&(dyn TT + 'static)`
             found reference `&dyn TT`
note: the anonymous lifetime #1 defined on the body at 8:13...
 --> <source>:8:13
  |
8 |     let f = |x: &dyn TT| x.func();
  |             ^^^^^^^^^^^^^^^^^^^^^
  = note: ...does not necessarily outlive the static lifetime

error: aborting due to previous error

Changing the closure argument type to &(dyn TT + 'static) compiles successfully on both verions.

@rustbot modify labels: +A-diagnostics +A-lifetimes +regression-from-stable-to-stable

@rustbot rustbot added A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions regression-from-stable-to-stable Performance or correctness regression from one stable version to another. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 23, 2020
@JohnTitor JohnTitor self-assigned this Oct 23, 2020
@nvksv
Copy link
Author

nvksv commented Oct 23, 2020

With impl (dyn TT + '_) {...} instead of impl dyn TT {...} it compiles successfully too.

Code
trait TT {}

impl (dyn TT + '_) {
    fn func(&self) {}
}

fn main() {
    let _f = |x: &dyn TT| x.func();
}

@lcnr
Copy link
Contributor

lcnr commented Oct 23, 2020

We probably have to check for closures in try_report_static_impl_trait here.

@JohnTitor
Copy link
Member

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@JohnTitor JohnTitor added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 23, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 25, 2020
Do not try to report on closures to avoid ICE

Fixes rust-lang#78262
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 25, 2020
Do not try to report on closures to avoid ICE

Fixes rust-lang#78262
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 26, 2020
Do not try to report on closures to avoid ICE

Fixes rust-lang#78262
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 26, 2020
Do not try to report on closures to avoid ICE

Fixes rust-lang#78262
@bors bors closed this as completed in 463b6cc Oct 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants