Skip to content

Unexpected type for constructor Struct #124004

Closed

Description

@Naserume

Code

(reduced)

#![feature(box_patterns)]

use std::ops::{ Deref };

struct X(dyn Iterator<Item = &'a ()>);

impl Deref for X {
    type Target = isize;

    fn deref(&self) -> &isize {
        let &X(box ref x) = self;
        x
    }
}

fn main() { }

(original)

//@ run-pass
#![feature(box_patterns)]

use std::ops::{Deref, DerefMut};

struct X(Iterator<Item = &'a ()>);

static mut DESTRUCTOR_RAN: bool = false;

impl Drop for X {
    fn drop(&mut self) {
        unsafe {
            assert!(!DESTRUCTOR_RAN);
            DESTRUCTOR_RAN = true;
        }
    }
}

impl Deref for X {
    type Target = isize;

    fn deref(&self) -> &isize {
        let &X(box ref x) = self;
        x
    }
}

impl DerefMut for X {
    fn deref_mut(&mut self) -> &mut isize {
        let &mut X(box ref mut x) = self
        x
    }
}

fn main() {
    {
        let mut test = X(Box::new(5));
        {
            let mut change = || { *test = 10 };
            change();
        }
        assert_eq!(*test, 10);
    }
    assert!(unsafe { DESTRUCTOR_RAN });
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (0d8b3346a 2024-04-14)
binary: rustc
commit-hash: 0d8b3346a3992ab11ea35ff0fb95a6864b91f797
commit-date: 2024-04-14
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Error output

error[E0261]: use of undeclared lifetime name `'a`
 --> ./42014B0E5BEE51773962BDC66C19A687BF2BCA268F20494CFBF764F616612328.rs:5:31
  |
5 | struct X(dyn Iterator<Item = &'a ()>);
  |                               ^^ undeclared lifetime
  |
  = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
  |
5 | struct X(dyn for<'a> Iterator<Item = &'a ()>);
  |              +++++++
help: consider introducing lifetime `'a` here
  |
5 | struct X<'a>(dyn Iterator<Item = &'a ()>);
  |         ++++
Backtrace

error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:235:22: Unexpected type for constructor `Struct`: dyn [Binder(Trait(std::iter::Iterator), []), Binder(Projection(ExistentialProjection { def_id: DefId(2:8346 ~ core[5d06]::iter::traits::iterator::Iterator::Item), args: [], term: Term::Ty(&'{erased} ()) }), [])] + '{erased}

thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:235:22:
Box<dyn Any>
stack backtrace:
   0:        0x10d2abc33 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h64c2afb309c31778
   1:        0x10d2f76eb - core::fmt::write::hc23fab116e688c5a
   2:        0x10d2a1d7e - std::io::Write::write_fmt::hc554712574aee1b1
   3:        0x10d2aba21 - std::sys_common::backtrace::print::h8d045d1d6d8eda73
   4:        0x10d2ae719 - std::panicking::default_hook::{{closure}}::h65ac21535f58ee0a
   5:        0x10d2ae460 - std::panicking::default_hook::h24915649deb9e4fc
   6:        0x115f1d56c - std[28e242a172f62cc5]::panicking::update_hook::<alloc[d18bf54b8bbef4a6]::boxed::Box<rustc_driver_impl[a82bc910fff4ad06]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x10d2af23c - std::panicking::rust_panic_with_hook::hfb2063d444201996
   8:        0x115f8418a - std[28e242a172f62cc5]::panicking::begin_panic::<rustc_errors[748ffab8893d222]::ExplicitBug>::{closure#0}
   9:        0x115f7c6b9 - std[28e242a172f62cc5]::sys_common::backtrace::__rust_end_short_backtrace::<std[28e242a172f62cc5]::panicking::begin_panic<rustc_errors[748ffab8893d222]::ExplicitBug>::{closure#0}, !>
  10:        0x11a6b3f19 - std[28e242a172f62cc5]::panicking::begin_panic::<rustc_errors[748ffab8893d222]::ExplicitBug>
  11:        0x115f978d6 - <rustc_errors[748ffab8893d222]::diagnostic::BugAbort as rustc_errors[748ffab8893d222]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:        0x116a7275e - rustc_middle[e34a00149b4583d7]::util::bug::opt_span_bug_fmt::<rustc_span[708ae0672d259dca]::span_encoding::Span>::{closure#0}
  13:        0x116a23417 - rustc_middle[e34a00149b4583d7]::ty::context::tls::with_opt::<rustc_middle[e34a00149b4583d7]::util::bug::opt_span_bug_fmt<rustc_span[708ae0672d259dca]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:        0x116a22f25 - rustc_middle[e34a00149b4583d7]::ty::context::tls::with_context_opt::<rustc_middle[e34a00149b4583d7]::ty::context::tls::with_opt<rustc_middle[e34a00149b4583d7]::util::bug::opt_span_bug_fmt<rustc_span[708ae0672d259dca]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:        0x11a772a0b - rustc_middle[e34a00149b4583d7]::util::bug::bug_fmt
  16:        0x117087998 - <rustc_pattern_analysis[44ef45dd33bf8897]::rustc::RustcPatCtxt as rustc_pattern_analysis[44ef45dd33bf8897]::PatCx>::ctor_sub_tys
  17:        0x1170912d9 - rustc_pattern_analysis[44ef45dd33bf8897]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[44ef45dd33bf8897]::rustc::RustcPatCtxt>
  18:        0x117091c87 - rustc_pattern_analysis[44ef45dd33bf8897]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[44ef45dd33bf8897]::rustc::RustcPatCtxt>
  19:        0x117091c87 - rustc_pattern_analysis[44ef45dd33bf8897]::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis[44ef45dd33bf8897]::rustc::RustcPatCtxt>
  20:        0x11708c477 - rustc_pattern_analysis[44ef45dd33bf8897]::analyze_match
  21:        0x116b6e783 - <rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor>::analyze_patterns
  22:        0x116ba23c5 - <rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor>::check_binding_is_irrefutable
  23:        0x116ba2275 - <rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor>::check_let
  24:        0x116ae4bc3 - rustc_middle[e34a00149b4583d7]::thir::visit::walk_block::<rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor>
  25:        0x116ba1a9d - <rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor as rustc_middle[e34a00149b4583d7]::thir::visit::Visitor>::visit_expr
  26:        0x116ba151c - <rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::MatchVisitor as rustc_middle[e34a00149b4583d7]::thir::visit::Visitor>::visit_expr
  27:        0x116b6da69 - rustc_mir_build[f8655712974bcade]::thir::pattern::check_match::check_match
  28:        0x11736aeba - rustc_query_impl[1cf588037da06ac4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1cf588037da06ac4]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 1usize]>>
  29:        0x1171f1afc - rustc_query_system[98688be416762701]::query::plumbing::try_execute_query::<rustc_query_impl[1cf588037da06ac4]::DynamicConfig<rustc_query_system[98688be416762701]::query::caches::VecCache<rustc_span[708ae0672d259dca]::def_id::LocalDefId, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1cf588037da06ac4]::plumbing::QueryCtxt, false>
  30:        0x11739da90 - rustc_query_impl[1cf588037da06ac4]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  31:        0x116b227d2 - rustc_mir_build[f8655712974bcade]::build::mir_build
  32:        0x116dbd63f - rustc_mir_transform[f6c980be58df0e21]::mir_built
  33:        0x11736fa5a - rustc_query_impl[1cf588037da06ac4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1cf588037da06ac4]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 8usize]>>
  34:        0x1171fa517 - rustc_query_system[98688be416762701]::query::plumbing::try_execute_query::<rustc_query_impl[1cf588037da06ac4]::DynamicConfig<rustc_query_system[98688be416762701]::query::caches::VecCache<rustc_span[708ae0672d259dca]::def_id::LocalDefId, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1cf588037da06ac4]::plumbing::QueryCtxt, false>
  35:        0x11738004b - rustc_query_impl[1cf588037da06ac4]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  36:        0x116b66eff - rustc_mir_build[f8655712974bcade]::check_unsafety::check_unsafety
  37:        0x11736b53a - rustc_query_impl[1cf588037da06ac4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1cf588037da06ac4]::query_impl::check_unsafety::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 0usize]>>
  38:        0x1171eaacb - rustc_query_system[98688be416762701]::query::plumbing::try_execute_query::<rustc_query_impl[1cf588037da06ac4]::DynamicConfig<rustc_query_system[98688be416762701]::query::caches::VecCache<rustc_span[708ae0672d259dca]::def_id::LocalDefId, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[1cf588037da06ac4]::plumbing::QueryCtxt, false>
  39:        0x11738e830 - rustc_query_impl[1cf588037da06ac4]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace
  40:        0x116684db2 - <rustc_middle[e34a00149b4583d7]::hir::map::Map>::par_body_owners::<rustc_interface[2cf32266391f9a3e]::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
  41:        0x1166d728c - rustc_interface[2cf32266391f9a3e]::passes::run_required_analyses
  42:        0x1166d9770 - rustc_interface[2cf32266391f9a3e]::passes::analysis
  43:        0x11736f74a - rustc_query_impl[1cf588037da06ac4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1cf588037da06ac4]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 1usize]>>
  44:        0x11715141e - rustc_query_system[98688be416762701]::query::plumbing::try_execute_query::<rustc_query_impl[1cf588037da06ac4]::DynamicConfig<rustc_query_system[98688be416762701]::query::caches::SingleCache<rustc_middle[e34a00149b4583d7]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[1cf588037da06ac4]::plumbing::QueryCtxt, false>
  45:        0x117379b17 - rustc_query_impl[1cf588037da06ac4]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:        0x115eca3a7 - <rustc_interface[2cf32266391f9a3e]::queries::QueryResult<&rustc_middle[e34a00149b4583d7]::ty::context::GlobalCtxt>>::enter::<core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>, rustc_driver_impl[a82bc910fff4ad06]::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  47:        0x115f1bbdf - rustc_interface[2cf32266391f9a3e]::interface::run_compiler::<core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>, rustc_driver_impl[a82bc910fff4ad06]::run_compiler::{closure#0}>::{closure#0}
  48:        0x115f0bdad - std[28e242a172f62cc5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[2cf32266391f9a3e]::util::run_in_thread_with_globals<rustc_interface[2cf32266391f9a3e]::util::run_in_thread_pool_with_globals<rustc_interface[2cf32266391f9a3e]::interface::run_compiler<core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>, rustc_driver_impl[a82bc910fff4ad06]::run_compiler::{closure#0}>::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>
  49:        0x115f254d6 - <<std[28e242a172f62cc5]::thread::Builder>::spawn_unchecked_<rustc_interface[2cf32266391f9a3e]::util::run_in_thread_with_globals<rustc_interface[2cf32266391f9a3e]::util::run_in_thread_pool_with_globals<rustc_interface[2cf32266391f9a3e]::interface::run_compiler<core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>, rustc_driver_impl[a82bc910fff4ad06]::run_compiler::{closure#0}>::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5d06e84208279116]::result::Result<(), rustc_span[708ae0672d259dca]::ErrorGuaranteed>>::{closure#2} as core[5d06e84208279116]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:        0x10d2b895b - std::sys::pal::unix::thread::Thread::new::thread_start::h46ddcf9131ad2508
  51:     0x7ff818270202 - __pthread_start

query stack during panic:
#0 [check_match] match-checking `<impl at ./42014B0E5BEE51773962BDC66C19A687BF2BCA268F20494CFBF764F616612328.rs:7:1: 7:17>::deref`
#1 [mir_built] building MIR for `<impl at ./42014B0E5BEE51773962BDC66C19A687BF2BCA268F20494CFBF764F616612328.rs:7:1: 7:17>::deref`
#2 [check_unsafety] unsafety-checking `<impl at ./42014B0E5BEE51773962BDC66C19A687BF2BCA268F20494CFBF764F616612328.rs:7:1: 7:17>::deref`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0261`.

### Tasks

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Apr 16, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 16, 2024
  3. cushionbadak commented on Apr 16, 2024

    @cushionbadak

    searched nightlies: from nightly-2024-01-01 to nightly-2024-04-04
    regressed nightly: nightly-2024-03-22
    searched commit range: 1388d7a...0ad927c
    regressed commit: 6a6cd65

    bisected with cargo-bisect-rustc v0.6.8

    Host triple: x86_64-apple-darwin
    Reproduce with:

    cargo bisect-rustc --start=2024-01-01 --end=2024-04-04 --preserve --regress=ice
  4. matthiaskrgr commented on Apr 16, 2024

    @matthiaskrgr
    Member

    might be #122749

  5. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Apr 18, 2024
  6. saethlin commented on Apr 28, 2024

    @saethlin
    Member

    This still ICEs, so I don't think so.

  7. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Apr 28, 2024
  8. matthiaskrgr commented on Apr 28, 2024

    @matthiaskrgr
    Member

    @saethlin huh, what do you mean?

  9. matthiaskrgr commented on Apr 28, 2024

    @matthiaskrgr
    Member

    #122749 is a PR, not a different issue 😅

  10. saethlin commented on Apr 28, 2024

    @saethlin
    Member

    Oh you meant the cause not that this is a duplicate 🤦

  11. matthiaskrgr commented on Apr 28, 2024

    @matthiaskrgr
    Member

    yeh :D

  12. added a commit that references this issue on Jun 13, 2024
    2a7a689
  13. added 6 commits that reference this issue on Jun 13, 2024
    29cb7a9
    758f890
    5bb74de
    dd3a02f
    5725958
    2b3fb62
  14. added a commit that references this issue on Jun 14, 2024
    08510cf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions