Skip to content

Unconstrained lifetimes allowed with member_constraints/type_alias_impl_trait #74761

Closed
@samlich

Description

@samlich

Code

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

pub trait A {
  type B;
  fn f(&self) -> Self::B;
}
impl<'a, 'b> A for () {
  type B = impl core::fmt::Debug;

  fn f(&self) -> Self::B {}
}

fn main() {}

Playground

Meta

rustc --version --verbose:

rustc 1.47.0-nightly (5ef299eb9 2020-07-24) running on x86_64-unknown-linux-gnu

Error output

   Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'assertion failed: self.universal_regions.is_universal_region(shorter)', src/librustc_mir/borrow_check/type_check/free_region_relations.rs:377:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I had first seen:

thread 'rustc' panicked at 'assertion failed: self.universal_regions.is_universal_region(longer)', src/librustc_mir/borrow_check/type_check/free_region_relations.rs:379:9

Removing the second lifetime (impl<'a> A for () {) gives the correct error,

error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
 --> src/main.rs:8:6
  |
8 | impl<'a> A for () {
  |      ^^ unconstrained lifetime parameter

Additionally, disabling either type_alias_impl_trait or member_constraints still panics (and prompts to enable those features), except in stable where it prompts to enable the features, but does not panic.

Perhaps similar to #57200

Backtrace

Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'assertion failed: self.universal_regions.is_universal_region(shorter)', src/librustc_mir/borrow_check/type_check/free_region_relations.rs:377:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.46/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1117
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1508
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:198
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:217
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:530
  12: std::panicking::begin_panic
  13: <rustc_mir::borrow_check::type_check::free_region_relations::UniversalRegionRelations as rustc_infer::infer::free_regions::FreeRegionRelations>::sub_free_regions
  14: rustc_infer::infer::InferCtxt::commit_if_ok
  15: rustc_mir::borrow_check::type_check::TypeChecker::eq_opaque_type_and_type
  16: rustc_mir::borrow_check::type_check::type_check
  17: rustc_mir::borrow_check::nll::compute_regions
  18: rustc_mir::borrow_check::do_mir_borrowck
  19: rustc_infer::infer::InferCtxtBuilder::enter
  20: rustc_mir::borrow_check::mir_borrowck
  21: core::ops::function::FnOnce::call_once
  22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  27: rustc_hir::intravisit::walk_impl_item_ref
  28: rustc_hir::intravisit::walk_item
  29: rustc_typeck::collect::type_of::type_of
  30: 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
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_query_system::query::plumbing::get_query_impl
  34: rustc_query_system::query::plumbing::ensure_query_impl
  35: <rustc_typeck::collect::CollectItemTypesVisitor as rustc_hir::intravisit::Visitor>::visit_item
  36: rustc_middle::hir::map::Map::visit_item_likes_in_module
  37: rustc_typeck::collect::collect_mod_item_types
  38: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_mod_item_types>::compute
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::get_query_impl
  42: rustc_query_system::query::plumbing::ensure_query_impl
  43: rustc_session::session::Session::track_errors
  44: rustc_typeck::check_crate
  45: rustc_interface::passes::analysis
  46: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  47: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  48: rustc_data_structures::stack::ensure_sufficient_stack
  49: rustc_query_system::query::plumbing::get_query_impl
  50: rustc_middle::ty::context::tls::enter_global
  51: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  52: rustc_span::with_source_map
  53: rustc_interface::interface::create_compiler_and_run
  54: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.47.0-nightly (5ef299eb9 2020-07-24) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `<() as A>::f`
#1 [type_of] computing type of `<() as A>::B::{{opaque}}#0`
#2 [collect_mod_item_types] collecting item types in top-level module
#3 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `playground`.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-member-constraints`#[feature(member_constraints)]`C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions