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

Compiler Unexpectedly Panicked, call function with wrong number of arguments #47706

Closed
adrian-budau opened this issue Jan 24, 2018 · 8 comments
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. P-high High priority 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.

Comments

@adrian-budau
Copy link
Contributor

First of all, this only happens on nightly

rustc --version --verbose
binary: rustc
commit-hash: 97520ccb101609af63f29919bb0a39115269c89e
commit-date: 2018-01-21
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 4.0

I tried to make the code as simple as possible, so it might look like something no sane person would write

pub struct Foo {
    foo: Option<i32>,
}

impl Foo {
    pub fn new(foo: Option<i32>, _: ()) -> Foo {
        Foo { foo }
    }

    pub fn map(self) -> Option<Foo> {
        self.foo.map(Foo::new)
    }
}

This is what i get as output

thread 'rustc' panicked at 'non-FnLike node found: NodeImplItem(ImplItem { id: NodeId(14), name: new, hir_id: HirId { owner: DefIndex(0:6), local_id: ItemLocalId(0) }, vis: Public, defaultness: Final, attrs: [], generics: Generics { params: [], where_clause: WhereClause { id: NodeId(15), predicates: [] }, span: src/lib.rs:1:1: 1:1 }, node: Method(MethodSig { unsafety: Normal, constness: NotConst, abi: Rust, decl: FnDecl { inputs: [type(Option<i32>), type(())], output: Return(type(Foo)), variadic: false, has_implicit_self: false } }, BodyId { node_id: NodeId(41) }), span: src/run_info.rs:6:5: 8:6 })', librustc/traits/error_reporting.rs:837:13
note: Run with `RUST_BACKTRACE=1` for a backtrace.
@emilio
Copy link
Contributor

emilio commented Jan 24, 2018

I also hit this, but my test-case was "apply this patch to servo", so I'm glad you had a reduced test-case already, thanks!

@dtolnay dtolnay added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jan 25, 2018
@dtolnay
Copy link
Member

dtolnay commented Jan 25, 2018

Stable: rustc 1.23.0 (766bd11 2018-01-01)

error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
  --> src/main.rs:21:18
   |
11 |         self.foo.map(Foo::new)
   |                  ^^^ expected function that takes 1 argument

Beta: rustc 1.24.0-beta.8 (ed9751a 2018-01-23)

error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
  --> src/main.rs:11:18
   |
6  |     pub fn new(foo: Option<i32>, _: ()) -> Foo {
   |     ------------------------------------------ takes 2 arguments
...
11 |         self.foo.map(Foo::new)
   |                  ^^^ expected function that takes 1 argument

@nikomatsakis
Copy link
Contributor

cc @rust-lang/infra -- any chance we could bisect this down to a PR?

@nikomatsakis
Copy link
Contributor

triage: P-high

Regression. Should be an easy fix.

@rust-highfive rust-highfive added the P-high High priority label Jan 25, 2018
@pnkfelix pnkfelix self-assigned this Jan 25, 2018
@kennytm
Copy link
Member

kennytm commented Jan 25, 2018

Bisecting between b65f0be...a0dcecf.

Script:

#!/bin/sh
$RUSTC_RELATIVE 1.rs 2>&1 | grep FnLike

Bisection result:

$ target/release/bisect --preserve --test test.sh --start b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d --end a0dcecff90c45ad5d4eb60859e22bb3f1b03842a
INFO:rust_sysroot: Getting commits from the git checkout in b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d...a0dcecff90c45ad5d4eb60859e22bb3f1b03842a
INFO:rust_sysroot: Received 93 commits
Searching in 93 commits; about 7 steps
thread 'rustc' panicked at 'non-FnLike node found: NodeImplItem(ImplItem { id: NodeId(13), name: new, hir_id: HirId { owner: DefIndex(0:5), local_id: ItemLocalId(0) }, vis: Public, defaultness: Final, attrs: [], generics: Generics { params: [], where_clause: WhereClause { id: NodeId(14), predicates: [] }, span: 1.rs:1:1: 1:1 }, node: Method(MethodSig { unsafety: Normal, constness: NotConst, abi: Rust, decl: FnDecl { inputs: [type(Option<i32>), type(())], output: Return(type(Foo)), variadic: false, has_implicit_self: false } }, BodyId { node_id: NodeId(40) }), span: 1.rs:6:5: 8:6 })', librustc/traits/error_reporting.rs:837:13
thread 'rustc' panicked at 'non-FnLike node found: NodeImplItem(ImplItem { id: NodeId(13), name: new, hir_id: HirId { owner: DefIndex(0:5), local_id: ItemLocalId(0) }, vis: Public, defaultness: Final, attrs: [], generics: Generics { params: [], where_clause: WhereClause { id: NodeId(14), predicates: [] }, span: 1.rs:1:1: 1:1 }, node: Method(MethodSig { unsafety: Normal, constness: NotConst, abi: Rust, decl: FnDecl { inputs: [type(Option<i32>), type(())], output: Return(type(Foo)), variadic: false, has_implicit_self: false } }, BodyId { node_id: NodeId(40) }), span: 1.rs:6:5: 8:6 })', librustc/traits/error_reporting.rs:837:13
searched commits b65f0bedd2f22d9661ecb7092f07746dc2ccfb0d through a0dcecff90c45ad5d4eb60859e22bb3f1b03842a
regression in 76; Some(Commit { sha: "8d3e93beae9562f8b32b7f82c3824389f6ac5bad", date: 2018-01-21T06:32:03Z, summary: "Auto merge of #47622 - GuillaumeGomez:rollup, r=GuillaumeGomez" })

Actual cause is #47573, cc @estebank.

@kennytm kennytm added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Jan 25, 2018
@estebank
Copy link
Contributor

estebank commented Jan 25, 2018

Confirmed, panic introduced in that PR. Will submit for review once local test run completes.

Sorry about this, I failed to account for impl methods.


Fix: #47747. I've kept the panic there, as this code should never be called with a non-fn element and would want it to complain loudly if it happens, but if an ICE ever happens again, we can fall through silently (at the very least in stable) as only con of doing so is having no label in the original item's span.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 25, 2018
@CAD97
Copy link
Contributor

CAD97 commented Jan 29, 2018

@estebank ICE still occurs with NodeTraitItem (trait default fn)

trait T {
    fn f(&self, _: ()) {
        None::<()>.map(Self::f);
    }
}
Stack Trace
thread 'rustc' panicked at 'non-FnLike node found: NodeTraitItem(TraitItem { id: NodeId(6), name: f, hir_id: HirId { owner: DefIndex(0:4), local_id: ItemLocalId(0) }, attrs: [], generics: Generics { params: [], where_clause: WhereClause { id: NodeId(7), predicates: [] }, span: src\main.rs:1:1: 1:1 }, node: Method(MethodSig { unsafety: Normal, constness: NotConst, abi: Rust, decl: FnDecl { inputs: [type(&Self), type(())], output: DefaultReturn(src\main.rs:2:24: 2:24), variadic: false, has_implicit_self: true } }, Provided(BodyId { node_id: NodeId(25) })), span: src\main.rs:2:5: 4:6 })', librustc\traits\error_reporting.rs:846:18
stack backtrace:
   0:     0x7ffedcc846dd - std::rt::lang_start_internal::h6a4891cd6ad9df3d
   1:     0x7ffedcc872ef - std::fs::FileType::is_dir::hf1c2aa54924656a2
   2:     0x7ffedcc9082f - std::panicking::Location::column::hdc2cb9a904b38b88
   3:     0x7ffedcc904d5 - std::panicking::Location::column::hdc2cb9a904b38b88
   4:     0x7ffedcc90dfc - std::panicking::rust_panic_with_hook::h722955029fa85c2e
   5:     0x7ffedcc90c00 - std::panicking::begin_panic_fmt::hdf8109b479eeb360
   6:     0x7ffedcc90b51 - std::panicking::begin_panic_fmt::hdf8109b479eeb360
   7:     0x7ffeccc0b739 - rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_selection_error::hc013179b5351d84d
   8:     0x7ffeccc00069 - rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_fulfillment_errors::h4433be3ed2c84ec8
   9:     0x7ffee2e425ca - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  10:     0x7ffee2e4387a - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  11:     0x7ffee2e43016 - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  12:     0x7ffee2e52da9 - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  13:     0x7ffee2e46a06 - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  14:     0x7ffee2e5930e - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  15:     0x7ffee2e46fb8 - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  16:     0x7ffee2e46a06 - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  17:     0x7ffee2e4595f - <rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx> as rustc_typeck::astconv::AstConv<'gcx, 'tcx>>::record_ty::h9b01acacbcbaff91
  18:     0x7ffee2e3678d - <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_pat::hb7b0709391a3fd8d
  19:     0x7ffee2ebe159 - <rustc_typeck::outlives::test::OutlivesTest<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item::h0e25c0a16f74e38c
  20:     0x7ffee2e76746 - <rustc_typeck::check::Diverges as core::fmt::Debug>::fmt::h1c65dfb30c7b3c51
  21:     0x7ffee2e350c2 - <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item::hf39656246afa540d
  22:     0x7ffecca7c126 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure::hba2ab45518988f23
  23:     0x7ffecd074c9a - rustc::dep_graph::graph::DepGraph::assert_ignored::h3d788a943cdbafc4
  24:     0x7ffeccb5c046 - rustc::ty::maps::<impl rustc::ty::maps::queries::instance_def_size_estimate<'tcx>>::try_get::h23404c885dbf382f
  25:     0x7ffeccd3fe27 - <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx::h93da4ee47aa7f377
  26:     0x7ffecca7c1d6 - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure::hba2ab45518988f23
  27:     0x7ffecca7c9ba - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get::h96e5020f96e0297c
  28:     0x7ffeccd95b6f - rustc::ty::maps::TyCtxtAt::typeck_tables_of::h4054dbb665aa1f74
  29:     0x7ffecca7c09c - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure::hba2ab45518988f23
  30:     0x7ffee2f3af66 - <rustc_typeck::variance::terms::InferredIndex as core::fmt::Debug>::fmt::h774c8f2cd3b8f384
  31:     0x7ffee2e34c4d - <rustc_typeck::check::CheckItemTypesVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'tcx>>::visit_item::hf39656246afa540d
  32:     0x7ffecd0936ae - rustc::dep_graph::graph::DepGraph::assert_ignored::h3d788a943cdbafc4
  33:     0x7ffeccb646b7 - rustc::ty::maps::<impl rustc::ty::maps::queries::instance_def_size_estimate<'tcx>>::try_get::h23404c885dbf382f
  34:     0x7ffeccd0ea17 - <rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx> as rustc::ty::layout::HasTyCtxt<'gcx>>::tcx::h93da4ee47aa7f377
  35:     0x7ffecca7ab8a - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::ensure::h5a89529d361a30e7
  36:     0x7ffecca7b24f - rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get::hcd0c852dadf7529b
  37:     0x7ffeccd95a57 - rustc::ty::maps::TyCtxtAt::typeck_item_bodies::h58611989c649d001
  38:     0x7ffeccd921a2 - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies::h585d4c02703c78ad
  39:     0x7ffee2f6d5c3 - rustc_typeck::check_crate::h05100ae6a011b747
  40:     0x7ffee6cfe07d - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::hae9e730b8990bdb8
  41:     0x7ffee6d010f0 - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::hae9e730b8990bdb8
  42:     0x7ffee6d45fb0 - <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item::h34e7b02473305531
  43:     0x7ffee6c80397 - rustc_driver::driver::compile_input::hc6aa0b074e7a66c3
  44:     0x7ffee6d5ee9d - rustc_driver::run_compiler::hf2ae78daa657a043
  45:     0x7ffee6c3ee2a - <unknown>
  46:     0x7ffedccbd271 - _rust_maybe_catch_panic
  47:     0x7ffee6cb490a - <rustc_driver::pretty::UserIdentifiedItem as core::fmt::Debug>::fmt::hae9e730b8990bdb8
  48:     0x7ffedccbc1cb - <<std::sys_common::remutex::ReentrantMutex<T> as core::fmt::Debug>::fmt::LockedPlaceholder as core::fmt::Debug>::fmt::h6a90c306f5c106da
  49:     0x7ffedcc8ce36 - std::sys::windows::thread::Thread::new::h62f006ffe7a96a67
  50:     0x7fff1b1a1fe3 - BaseThreadInitThunk
  51:     0x7fff1d5aefb0 - RtlUserThreadStart

error: internal compiler error: unexpected panic

@kennytm kennytm reopened this Jan 29, 2018
kennytm added a commit to kennytm/rust that referenced this issue Jan 31, 2018
Fix regression: account for trait methods in arg count mismatch error

Fixed rust-lang#47706 (rust-lang#47706 (comment))

Original PR rust-lang#47747 missed methods on trait definitions.

This edit was done in GitHub. I think I got the signature of the variant right, going by the ICE debug output and the other cases above.
@FraGag
Copy link
Contributor

FraGag commented Feb 15, 2018

@estebank ICE still occurs with NodeVariant (enum variant):

enum Foo {
    Bar(i32),
}

fn foo<F>(f: F)
where
    F: Fn(),
{
}

fn main() {
    foo(Foo::Bar);
}

Stack trace:

thread 'rustc' panicked at 'non-FnLike node found: NodeVariant(Spanned { node: Variant_ { name: Bar, attrs: [], data: Tuple([StructField { span: src/main.rs:2:9: 2:13, name: 0, vis: Inherited, id: NodeId(6), ty: type(i32), attrs: [] }], NodeId(8)), disr_expr: None }, span: src/main.rs:2:5: 2:13 })', librustc/traits/error_reporting.rs:873:18
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59
             at libstd/panicking.rs:380
   3: std::panicking::default_hook
             at libstd/panicking.rs:396
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:576
   5: std::panicking::begin_panic
             at libstd/panicking.rs:537
   6: std::panicking::begin_panic_fmt
             at libstd/panicking.rs:521                                                                                                                                                                                                      
   7: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_selection_error                                                                                                                                 
   8: rustc::traits::error_reporting::<impl rustc::infer::InferCtxt<'a, 'gcx, 'tcx>>::report_fulfillment_errors                                                                                                                              
   9: rustc_typeck::check::FnCtxt::select_obligations_where_possible                                                                                                                                                                         
  10: rustc_typeck::check::FnCtxt::check_argument_types                                                                                                                                                                                      
  11: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::confirm_builtin_call                                                                                                                                  
  12: rustc_typeck::check::FnCtxt::check_expr_kind                                                                                                                                                                                           
  13: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs                                                                                                                                                                     
  14: rustc_typeck::check::FnCtxt::check_block_with_expected::{{closure}}                                                                                                                                                                    
  15: rustc_typeck::check::FnCtxt::check_block_with_expected                                                                                                                                                                                 
  16: rustc_typeck::check::FnCtxt::check_expr_kind                                                                                                                                                                                           
  17: rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs                                                                                                                                                                     
  18: rustc_typeck::check::FnCtxt::check_return_expr                                                                                                                                                                                         
  19: rustc_typeck::check::check_fn                                                                                                                                                                                                          
  20: rustc_typeck::check::typeck_tables_of::{{closure}}
  21: rustc_typeck::check::typeck_tables_of
  22: rustc::dep_graph::graph::DepGraph::with_task_impl
  23: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::force
  24: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::try_get
  25: rustc::ty::maps::TyCtxtAt::typeck_tables_of
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_tables_of<'tcx>>::ensure
  27: rustc_typeck::check::typeck_item_bodies
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::force
  30: rustc::ty::maps::<impl rustc::ty::maps::queries::typeck_item_bodies<'tcx>>::try_get
  31: rustc::ty::maps::TyCtxtAt::typeck_item_bodies
  32: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::typeck_item_bodies
  33: rustc_typeck::check_crate
  34: rustc::ty::context::TyCtxt::create_and_enter
  35: rustc_driver::driver::compile_input
  36: rustc_driver::run_compiler

error: internal compiler error: unexpected panic

This is on rustc 1.25.0-nightly (3ec5a99aa 2018-02-14).

@shepmaster shepmaster reopened this Feb 15, 2018
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 24, 2018
Avoid ICE in arg mistmatch error for tuple variants

Fix rust-lang#47706.
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 24, 2018
Avoid ICE in arg mistmatch error for tuple variants

Fix rust-lang#47706.
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-bug Category: This is a bug. P-high High priority 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.
Projects
None yet
Development

No branches or pull requests