Skip to content

ICE: tuple_fields called on non-tuple with type_alias_impl_trait, async block, and non-static trait lifetime #78456

Description

@samlich

Code

Removing or making the lifetime static fixes it, as does removing the early return (but not making it conditional). Moving the async part to a standalone function also does not crash. Undef can be defined, but doesn't have to be.

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=de619bbd48328b8854fd77e3338dfb3c

#![feature(type_alias_impl_trait)]
#![no_std]

pub trait Tr<'x> {
    type Fut: core::future::Future<Output = ()>;

    fn f() -> Self::Fut;
}

impl<'x> Tr<'x> for () {
    type Fut = impl core::future::Future<Output = ()>;

    fn f() -> Self::Fut {
        async {
            //if false {
            return ();
            //}
            let res: Undef = ();
            res
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
binary: rustc
commit-hash: ffa2e7ae8fbf9badc035740db949b9dae271c29f
commit-date: 2020-10-24
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly
LLVM version: 11.0

Error output

    Running `rustc --crate-name tuple_fields --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=c6835f7100680813 -C extra-filename=-c6835f7100680813 --out-dir /home/s/.cargo_target/debug/deps -C incremental=/home/s/.cargo_target/debug/incremental -L dependency=/home/s/.cargo_target/debug/deps -C link-arg=-fuse-ld=lld`
error[E0412]: cannot find type `Undef` in this scope
  --> src/lib.rs:18:22
   |
18 |             let res: Undef = ();
   |                      ^^^^^ not found in this scope

warning: unreachable statement
  --> src/lib.rs:18:13
   |
16 |             return ();
   |             --------- any code following this expression is unreachable
17 |             //}
18 |             let res: Undef = ();
   |             ^^^^^^^^^^^^^^^^^^^^ unreachable statement
   |
   = note: `#[warn(unreachable_code)]` on by default

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:2150:18: tuple_fields called on non-tuple

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945: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.49.0-nightly (ffa2e7ae8 2020-10-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C link-arg=-fuse-ld=lld --crate-type lib

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

query stack during panic:
#0 [typeck] type-checking `<() as Tr<'x>>::f`
#1 [type_of] computing type of `<() as Tr<'x>>::Fut::{opaque#0}`
end of query stack
error: aborting due to 2 previous errors; 1 warning emitted

For more information about this error, try `rustc --explain E0412`.
error: could not compile `tuple_fields`

Caused by:
  process didn't exit successfully: `rustc --crate-name tuple_fields --edition=2018 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=c6835f7100680813 -C extra-filename=-c6835f7100680813 --out-dir /home/s/.cargo_target/debug/deps -C incremental=/home/s/.cargo_target/debug/incremental -L dependency=/home/s/.cargo_target/debug/deps -C link-arg=-fuse-ld=lld` (exit code: 101)
Backtrace

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945:9                                                                                                                                                                                                                                        [24/44328]
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_middle::ty::sty::<impl rustc_middle::ty::TyS>::tuple_fields
   9: <rustc_trait_selection::opaque_types::ConstrainOpaqueTypeRegionVisitor<OP> as rustc_middle::ty::fold::TypeVisitor>::visit_ty
  10: rustc_middle::ty::fold::TypeFoldable::visit_with
  11: rustc_middle::ty::structural_impls::<impl rustc_middle::ty::fold::TypeFoldable for &rustc_middle::ty::TyS>::super_visit_with
  12: <rustc_trait_selection::opaque_types::ConstrainOpaqueTypeRegionVisitor<OP> as rustc_middle::ty::fold::TypeVisitor>::visit_ty
  13: <rustc_infer::infer::InferCtxt as rustc_trait_selection::opaque_types::InferCtxtExt>::constrain_opaque_types
  14: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
  15: rustc_hir::intravisit::walk_expr
  16: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
  17: rustc_hir::intravisit::walk_expr
  18: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
  19: <rustc_typeck::check::regionck::RegionCtxt as rustc_hir::intravisit::Visitor>::visit_expr
  20: rustc_typeck::check::regionck::RegionCtxt::visit_fn_body
  21: rustc_typeck::check::regionck::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::regionck_fn
  22: rustc_infer::infer::InferCtxtBuilder::enter
  23: rustc_typeck::check::typeck
  24: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  25: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  26: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  27: rustc_data_structures::stack::ensure_sufficient_stack
  28: rustc_query_system::query::plumbing::get_query_impl
  29: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  30: rustc_hir::intravisit::walk_impl_item_ref
  31: rustc_hir::intravisit::walk_item
  32: rustc_typeck::collect::type_of::type_of
  33: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::type_of>::compute
  34: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::get_query_impl
  38: rustc_typeck::check::check::check_item_type
  39: rustc_middle::hir::map::Map::visit_item_likes_in_module
  40: rustc_typeck::check::check::check_mod_item_types
  41: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_item_types>::compute
  42: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  43: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  44: rustc_data_structures::stack::ensure_sufficient_stack
  45: rustc_query_system::query::plumbing::get_query_impl
  46: rustc_query_system::query::plumbing::ensure_query_impl
  47: rustc_session::utils::<impl rustc_session::session::Session>::time
  48: rustc_typeck::check_crate
  49: rustc_interface::passes::analysis
  50: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  51: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  52: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  53: rustc_middle::ty::query::plumbing::<impl rustc_query_system::query::QueryContext for rustc_middle::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}::{{closure}}
  54: rustc_query_system::query::plumbing::get_query_impl
  55: rustc_interface::passes::QueryContext::enter
  56: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  57: rustc_span::with_source_map
  58: rustc_interface::interface::create_compiler_and_run
  59: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.

    Type

    No type

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions