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: deref projection of non-dereferenceable ty PlaceTy #131294

Closed
matthiaskrgr opened this issue Oct 5, 2024 · 1 comment · Fixed by #133365
Closed

ICE: deref projection of non-dereferenceable ty PlaceTy #131294

matthiaskrgr opened this issue Oct 5, 2024 · 1 comment · Fixed by #133365
Labels
C-bug Category: This is a bug. 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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

pub struct Statement;

pub struct Rows<'stmt>(&'stmt Statement);

impl<'stmt> Iterator for Rows<'stmt> {
    type Item = String;

    fn next() -> Option<Self::Item> {
        format!("Hello {}", "world").into()
    }
}

fn get_names() -> Option<String> {
    let stmt = Statement;
    let rows = Rows(&stmt);
    rows.map(|row| row).next()
}

original:

pub struct Statement;

pub struct Rows<'stmt>(&'stmt Statement);

impl<'stmt> Iterator for Rows<'stmt> {
    type Item = String;

    fn next() -> Option<Self::Item> {
        let stmt = Statement;
        let rows = Rows(&stmt);
        format!("Hello {}", "world").into()

        // x
        //
    }
}

fn get_names() -> Option<String> {
    let stmt = Statement;
    let rows = Rows(&stmt);
    rows.map(|row| row).next()

    // x
    //
}

Version information

rustc 1.83.0-nightly (5a4ee43c3 2024-10-05)
binary: rustc
commit-hash: 5a4ee43c387110736440cecc375cb5aedc441dbc
commit-date: 2024-10-05
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 -Zvalidate-mir -Zcross-crate-inline-threshold=always

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.6F6DD8mcNIb4/rustc_testrunner_tmpdir_reporting.T2OQxr9MgywH/mvce.rs:23:2
   |
23 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.6F6DD8mcNIb4/rustc_testrunner_tmpdir_reporting.T2OQxr9MgywH/mvce.rs`

error[E0186]: method `next` has a `&mut self` declaration in the trait, but not in the impl
 --> /tmp/icemaker_global_tempdir.6F6DD8mcNIb4/rustc_testrunner_tmpdir_reporting.T2OQxr9MgywH/mvce.rs:8:5
  |
8 |     fn next() -> Option<Self::Item> {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&mut self` in impl
  |
  = note: `next` from trait: `fn(&mut Self) -> Option<<Self as Iterator>::Item>`

error: internal compiler error: compiler/rustc_middle/src/mir/tcx.rs:84:21: deref projection of non-dereferenceable ty PlaceTy { ty: [core::fmt::rt::Argument<'{erased}>; 0_usize], variant_index: None }

thread 'rustc' panicked at compiler/rustc_middle/src/mir/tcx.rs:84:21:
Box<dyn Any>
stack backtrace:
   0:     0x74eb187249fa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h585b06d402bc00d5
   1:     0x74eb18e03426 - core::fmt::write::h62d1c51a5a367817
   2:     0x74eb1a01a651 - std::io::Write::write_fmt::hd7881933ac2a1e16
   3:     0x74eb18724852 - std::sys::backtrace::BacktraceLock::print::ha0ac5d8e3803f857
   4:     0x74eb18726d26 - std::panicking::default_hook::{{closure}}::h7a48a96dd6d0b686
   5:     0x74eb18726b70 - std::panicking::default_hook::h4ad77b5924a748da
   6:     0x74eb177db8ff - std[f6927571c1bb7893]::panicking::update_hook::<alloc[1b6d6df6cca9b2d3]::boxed::Box<rustc_driver_impl[83de0f0d7a3bbaf8]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x74eb18727438 - std::panicking::rust_panic_with_hook::h15ea114d0f0705b7
   8:     0x74eb17815451 - std[f6927571c1bb7893]::panicking::begin_panic::<rustc_errors[33bfe5951055d2f3]::ExplicitBug>::{closure#0}
   9:     0x74eb178084f6 - std[f6927571c1bb7893]::sys::backtrace::__rust_end_short_backtrace::<std[f6927571c1bb7893]::panicking::begin_panic<rustc_errors[33bfe5951055d2f3]::ExplicitBug>::{closure#0}, !>
  10:     0x74eb178084b3 - std[f6927571c1bb7893]::panicking::begin_panic::<rustc_errors[33bfe5951055d2f3]::ExplicitBug>
  11:     0x74eb1781ece1 - <rustc_errors[33bfe5951055d2f3]::diagnostic::BugAbort as rustc_errors[33bfe5951055d2f3]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74eb17e49ca4 - rustc_middle[4aa8808438232afe]::util::bug::opt_span_bug_fmt::<rustc_span[b73f4c38f6b79966]::span_encoding::Span>::{closure#0}
  13:     0x74eb17e2fb1a - rustc_middle[4aa8808438232afe]::ty::context::tls::with_opt::<rustc_middle[4aa8808438232afe]::util::bug::opt_span_bug_fmt<rustc_span[b73f4c38f6b79966]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x74eb17e2f9ab - rustc_middle[4aa8808438232afe]::ty::context::tls::with_context_opt::<rustc_middle[4aa8808438232afe]::ty::context::tls::with_opt<rustc_middle[4aa8808438232afe]::util::bug::opt_span_bug_fmt<rustc_span[b73f4c38f6b79966]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x74eb153daa80 - rustc_middle[4aa8808438232afe]::util::bug::bug_fmt
  16:     0x74eb1a1cac71 - <rustc_middle[4aa8808438232afe]::mir::tcx::PlaceTy>::projection_ty.cold
  17:     0x74eb1637d221 - rustc_mir_transform[e62bc607d4a6429b]::validate::validate_types
  18:     0x74eb163bb165 - <rustc_mir_transform[e62bc607d4a6429b]::validate::Validator as rustc_mir_transform[e62bc607d4a6429b]::pass_manager::MirPass>::run_pass
  19:     0x74eb171067c0 - rustc_mir_transform[e62bc607d4a6429b]::pass_manager::validate_body
  20:     0x74eb18e0bb06 - rustc_mir_transform[e62bc607d4a6429b]::pass_manager::run_passes_inner
  21:     0x74eb190ae9a2 - rustc_mir_transform[e62bc607d4a6429b]::optimized_mir
  22:     0x74eb190ad25b - rustc_query_impl[7b31fe52c1943d23]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7b31fe52c1943d23]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4aa8808438232afe]::query::erase::Erased<[u8; 8usize]>>
  23:     0x74eb18e2f378 - rustc_query_system[af74fb06ba218297]::query::plumbing::try_execute_query::<rustc_query_impl[7b31fe52c1943d23]::DynamicConfig<rustc_query_system[af74fb06ba218297]::query::caches::DefIdCache<rustc_middle[4aa8808438232afe]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[7b31fe52c1943d23]::plumbing::QueryCtxt, false>
  24:     0x74eb18e2e933 - rustc_query_impl[7b31fe52c1943d23]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  25:     0x74eb16135e79 - <rustc_middle[4aa8808438232afe]::ty::context::TyCtxt>::instance_mir
  26:     0x74eb1921e74a - rustc_interface[a7beddea6b2aa80d]::passes::run_required_analyses
  27:     0x74eb19bf6f9e - rustc_interface[a7beddea6b2aa80d]::passes::analysis
  28:     0x74eb19bf6f71 - rustc_query_impl[7b31fe52c1943d23]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[7b31fe52c1943d23]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[4aa8808438232afe]::query::erase::Erased<[u8; 1usize]>>
  29:     0x74eb19cd31ee - rustc_query_system[af74fb06ba218297]::query::plumbing::try_execute_query::<rustc_query_impl[7b31fe52c1943d23]::DynamicConfig<rustc_query_system[af74fb06ba218297]::query::caches::SingleCache<rustc_middle[4aa8808438232afe]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[7b31fe52c1943d23]::plumbing::QueryCtxt, false>
  30:     0x74eb19cd2ecf - rustc_query_impl[7b31fe52c1943d23]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  31:     0x74eb19b2151e - rustc_interface[a7beddea6b2aa80d]::interface::run_compiler::<core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>, rustc_driver_impl[83de0f0d7a3bbaf8]::run_compiler::{closure#0}>::{closure#1}
  32:     0x74eb19bd9150 - std[f6927571c1bb7893]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[a7beddea6b2aa80d]::util::run_in_thread_with_globals<rustc_interface[a7beddea6b2aa80d]::util::run_in_thread_pool_with_globals<rustc_interface[a7beddea6b2aa80d]::interface::run_compiler<core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>, rustc_driver_impl[83de0f0d7a3bbaf8]::run_compiler::{closure#0}>::{closure#1}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>::{closure#0}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>
  33:     0x74eb19bd9817 - <<std[f6927571c1bb7893]::thread::Builder>::spawn_unchecked_<rustc_interface[a7beddea6b2aa80d]::util::run_in_thread_with_globals<rustc_interface[a7beddea6b2aa80d]::util::run_in_thread_pool_with_globals<rustc_interface[a7beddea6b2aa80d]::interface::run_compiler<core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>, rustc_driver_impl[83de0f0d7a3bbaf8]::run_compiler::{closure#0}>::{closure#1}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>::{closure#0}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[e1b34d82e9cff2ed]::result::Result<(), rustc_span[b73f4c38f6b79966]::ErrorGuaranteed>>::{closure#1} as core[e1b34d82e9cff2ed]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x74eb19bda701 - std::sys::pal::unix::thread::Thread::new::thread_start::h4498a525a6fc6a9e
  35:     0x74eb1b27639d - <unknown>
  36:     0x74eb1b2fb49c - <unknown>
  37:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.83.0-nightly (5a4ee43c3 2024-10-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z validate-mir -Z cross-crate-inline-threshold=always -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `get_names`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0186, E0601.
For more information about an error, try `rustc --explain E0186`.

@matthiaskrgr matthiaskrgr 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 Oct 5, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 5, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Oct 5, 2024

Reduced:

struct Rows;

impl Iterator for Rows {
    type Item = String;
	
    fn next() -> Option<Self::Item> {
        std::fmt::format(format_args!("Hello world")).into()
    }
}

fn main() {
    Rows.next();
}

Inlining and reducing further changes the error:

struct Rows;

impl Iterator for Rows {
    type Item = String;

    fn next() -> Option<String> {
        let args = format_args!("Hello world");

        {
            match args.as_str() {
                Some(t) => t.to_owned(),
                None => String::new(),
            }
        }
            .into()
    }
}

fn main() {
    Rows.next();
}
thread 'rustc' panicked at /rustc/14f303bc1430a78ddaa91b3e104bbe4c0413184e/compiler/rustc_middle/src/ty/adt.rs:188:27:
index out of bounds: the len is 1 but the index is 1
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <rustc_mir_transform::validate::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_operand
   4: <rustc_mir_transform::validate::TypeChecker as rustc_middle::mir::visit::Visitor>::visit_rvalue
   5: rustc_mir_transform::validate::validate_types
   6: <rustc_mir_transform::validate::Validator as rustc_mir_transform::pass_manager::MirPass>::run_pass
   7: rustc_mir_transform::pass_manager::validate_body
   8: rustc_mir_transform::pass_manager::run_passes_inner
   9: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
  10: <rustc_middle::ty::context::TyCtxt>::instance_mir
  11: rustc_interface::passes::run_required_analyses
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Oct 12, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 15, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 26, 2024
…=lcnr

Make `compare_impl_item` into a query

Turns `compare_impl_item` into a query (generalizing the existing query for `compare_impl_const`), and uses that in `Instance::resolve` to fail resolution when an implementation is incompatible with the trait it comes from.

Fixes rust-lang#119701
Fixes rust-lang#121127
Fixes rust-lang#121411
Fixes rust-lang#129075
Fixes rust-lang#129127
Fixes rust-lang#129214
Fixes rust-lang#131294
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 27, 2024
…=lcnr

Make `compare_impl_item` into a query

Turns `compare_impl_item` into a query (generalizing the existing query for `compare_impl_const`), and uses that in `Instance::resolve` to fail resolution when an implementation is incompatible with the trait it comes from.

Fixes rust-lang#119701
Fixes rust-lang#121127
Fixes rust-lang#121411
Fixes rust-lang#129075
Fixes rust-lang#129127
Fixes rust-lang#129214
Fixes rust-lang#131294
@bors bors closed this as completed in 4af7fa7 Dec 1, 2024
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-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants