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

Error using impl_trait_in_bindings #86642

Closed
TomerAberbach opened this issue Jun 26, 2021 · 1 comment · Fixed by #87383
Closed

Error using impl_trait_in_bindings #86642

TomerAberbach opened this issue Jun 26, 2021 · 1 comment · Fixed by #87383
Labels
C-bug Category: This is a bug. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` glacier ICE tracked in rust-lang/glacier. 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

@TomerAberbach
Copy link

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`.

@TomerAberbach TomerAberbach 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 Jun 26, 2021
@jonas-schievink jonas-schievink added the F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` label Jun 26, 2021
@hellow554
Copy link
Contributor

Looks like a dup of #83919

fanninpm added a commit to fanninpm/glacier that referenced this issue Jul 4, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 6, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 23, 2021
…sts, r=oli-obk

Add regression tests for the impl_trait_in_bindings ICEs

Closes rust-lang#54600, closes rust-lang#54840, closes rust-lang#58504, closes rust-lang#58956, closes rust-lang#70971, closes rust-lang#79099, closes rust-lang#84919, closes rust-lang#86201, closes rust-lang#86642, closes rust-lang#87295

r? `@oli-obk`
@bors bors closed this as completed in 7c0c329 Jul 23, 2021
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. F-impl_trait_in_bindings `#![feature(impl_trait_in_bindings)]` glacier ICE tracked in rust-lang/glacier. 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.

4 participants