thepowersgang / mrustc

Alternative rust compiler (re-implementation)
MIT License
2.18k stars 109 forks source link

BUG:src/hir_typeck/common.cpp:751: Impl parameters were not expected (got T/*I:0*/) #322

Open iamanonymouscs opened 1 year ago

iamanonymouscs commented 1 year ago

Code

$ cat small.rs

#![crate_type = "lib"]
struct Assert<const COND: bool>;
trait IsTrue {}
impl IsTrue for Assert<true> {}
trait IsNotZst {}
impl<T> IsNotZst for T
where
    Assert<{ std::mem::size_of::<T>() > 0 }>: IsTrue,
{}
fn assert_not_zero_sized<T: IsNotZst>(_: T) {}
fn main() {
    assert_not_zero_sized(vec![]);
}

Version

mrustc --version

rustc 1.29.100 (mrustc v0.10.0 master:4c7e8171)
release: 1.29.100
- Build time: Tue, 26 Sep 2023 07:36:21 +0000
- Commit: 4c7e81716493678df9fe9cac86ea9beedc57db44

Command

mrustc -L output-1.54.0 small.rs

Output

The error message I received is: ":0:0 BUG: src/hir_typeck/common.cpp:751: Impl parameters were not expected (got T/I:0/)".

I found that when I remove the first line, the compiler could output the correct error message🤣

Setup: V V V
(0.00 s) Setup: DONE
Target Load: V V V
(0.00 s) Target Load: DONE
Parse: V V V
(0.00 s) Parse: DONE
LoadCrates: V V V
(0.39 s) LoadCrates: DONE
Expand: V V V
(0.00 s) Expand: DONE
- main: params.outfile = lib3.rlib
Implicit Crates: V V V
(0.00 s) Implicit Crates: DONE
Resolve Use: V V V
(0.00 s) Resolve Use: DONE
Resolve Index: V V V
(0.00 s) Resolve Index: DONE
Resolve Absolute: V V V
(0.00 s) Resolve Absolute: DONE
HIR Lower: V V V
(0.00 s) HIR Lower: DONE
Lifetime Elision: V V V
(0.00 s) Lifetime Elision: DONE
Resolve Type Aliases: V V V
(0.00 s) Resolve Type Aliases: DONE
Resolve Bind: V V V
(0.10 s) Resolve Bind: DONE
Resolve UFCS Outer: V V V
(0.00 s) Resolve UFCS Outer: DONE
Resolve HIR Self Type: V V V
(0.00 s) Resolve HIR Self Type: DONE
Resolve HIR Markings: V V V
(0.00 s) Resolve HIR Markings: DONE
Sort Impls: V V V
(0.01 s) Sort Impls: DONE
Resolve UFCS paths: V V V
(0.00 s) Resolve UFCS paths: DONE
Constant Evaluate: V V V
:0:0 BUG:src/hir_typeck/common.cpp:751: Impl parameters were not expected (got T/*I:0*/)
Aborted (core dumped)

If remove the first line of the code:

Implicit Crates: V V V
:0:0 warn:0:Multiple panic_runtime crates loaded - panic_abort-0_0_0 and panic_unwind-0_0_0
:0:0 error:0:Unable to locate crate 'alloc_system' in search directories
Aborted (core dumped)
thepowersgang commented 1 year ago

Removing the first line just causes it to fail to compile earlier.

thepowersgang commented 1 year ago

The std::mem::size_of::<T>() > 0 is the cause of the issue, constant evaluation isn't correctly propagating the generic parameter through to the expansion/evaluation of that expression.

iamanonymouscs commented 1 year ago

The std::mem::size_of::<T>() > 0 is the cause of the issue, constant evaluation isn't correctly propagating the generic parameter through to the expansion/evaluation of that expression.

Will this issue be fixed in the future? 🤣It seems that the compiler did not successfully output the error message and instead caused an internal error in the compiler😶‍🌫️

thepowersgang commented 1 year ago

It's an ICE because the generic type was copied to a scope with no generics. I'll address the issue when I get time.

iamanonymouscs commented 1 year ago

It's an ICE because the generic type was copied to a scope with no generics. I'll address the issue when I get time.

Thank you for your dedication and responsiveness. I look forward to seeing the issue resolved soon~