Skip to content

Error using impl_trait_in_bindings #86642

Closed
@TomerAberbach

Description

@TomerAberbach

Code

#![feature(impl_trait_in_bindings)]
#![allow(incomplete_features)]

macro_rules! seq {
    ($( $x:expr ),*) => {
        move |source| {
            $(
                let source = $x(source)?;
            )*
            Ok(source)
        }
    };
}

macro_rules! alt {
    ($first:expr, $( $rest:expr ),*) => {
        move |source| {
            let res = $first(source);
            $(
                let res = res.or($rest(source));
            )*
            res
        }
    };
}

static x: impl Fn(&str) -> Result<&str, ()> = alt!(seq!(), seq!());

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (ed597e7e1 2021-06-08)
binary: rustc
commit-hash: ed597e7e19d0fe716d9f81b1e840a5abbfd7c28d
commit-date: 2021-06-08
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.1

Error output

error[E0282]: type annotations needed for `Result<&str, E>`
  --> src/lib.rs:10:13
   |
10 |             Ok(source)
   |             ^^ cannot infer type for type parameter `E` declared on the enum `Result`
...
18 |             let res = $first(source);
   |                 --- consider giving `res` the explicit type `Result<&str, E>`, where the type parameter `E` is specified
...
27 | static x: impl Fn(&str) -> Result<&str, ()> = alt!(seq!(), seq!());
   |                                                    ------ in this macro invocation
   |
   = note: this error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)

error: internal compiler error: compiler/rustc_mir/src/borrow_check/universal_regions.rs:533:26: expected defining type for `DefId(0:8 ~ playground[61eb]::x::{closure#0}::{closure#0})`: `[type error]`
  --> src/lib.rs:6:9
   |
6  | /         move |source| {
7  | |             $(
8  | |                 let source = $x(source)?;
9  | |             )*
10 | |             Ok(source)
11 | |         }
   | |_________^
...
27 |   static x: impl Fn(&str) -> Result<&str, ()> = alt!(seq!(), seq!());
   |                                                      ------ in this macro invocation
   |
   = note: this error: internal compiler error originates in the macro `seq` (in Nightly builds, run with -Z macro-backtrace for more info)
Backtrace

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/e6b4c252ea33e9f80ab8b8d7b3f6393e54166127/compiler/rustc_errors/src/lib.rs:953:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::span_bug
   3: rustc_errors::Handler::span_bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::span_bug_fmt
   7: rustc_mir::borrow_check::universal_regions::UniversalRegions::new
   8: rustc_mir::borrow_check::nll::replace_regions_in_mir
   9: rustc_mir::borrow_check::do_mir_borrowck
  10: rustc_infer::infer::InferCtxtBuilder::enter
  11: rustc_mir::borrow_check::mir_borrowck
  12: core::ops::function::FnOnce::call_once
  13: rustc_query_system::query::plumbing::get_query_impl
  14: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  15: rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator::check
  16: <rustc_typeck::collect::type_of::find_opaque_ty_constraints::ConstraintLocator as rustc_hir::intravisit::Visitor>::visit_expr
  17: rustc_hir::intravisit::walk_expr
  18: rustc_hir::intravisit::walk_local
  19: rustc_hir::intravisit::walk_block
  20: rustc_hir::intravisit::Visitor::visit_nested_body
  21: rustc_hir::intravisit::walk_expr
  22: rustc_hir::intravisit::Visitor::visit_nested_body
  23: rustc_typeck::collect::type_of::type_of
  24: rustc_query_system::query::plumbing::get_query_impl
  25: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  26: <rustc_trait_selection::traits::query::normalize::QueryNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  27: <rustc_infer::infer::at::At as rustc_trait_selection::traits::query::normalize::AtExt>::normalize
  28: rustc_infer::infer::InferCtxtBuilder::enter
  29: core::ops::function::FnOnce::call_once
  30: rustc_query_system::query::plumbing::get_query_impl
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::normalize_generic_arg_after_erasing_regions
  32: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
  33: <rustc_middle::ty::layout::LayoutCx<rustc_middle::ty::context::TyCtxt> as rustc_target::abi::LayoutOf>::layout_of
  34: rustc_typeck::check::check::check_static_inhabited
  35: rustc_typeck::check::check::check_item_type
  36: rustc_middle::hir::map::Map::visit_item_likes_in_module
  37: rustc_typeck::check::check::check_mod_item_types
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  40: rustc_session::utils::<impl rustc_session::session::Session>::time
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: rustc_query_system::query::plumbing::get_query_impl
  44: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  45: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  46: rustc_span::with_source_map
  47: rustc_interface::interface::create_compiler_and_run
  48: 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.55.0-nightly (e6b4c252e 2021-06-25) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `x::{closure#0}::{closure#0}`
#1 [type_of] computing type of `x::{opaque#0}`
#2 [normalize_generic_arg_after_erasing_regions] normalizing `impl for<'r> std::ops::Fn<(&'r str,)>`
#3 [check_mod_item_types] checking item types in top-level module
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0282`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-impl_trait_in_bindings`#![feature(impl_trait_in_bindings)]`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

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions