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

assign a Closure in Enum #48838

Closed
ulinlong opened this issue Mar 8, 2018 · 1 comment · Fixed by #50851
Closed

assign a Closure in Enum #48838

ulinlong opened this issue Mar 8, 2018 · 1 comment · Fixed by #50851
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

@ulinlong
Copy link

ulinlong commented Mar 8, 2018

Compiler say it's a bug :note: the compiler unexpectedly panicked. this is a bug.

I tried this code:

fn main() {
    
    let x:i32 = 0;

    let square = Functions::Square;

    println!("x square is {}", square(x));

}

enum Functions{
    Square = |x:i32|{x*x},
}

Meta

 Compiling advanced_function v0.1.0 (file:///C:/Users/tt/IdeaProjects/advanced_function)
error: internal compiler error: src\librustc_typeck\check\mod.rs:820: can't type-check body of DefId(0/0:4 ~ advanced_function[1c36]::Functions[0])
  --> src\main.rs:13:1
   |
13 | / enum Functions{
14 | |     Square = |x:i32|{x*x},
15 | | }
   | |_^

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.24.1 (d3ae9a9e0 2018-02-27) running on x86_64-pc-windows-msvc

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:451:9
stack backtrace:
   0: <std::sync::condvar::WaitTimeoutResult as core::fmt::Debug>::fmt
   1: <std::time::SystemTimeError as core::fmt::Display>::fmt
   2: std::panicking::Location::column
   3: std::panicking::Location::column
   4: std::panicking::rust_panic_with_hook
   5: <rustc_typeck::check::method::probe::ProbeScope as core::fmt::Debug>::fmt
   6: <rustc_typeck::constrained_type_params::Parameter as core::fmt::Debug>::fmt
   7: <rustc::hir::Arm as rustc_typeck::check::coercion::AsCoercionSite>::as_coercion_site
   8: <rustc_typeck::check::upvar::InferBorrowKindVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::nested_visit_map
   9: <rustc_typeck::check::op::Op as core::fmt::Debug>::fmt
  10: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  11: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  12: rustc::dep_graph::graph::DepGraph::in_ignore
  13: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
  14: <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx
  15: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  16: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  17: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  18: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  19: <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item
  20: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  21: rustc::dep_graph::graph::DepGraph::in_ignore
  22: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
  23: <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx
  24: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  25: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  26: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  27: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_tables_of
  28: rustc_mir::interpret::const_eval::const_eval_provider
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::ensure
  30: rustc::dep_graph::graph::DepGraph::in_ignore
  31: rustc::util::ppaux::<impl core::fmt::Debug for rustc::ty::Predicate<'tcx>>::fmt
  32: <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx
  33: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::ensure
  34: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  35: rustc::ty::maps::TyCtxtAt::const_eval
  36: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  37: <unknown>
  38: rustc_typeck::check_crate
  39: rustc_driver::profile::dump
  40: rustc_driver::profile::dump
  41: <rustc_driver::Compilation as core::fmt::Debug>::fmt
  42: rustc_driver::driver::compile_input
  43: rustc_driver::run_compiler
  44: rustc_driver::profile::dump
  45: _rust_maybe_catch_panic
  46: <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt
  47: <std::sync::condvar::Condvar as core::fmt::Debug>::fmt
  48: std::sys::windows::thread::Thread::new
  49: BaseThreadInitThunk

error: Could not compile `advanced_function`.

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

Process finished with exit code 101
@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Mar 8, 2018
@Centril
Copy link
Contributor

Centril commented Mar 8, 2018

Minimal reproducing example

#![crate_type = "rlib"]

enum Functions {
    Square = |x| x,
}

@Centril Centril added the A-diagnostics Area: Messages for errors, warnings, and lints label Mar 8, 2018
leoyvens added a commit to leoyvens/rust that referenced this issue May 10, 2018
During type collection, error if a closures is found in constant
position, catching that before they go causing ICEs.

Fixes rust-lang#50600.
Fixes rust-lang#48838.
@XAMPPRocky XAMPPRocky added C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 14, 2018
bors added a commit that referenced this issue May 20, 2018
rustc: introduce {ast,hir}::AnonConst to consolidate so-called "embedded constants".

Previously, constants in array lengths and enum variant discriminants were "merely an expression", and had no separate ID for, e.g. type-checking or const-eval, instead reusing the expression's.

That complicated code working with bodies, because such constants were the only special case where the "owner" of the body wasn't the HIR parent, but rather the same node as the body itself.
Also, if the body happened to be a closure, we had no way to allocate a `DefId` for both the constant *and* the closure, leading to *several* bugs (mostly ICEs where type errors were expected).

This PR rectifies the situation by adding another (`{ast,hir}::AnonConst`) node around every such constant. Also, const generics are expected to rely on the new `AnonConst` nodes, as well (cc @varkor).
* fixes #48838
* fixes #50600
* fixes #50688
* fixes #50689
* obsoletes #50623

r? @nikomatsakis
jieyouxu added a commit to jieyouxu/rust that referenced this issue Feb 5, 2025
Rename and Move some UI tests to more suitable subdirs

## Affected Tests
- tests/ui/issues/issue-48838.rs -> tests/ui/enum/closure-in-enum-issue-48838.rs rust-lang#48838
- tests/ui/issues/issue-40350.rs -> tests/ui/enum/enum-inside-enum-issue-40350.rs rust-lang#40350
- tests/ui/issues/issue-41272.rs -> tests/ui/expr/if/if-let-no-match-guards-issue-41272.rs rust-lang#41272
- tests/ui/issues/issue-40408.rs -> tests/ui/lexer/floating-point-0e10-issue-40408.rs rust-lang#40408
- tests/ui/issues/issue-40136.rs -> tests/ui/macros/const-expr-invocations-issue-40136.rs rust-lang#40136
- tests/ui/issues/issue-40845.rs -> tests/ui/macros/macros-in-trait-positions-issue-40845.rs rust-lang#40845
- tests/ui/issues/issue-41213.rs -> tests/ui/match/enum-and-break-in-match-issue-41213.rs rust-lang#41213
- tests/ui/issues/issue-40782.rs -> tests/ui/suggestions/for-loop-missing-in.rs rust-lang#40782
- tests/ui/issues/issue-40827.rs -> tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.rs rust-lang#40827
- tests/ui/issues/issue-40610.rs -> tests/ui/typeck/coercion-check-for-addition-issue-40610.rs rust-lang#40610
- tests/ui/issues/issue-40883.rs -> tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs rust-lang#40883
- tests/ui/issues/issue-40861.rs -> tests/ui/typeck/coercion-check-for-indexing-expression-issue-40861.rs rust-lang#40861
- tests/ui/issues/issue-41139.rs -> tests/ui/typeck/unsized-rvalue-issue-41139.rs rust-lang#41139
- tests/ui/issues/issue-40749.rs -> tests/ui/wf/range-expr-root-of-constant-issue-40749.rs rust-lang#40749
- tests/ui/issues/issue-40235.rs -> tests/ui/while/while-let-scope-issue-40235.rs rust-lang#40235
jieyouxu added a commit to jieyouxu/rust that referenced this issue Feb 5, 2025
Rename and Move some UI tests to more suitable subdirs

## Affected Tests
- tests/ui/issues/issue-48838.rs -> tests/ui/enum/closure-in-enum-issue-48838.rs rust-lang#48838
- tests/ui/issues/issue-40350.rs -> tests/ui/enum/enum-inside-enum-issue-40350.rs rust-lang#40350
- tests/ui/issues/issue-41272.rs -> tests/ui/expr/if/if-let-no-match-guards-issue-41272.rs rust-lang#41272
- tests/ui/issues/issue-40408.rs -> tests/ui/lexer/floating-point-0e10-issue-40408.rs rust-lang#40408
- tests/ui/issues/issue-40136.rs -> tests/ui/macros/const-expr-invocations-issue-40136.rs rust-lang#40136
- tests/ui/issues/issue-40845.rs -> tests/ui/macros/macros-in-trait-positions-issue-40845.rs rust-lang#40845
- tests/ui/issues/issue-41213.rs -> tests/ui/match/enum-and-break-in-match-issue-41213.rs rust-lang#41213
- tests/ui/issues/issue-40782.rs -> tests/ui/suggestions/for-loop-missing-in.rs rust-lang#40782
- tests/ui/issues/issue-40827.rs -> tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.rs rust-lang#40827
- tests/ui/issues/issue-40610.rs -> tests/ui/typeck/coercion-check-for-addition-issue-40610.rs rust-lang#40610
- tests/ui/issues/issue-40883.rs -> tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs rust-lang#40883
- tests/ui/issues/issue-40861.rs -> tests/ui/typeck/coercion-check-for-indexing-expression-issue-40861.rs rust-lang#40861
- tests/ui/issues/issue-41139.rs -> tests/ui/typeck/unsized-rvalue-issue-41139.rs rust-lang#41139
- tests/ui/issues/issue-40749.rs -> tests/ui/wf/range-expr-root-of-constant-issue-40749.rs rust-lang#40749
- tests/ui/issues/issue-40235.rs -> tests/ui/while/while-let-scope-issue-40235.rs rust-lang#40235
jieyouxu added a commit to jieyouxu/rust that referenced this issue Feb 5, 2025
Rename and Move some UI tests to more suitable subdirs

## Affected Tests
- tests/ui/issues/issue-48838.rs -> tests/ui/enum/closure-in-enum-issue-48838.rs rust-lang#48838
- tests/ui/issues/issue-40350.rs -> tests/ui/enum/enum-inside-enum-issue-40350.rs rust-lang#40350
- tests/ui/issues/issue-41272.rs -> tests/ui/expr/if/if-let-no-match-guards-issue-41272.rs rust-lang#41272
- tests/ui/issues/issue-40408.rs -> tests/ui/lexer/floating-point-0e10-issue-40408.rs rust-lang#40408
- tests/ui/issues/issue-40136.rs -> tests/ui/macros/const-expr-invocations-issue-40136.rs rust-lang#40136
- tests/ui/issues/issue-40845.rs -> tests/ui/macros/macros-in-trait-positions-issue-40845.rs rust-lang#40845
- tests/ui/issues/issue-41213.rs -> tests/ui/match/enum-and-break-in-match-issue-41213.rs rust-lang#41213
- tests/ui/issues/issue-40782.rs -> tests/ui/suggestions/for-loop-missing-in.rs rust-lang#40782
- tests/ui/issues/issue-40827.rs -> tests/ui/trait-bounds/deep-level-Send-bound-check-issue-40827.rs rust-lang#40827
- tests/ui/issues/issue-40610.rs -> tests/ui/typeck/coercion-check-for-addition-issue-40610.rs rust-lang#40610
- tests/ui/issues/issue-40883.rs -> tests/ui/codegen/StackColoring-not-blowup-stack-issue-40883.rs rust-lang#40883
- tests/ui/issues/issue-40861.rs -> tests/ui/typeck/coercion-check-for-indexing-expression-issue-40861.rs rust-lang#40861
- tests/ui/issues/issue-41139.rs -> tests/ui/typeck/unsized-rvalue-issue-41139.rs rust-lang#41139
- tests/ui/issues/issue-40749.rs -> tests/ui/wf/range-expr-root-of-constant-issue-40749.rs rust-lang#40749
- tests/ui/issues/issue-40235.rs -> tests/ui/while/while-let-scope-issue-40235.rs rust-lang#40235
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. 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