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: compiler/rustc_middle/src/ty/sty.rs:399:33: upvar_tys called before capture types are inferred #78720

Closed
chengniansun opened this issue Nov 4, 2020 · 7 comments · Fixed by #78725
Assignees
Labels
C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc 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

@chengniansun
Copy link

chengniansun commented Nov 4, 2020

Code

fn server() -> impl {
    ().map2(|| "")
}
trait FilterBase2 {
    fn map2<F>(self, F) -> Map2<F> {}
}
struct Map2<segment2> {
    _func: F,
}
impl<F> FilterBase2 for F {}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (338f939a8 2020-11-02)
binary: rustc
commit-hash: 338f939a8d77061896cd0a1ca87a2c6d1f4ec359
commit-date: 2020-11-02
host: x86_64-unknown-linux-gnu
release: 1.49.0-nightly

Error output

error: at least one trait must be specified
 --> reduced-mutant.rs:1:16
  |
1 | fn server() -> impl {
  |                ^^^^

error[E0412]: cannot find type `F` in this scope
  --> reduced-mutant.rs:8:12
   |
8  |       _func: F,
   |              ^
   |
help: a trait with a similar name exists
   |
8  |     _func: Fn,
   |            ^^
help: you might be missing a type parameter
   |
7  | struct Map2<segment2, F> {
   |                     ^^^

warning: type parameter `segment2` should have an upper camel case name
 --> reduced-mutant.rs:7:13
  |
7 | struct Map2<segment2> {
  |             ^^^^^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Segment2`
  |
  = note: `#[warn(non_camel_case_types)]` on by default

error[E0601]: `main` function not found in crate `reduced_mutant`
  --> reduced-mutant.rs:1:1
   |
1  | / fn server() -> impl {
2  | |     ().map2(|| "")
3  | | }
4  | | trait FilterBase2 {
...  |
9  | | }
10 | | impl<F> FilterBase2 for F {}
   | |____________________________^ consider adding a `main` function to `reduced-mutant.rs`

error: internal compiler error: /rustc/338f939a8d77061896cd0a1ca87a2c6d1f4ec359/compiler/rustc_middle/src/ty/sty.rs:399:33: upvar_tys called before capture types are inferred

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958: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 (338f939a8 2020-11-02) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `server`
#1 [mir_built] building MIR for `server`
end of query stack
error: aborting due to 4 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.
Backtrace

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
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::ClosureSubsts::upvar_tys
   9: <rustc_trait_selection::opaque_types::ConstrainOpaqueTypeRegionVisitor<OP> as rustc_middle::ty::fold::TypeVisitor>::visit_ty
  10: <core::iter::adapters::Copied<I> as core::iter::traits::iterator::Iterator>::try_fold
  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_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_middle::ty::context::TyCtxt::typeck_opt_const_arg
  28: rustc_mir_build::thir::cx::Cx::new
  29: rustc_infer::infer::InferCtxtBuilder::enter
  30: rustc_mir_build::build::mir_built
  31: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_built>::compute
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::get_query_impl
  35: rustc_mir::transform::check_unsafety::unsafety_check_result
  36: core::ops::function::FnOnce::call_once
  37: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::unsafety_check_result>::compute
  38: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  39: rustc_data_structures::stack::ensure_sufficient_stack
  40: rustc_query_system::query::plumbing::get_query_impl
  41: rustc_query_system::query::plumbing::ensure_query_impl
  42: rustc_mir::transform::mir_const
  43: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_const>::compute
  44: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  45: rustc_data_structures::stack::ensure_sufficient_stack
  46: rustc_query_system::query::plumbing::get_query_impl
  47: rustc_mir::transform::mir_promoted
  48: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_promoted>::compute
  49: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  50: rustc_data_structures::stack::ensure_sufficient_stack
  51: rustc_query_system::query::plumbing::get_query_impl
  52: rustc_mir::borrow_check::mir_borrowck
  53: core::ops::function::FnOnce::call_once
  54: 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
  55: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  56: rustc_data_structures::stack::ensure_sufficient_stack
  57: rustc_query_system::query::plumbing::get_query_impl
  58: rustc_typeck::collect::type_of::type_of
  59: 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
  60: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  61: rustc_data_structures::stack::ensure_sufficient_stack
  62: rustc_query_system::query::plumbing::get_query_impl
  63: rustc_typeck::check::check::check_item_type
  64: rustc_middle::hir::map::Map::visit_item_likes_in_module
  65: rustc_typeck::check::check::check_mod_item_types
  66: 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
  67: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  68: rustc_data_structures::stack::ensure_sufficient_stack
  69: rustc_query_system::query::plumbing::get_query_impl
  70: rustc_query_system::query::plumbing::ensure_query_impl
  71: rustc_session::utils::<impl rustc_session::session::Session>::time
  72: rustc_typeck::check_crate
  73: rustc_interface::passes::analysis
  74: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  75: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  76: rustc_data_structures::stack::ensure_sufficient_stack
  77: rustc_query_system::query::plumbing::get_query_impl
  78: rustc_interface::passes::QueryContext::enter

NOTE: The bug is found by our work-in-progress compiler testing tool Kira, and the test program is reduced/minimized by Perses

@chengniansun chengniansun 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 Nov 4, 2020
@jyn514
Copy link
Member

jyn514 commented Nov 4, 2020

@chengniansun does this still panic after #78432 ? That only merged a couple days ago so you'll need to update your version of nightly.

@jyn514
Copy link
Member

jyn514 commented Nov 4, 2020

Hmm I checked and it does, and it also panics before. So probably unrelated?

cc @arora-aman just in case

@jyn514
Copy link
Member

jyn514 commented Nov 4, 2020

Note that this works fine on +nightly-2020-06-22.

@jyn514 jyn514 added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Nov 4, 2020
@chengniansun
Copy link
Author

@chengniansun does this still panic after #78432 ? That only merged a couple days ago so you'll need to update your version of nightly.

@chengniansun
Copy link
Author

Sorry, I accidentally closed the issue.

@jyn514 Yes, you are right. It still crashes on the latest nightly version. I have a cron job to update my rust version everyday.

@arora-aman
Copy link
Member

arora-aman commented Nov 4, 2020

I think we ended up (incorrectly) removing a check in a64ad51#diff-98923b31651a0150fc5eae47f5ceb44f716b521762db4e37cf9292dac7b3e040L724-L733

We shouldn't be calling upvars_ty if tupled_upvars_ty is ty::Infer. This is a separate issue than that was fixed in #78432

@arora-aman
Copy link
Member

@rustbot claim

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 1, 2020
Remove extra call to upvar_tys

We already visit the tuple of upvar_tys, we don't need to visit each individual type.

Fixes rust-lang#78720

r? `@ghost`
@bors bors closed this as completed in 5da2bf1 Dec 1, 2020
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-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc 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.

3 participants