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 when trying to Add a Vec and vec![] on 1.17 nightly #40610

Closed
kennytm opened this issue Mar 17, 2017 · 2 comments
Closed

ICE when trying to Add a Vec and vec![] on 1.17 nightly #40610

kennytm opened this issue Mar 17, 2017 · 2 comments
Assignees
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kennytm
Copy link
Member

kennytm commented Mar 17, 2017

Repro case:

fn r(v: Vec<f32>) {
    v + <[f32]>::into_vec(Box::new([])); 
}

The <[f32]>::into_vec(Box::new([])) is expanded from vec![].

No ICE on 1.16 stable.
No ICE when trying using -, *, / etc.
No ICE when swapping the two arguments vec![] + v.
No ICE when using v + Vec::new().
No ICE when not using UFCS v + (Box::new([]) as Box<[f32]>).into_vec();


Error (panic on this line):

error: main function not found

error[E0369]: binary operation `+` cannot be applied to type `std::vec::Vec<f32>`
 --> 1.rs:2:5
  |
2 |     v + <[f32]>::into_vec(Box::new([]));
  |     ^
  |
  = note: an implementation of `std::ops::Add` might be missing for `std::vec::Vec<f32>`

error: internal compiler error: src/librustc_typeck/check/coercion.rs:693: expr already has an adjustment on it!

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:418
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: rustc_errors::Handler::bug
   1: rustc::session::opt_span_bug_fmt::{{closure}}
   2: rustc::session::opt_span_bug_fmt
   3: rustc::session::bug_fmt
   4: rustc_typeck::check::coercion::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::try_coerce
   5: rustc_typeck::check::demand::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::demand_coerce
   6: rustc_typeck::check::FnCtxt::check_argument_types
   7: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::confirm_builtin_call
   8: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_call
   9: rustc_typeck::check::FnCtxt::check_expr_kind
  10: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  11: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_overloaded_binop
  12: rustc_typeck::check::op::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_binop
  13: rustc_typeck::check::FnCtxt::check_expr_kind
  14: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  15: rustc_typeck::check::FnCtxt::check_stmt
  16: rustc_typeck::check::FnCtxt::check_block_with_expected
  17: rustc_typeck::check::FnCtxt::check_expr_kind
  18: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_lvalue_pref
  19: rustc_typeck::check::check_fn
  20: rustc_typeck::check::typeck_tables
  21: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::try_get
  22: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables<'tcx>>::get
  23: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::item_tables
  24: rustc_typeck::check::check_item_bodies
  25: rustc_typeck::check_crate
  26: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  27: rustc_driver::driver::phase_3_run_analysis_passes
  28: rustc_driver::driver::compile_input
  29: rustc_driver::run_compiler
  30: std::panicking::try::do_call
  31: __rust_maybe_catch_panic
  32: <F as alloc::boxed::FnBox<A>>::call_box
  33: std::sys::imp::thread::Thread::new::thread_start
  34: _pthread_body
  35: _pthread_start

Version:

$ rustc +nightly -vV
rustc 1.17.0-nightly (0aeb9c129 2017-03-15)
binary: rustc
commit-hash: 0aeb9c12979e6da753701a798d04105b6b1a8c28
commit-date: 2017-03-15
host: x86_64-apple-darwin
release: 1.17.0-nightly
LLVM version: 3.9
@TimNN TimNN added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 17, 2017
@kennytm
Copy link
Member Author

kennytm commented Mar 17, 2017

Simplified:

fn f(_: &[f32]) {}
fn r() {
    () + f(&[1.0]);
}

Turning on the debug log just for try_coerce (in commit 9fae040) gives:

error: main function not found

coercion::try(expr(23: { }): () -> ())
coercion::try(expr(17: 1.0): f32 -> f32)
coercion::try(expr(19: &[1.0]): &[f32; 1] -> &[f32])
Success, coerced with DerefRef { autoderefs: 1, autoref: Some(Ref('_#2r, MutImmutable)), unsize: true } -> _
coercion::try(expr(20: f(&[1.0])): () -> _)
error[E0369]: binary operation `+` cannot be applied to type `()`
 --> 1.rs:3:5
  |
3 |     () + f(&[1.0]);
  |     ^^
  |
  = note: an implementation of `std::ops::Add` might be missing for `()`

coercion::try(expr(17: 1.0): f32 -> f32)
coercion::try(expr(19: &[1.0]): &[f32; 1] -> &[f32])
Success, coerced with DerefRef { autoderefs: 1, autoref: Some(Ref('_#8r, MutImmutable)), unsize: true } -> _
error: internal compiler error: /Users/kennytm/XCodeProjects/rust/rust/src/librustc_typeck/check/coercion.rs:693: expr already has an adjustment on it!

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

thread 'rustc' panicked at 'Box<Any>', /Users/kennytm/XCodeProjects/rust/rust/src/librustc_errors/lib.rs:418
note: Run with `RUST_BACKTRACE=1` for a backtrace.

Something's wrong with CoerceUnsized?

Besides +, indexing is also affected () [ f(&[1.0]) ] (Index and IndexMut). All other operators are not affected.

@arielb1 arielb1 added regression-from-stable-to-beta Performance or correctness regression from stable to beta. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Mar 19, 2017
@brson brson added the P-high High priority label Mar 23, 2017
@eddyb
Copy link
Member

eddyb commented Mar 27, 2017

The + case is indeed a regression, caused by #39116 - this line triggers the first coercion attempt (which succeeds) but then the common path is hit, which is where the ICE is (correctly) produced. I'll prepare a fix.

As for indexing, that looks like a regression between 1.8 and 1.9 - I've opened #40861 for it.

bors added a commit that referenced this issue Apr 6, 2017
Avoid type-checking addition and indexing twice.

Fixes #40610 by moving the common `check_expr_coercable_to_type` call before the error reporting logic for binops and removing the one from `check_str_addition`.
Fixes #40861 by removing an unnecessary `check_expr_coercable_to_type` call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants