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: type mismatch when copying! with no feature provided #124552

Closed
cushionbadak opened this issue Apr 30, 2024 · 2 comments · Fixed by #126045
Closed

ICE: type mismatch when copying! with no feature provided #124552

cushionbadak opened this issue Apr 30, 2024 · 2 comments · Fixed by #126045
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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

@cushionbadak
Copy link

cushionbadak commented Apr 30, 2024

Code

(reduced)

struct B;

struct Foo {
    b: u32,
    b: B,
}

static BAR: Foo = Foo { b: B };

fn main() {}
Original Code

// Verifies that static items can't be moved

struct B;

struct Foo {
    pub(crate) b: u32,
    b: B,
}

static BAR: Foo = Foo { , b: B };


fn test(f: Foo) {
    let _val: &'static _ = &(i32::MIN/(0-1));
}

fn main() {
    test(BAR); //~ ERROR cannot move out of static item
}

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (0ad927c0c 2024-03-21)
binary: rustc
commit-hash: 0ad927c0c07b65fc0dae37105e09c877c87c296a
commit-date: 2024-03-21
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.2

Command

rustc

Error output

error[E0124]: field `b` is already declared
 --> r_7A4EF4620B2BDD7720B5AEE6CE4584307D5131538726D4919292E63C73428A66.rs:5:5
  |
4 |     b: u32,
  |     ------ `b` first declared here
5 |     b: B,
  |     ^^^^ field already declared

error: internal compiler error: compiler/rustc_const_eval/src/interpret/place.rs:849:13: type mismatch when copying!
                                src: B,
                                dest: u32
 --> r_7A4EF4620B2BDD7720B5AEE6CE4584307D5131538726D4919292E63C73428A66.rs:8:19
  |
8 | static BAR: Foo = Foo { b: B };
  |                   ^^^^^^^^^^^^
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/place.rs:849:13:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxt>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::copy_op_no_validate::<rustc_const_eval::interpret::operand::OpTy, rustc_const_eval::interpret::place::PlaceTy>
   8: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeInterpreter>>::statement
   9: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider
      [... omitted 2 frames ...]
  10: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#3}>::{closure#0}
  11: rustc_hir_analysis::check_crate
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  14: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: it seems that this compiler `1.79.0-nightly (0ad927c0c 2024-03-21)` is outdated, a newer nightly should have been released in the mean time
  |
  = note: please consider running `rustup update nightly` to update the nightly channel and check if this problem still persists
  = note: if the problem still persists, 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 attach the file at `/Users/jb/Desktop/tmp/0428_files/rustc-ice-2024-04-30T08_38_48-56156.txt` to your bug report

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `BAR`
#1 [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 E0124`.

Note

@cushionbadak cushionbadak 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 Apr 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 30, 2024
@cushionbadak
Copy link
Author

bisects to #121087

searched nightlies: from nightly-2024-01-01 to nightly-2024-04-30
regressed nightly: nightly-2024-02-21
searched commit range: 3246e79...bb59453
regressed commit: cce6a6e

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-apple-darwin
Reproduce with:

cargo bisect-rustc --script=rustc --start=2024-01-01 --end=2024-04-30 --preserve --regress=ice -- r_7A4EF4620B2BDD7720B5AEE6CE4584307D5131538726D4919292E63C73428A66.rs 

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 9, 2024
@jieyouxu jieyouxu added A-const-eval Area: Constant evaluation (MIR interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 13, 2024
@oli-obk
Copy link
Contributor

oli-obk commented May 22, 2024

The following already reproduces on 1.77 stable

struct B;

struct Foo {
    b: u32,
    b: B,
}

const BAR: Foo = Foo { b: B };

const _:[();{
BAR;
    0
}] = [];

fn main() {}

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 5, 2024
check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes rust-lang#125842, fixes rust-lang#124464, fixes rust-lang#124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was rust-lang#125947 but i messed something up, sorry)
r? `@compiler-errors`
@bors bors closed this as completed in 3121a5c Jun 6, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 6, 2024
Rollup merge of rust-lang#126045 - olafes:master, r=compiler-errors

check_expr_struct_fields: taint context with errors if struct definit…

Taint errors while checking `struct { field: 1 }` below if struct definition has duplicated fields so that we don't pass it to const eval.

fixes rust-lang#125842, fixes rust-lang#124464, fixes rust-lang#124552
```rust
struct Struct {
    field: Option<u8>,
    field: u8,
}

static STATIC: Struct = Struct {
    field: 1,
};

pub fn main() {}
```
(This was rust-lang#125947 but i messed something up, sorry)
r? ``@compiler-errors``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) 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
5 participants