Skip to content

Const generics: Clippy: "expected bits of usize, got Const" #4775

@andre-richter

Description

@andre-richter

I ran into this error

error: internal compiler error: src/librustc/ty/sty.rs:2355: expected bits of usize, got Const {
    ty: usize,
    val: Param(
        NUM_SPECIAL_RANGES/#0,
    ),
}

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:931:9

Steps to repro:

  1. Install Rust nightly
  2. cargo install xbuild
  3. git clone git@github.com:rust-embedded/rust-raspi3-OS-tutorials.git
  4. cd rust-raspi3-OS-tutorials/11_virtual_memory
  5. make clippy

It might be about this code:

pub struct KernelVirtualLayout<const NUM_SPECIAL_RANGES: usize> {
    max_virt_addr_inclusive: usize,
    inner: [RangeDescriptor; NUM_SPECIAL_RANGES],
}

impl<const NUM_SPECIAL_RANGES: usize> KernelVirtualLayout<{ NUM_SPECIAL_RANGES }> {
    pub const fn new(max: usize, layout: [RangeDescriptor; NUM_SPECIAL_RANGES]) -> Self {
        Self {
            max_virt_addr_inclusive: max,
            inner: layout,
        }
    }

Meta

rustc 1.40.0-nightly (2477e2493 2019-11-04)
binary: rustc
commit-hash: 2477e2493e67527fc282c7239e019f7ebd513a1a
commit-date: 2019-11-04
host: x86_64-unknown-linux-gnu
release: 1.40.0-nightly
LLVM version: 9.0

Backtrace:

 RUST_BACKTRACE=1 make clippy
cargo xclippy --target=aarch64-unknown-none-softfloat --features bsp_rpi3
    Checking kernel v0.1.0 (/home/arichter/repos/rust-raspi3-OS-tutorials/11_virtual_memory)
error: internal compiler error: src/librustc/ty/sty.rs:2355: expected bits of usize, got Const {
    ty: usize,
    val: Param(
        NUM_SPECIAL_RANGES/#0,
    ),
}

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:931:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.40/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:77
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:61
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1028
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1412
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:65
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:50
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:188
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:205
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:468
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_context_opt
  18: rustc::ty::context::tls::with_opt
  19: rustc::util::bug::opt_span_bug_fmt
  20: rustc::util::bug::bug_fmt
  21: rustc::ty::sty::Const::eval_bits::{{closure}}
  22: clippy_lints::loops::check_for_loop
  23: <clippy_lints::loops::Loops as rustc::lint::LateLintPass>::check_expr
  24: <rustc::lint::context::LateLintPassObjects as rustc::lint::LateLintPass>::check_expr
  25: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_expr
  26: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_expr
  27: rustc::hir::intravisit::walk_block
  28: rustc::hir::intravisit::walk_expr
  29: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_expr
  30: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_nested_body
  31: <rustc::lint::context::LateContextAndPass<T> as rustc::hir::intravisit::Visitor>::visit_fn
  32: rustc::hir::intravisit::walk_impl_item
  33: rustc::hir::intravisit::Visitor::visit_nested_impl_item
  34: rustc::hir::intravisit::walk_item
  35: rustc::hir::intravisit::Visitor::visit_nested_item
  36: rustc::hir::intravisit::walk_item
  37: rustc::hir::intravisit::Visitor::visit_nested_item
  38: rustc::hir::intravisit::walk_crate
  39: rustc::lint::context::late_lint_pass_crate
  40: rustc::lint::context::late_lint_crate
  41: rustc::util::common::time
  42: rustc::util::common::time
  43: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:78
  44: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  45: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:78
  46: rustc_interface::passes::analysis::{{closure}}
  47: rustc_interface::passes::analysis
  48: rustc::ty::query::__query_compute::analysis
  49: rustc::dep_graph::graph::DepGraph::with_task_impl
  50: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  51: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  52: rustc_interface::passes::create_global_ctxt::{{closure}}
  53: rustc_interface::passes::BoxedGlobalCtxt::enter
  54: rustc_interface::interface::run_compiler_in_existing_thread_pool
  55: std::thread::local::LocalKey<T>::with
  56: scoped_tls::ScopedKey<T>::set
  57: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.40.0-nightly (2477e2493 2019-11-04) 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

query stack during panic:
#0 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `kernel`.

To learn more, run the command again with --verbose.
Makefile:115: recipe for target 'clippy' failed
make: *** [clippy] Error 101

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-ICEIssue: Clippy panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions