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

ICE involving match and never type with never type as fallback enabled #120600

Closed
matthiaskrgr opened this issue Feb 3, 2024 · 3 comments · Fixed by #123571
Closed

ICE involving match and never type with never type as fallback enabled #120600

matthiaskrgr opened this issue Feb 3, 2024 · 3 comments · Fixed by #123571
Labels
C-bug Category: This is a bug. F-never_type `#![feature(never_type)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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

@matthiaskrgr
Copy link
Member

snippet:

#![feature(never_type)]
#![feature(never_type_fallback)]

#[derive(Ord, Eq, PartialOrd, PartialEq)]
enum E {
    Foo,
    Bar(!, i32, i32),
}

fn main() {}

Version information

rustc 1.77.0-nightly (bf3c6c5be 2024-02-01)
binary: rustc
commit-hash: bf3c6c5bed498f41ad815641319a1ad9bcecb8e8
commit-date: 2024-02-01
host: x86_64-unknown-linux-gnu
release: 1.77.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

warning: unreachable expression
 --> /tmp/icemaker_global_tempdir.NY1Bi1E4YUo0/rustc_testrunner_tmpdir_reporting.8YbPtnxsZhHF/mvce.rs:7:9
  |
4 | #[derive(Ord, Eq, PartialOrd, PartialEq)]
  |                               --------- in this derive macro expansion
...
7 |     Bar(!, i32, i32),
  |         ^
  |         |
  |         unreachable expression
  |         any code following this expression is unreachable
  |
  = note: `#[warn(unreachable_code)]` on by default
  = note: this warning originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: variants `Foo` and `Bar` are never constructed
 --> /tmp/icemaker_global_tempdir.NY1Bi1E4YUo0/rustc_testrunner_tmpdir_reporting.8YbPtnxsZhHF/mvce.rs:6:5
  |
5 | enum E {
  |      - variants in this enum
6 |     Foo,
  |     ^^^
7 |     Bar(!, i32, i32),
  |     ^^^
  |
  = note: `#[warn(dead_code)]` on by default

note: no errors encountered even though `span_delayed_bug` issued

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: broken MIR in DefId(0:20 ~ mvce[954a]::{impl#4}::eq) (Terminator { source_info: SourceInfo { span: /tmp/icemaker_global_tempdir.NY1Bi1E4YUo0/rustc_testrunner_tmpdir_reporting.8YbPtnxsZhHF/mvce.rs:7:9: 7:10 (#7), scope: scope[3] }, kind: _21 = <! as PartialEq>::eq(move _22, move _23) -> [return: bb9, unwind: bb18] }): bad arg #0 (&'?38 ! <- !): NoSolution
 --> /tmp/icemaker_global_tempdir.NY1Bi1E4YUo0/rustc_testrunner_tmpdir_reporting.8YbPtnxsZhHF/mvce.rs:7:9
  |
4 | #[derive(Ord, Eq, PartialOrd, PartialEq)]
  |                               --------- in this derive macro expansion
...
7 |     Bar(!, i32, i32),
  |         ^
  |
note: delayed at compiler/rustc_borrowck/src/type_check/mod.rs:1678:17
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxt>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_borrowck::type_check::TypeChecker>::typeck_mir
         4: rustc_borrowck::type_check::type_check
         5: rustc_borrowck::nll::compute_regions
         6: rustc_borrowck::do_mir_borrowck
         7: rustc_borrowck::mir_borrowck
         8: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         9: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        10: rustc_query_impl::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
        11: rustc_interface::passes::analysis
        12: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        13: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        14: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        15: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        16: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        17: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        18: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/alloc/src/boxed.rs:2015:9
        19: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
                   at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/alloc/src/boxed.rs:2015:9
        20: std::sys::pal::unix::thread::Thread::new::thread_start
                   at /rustc/bf3c6c5bed498f41ad815641319a1ad9bcecb8e8/library/std/src/sys/pal/unix/thread.rs:108:17
        21: <unknown>
        22: <unknown>
 --> /tmp/icemaker_global_tempdir.NY1Bi1E4YUo0/rustc_testrunner_tmpdir_reporting.8YbPtnxsZhHF/mvce.rs:7:9
  |
4 | #[derive(Ord, Eq, PartialOrd, PartialEq)]
  |                               --------- in this derive macro expansion
...
7 |     Bar(!, i32, i32),
  |         ^
  = note: this error: internal compiler error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info)

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.77.0-nightly (bf3c6c5be 2024-02-01) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. F-never_type `#![feature(never_type)]` F-never_patterns `#![feature(never_patterns)]` labels Feb 3, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 3, 2024
@matthiaskrgr
Copy link
Member Author

Regression in nightly-2023-05-23
commit[0] 2023-05-21: Auto merge of #111731 - MU001999:fix/issue-111727, r=cjgillot
commit[1] 2023-05-21: Auto merge of #111808 - Zoxc:query-structs-trim, r=cjgillot
commit[2] 2023-05-22: Auto merge of #111824 - lukas-code:strike, r=notriddle
commit[3] 2023-05-22: Auto merge of #111781 - the8472:filter-map-chunk, r=thomcc
commit[4] 2023-05-22: Auto merge of #111835 - matthiaskrgr:rollup-qd4b2vu, r=matthiaskrgr
commit[5] 2023-05-22: Auto merge of #111711 - Jules-Bertholet:document-pin-layout, r=thomcc
commit[6] 2023-05-22: Auto merge of #111775 - compiler-errors:triple-check, r=Nilstrieb
commit[7] 2023-05-22: Auto merge of #111634 - marc0246:arc-new-uninit-bloat, r=thomcc
commit[8] 2023-05-22: Auto merge of #111754 - lcnr:recursion-depth, r=matthewjasper
commit[9] 2023-05-22: Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPC
ERROR: no CI builds available between 9d871b0 and 8b4b208 within last 167 days

cc @Nadrieril

@fmease
Copy link
Member

fmease commented Feb 3, 2024

Minimized:

#![feature(never_type, never_type_fallback)]

enum E { Bar(!) }

fn f(a: &E, b: &E) {
    match (a, b) {
        (E::Bar(a), E::Bar(b)) => { *a == *b; }
        _ => {}
    }
}

@fmease fmease added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 3, 2024
@fmease fmease changed the title ICE: deriving PartialEq for ! ICE involving match and never type with never type as fallback enabled Feb 3, 2024
@fmease fmease removed the F-never_patterns `#![feature(never_patterns)]` label Feb 3, 2024
@WaffleLapkin
Copy link
Member

Minimized even more:

#![feature(never_type)]
#![feature(never_type_fallback)]

fn ice(a: !) {
    a == a;
}

fn main() {}

(I independently found the same bug while running crater with the fallback being !)

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 18, 2024
…, r=compiler-errors

Correctly change type when adding adjustments on top of `NeverToAny`

I'm concerned that the check only caught the problem with `fallback = !`, because at least MIR contained `<() as PartialEq>::eq(move _5, move _7)` where `_5: ()`.

I rediscovered the issue when looking at rust-lang#123482's crater run.

r? compiler-errors
Fixes rust-lang#120600
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Apr 18, 2024
…, r=compiler-errors

Correctly change type when adding adjustments on top of `NeverToAny`

I'm concerned that the check only caught the problem with `fallback = !`, because at least MIR contained `<() as PartialEq>::eq(move _5, move _7)` where `_5: ()`.

I rediscovered the issue when looking at rust-lang#123482's crater run.

r? compiler-errors
Fixes rust-lang#120600
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Apr 18, 2024
…, r=compiler-errors

Correctly change type when adding adjustments on top of `NeverToAny`

I'm concerned that the check only caught the problem with `fallback = !`, because at least MIR contained `<() as PartialEq>::eq(move _5, move _7)` where `_5: ()`.

I rediscovered the issue when looking at rust-lang#123482's crater run.

r? compiler-errors
Fixes rust-lang#120600
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 19, 2024
…, r=compiler-errors

Correctly change type when adding adjustments on top of `NeverToAny`

I'm concerned that the check only caught the problem with `fallback = !`, because at least MIR contained `<() as PartialEq>::eq(move _5, move _7)` where `_5: ()`.

I rediscovered the issue when looking at rust-lang#123482's crater run.

r? compiler-errors
Fixes rust-lang#120600
@bors bors closed this as completed in 6c4657c Apr 19, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 19, 2024
Rollup merge of rust-lang#123571 - WaffleLapkin:properly-adjust-never, r=compiler-errors

Correctly change type when adding adjustments on top of `NeverToAny`

I'm concerned that the check only caught the problem with `fallback = !`, because at least MIR contained `<() as PartialEq>::eq(move _5, move _7)` where `_5: ()`.

I rediscovered the issue when looking at rust-lang#123482's crater run.

r? compiler-errors
Fixes rust-lang#120600
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. F-never_type `#![feature(never_type)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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.

4 participants