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

ICE in stable 1.57.0 when missing generic argument in return type #92305

Closed
arknave opened this issue Dec 26, 2021 · 6 comments · Fixed by #96614
Closed

ICE in stable 1.57.0 when missing generic argument in return type #92305

arknave opened this issue Dec 26, 2021 · 6 comments · Fixed by #96614
Labels
C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@arknave
Copy link

arknave commented Dec 26, 2021

Repro steps: create a new cargo binary with cargo new. Replace src/main.rs with the following code. Then run cargo build. Hope this is helpful! I've tried to minimize the code as much as possible.

Code

use std::iter;

fn f<T>(data: &[T]) -> impl Iterator<Item = Vec> {
    iter::empty()
}

fn g<T>(data: &[T], target: T) -> impl Iterator<Item = Vec<T>> {
    f(data).filter(|x| x == target)
}

fn main() {}

Meta

rustc --version --verbose:

rustc 1.57.0 (f1edd0429 2021-11-29)
binary: rustc
commit-hash: f1edd0429582dd29cccacaf50fd134b05593bd9c
commit-date: 2021-11-29
host: x86_64-apple-darwin
release: 1.57.0
LLVM version: 13.0.0

Error output

error[E0107]: missing generics for struct `Vec`
 --> src/main.rs:3:43
  |
3 | fn f<T>(data: &[T]) -> impl Iterator<Item=Vec> {
  |                                           ^^^ expected at least 1 generic argument
  |
help: add missing generic argument
  |
3 | fn f<T>(data: &[T]) -> impl Iterator<Item=Vec<T>> {
  |                                           ~~~~~~

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: PlaceBuilder { base: Upvar { var_hir_id: HirId { owner: DefId(0:9 ~ ice_repro[c5a9]::g), local_id: 4 }, closure_def_id: DefId(0:12 ~ ice_repro[c5a9]::g::{closure#0}), closure_kind: FnMut }, projection: [] }', compiler/rustc_mir_build/src/build/expr/as_place.rs:306:69
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 (f1edd0429 2021-11-29) running on x86_64-apple-darwin

note: compiler flags: -C embed-bitcode=no -C split-debuginfo=unpacked -C debuginfo=2 -C incremental --crate-type bin

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

query stack during panic:
#0 [mir_built] building MIR for `g::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `g::{closure#0}`
end of query stack
For more information about this error, try `rustc --explain E0107`.
error: could not compile `ice_repro` due to previous error
Backtrace

thread 'rustc' panicked at 'called `Result::unwrap()` on an `Err` value: PlaceBuilder { base: Upvar { var_hir_id: HirId { owner: DefId(0:9 ~ ice_repro[c5a9]::g), local_id: 4 }, closure_def_id: DefId(0:12 ~ ice_repro[c5a9]::g::{closure#0}), closure_kind: FnMut }, projection: [] }', compiler/rustc_mir_build/src/build/expr/as_place.rs:306:69
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: rustc_mir_build::build::expr::as_place::PlaceBuilder::into_place
   4: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
   5: rustc_mir_build::build::expr::as_temp::<impl rustc_mir_build::build::Builder>::as_temp_inner
   6: rustc_mir_build::build::expr::as_operand::<impl rustc_mir_build::build::Builder>::as_operand
   7: rustc_mir_build::build::expr::as_operand::<impl rustc_mir_build::build::Builder>::as_call_operand
   8: rustc_mir_build::build::expr::as_operand::<impl rustc_mir_build::build::Builder>::as_call_operand
   9: <core::iter::adapters::copied::Copied<I> as core::iter::traits::iterator::Iterator>::fold
  10: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  11: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  12: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  13: rustc_data_structures::stack::ensure_sufficient_stack
  14: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  15: rustc_mir_build::build::scope::<impl rustc_mir_build::build::Builder>::in_scope
  16: rustc_data_structures::stack::ensure_sufficient_stack
  17: rustc_mir_build::build::expr::into::<impl rustc_mir_build::build::Builder>::expr_into_dest
  18: rustc_mir_build::build::construct_fn
  19: rustc_infer::infer::InferCtxtBuilder::enter
  20: rustc_mir_build::build::mir_built
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  22: rustc_data_structures::stack::ensure_sufficient_stack
  23: rustc_query_system::query::plumbing::try_execute_query
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_built
  25: rustc_mir_transform::check_unsafety::unsafety_check_result
  26: core::ops::function::FnOnce::call_once
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  28: rustc_data_structures::stack::ensure_sufficient_stack
  29: rustc_query_system::query::plumbing::try_execute_query
  30: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  31: <rustc_mir_transform::check_unsafety::UnsafetyChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
  32: rustc_mir_transform::check_unsafety::unsafety_check_result
  33: core::ops::function::FnOnce::call_once
  34: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  35: rustc_data_structures::stack::ensure_sufficient_stack
  36: rustc_query_system::query::plumbing::try_execute_query
  37: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
  38: rustc_mir_transform::mir_const
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::try_execute_query
  42: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_const
  43: rustc_mir_transform::mir_promoted
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::try_execute_query
  47: rustc_query_system::query::plumbing::get_query
  48: rustc_borrowck::mir_borrowck
  49: core::ops::function::FnOnce::call_once
  50: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  51: rustc_data_structures::stack::ensure_sufficient_stack
  52: rustc_query_system::query::plumbing::try_execute_query
  53: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::mir_borrowck
  54: rustc_typeck::collect::type_of::type_of
  55: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  56: rustc_data_structures::stack::ensure_sufficient_stack
  57: rustc_query_system::query::plumbing::try_execute_query
  58: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::type_of
  59: rustc_typeck::check::check::check_item_type
  60: rustc_middle::hir::map::Map::visit_item_likes_in_module
  61: rustc_typeck::check::check::check_mod_item_types
  62: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  63: rustc_data_structures::stack::ensure_sufficient_stack
  64: rustc_query_system::query::plumbing::try_execute_query
  65: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  66: rustc_middle::hir::map::Map::for_each_module
  67: rustc_typeck::check_crate
  68: rustc_interface::passes::analysis
  69: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  70: rustc_data_structures::stack::ensure_sufficient_stack
  71: rustc_query_system::query::plumbing::try_execute_query
  72: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  73: rustc_interface::passes::QueryContext::enter
  74: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  75: rustc_span::with_source_map
  76: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

...

query stack during panic:
#0 [mir_built] building MIR for `g::{closure#0}`
#1 [unsafety_check_result] unsafety-checking `g::{closure#0}`
#2 [unsafety_check_result] unsafety-checking `g`
#3 [mir_const] processing MIR for `g`
#4 [mir_promoted] processing `g`
#5 [mir_borrowck] borrow-checking `g`
#6 [type_of] computing type of `g::{opaque#0}`
#7 [check_mod_item_types] checking item types in top-level module
#8 [analysis] running analysis passes on this crate
end of query stack

@arknave arknave 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 Dec 26, 2021
@arknave arknave changed the title Internal Compiler Error when missing generic argument in return type ICE in stable 1.57.0 when missing generic argument in return type Dec 26, 2021
@arknave
Copy link
Author

arknave commented Dec 26, 2021

The same issue happens in the latest nightly as well.

$ rustup run nightly rustc --version --verbose 
rustc 1.59.0-nightly (51e8031e1 2021-12-25)
binary: rustc
commit-hash: 51e8031e14a899477a5e2d78ce461cab31123354
commit-date: 2021-12-25
host: x86_64-apple-darwin
release: 1.59.0-nightly
LLVM version: 13.0.0

@dtolnay dtolnay added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 27, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 27, 2021
@dtolnay
Copy link
Member

dtolnay commented Dec 27, 2021

This bisects to nightly-2021-06-25. Commit range: 5a78340...7c3872e.

It only reproduces with edition = "2021", not edition = "2018", which means bisecting to the old nightly needs cargo-features = ["edition2021"] in Cargo.toml.

In that range, #86536 looks the most relevant because it is the only thing introducing edition-specific behavior, and it's dealing with closure capture and the presence of a closure appears necessary in the minimal repro. @arora-aman would you be interested in taking a look?

@apiraino
Copy link
Contributor

For comparison, the same code with edition=2018 doesn't emit a compiler error and has a bit more info:

error[E0107]: missing generics for struct `Vec`
   --> src/main.rs:3:45
    |
3   | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec> {
    |                                             ^^^ expected at least 1 generic argument
    |
note: struct defined here, with at least 1 generic parameter: `T`
   --> /home/jman/.rustup/toolchains/1.56.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/vec/mod.rs:398:12
    |
398 | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
    |            ^^^ -
help: add missing generic argument
    |
3   | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec<T>> {
    |                                             ~~~~~~

error[E0282]: type annotations needed
 --> src/main.rs:4:5
  |
4 |     iter::empty()
  |     ^^^^^^^^^^^ cannot infer type for type parameter `T` declared on the function `empty`

error[E0720]: cannot resolve opaque type
 --> src/main.rs:7:35
  |
3 | fn f<T>(data: &[T]) -> impl Iterator<Item = Vec> {
  |                        ------------------------- returning this opaque type `Filter<impl Iterator, [closure@src/main.rs:8:20: 8:35]>`
...
7 | fn g<T>(data: &[T], target: T) -> impl Iterator<Item = Vec<T>> {
  |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ recursive opaque type
8 |     f(data).filter(|x| x == target)
  |     ------------------------------- returning here with type `Filter<impl Iterator, [closure@src/main.rs:8:20: 8:35]>`

Some errors have detailed explanations: E0107, E0282, E0720.
For more information about an error, try `rustc --explain E0107`.
error: could not compile `issue-92305` due to 3 previous errors

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Dec 27, 2021
@apiraino
Copy link
Contributor

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-low

@rustbot rustbot added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Dec 28, 2021
@ouz-a
Copy link
Contributor

ouz-a commented Dec 28, 2021

In both version=2018 and version=2021, this function returns Ok value every time but somehow in version=2021 value unwraps into error, even though it's Ok

This is the returned value:

PlaceBuilder { base: Local(_1), projection: [Deref, Field(field[0], &T), Deref] }

@JohnTitor
Copy link
Member

Triage: This is no longer ICE with the latest nightly, since #96548 (presumably #96516). Marked as E-needs-test.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 30, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue May 1, 2022
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue May 2, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue May 3, 2022
Rollup of 8 pull requests

Successful merges:

 - rust-lang#93097 (Switch settings menu to full js)
 - rust-lang#96587 (Refactor the WriteBackendMethods and ExtraBackendMethods traits)
 - rust-lang#96589 (Use source callsite in check_argument_types suggestion)
 - rust-lang#96599 (Update `RValue::Discriminant` documentation)
 - rust-lang#96614 (Add a regression test for rust-lang#92305)
 - rust-lang#96629 (Fix invalid keyword order for function declarations)
 - rust-lang#96641 (Use a yes/no enum instead of a bool.)
 - rust-lang#96646 (Mitigate impact of subtle invalid call suggestion logic)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 492d403 May 3, 2022
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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

7 participants