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

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:847:21: expected type for param #0 #110131

Closed
1 task
yegawong opened this issue Apr 10, 2023 · 1 comment · Fixed by #110133
Closed
1 task
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@yegawong
Copy link

yegawong commented Apr 10, 2023

Code

struct SqueneceBuffer<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    iter: <&'a T as IntoIterator>::IntoIter,
}

impl<'a, T> SqueneceBuffer<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    fn new(sq: &'a T) -> Self {
        Self {
            iter: sq.into_iter(),
        }
    }

    fn get(&mut self) -> Option<&'a u8> {
        self.iter.next()
    }
}

#[allow(dead_code)]
pub struct Helper<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    buf: SqueneceBuffer<'a, T>,
    unit: u8,
    num: u8,
    used_bit: u8,
}

#[allow(dead_code)]
impl<'a, T> Helper<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    pub fn new(sq: &'a T) -> Self {
        let mut result = Self {
            buf: SqueneceBuffer::new(sq),
            unit: 8,
            num: 0,
            used_bit: 0,
        };
        match result.update() {
            true => result,
            _ => panic!("the squenece can not be empty!"),
        }
    }

    fn update(&mut self) -> bool {
        let nop = self.buf.get();
        match nop {
            Some(n) => {
                self.num = *n;
                self.used_bit = 0;
                true
            }
            _ => false,
        }
    }

    pub fn set_unit(&mut self, u: u8) {
        if u > 32 || u == 0 {
            panic!("the unit can neither be greater than 32 nor 0")
        }
        self.unit = u;
    }

    pub fn get_num_by_bit(&mut self, bit: u8) -> GetResult {
        if bit > 32 || bit == 0 {
            return GetResult::Error;
        }
        let mut rest_bit = 8 - self.used_bit;
        if rest_bit == 0 {
            if self.update() {
                rest_bit = 8
            } else {
                return GetResult::Fail;
            }
        }
        let diff: i8 = bit as i8 - rest_bit as i8;
        if diff <= 0 {
            let num: u32 = (((0xff as u8 >> self.used_bit) & self.num) >> -diff as u8) as u32;
            self.used_bit += bit;
            return GetResult::Whole(num);
        }
        let mut slice: [Option<u8>; 4] = [None; 4];
        slice[0] = Some((0xff as u8 >> self.used_bit) & self.num);
        let mut result: u32 = slice[0].unwrap() as u32;
        let mut bits = rest_bit;
        let exp_bytes: u8 = (diff / 8) as u8;
        let exp_bits: u8 = (diff % 8) as u8;
        let mut i: u8 = 1;
        while i <= exp_bytes {
            if self.update() == false {
                break;
            }
            slice[i as usize] = Some(self.num);
            i += 1;
        }
        for j in &slice[1..] {
            match j {
                Some(n) => {
                    result = (result << 8) + *n as u32;
                    bits += 8;
                }
                _ => break,
            }
        }
        self.used_bit = 8;
        if i <= exp_bytes {
            return GetResult::Semi(result, bits);
        }
        if exp_bits == 0 {
            return GetResult::Whole(result);
        }
        if !self.update() {
            return GetResult::Semi(result, bits);
        }
        result = (result << exp_bits as u32) + (self.num >> (8 - exp_bits as u32) as u8) as u32;
        self.used_bit = exp_bits;
        return GetResult::Whole(result);
    }
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum GetResult {
    Whole(u32),
    Semi(u32, u8),
    Fail,
    Error,
}

// bug!!!
pub struct BitReaderWrapper<T>(T);

impl<'a, T> IntoIterator for &'a BitReaderWrapper<T> 
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    type Item = u32;

    type IntoIter = Helper<'a, T>;

    fn into_iter(self) -> Self::IntoIter {
        Helper::new(&self.0)
    }
}

impl<'a, T> Iterator for Helper<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    type Item = u32;

    fn next(&mut self) -> Option<Self::Item> {
        match self.get_num_by_bit(self.unit) {
            GetResult::Error => panic!("can not read the data"),
            GetResult::Semi(result, _) => Some(result),
            GetResult::Whole(result) => Some(result),
            _ => None
        }
    }
}

fn main() {}

Meta

Tasks

rustc --version --verbose:

rustc 1.68.2 (9eb3afe9e 2023-03-27)
binary: rustc
commit-hash: 9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0
commit-date: 2023-03-27
host: x86_64-unknown-linux-gnu
release: 1.68.2
LLVM version: 15.0.6

Error output

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:847:21: expected type for param #0 in [ReErased, BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<BitReaderWrapper<_>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/compiler/rustc_errors/src/lib.rs:1609:9
stack backtrace:
   0:     0x7f784d9ac59a - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f784d9ac59a - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   ......
 969:     0x7f784d9b9823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205ec2d7fc232c5
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
 970:     0x7f784d9b9823 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3bb5daec8177f56b
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/alloc/src/boxed.rs:1988:9
 971:     0x7f784d9b9823 - std::sys::unix::thread::Thread::new::thread_start::had7b8061e306bb5c
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/sys/unix/thread.rs:108:17
 972:     0x7f784d871609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
 973:     0x7f784d794133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
 974:                0x0 - <unknown>
Backtrace

query stack during panic:
#0 [typeck] type-checking `<impl at src/main.rs:39:1: 39:26>::new`
#1 [typeck_item_bodies] type-checking all item bodies
#2 [analysis] running analysis passes on this crate
end of query stack
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/compiler/rustc_errors/src/lib.rs:1609:9
stack backtrace:
   0:     0x7f784d9ac59a - std::backtrace_rs::backtrace::libunwind::trace::ha271a8a7e1f3d4ef
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f784d9ac59a - std::backtrace_rs::backtrace::trace_unsynchronized::h85739da0352c791a
                               at /rustc/9eb3afe9ebe9c7d2b84b71002d44f4a0edac95e0/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
  ......
 970:     0x7f784d794133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
 971:                0x0 - <unknown>

@yegawong yegawong 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 Apr 10, 2023
@compiler-errors
Copy link
Member

compiler-errors commented Apr 10, 2023

Minimized via cargo minimize and some manual item deletion:

struct SeqBuffer<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    iter: <&'a T as IntoIterator>::IntoIter,
}

struct Helper<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    buf: SeqBuffer<'a, T>,
}

impl<'a, T> Helper<'a, T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    fn new(sq: &'a T) -> Self {
        loop {}
    }
}

struct BitReaderWrapper<T>(T);

impl<'a, T> IntoIterator for &'a BitReaderWrapper<T>
where
    &'a T: IntoIterator<Item = &'a u8>,
{
    type Item = u32;

    type IntoIter = Helper<'a, T>;

    fn into_iter(self) -> Self::IntoIter {
        Helper::new(&self.0)
    }
}

I can take a quick look into this one I guess.

@rustbot claim

@jyn514 jyn514 added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Apr 10, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this issue Apr 11, 2023
…trochenkov

Do not use ImplDerivedObligationCause for inherent impl method error reporting

We were constructing a `TraitRef` out of impl substs, for an *inherent* impl that has no corresponding trait. Instead of doing that, let's construct a meaningful obligation cause code, and instead adjust the error reporting machinery to handle that correctly.

Fixes rust-lang#110131
cc rust-lang#106702, which introduced this regression
@bors bors closed this as completed in 5d6aeb9 Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

3 participants