Skip to content

rustc should error instead of panic when the generator trait is not found #63912

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

Closed
bjorn3 opened this issue Aug 26, 2019 · 1 comment · Fixed by #63917
Closed

rustc should error instead of panic when the generator trait is not found #63912

bjorn3 opened this issue Aug 26, 2019 · 1 comment · Fixed by #63917
Labels
A-coroutines Area: Coroutines A-lang-item Area: Language items C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. 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

@bjorn3
Copy link
Member

bjorn3 commented Aug 26, 2019

This somehow doesn't occur when putting the abc function in a non #![no_core] crate, yet I can't find any difference between the libcore version of FnOnce and this one.

#![feature(no_core, lang_items, unboxed_closures)]
#![no_core]

#[lang = "sized"]
pub trait Sized {}

#[lang = "fn_once"]
#[rustc_paren_sugar]
pub trait FnOnce<Args> {
    type Output;

    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}

pub fn abc() -> impl FnOnce(f32) {
    |_| {}
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', src/libcore/option.rs:378:21
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
   8: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:384
   9: rust_begin_unwind
             at src/libstd/panicking.rs:311
  10: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  11: core::panicking::panic
             at src/libcore/panicking.rs:49
  12: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::deduce_sig_from_projection
  13: rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt>::check_expr_closure
  14: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  15: rustc_typeck::check::FnCtxt::check_block_with_expected
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  18: rustc_typeck::check::check_fn
  19: rustc::ty::context::GlobalCtxt::enter_local
  20: rustc_typeck::check::typeck_tables_of
  21: rustc::ty::query::__query_compute::typeck_tables_of
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  25: rustc_typeck::collect::checked_type_of
  26: rustc_typeck::collect::type_of
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::type_of>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc::ty::util::<impl rustc::ty::context::TyCtxt>::try_expand_impl_trait_type::OpaqueTypeExpander::expand_opaque_ty
  31: rustc::ty::util::<impl rustc::ty::context::TyCtxt>::try_expand_impl_trait_type
  32: rustc_typeck::check::check_item_type
  33: rustc::hir::map::Map::visit_item_likes_in_module
  34: rustc_typeck::check::check_mod_item_types
  35: rustc::ty::query::__query_compute::check_mod_item_types
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_mod_item_types>::compute
  37: rustc::dep_graph::graph::DepGraph::with_task_impl
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  39: rustc_typeck::check_crate::{{closure}}
  40: rustc::util::common::time
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: rustc::ty::query::__query_compute::analysis
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  46: rustc::ty::context::tls::enter_global
  47: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  48: rustc_interface::passes::create_global_ctxt::{{closure}}
  49: rustc_interface::passes::BoxedGlobalCtxt::enter
  50: rustc_interface::interface::run_compiler_in_existing_thread_pool
  51: std::thread::local::LocalKey<T>::with
  52: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [typeck_tables_of] processing `abc`
#1 [type_of] processing `abc::{{opaque}}#0`
#2 [check_mod_item_types] checking item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack

error: internal compiler error: unexpected panic

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.39.0-nightly (9eae1fc0e 2019-08-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

@bjorn3
Copy link
Member Author

bjorn3 commented Aug 26, 2019

Seems like it panic when the Generator trait is not found:

let gen_trait = tcx.lang_items().gen_trait().unwrap();

Maybe it can use tcx.require_lang_item instead.

@bjorn3 bjorn3 changed the title Panic in rustc_typeck::check::closure::...::deduce_sig_from_projection rustc should error instead of panic when the generator trait is not found Aug 26, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. 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. A-coroutines Area: Coroutines A-lang-item Area: Language items labels Aug 26, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 27, 2019
…l,cramert

Error when generator trait is not found

Closes rust-lang#63912
@bors bors closed this as completed in 23116ba Aug 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-coroutines Area: Coroutines A-lang-item Area: Language items C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants