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: encountered unexpected unsized field in layout of #135020

Open
matthiaskrgr opened this issue Jan 2, 2025 · 5 comments · May be fixed by #135158
Open

ICE: encountered unexpected unsized field in layout of #135020

matthiaskrgr opened this issue Jan 2, 2025 · 5 comments · May be fixed by #135158
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue 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

Code

This is a more reduced & modified version of one of the snippets of #131342 but none of those seem to bisect to same nightly for me ( nightly-2024-04-05 )

fn problem_thingy(items: &mut impl Iterator<Item = str>) {
    let mut peeker = items.peekable();
    match peeker.peek() {
        Some(_) => (),
        None => return (),
    }
}

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (45d11e51b 2025-01-01)
binary: rustc
commit-hash: 45d11e51bb66c2deb63a006fe3953c4b6fbc50c2
commit-date: 2025-01-01
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6

Error output

<output>
Backtrace

warning: function `problem_thingy` is never used
 --> /tmp/crash.rs:1:4
  |
1 | fn problem_thingy(items: &mut impl Iterator<Item = str>) {
  |    ^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: 1 warning emitted

note: no errors encountered even though delayed bugs were created

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

error: internal compiler error: encountered unexpected unsized field in layout of std::option::Option<str>: TyAndLayout {
                                    ty: str,
                                    layout: Layout {
                                        size: Size(0 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(1 bytes),
                                            pref: Align(1 bytes),
                                        },
                                        abi: Memory {
                                            sized: false,
                                        },
                                        fields: Array {
                                            stride: Size(1 bytes),
                                            count: 0,
                                        },
                                        largest_niche: None,
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(1 bytes),
                                    },
                                }
  |
  = note: delayed at compiler/rustc_ty_utils/src/layout.rs:108:32
             0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
             1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
             2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
             3: <rustc_errors::DiagCtxtHandle>::delayed_bug::<alloc::string::String>
             4: rustc_ty_utils::layout::map_error
             5: rustc_ty_utils::layout::layout_of_uncached
             6: rustc_ty_utils::layout::layout_of
             7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
             8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, true, false>, rustc_query_impl::plumbing::QueryCtxt, false>
             9: rustc_query_impl::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
            10: <core::iter::adapters::GenericShunt<core::iter::adapters::by_ref_sized::ByRefSized<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}>>, core::result::Result<core::convert::Infallible, &rustc_middle::ty::layout::LayoutError>> as core::iter::traits::iterator::Iterator>::next
            11: rustc_ty_utils::layout::layout_of_uncached
            12: rustc_ty_utils::layout::layout_of
            13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
            14: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, true, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            15: rustc_query_impl::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
            16: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>>
            17: rustc_ty_utils::layout::layout_of
            18: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
            19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, true, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            20: rustc_query_impl::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
            21: <core::iter::adapters::GenericShunt<core::iter::adapters::by_ref_sized::ByRefSized<core::iter::adapters::map::Map<core::slice::iter::Iter<rustc_middle::ty::VariantDef>, rustc_ty_utils::layout::layout_of_uncached::{closure#13}>>, core::result::Result<core::convert::Infallible, &rustc_middle::ty::layout::LayoutError>> as core::iter::traits::iterator::Iterator>::next
            22: rustc_ty_utils::layout::layout_of_uncached
            23: rustc_ty_utils::layout::layout_of
            24: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 16]>>
            25: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_middle::ty::PseudoCanonicalInput<rustc_middle::ty::Ty>, rustc_middle::query::erase::Erased<[u8; 16]>>, false, true, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            26: rustc_query_impl::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
            27: <rustc_mir_transform::known_panics_lint::KnownPanicsLint as rustc_mir_transform::pass_manager::MirLint>::run_lint
            28: rustc_mir_transform::run_analysis_to_runtime_passes
            29: rustc_mir_transform::mir_drops_elaborated_and_const_checked
            30: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
            31: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            32: rustc_query_impl::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
            33: rustc_interface::passes::run_required_analyses
            34: rustc_interface::passes::analysis
            35: 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; 0]>>
            36: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
            37: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
            38: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
            39: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
            40: std::sys::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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
            41: <<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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
            42: std::sys::pal::unix::thread::Thread::new::thread_start
            43: <unknown>
            44: <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: please attach the file at `/home/matthias/vcs/github/rust_bisect/rustc-ice-2025-01-02T11_37_14-1305953.txt` to your bug report

note: compiler flags: --crate-type lib

query stack during panic:
end of query stack

@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 Jan 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 2, 2025
@matthiaskrgr matthiaskrgr changed the title ICE: `encountered unexpected unsized field in layout of ICE: encountered unexpected unsized field in layout of Jan 2, 2025
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jan 2, 2025

This compiled without error with previous nightly rustc 1.79.0-nightly (4fd4797c2 2024-04-03) but 2024-04-04 issues ICE.

@matthiaskrgr matthiaskrgr added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jan 2, 2025
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 2, 2025
@matthiaskrgr
Copy link
Member Author

This caught my eye because with --crate-type lib -Zmir-opt-level=3 -Zvalidate-mir
this issues a backtrace which I didn't remember seeing yet

error: internal compiler error: /rustc/45d11e51bb66c2deb63a006fe3953c4b6fbc50c2/compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid field type in Immediate::offset: value Scalar(0x0000000000000000) does not match ABI ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }))

thread 'rustc' panicked at /rustc/45d11e51bb66c2deb63a006fe3953c4b6fbc50c2/compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
Box<dyn Any>
stack backtrace:
   0:     0x7bcb786d196a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4f6a4ee866651707
   1:     0x7bcb78e13426 - core::fmt::write::h9e6f8d90343a57f6
   2:     0x7bcb79d30991 - std::io::Write::write_fmt::h66c66b1419a58ace
   3:     0x7bcb786d17c2 - std::sys::backtrace::BacktraceLock::print::h498d080cb25470cd
   4:     0x7bcb786d3cc9 - std::panicking::default_hook::{{closure}}::hbbfe0167a7d38133
   5:     0x7bcb786d3b12 - std::panicking::default_hook::h9a3de122a21c6cbb
   6:     0x7bcb77842398 - std[8bfb91823dd31ae1]::panicking::update_hook::<alloc[6d3b84562c9c9b42]::boxed::Box<rustc_driver_impl[a4f26dc2be1bc8fc]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x7bcb786d4483 - std::panicking::rust_panic_with_hook::hce10802d9af4ae90
   8:     0x7bcb7787a6b1 - std[8bfb91823dd31ae1]::panicking::begin_panic::<rustc_errors[bdbedb9356ccbc6e]::ExplicitBug>::{closure#0}
   9:     0x7bcb7786f896 - std[8bfb91823dd31ae1]::sys::backtrace::__rust_end_short_backtrace::<std[8bfb91823dd31ae1]::panicking::begin_panic<rustc_errors[bdbedb9356ccbc6e]::ExplicitBug>::{closure#0}, !>
  10:     0x7bcb7786c55d - std[8bfb91823dd31ae1]::panicking::begin_panic::<rustc_errors[bdbedb9356ccbc6e]::ExplicitBug>
  11:     0x7bcb77884611 - <rustc_errors[bdbedb9356ccbc6e]::diagnostic::BugAbort as rustc_errors[bdbedb9356ccbc6e]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x7bcb77e648e3 - rustc_middle[1fd816385aa193f]::util::bug::opt_span_bug_fmt::<rustc_span[af3532371e21fe]::span_encoding::Span>::{closure#0}
  13:     0x7bcb77e4998a - rustc_middle[1fd816385aa193f]::ty::context::tls::with_opt::<rustc_middle[1fd816385aa193f]::util::bug::opt_span_bug_fmt<rustc_span[af3532371e21fe]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x7bcb77e4981b - rustc_middle[1fd816385aa193f]::ty::context::tls::with_context_opt::<rustc_middle[1fd816385aa193f]::ty::context::tls::with_opt<rustc_middle[1fd816385aa193f]::util::bug::opt_span_bug_fmt<rustc_span[af3532371e21fe]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x7bcb761a9e50 - rustc_middle[1fd816385aa193f]::util::bug::bug_fmt
  16:     0x7bcb7a7e5043 - <rustc_const_eval[180ac8504a62d3dd]::interpret::operand::Immediate>::assert_matches_abi::<rustc_const_eval[180ac8504a62d3dd]::interpret::eval_context::InterpCx<rustc_const_eval[180ac8504a62d3dd]::const_eval::dummy_machine::DummyMachine>>.cold
  17:     0x7bcb79930cf8 - <rustc_const_eval[180ac8504a62d3dd]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[180ac8504a62d3dd]::interpret::eval_context::InterpCx<rustc_const_eval[180ac8504a62d3dd]::const_eval::dummy_machine::DummyMachine>>
  18:     0x7bcb7992ef0d - <rustc_const_eval[180ac8504a62d3dd]::interpret::operand::OpTy as rustc_const_eval[180ac8504a62d3dd]::interpret::projection::Projectable<rustc_middle[1fd816385aa193f]::mir::interpret::pointer::CtfeProvenance>>::offset_with_meta::<rustc_const_eval[180ac8504a62d3dd]::const_eval::dummy_machine::DummyMachine>
  19:     0x7bcb7a11b8a7 - <rustc_const_eval[180ac8504a62d3dd]::interpret::eval_context::InterpCx<rustc_const_eval[180ac8504a62d3dd]::const_eval::dummy_machine::DummyMachine>>::project_downcast::<rustc_const_eval[180ac8504a62d3dd]::interpret::operand::OpTy>
  20:     0x7bcb78048e2e - <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#0}
  21:     0x7bcb77f532bf - <rustc_mir_dataflow[f45e8f9b9136a50b]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[180ac8504a62d3dd]::interpret::operand::OpTy, <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#0}, <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis>::assign_constant::{closure#1}>
  22:     0x7bcb78048d5e - <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis>::assign_constant
  23:     0x7bcb7800d1a6 - <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis>::assign_operand
  24:     0x7bcb7800bc1f - <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::ConstAnalysis as rustc_mir_dataflow[f45e8f9b9136a50b]::framework::Analysis>::apply_primary_statement_effect
  25:     0x7bcb78049a6c - <rustc_mir_transform[3a0403f4a2d1bba5]::dataflow_const_prop::DataflowConstProp as rustc_mir_transform[3a0403f4a2d1bba5]::pass_manager::MirPass>::run_pass
  26:     0x7bcb78e0eeee - rustc_mir_transform[3a0403f4a2d1bba5]::pass_manager::run_passes_inner
  27:     0x7bcb78f3be9f - rustc_mir_transform[3a0403f4a2d1bba5]::optimized_mir
  28:     0x7bcb78f3b75f - rustc_query_impl[5253828023562b54]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5253828023562b54]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1fd816385aa193f]::query::erase::Erased<[u8; 8usize]>>
  29:     0x7bcb78f0419f - rustc_query_system[b85e5bdbcfc10045]::query::plumbing::try_execute_query::<rustc_query_impl[5253828023562b54]::DynamicConfig<rustc_query_system[b85e5bdbcfc10045]::query::caches::DefIdCache<rustc_middle[1fd816385aa193f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5253828023562b54]::plumbing::QueryCtxt, false>
  30:     0x7bcb78f0365f - rustc_query_impl[5253828023562b54]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7bcb75d7e8c9 - <rustc_middle[1fd816385aa193f]::ty::context::TyCtxt>::instance_mir
  32:     0x7bcb7925a912 - rustc_interface[15f87623c1d0da48]::passes::run_required_analyses
  33:     0x7bcb79d4479e - rustc_interface[15f87623c1d0da48]::passes::analysis
  34:     0x7bcb79d4476f - rustc_query_impl[5253828023562b54]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5253828023562b54]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[1fd816385aa193f]::query::erase::Erased<[u8; 0usize]>>
  35:     0x7bcb79da1815 - rustc_query_system[b85e5bdbcfc10045]::query::plumbing::try_execute_query::<rustc_query_impl[5253828023562b54]::DynamicConfig<rustc_query_system[b85e5bdbcfc10045]::query::caches::SingleCache<rustc_middle[1fd816385aa193f]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[5253828023562b54]::plumbing::QueryCtxt, false>
  36:     0x7bcb79da154e - rustc_query_impl[5253828023562b54]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7bcb79df445e - rustc_interface[15f87623c1d0da48]::passes::create_and_enter_global_ctxt::<core[d95970c0d684ac01]::option::Option<rustc_interface[15f87623c1d0da48]::queries::Linker>, rustc_driver_impl[a4f26dc2be1bc8fc]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  38:     0x7bcb79dcec96 - rustc_interface[15f87623c1d0da48]::interface::run_compiler::<(), rustc_driver_impl[a4f26dc2be1bc8fc]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7bcb79cfe85b - std[8bfb91823dd31ae1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[15f87623c1d0da48]::util::run_in_thread_with_globals<rustc_interface[15f87623c1d0da48]::util::run_in_thread_pool_with_globals<rustc_interface[15f87623c1d0da48]::interface::run_compiler<(), rustc_driver_impl[a4f26dc2be1bc8fc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  40:     0x7bcb79cfed18 - <<std[8bfb91823dd31ae1]::thread::Builder>::spawn_unchecked_<rustc_interface[15f87623c1d0da48]::util::run_in_thread_with_globals<rustc_interface[15f87623c1d0da48]::util::run_in_thread_pool_with_globals<rustc_interface[15f87623c1d0da48]::interface::run_compiler<(), rustc_driver_impl[a4f26dc2be1bc8fc]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[d95970c0d684ac01]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7bcb79d002ef - std::sys::pal::unix::thread::Thread::new::thread_start::hf62fdb37efc5763b
  42:     0x7bcb740a339d - <unknown>
  43:     0x7bcb7412849c - <unknown>
  44:                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: please attach the file at `/tmp/im/rustc-ice-2025-01-02T11_44_39-1308394.txt` to your bug report

note: compiler flags: --crate-type lib -Z mir-opt-level=3 -Z validate-mir

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

@cyrgani
Copy link
Contributor

cyrgani commented Jan 2, 2025

reduced:

fn problem_thingy(items: &mut impl Iterator<Item = str>) {
    items.peekable();
}

and without any external items:

struct Wrap<T>(T);

struct Peekable<I: Iterator>(Wrap<I::Item>);

fn problem_thingy(items: impl Iterator<Item = str>) {
    p(items);
}

trait Iterator {
    type Item;
}

fn p<I: Iterator>(_: I) -> Peekable<I> {
    loop {}
}

@apiraino
Copy link
Contributor

apiraino commented Jan 2, 2025

thanks @cyrgani for reducing the sample.

I've run your code and run a bisection (without the additional compile flags mentioned in this comment) and I was taken to #129970, so cc @compiler-errors @lukas-code for an opinion here.

searched nightlies: from nightly-2024-07-20 to nightly-2025-01-02
regressed nightly: nightly-2024-09-18
searched commit range: c52c23b...28e8f01
regressed commit: e2dc1a1

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --without-cargo --preserve --start 1.81.0 --script test.sh 

@lukas-code
Copy link
Member

Looks like this assertion is actually wrong:

if !field.ty.is_sized(cx.tcx(), cx.typing_env) {
cx.tcx().dcx().delayed_bug(format!(
"encountered unexpected unsized field in layout of {ty:?}: {field:#?}"
));
}

Currently T: Iterator<Item = str> does not imply str: Sized (in either solver) and we eagerly normalize Wrap<I::Item> to Wrap<str> in the layout_of query.

When we compute the layout of Wrap<str> and find the unsized type str in a field that is expected to be sized, the layout computation returns LayoutCalculatorError::UnexpectedUnsized and the assertion then checks for a str: Sized bound, but in this case we only know I::Item: Sized and not str: Sized even though I::Item normalizes to str.

Keeping this assertion in some sensible manner seems like it would be more effort than it's worth, so I'm inclined to just remove it.

@lukas-code lukas-code added A-layout Area: Memory layout of types S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue S-has-bisection Status: a bisection has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 2, 2025
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. S-has-bisection Status: a bisection has been found for this issue 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.

5 participants