Skip to content

int.rs:230:13: expected int of size 8, but got size 1 #86820

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
alan-signal opened this issue Jul 2, 2021 · 1 comment · Fixed by #86843
Closed

int.rs:230:13: expected int of size 8, but got size 1 #86820

alan-signal opened this issue Jul 2, 2021 · 1 comment · Fixed by #86843
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alan-signal
Copy link

alan-signal commented Jul 2, 2021

Code

use std::ops::BitAnd;

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn is_set() {
        assert!(0xffu8.bit::<0>());
    }
}

trait Bits {
    fn bit<const I: u8>(self) -> bool;
}

impl<T> Bits for T where
    T: Copy + BitAnd<T, Output=T> + From<u8> + Eq
{
    fn bit<const I: usize>(self) -> bool {
        let i = 1 << I;
        let mask = T::from(i);
        mask & self == mask
    }
}

Meta

rustc --version --verbose:

rustc 1.52.1 (9bc8c42bb 2021-05-09)
binary: rustc
commit-hash: 9bc8c42bb2f19e745a63f3445f1ac248fb015e53
commit-date: 2021-05-09
host: x86_64-apple-darwin
release: 1.52.1
LLVM version: 12.0.0

Error output

error: internal compiler error: /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/compiler/rustc_middle/src/ty/consts/int.rs:230:13: expected int of size 8, but got size 1

thread 'rustc' panicked at 'Box<Any>', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: the compiler unexpectedly panicked. this is a bug.
Backtrace

$ RUST_BACKTRACE=1 cargo test
thread 'rustc' panicked at 'Box<Any>', /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt::{{closure}}
   6: rustc_middle::ty::context::tls::with_opt
   7: rustc_middle::util::bug::opt_span_bug_fmt
   8: rustc_middle::util::bug::bug_fmt
   9: rustc_middle::ty::consts::int::ScalarInt::assert_bits::{{closure}}
  10: rustc_codegen_llvm::common::<impl rustc_codegen_ssa::traits::consts::ConstMethods for rustc_codegen_llvm::context::CodegenCx>::scalar_to_backend
  11: rustc_codegen_ssa::mir::operand::OperandRef<V>::from_const
  12: rustc_codegen_ssa::mir::operand::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_operand
  13: rustc_codegen_ssa::mir::rvalue::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_rvalue_operand
  14: rustc_codegen_ssa::mir::codegen_mir
  15: rustc_codegen_ssa::base::codegen_instance
  16: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  17: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  18: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  19: rustc_codegen_llvm::base::compile_codegen_unit
  20: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  21: rustc_interface::passes::QueryContext::enter
  22: rustc_interface::queries::Queries::ongoing_codegen
  23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  24: rustc_span::with_source_map
  25: rustc_interface::interface::create_compiler_and_run
  26: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@alan-signal alan-signal added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 2, 2021
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 2, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Jul 4, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 6, 2021
@apiraino
Copy link
Contributor

apiraino commented Jul 7, 2021

Assigning priority as discussed in the Zulip thread of the Prioritization Working Group.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 7, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 17, 2021
Check that const parameters of trait methods have compatible types

This PR fixes rust-lang#86820. The problem is that this currently passes the type checker:
```rust
trait Tr {
    fn foo<const N: u8>(self) -> u8;
}

impl Tr for f32 {
    fn foo<const N: bool>(self) -> u8 { 42 }
}
```
i.e. the type checker fails to check whether const parameters in `impl` methods have the same type as the corresponding declaration in the trait. With my changes, I get, for the above code:
```
error[E0053]: method `foo` has an incompatible const parameter type for trait
 --> test.rs:6:18
  |
6 |     fn foo<const N: bool>(self) -> u8 { 42 }
  |                  ^
  |
note: the const parameter `N` has type `bool`, but the declaration in trait `Tr::foo` has type `u8`
 --> test.rs:2:18
  |
2 |     fn foo<const N: u8>(self) -> u8;
  |                  ^

error: aborting due to previous error
```
This fixes rust-lang#86820, where an ICE happens later on because the trait method is declared with a const parameter of type `u8`, but the `impl` uses one of type `usize`:
> `expected int of size 8, but got size 1`
@bors bors closed this as completed in 783efd2 Jul 18, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants