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 DefId::expect_local when returning impl Future type alias from default trait method using async move block #89686

Closed
wxb1ank opened this issue Oct 8, 2021 · 1 comment · Fixed by #89946
Labels
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.

Comments

@wxb1ank
Copy link

wxb1ank commented Oct 8, 2021

Code

#![feature(type_alias_impl_trait)]

use std::future::Future;

type G<'a, T> = impl Future<Output = ()>;

trait Trait {
    type F: Future<Output = ()>;

    fn f(&self) -> Self::F;

    fn g<'a>(&'a self) -> G<'a, Self>
    where
        Self: Sized,
    {
        async move { self.f().await }
    }
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (0eabf25b9 2021-10-06)
binary: rustc
commit-hash: 0eabf25b90396dead0b2a1aaa275af18a1ae6008
commit-date: 2021-10-06
host: x86_64-unknown-linux-gnu
release: 1.57.0-nightly
LLVM version: 13.0.0

Error output

thread 'rustc' panicked at 'DefId::expect_local: `DefId(2:12723 ~ core[cc79]::future::from_generator::{opaque#0})` isn't local', /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/compiler/rustc_span/src/def_id.rs:234:43
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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

note: rustc 1.57.0-nightly (0eabf25b9 2021-10-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C link-arg=-rtlib=compiler-rt -C linker=clang --crate-type bin

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

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

error: internal compiler error: trimmed_def_paths constructed
  |
  = note: delayed at    0: rustc_errors::Handler::delay_good_path_bug
             1: rustc_middle::ty::print::pretty::trimmed_def_paths
             2: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
             3: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
             4: rustc_data_structures::stack::ensure_sufficient_stack
             5: rustc_query_system::query::plumbing::try_execute_query
             6: rustc_query_system::query::plumbing::get_query
             7: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::print_def_path
             8: rustc_middle::ty::print::Printer::default_print_def_path
             9: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::print_def_path
            10: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::pretty::PrettyPrinter>::in_binder
            11: std::thread::local::LocalKey<T>::with
            12: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::print_type
            13: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::path_qualified
            14: rustc_middle::ty::print::Printer::default_print_def_path
            15: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::Printer>::print_def_path
            16: rustc_middle::ty::print::pretty::<impl rustc_middle::ty::print::Print<P> for rustc_middle::ty::ProjectionPredicate>::print
            17: rustc_middle::ty::print::pretty::<impl rustc_middle::ty::print::Print<P> for rustc_middle::ty::PredicateKind>::print
            18: <rustc_middle::ty::print::pretty::FmtPrinter<F> as rustc_middle::ty::print::pretty::PrettyPrinter>::in_binder
            19: rustc_middle::ty::print::pretty::<impl core::fmt::Display for rustc_middle::ty::Predicate>::fmt
            20: core::fmt::write
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/core/src/fmt/mod.rs:1162:17
            21: core::fmt::Write::write_fmt
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/core/src/fmt/mod.rs:186:9
            22: alloc::fmt::format
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/alloc/src/fmt.rs:579:5
            23: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtPrivExt>::report_projection_error
            24: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::error_reporting::InferCtxtExt>::report_fulfillment_errors
            25: rustc_infer::infer::InferCtxtBuilder::enter
            26: rustc_typeck::check::check::check_item_type
            27: rustc_middle::hir::map::Map::visit_item_likes_in_module
            28: rustc_typeck::check::check::check_mod_item_types
            29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
            30: rustc_data_structures::stack::ensure_sufficient_stack
            31: rustc_query_system::query::plumbing::try_execute_query
            32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
            33: rustc_middle::hir::map::Map::for_each_module
            34: rustc_session::utils::<impl rustc_session::session::Session>::time
            35: rustc_typeck::check_crate
            36: rustc_interface::passes::analysis
            37: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
            38: rustc_data_structures::stack::ensure_sufficient_stack
            39: rustc_query_system::query::plumbing::try_execute_query
            40: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
            41: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
            42: rustc_span::with_source_map
            43: scoped_tls::ScopedKey<T>::set
            44: std::sys_common::backtrace::__rust_begin_short_backtrace
            45: core::ops::function::FnOnce::call_once{{vtable.shim}}
            46: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/alloc/src/boxed.rs:1638:9
            47: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/alloc/src/boxed.rs:1638:9
            48: std::sys::unix::thread::Thread::new::thread_start
                       at /rustc/0eabf25b90396dead0b2a1aaa275af18a1ae6008/library/std/src/sys/unix/thread.rs:106:17
            49: start_thread
            50: __GI___clone

@wxb1ank wxb1ank 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 8, 2021
@wxb1ank wxb1ank changed the title Panic at DefId::expect_local when returning impl Trait type alias from default trait method Panic at DefId::expect_local when returning impl Future type alias from default trait method using async move block Oct 8, 2021
@wxb1ank
Copy link
Author

wxb1ank commented Oct 8, 2021

If you rewrite the body of Trait::g as simply self.f(), rustc correctly emits:

error[E0271]: type mismatch resolving `<<T as Trait>::F as futures::Future>::Output == u8`
 --> src/main.rs:5:17
  |
5 | type G<'a, T> = impl Future<Output = u8>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^ expected `u8`, found associated type
  |
  = note:         expected type `u8`
          found associated type `<<T as Trait>::F as futures::Future>::Output`
  = help: consider constraining the associated type `<<T as Trait>::F as futures::Future>::Output` to `u8`
  = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

error[E0277]: the trait bound `T: Trait` is not satisfied
 --> src/main.rs:5:17
  |
5 | type G<'a, T> = impl Future<Output = u8>;
  |                 ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
  |
help: consider restricting type parameter `T`
  |
5 | type G<'a, T: Trait> = impl Future<Output = u8>;
  |             +++++++

If you accept the second suggestion, the code compiles successfully.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant