Skip to content

Macro causes panic #2636

Closed
Closed
@ambaxter

Description

@ambaxter

The macro in question from https://github.com/ambaxter/expert-rs/blob/master/src/network/node_cmp.rs#L514

macro_rules! test_hash {
    ($($t:ident => $ord:expr),+ ) => {
        impl<T:Fact>Hash for TestData<T> {
            fn hash < H: Hasher > ( & self, state: & mut H) {
                use self::TestData::*;
                    match self {
                    $ ( & $ t(accessor, ref test) => Self::hash_self($ord, accessor as usize, test, state),
                    )*
                }
            }
        }
    };
}


test_hash!(I8 => 0, I16 => 1, I32 => 2, I64 => 3,
    U8 => 4, U16 => 5, U32 => 6, U64 => 7,
    ISIZE => 8, USIZE => 9,
    F32 => 10, F64 => 11,
    STR => 12
);

Backtrace output:

warning: you don't need to add `&` to all patterns
   --> src/network/node_cmp.rs:519:21
    |
519 | /                     match self {
520 | |                     $ ( & $ t(accessor, ref test) => Self::hash_self($ord, accessor as usize, test, state),
521 | |                     )*
522 | |                 }
    | |_________________^
...
529 | / test_hash!(I8 => 0, I16 => 1, I32 => 2, I64 => 3,
530 | |     U8 => 4, U16 => 5, U32 => 6, U64 => 7,
531 | |     ISIZE => 8, USIZE => 9,
532 | |     F32 => 10, F64 => 11,
533 | |     STR => 12
534 | | );
    | |__- in this macro invocation
    |
    = help: for further information visit https://rust-lang-nursery.github.io/rust-clippy/v0.0.192/index.html#match_ref_pats
thread 'main' panicked at 'begin <= end (49 <= 24) when slicing `                    $ ( & $ t(accessor, ref test) => Self::hash_self($ord, accessor as usize, test, state),`', libcore/str/mod.rs:2244:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: core::ops::function::Fn::call
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic_fmt
   7: rust_begin_unwind
   8: core::panicking::panic_fmt
   9: core::str::slice_error_fail
  10: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}
  11: rustc_errors::CodeSuggestion::splice_lines::push_trailing
  12: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
  13: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  14: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit
  15: rustc_errors::Handler::emit_db
  16: rustc_errors::diagnostic_builder::DiagnosticBuilder::emit
  17: clippy_lints::utils::span_lint_and_then
  18: <clippy_lints::matches::MatchPass as rustc::lint::LateLintPass<'a, 'tcx>>::check_expr
  19: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  20: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_block
  21: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  22: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_body
  23: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_nested_body
  24: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_fn
  25: rustc::hir::intravisit::walk_impl_item
  26: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_impl_item
  27: rustc::hir::intravisit::walk_impl_item_ref
  28: rustc::hir::intravisit::walk_item
  29: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  30: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  31: rustc::hir::intravisit::walk_item
  32: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  33: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  34: rustc::hir::intravisit::walk_item
  35: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  36: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
  37: rustc::hir::intravisit::walk_crate
  38: rustc::lint::context::check_crate
  39: rustc::ty::context::tls::enter_context
  40: <std::thread::local::LocalKey<T>>::with
  41: rustc::ty::context::TyCtxt::create_and_enter
  42: rustc_driver::driver::compile_input
  43: rustc_driver::run_compiler_impl
  44: syntax::with_globals
  45: rustc_driver::run_compiler
  46: rustc_driver::run
  47: clippy_driver::main
  48: std::rt::lang_start::{{closure}}
  49: std::panicking::try::do_call
  50: __rust_maybe_catch_panic
  51: std::rt::lang_start_internal
  52: main
error: Could not compile `expert`.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️T-macrosType: Issues with macros and macro expansion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions