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

Panic on relm macro with "there must be a else here" message #3741

Closed
konchunas opened this issue Feb 5, 2019 · 7 comments · Fixed by #3960
Closed

Panic on relm macro with "there must be a else here" message #3741

konchunas opened this issue Feb 5, 2019 · 7 comments · Fixed by #3960
Assignees
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@konchunas
Copy link

clippy 0.0.212 (1b89724 2019-01-15)

When using clippy on a project with #[widget] macro from "relm" crate I get the following panic:

thread 'rustc' panicked at 'there must be a `else` here', src/libcore/option.rs:1038:5
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 src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   6: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:385
   7: rust_begin_unwind
             at src/libstd/panicking.rs:312
   8: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   9: core::option::expect_failed
             at src/libcore/option.rs:1038
  10: <clippy_lints::formatting::Formatting as rustc::lint::EarlyLintPass>::check_expr
  11: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  12: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  13: syntax::visit::walk_expr
  14: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  15: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  16: syntax::visit::walk_expr
  17: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_expr
  18: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_local
  19: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_block
  20: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_fn
  21: syntax::visit::walk_impl_item
  22: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_impl_item
  23: syntax::visit::walk_item
  24: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_item
  25: <rustc::lint::context::EarlyContext<'a> as syntax::visit::Visitor<'a>>::visit_mod
  26: rustc::lint::context::check_ast_crate
  27: rustc::util::common::time
  28: rustc_driver::driver::phase_2_configure_and_expand
  29: rustc_driver::driver::compile_input
  30: rustc_driver::run_compiler_with_pool
  31: <scoped_tls::ScopedKey<T>>::set
  32: rustc_driver::run_compiler
  33: <scoped_tls::ScopedKey<T>>::set
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.33.0-nightly (c76f3c374 2019-01-18) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

Normal cargo build works just fine
I've created small project where this crash can be easily reproduced.
Here are repro steps:

git clone https://github.com/konchunas/clippy-relm-panic.git
cd clippy-relm-panic
RUST_BACKTRACE=1 cargo clippy

Thank you!

@phansch phansch added the I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️ label Feb 5, 2019
@SNCPlay42
Copy link

SNCPlay42 commented Feb 27, 2019

Small repro proc-derive for what I think is the same issue:

//test_derive/src/lib.rs

//dependencies for test_derive:
//proc-macro2 = "0.4"
//quote = "0.6"
//syn = "0.15"

extern crate proc_macro;
use quote::quote_spanned;

#[proc_macro_derive(Test)]
pub fn derive_test(input_stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let input: syn::DeriveInput = syn::parse(input_stream).unwrap();
    let name = input.ident;
    let span = name.span();
    let mut cases = Vec::new();
    for i in 0..3 {
        cases.push(quote_spanned!{span=>
            if n == #i {
                println!("case {}", #i);
            } else
        });
    }
    quote_spanned!(span=>
        fn code(n: i32) {
            #(#cases)*
            {
                println!("no case matched");
            }
        }
    ).into()
}
//src/main.rs
use test_derive::Test;

#[derive(Test)]
struct Test();

fn main() {
    code(2);
}

Both splitting the quote into multiple pieces and applying a span (quote_spanned! as opposed to quote!) appear necessary to trigger the ICE.

@phansch phansch self-assigned this Mar 3, 2019
@hcpl
Copy link

hcpl commented Mar 31, 2019

Minimized example from @SNCPlay42's code:

//test_macro/src/lib.rs

//dependencies for test_macro:
//proc-macro2 = "0.4"
//quote = "0.6"

extern crate proc_macro;
use quote::{quote, quote_spanned};

#[proc_macro]
pub fn macro_test(input_stream: proc_macro::TokenStream) -> proc_macro::TokenStream {
    let first_token = input_stream.into_iter().next().unwrap();
    let span: proc_macro2::Span = first_token.span().into();
    let clause = quote_spanned!(span=> {});

    quote!(
        fn code() {
            if true #clause else #clause
        }
    ).into()
}


//src/lib.rs
test_macro::macro_test!(2);

Both if and else clauses need to have a span from the input stream to trigger ICE.

@hcpl
Copy link

hcpl commented Mar 31, 2019

A zero crates.io dependency version of the minimal example above:

//test_macro/src/lib.rs

//no dependencies for test_macro:

extern crate proc_macro;

use proc_macro::{Delimiter, Group, Ident, Span, TokenStream, TokenTree};
use std::iter::FromIterator;

#[proc_macro]
pub fn macro_test(input_stream: TokenStream) -> TokenStream {
    let first_token = input_stream.into_iter().next().unwrap();
    let span = first_token.span();

    TokenStream::from_iter(vec![
        TokenTree::Ident(Ident::new("fn", Span::call_site())),
        TokenTree::Ident(Ident::new("code", Span::call_site())),
        TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
        TokenTree::Group(Group::new(Delimiter::Brace, {
            let mut clause = Group::new(Delimiter::Brace, TokenStream::new());
            clause.set_span(span);

            TokenStream::from_iter(vec![
                TokenTree::Ident(Ident::new("if", Span::call_site())),
                TokenTree::Ident(Ident::new("true", Span::call_site())),
                TokenTree::Group(clause.clone()),
                TokenTree::Ident(Ident::new("else", Span::call_site())),
                TokenTree::Group(clause.clone()),
            ])
        })),
    ])
}


//src/lib.rs
test_macro::macro_test!(2);

anelson added a commit to anelson/tracers that referenced this issue Apr 3, 2019
@phansch
Copy link
Member

phansch commented Apr 5, 2019

I'm going to have another look at this today. Last time I was stuck trying to create a failing test, but I think that it will work now with the example from @hcpl (thanks!) and #3922.

phansch added a commit to phansch/compiletest-rs that referenced this issue Apr 7, 2019
Taken from work on rust-lang/rust-clippy#3741.

I think this is a useful test to have because it tests

* the `run-pass` header
* the `aux-build` header, building auxiliary files
* the `no-prefer-dynamic` header
* proc-macro crate interactions with all of the above
* running of UI tests that include auxiliary files

There's no tests for any of the above right now.
bors added a commit that referenced this issue Apr 9, 2019
Fix ICE in suspicious_else_formatting

Fixes #3741
@bors bors closed this as completed in #3925 Apr 9, 2019
@lukasschlueter
Copy link

I'm still getting a panic in the latest version, however the error message seems to have changed:

thread 'rustc' panicked at 'there must be a `else` here', src/libcore/option.rs:1034:5
stack backtrace:
   0:     0x7ff4a476fd73 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::he0ba5a87706fdb06
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x7ff4a4767bfb - std::sys_common::backtrace::_print::h0f3483ebe5e1af88
                               at src/libstd/sys_common/backtrace.rs:71
   2:     0x7ff4a476bfd6 - std::panicking::default_hook::{{closure}}::haadf77e5fbe3559e
                               at src/libstd/sys_common/backtrace.rs:59
                               at src/libstd/panicking.rs:197
   3:     0x7ff4a476bd69 - std::panicking::default_hook::hdaa11accde9a3f58
                               at src/libstd/panicking.rs:211
   4:     0x7ff4a60031f0 - rustc::util::common::panic_hook::h4cbb878598297ef8
   5:     0x7ff4a476c7c8 - std::panicking::rust_panic_with_hook::hf72148e2f6bd5661
                               at src/libstd/panicking.rs:478
   6:     0x7ff4a476c261 - std::panicking::continue_panic_fmt::haefde3877ed690e2
                               at src/libstd/panicking.rs:381
   7:     0x7ff4a476c145 - rust_begin_unwind
                               at src/libstd/panicking.rs:308
   8:     0x7ff4a4794fdc - core::panicking::panic_fmt::h8a28410f697dd7a2
                               at src/libcore/panicking.rs:85
   9:     0x7ff4a47950f6 - core::option::expect_failed::h4d035692523f0da1
                               at src/libcore/option.rs:1034
  10:     0x7ff4a851a247 - <clippy_lints::formatting::Formatting as rustc::lint::EarlyLintPass>::check_expr::h73  7625a313237d61
  11:     0x7ff4a5c29e42 - <rustc::lint::context::EarlyLintPassObjects as rustc::lint::EarlyLintPass>::check_exp  r::h26609e2a4d9e8f4d
  12:     0x7ff4a77f1173 - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr:  :h3fd20942011fab12
  13:     0x7ff4a77fcb91 - syntax::visit::walk_expr::h508daccbcc062d2e
  14:     0x7ff4a77f117e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr:  :h3fd20942011fab12
  15:     0x7ff4a77fd1e1 - syntax::visit::walk_expr::h508daccbcc062d2e
  16:     0x7ff4a77f117e - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_expr:  :h3fd20942011fab12
  17:     0x7ff4a77f1ade - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_local  ::h3ba36508174efe28
  18:     0x7ff4a77fa181 - syntax::visit::walk_fn::hbe70496fd7caac6a
  19:     0x7ff4a77f6a25 - syntax::visit::walk_impl_item::he85907ae4517a1cc
  20:     0x7ff4a77f251d - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_impl_  item::hb2b16c30d232691e
  21:     0x7ff4a7800191 - syntax::visit::walk_item::h545ede774ce20491
  22:     0x7ff4a77f154c - <rustc::lint::context::EarlyContextAndPass<T> as syntax::visit::Visitor>::visit_item:  :h8a308fc68cf06b03
  23:     0x7ff4a77f4ebb - syntax::visit::walk_crate::he52a5a413ad180ef
  24:     0x7ff4a77e7983 - rustc::lint::context::early_lint_crate::h5200dc1fff4dd761
  25:     0x7ff4a77e629c - rustc::lint::context::check_ast_crate::he423b949ae51a95d
  26:     0x7ff4a7723923 - rustc::util::common::time::h2c68577d78486613
  27:     0x7ff4a778310e - rustc_interface::passes::BoxedResolver::access::{{closure}}::h696555a5ee99023c
  28:     0x7ff4a77bf6c5 - rustc_interface::passes::configure_and_expand::{{closure}}::hbac275e0705670fe
  29:     0x7ff4a779b3c9 - rustc_data_structures::box_region::PinnedGenerator<I,A,R>::access::hb1c93b268b37ce32
  30:     0x7ff4a7715eff - rustc_interface::queries::Query<T>::compute::ha8a2c1d5c5b1bb5e
  31:     0x7ff4a7714ed5 - rustc_interface::queries::Query<T>::compute::h5e91435478ea246b
  32:     0x7ff4a77f3993 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::prepare_output  s::hec87a3ebd25a76f2
  33:     0x7ff4a7b14c23 - rustc_interface::interface::run_compiler_in_existing_thread_pool::h46bba02ee59f142b
  34:     0x7ff4a7af5b63 - std::thread::local::LocalKey<T>::with::h34ffb00bfd367860
  35:     0x7ff4a7b5ac84 - scoped_tls::ScopedKey<T>::set::h7d0ef554ad6a2f92
  36:     0x7ff4a7b8bd4f - syntax::with_globals::h8119039844d87a66
  37:     0x7ff4a7af7357 - std::sys_common::backtrace::__rust_begin_short_backtrace::h04eb124b36b3f4b3
  38:     0x7ff4a477d4a9 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:87
  39:     0x7ff4a7b16b58 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h62a25d2cc7f5b35b
  40:     0x7ff4a474eefe - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h9112a5293838373  6
                               at /rustc/3de0106789468b211bcc3a25c09c0cf07119186d/src/liballoc/boxed.rs:702
  41:     0x7ff4a477c20f - std::sys::unix::thread::Thread::new::thread_start::h858b049c594cf60d
                               at /rustc/3de0106789468b211bcc3a25c09c0cf07119186d/src/liballoc/boxed.rs:702
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:80
  42:     0x7ff4a3d576da - start_thread
  43:     0x7ff4a443188e - __clone
  44:                0x0 - <unknown>
query stack during panic:
end of query stack

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/blob/master/CONTRIBUTING.md#bug-report  s

note: rustc 1.35.0-nightly (3de010678 2019-04-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile `clippy-relm`.
$ cargo clippy -V
clippy 0.0.212 (d516925e 2019-04-12)

@phansch
Copy link
Member

phansch commented Apr 13, 2019

Huh, that should definitely be fixed, I'll have another look, thanks!

@phansch phansch reopened this Apr 13, 2019
phansch added a commit to phansch/rust-clippy that referenced this issue Apr 14, 2019
This was causing two different ICEs in rust-lang#3741.
The first was fixed in rust-lang#3925.

The second one is fixed with this commit: We just don't `expect`
anymore. If the snippet doesn't contain an `else`, we stop emitting the
lint because it's not a suspiciously formatted else anyway.
@lukasschlueter
Copy link

Thanks a lot for the fix!

It's working with #3960 :-)

bors added a commit that referenced this issue Apr 14, 2019
Remove `except` in suspicious_else_formatting

96c34e8 contains the fix:

This was causing two different ICEs in #3741. The first was fixed in #3925.

The second one is fixed with this commit: We just don't `expect` anymore.
If the snippet doesn't contain an `else`, we stop emitting the lint because
it's not a suspiciously formatted else anyway.

Unfortunately I wasn't able to provide a minimal test case, but I think it's
fine since it's just ignoring the `None` case now.

And ad27e3f cleans up the lint code to use `if_chain`.

Fixes #3741 once more.
phansch added a commit to phansch/compiletest-rs that referenced this issue Aug 21, 2019
Taken from work on rust-lang/rust-clippy#3741.

I think this is a useful test to have because it tests

* the `run-pass` header
* the `aux-build` header, building auxiliary files
* the `no-prefer-dynamic` header
* proc-macro crate interactions with all of the above
* running of UI tests that include auxiliary files

There's no tests for any of the above right now.
phansch added a commit to phansch/compiletest-rs that referenced this issue Aug 21, 2019
Taken from work on rust-lang/rust-clippy#3741.

I think this is a useful test to have because it tests

* the `run-pass` header
* the `aux-build` header, building auxiliary files
* the `no-prefer-dynamic` header
* proc-macro crate interactions with all of the above
* running of UI tests that include auxiliary files

There's no tests for any of the above right now.
phansch added a commit to phansch/compiletest-rs that referenced this issue Aug 21, 2019
Taken from work on rust-lang/rust-clippy#3741.

I think this is a useful test to have because it tests

* the `run-pass` header
* the `aux-build` header, building auxiliary files
* the `no-prefer-dynamic` header
* proc-macro crate interactions with all of the above
* running of UI tests that include auxiliary files

There's no tests for any of the above right now.
anelson added a commit to anelson/tracers that referenced this issue Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants