rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
95.35k stars 12.28k forks source link

ICE: `!ty.is_copy_modulo_regions(tcx, param_env)` #122259

Open matthiaskrgr opened 4 months ago

matthiaskrgr commented 4 months ago

snippet:

#![feature(unsized_fn_params)]

use std::fmt::{self, Display};

pub enum MethodKind {
    Trait { body: str },
    Inherent,
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum Target {
    Method(MethodKind),
}

impl Display for Target {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "{}", Self::name(*self))
    }
}

impl Target {
    pub fn name(self) -> &'static str {}
}

Version information

rustc 1.78.0-nightly (840164571 2024-03-09)
binary: rustc
commit-hash: 8401645716b26a8b4c6974dc0680e55e81e9e8a1
commit-date: 2024-03-09
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 18.1.0

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

Program output

``` error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:23:2 | 23 | } | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs` error[E0277]: the size for values of type `str` cannot be known at compilation time --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:6:19 | 6 | Trait { body: str }, | ^^^ doesn't have a size known at compile-time | = help: the trait `Sized` is not implemented for `str` = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size help: borrowed types always have a statically known size | 6 | Trait { body: &str }, | + help: the `Box` type always has a statically known size and allocates its contents in the heap | 6 | Trait { body: Box }, | ++++ + error[E0277]: the size for values of type `str` cannot be known at compilation time --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:12:12 | 12 | Method(MethodKind), | ^^^^^^^^^^ doesn't have a size known at compile-time | = help: within `MethodKind`, the trait `Sized` is not implemented for `str`, which is required by `MethodKind: Sized` note: required because it appears within the type `MethodKind` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:5:10 | 5 | pub enum MethodKind { | ^^^^^^^^^^ = note: no field of an enum variant may have a dynamically sized type = help: change the field's type to have a statically known size help: borrowed types always have a statically known size | 12 | Method(&MethodKind), | + help: the `Box` type always has a statically known size and allocates its contents in the heap | 12 | Method(Box), | ++++ + error[E0204]: the trait `Copy` cannot be implemented for this type --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:10:10 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | ^^^^ 11 | pub enum Target { 12 | Method(MethodKind), | ---------- this field does not implement `Copy` | = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `str` cannot be known at compilation time --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:10:16 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | ^^^^^ doesn't have a size known at compile-time | = help: within `Target`, the trait `Sized` is not implemented for `str`, which is required by `Target: Sized` note: required because it appears within the type `Target` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:11:10 | 11 | pub enum Target { | ^^^^^^ note: required by a bound in `Clone` --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/clone.rs:147:18 | 147 | pub trait Clone: Sized { | ^^^^^ required by this bound in `Clone` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `MethodKind: Clone` is not satisfied --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:12:12 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | ----- in this derive macro expansion 11 | pub enum Target { 12 | Method(MethodKind), | ^^^^^^^^^^ the trait `Clone` is not implemented for `MethodKind` | note: required by a bound in `AssertParamIsClone` --> /home/matthias/.rustup/toolchains/master/lib/rustlib/src/rust/library/core/src/clone.rs:193:34 | 193 | pub struct AssertParamIsClone { | ^^^^^ required by this bound in `AssertParamIsClone` = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the size for values of type `str` cannot be known at compilation time --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:10:16 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | ^^^^^ doesn't have a size known at compile-time | = help: within `Target`, the trait `Sized` is not implemented for `str`, which is required by `Target: Sized` note: required because it appears within the type `Target` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:11:10 | 11 | pub enum Target { | ^^^^^^ = note: the return type of a function must have a statically known size = note: this error originates in the derive macro `Clone` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0369]: binary operation `==` cannot be applied to type `MethodKind` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:12:12 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | --------- in this derive macro expansion 11 | pub enum Target { 12 | Method(MethodKind), | ^^^^^^^^^^ | note: an implementation of `PartialEq` might be missing for `MethodKind` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:5:1 | 5 | pub enum MethodKind { | ^^^^^^^^^^^^^^^^^^^ must implement `PartialEq` = note: this error originates in the derive macro `PartialEq` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `MethodKind` with `#[derive(PartialEq)]` | 5 + #[derive(PartialEq)] 6 | pub enum MethodKind { | error[E0277]: `MethodKind` doesn't implement `Debug` --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:12:12 | 10 | #[derive(Copy, Clone, PartialEq, Debug)] | ----- in this derive macro expansion 11 | pub enum Target { 12 | Method(MethodKind), | ^^^^^^^^^^ `MethodKind` cannot be formatted using `{:?}` | = help: the trait `Debug` is not implemented for `MethodKind`, which is required by `&MethodKind: Debug` = note: add `#[derive(Debug)]` to `MethodKind` or manually `impl Debug for MethodKind` = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `MethodKind` with `#[derive(Debug)]` | 5 + #[derive(Debug)] 6 | pub enum MethodKind { | error[E0308]: mismatched types --> /tmp/icemaker_global_tempdir.Dod2gYKM516h/rustc_testrunner_tmpdir_reporting.txW3v63cD0Q3/mvce.rs:22:26 | 22 | pub fn name(self) -> &'static str {} | ---- ^^^^^^^^^^^^ expected `&str`, found `()` | | | implicitly returns `()` as its body has no tail or `return` expression thread 'rustc' panicked at compiler/rustc_mir_build/src/build/expr/as_operand.rs:170:17: assertion failed: !ty.is_copy_modulo_regions(tcx, param_env) stack backtrace: 0: 0x7f19a580fa02 - std::backtrace_rs::backtrace::libunwind::trace::hf3d4f3241dee1b61 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 1: 0x7f19a580fa02 - std::backtrace_rs::backtrace::trace_unsynchronized::h17349fea4d65ac90 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f19a580fa02 - std::sys_common::backtrace::_print_fmt::h45a7733b6e7ef79f at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys_common/backtrace.rs:68:5 3: 0x7f19a580fa02 - ::fmt::h3d166936f5a39350 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f19a586098c - core::fmt::rt::Argument::fmt::h3c678ecd54288730 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/core/src/fmt/rt.rs:142:9 5: 0x7f19a586098c - core::fmt::write::h5f9e1f9d47b97ff6 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/core/src/fmt/mod.rs:1153:17 6: 0x7f19a580447f - std::io::Write::write_fmt::h405197d4bb83f90f at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/io/mod.rs:1846:15 7: 0x7f19a580f7d4 - std::sys_common::backtrace::_print::hc3f73834b26ce985 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f19a580f7d4 - std::sys_common::backtrace::print::hf7cffd629e2559ea at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f19a58124db - std::panicking::default_hook::{{closure}}::h2e6bfd324cff11b7 10: 0x7f19a5812233 - std::panicking::default_hook::h4a51bd222c466c9e at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/panicking.rs:292:9 11: 0x7f19a2469057 - std[d016f499f7096d82]::panicking::update_hook::>::{closure#0} 12: 0x7f19a5812c40 - as core::ops::function::Fn>::call::h0d13de13827d8d7c at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/alloc/src/boxed.rs:2034:9 13: 0x7f19a5812c40 - std::panicking::rust_panic_with_hook::heea6de1892e55ab9 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/panicking.rs:783:13 14: 0x7f19a5812949 - std::panicking::begin_panic_handler::{{closure}}::h45ea0224ab637a2b at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/panicking.rs:649:13 15: 0x7f19a580fed6 - std::sys_common::backtrace::__rust_end_short_backtrace::h2bb303ad0af37de8 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys_common/backtrace.rs:171:18 16: 0x7f19a58126b4 - rust_begin_unwind at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/panicking.rs:645:5 17: 0x7f19a585cea5 - core::panicking::panic_fmt::hc32488af6c6f42f9 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/core/src/panicking.rs:72:14 18: 0x7f19a585cf63 - core::panicking::panic::hb4526bed2464a4b1 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/core/src/panicking.rs:145:5 19: 0x7f19a3a8ac2c - ::as_call_operand 20: 0x7f19a3a89516 - ::as_call_operand 21: 0x7f19a3f0de24 - ::expr_into_dest 22: 0x7f19a3855d7a - ::as_temp::{closure#0} 23: 0x7f19a3ccbbd7 - ::expr_as_place 24: 0x7f19a3ccc0c9 - ::expr_as_place 25: 0x7f19a3f0dafb - ::expr_into_dest 26: 0x7f19a3855d7a - ::as_temp::{closure#0} 27: 0x7f19a3ccbbd7 - ::expr_as_place 28: 0x7f19a3ccba7a - ::expr_as_place 29: 0x7f19a3f0dafb - ::expr_into_dest 30: 0x7f19a3855d7a - ::as_temp::{closure#0} 31: 0x7f19a385432e - ::as_operand 32: 0x7f19a3a88f11 - ::as_call_operand 33: 0x7f19a3a89516 - ::as_call_operand 34: 0x7f19a3f0de24 - ::expr_into_dest 35: 0x7f19a3855d7a - ::as_temp::{closure#0} 36: 0x7f19a385432e - ::as_operand 37: 0x7f19a3854010 - ::as_operand 38: 0x7f19a3ca783d - ::as_rvalue 39: 0x7f19a3f0d4cd - ::expr_into_dest 40: 0x7f19a3855d7a - ::as_temp::{closure#0} 41: 0x7f19a3ccbbd7 - ::expr_as_place 42: 0x7f19a3ccc0c9 - ::expr_as_place 43: 0x7f19a3f0dafb - ::expr_into_dest 44: 0x7f19a3855d7a - ::as_temp::{closure#0} 45: 0x7f19a3ccbbd7 - ::expr_as_place 46: 0x7f19a3ccba7a - ::expr_as_place 47: 0x7f19a3f0dafb - ::expr_into_dest 48: 0x7f19a3855d7a - ::as_temp::{closure#0} 49: 0x7f19a385432e - ::as_operand 50: 0x7f19a3ca759c - ::as_rvalue 51: 0x7f19a3f0d4cd - ::expr_into_dest 52: 0x7f19a3855d7a - ::as_temp::{closure#0} 53: 0x7f19a385432e - ::as_operand 54: 0x7f19a3a88f11 - ::as_call_operand 55: 0x7f19a3a89516 - ::as_call_operand 56: 0x7f19a3f0de24 - ::expr_into_dest 57: 0x7f19a3855d7a - ::as_temp::{closure#0} 58: 0x7f19a385432e - ::as_operand 59: 0x7f19a3a88f11 - ::as_call_operand 60: 0x7f19a3a89516 - ::as_call_operand 61: 0x7f19a3f0de24 - ::expr_into_dest 62: 0x7f19a3f0f24d - ::expr_into_dest 63: 0x7f19a0b0a040 - ::ast_block_stmts 64: 0x7f19a3f0e2bd - ::expr_into_dest 65: 0x7f19a3f0f24d - ::expr_into_dest 66: 0x7f19a4020783 - rustc_mir_build[d6b8fa08231a903]::build::mir_build::{closure#0} 67: 0x7f19a3bb7e03 - rustc_mir_build[d6b8fa08231a903]::build::mir_built 68: 0x7f19a3bb7ae9 - rustc_query_impl[68c32b4957ad6a92]::plumbing::__rust_begin_short_backtrace::> 69: 0x7f19a3986fbb - rustc_query_system[ecea68d83bd58356]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[68c32b4957ad6a92]::plumbing::QueryCtxt, false> 70: 0x7f19a3986a0c - rustc_query_impl[68c32b4957ad6a92]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace 71: 0x7f19a3c594de - rustc_mir_build[d6b8fa08231a903]::check_unsafety::check_unsafety 72: 0x7f19a3c592f3 - rustc_query_impl[68c32b4957ad6a92]::plumbing::__rust_begin_short_backtrace::> 73: 0x7f19a3bb71db - rustc_query_system[ecea68d83bd58356]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[68c32b4957ad6a92]::plumbing::QueryCtxt, false> 74: 0x7f19a3bb6ebf - rustc_query_impl[68c32b4957ad6a92]::query_impl::check_unsafety::get_query_non_incr::__rust_end_short_backtrace 75: 0x7f19a44f1f82 - rustc_interface[79f83bc025fc4d7f]::passes::analysis 76: 0x7f19a44f19d9 - rustc_query_impl[68c32b4957ad6a92]::plumbing::__rust_begin_short_backtrace::> 77: 0x7f19a459a7e5 - rustc_query_system[ecea68d83bd58356]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[68c32b4957ad6a92]::plumbing::QueryCtxt, false> 78: 0x7f19a459a549 - rustc_query_impl[68c32b4957ad6a92]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 79: 0x7f19a45a99ef - rustc_interface[79f83bc025fc4d7f]::interface::run_compiler::, rustc_driver_impl[bdf94cba6429e3e9]::run_compiler::{closure#0}>::{closure#0} 80: 0x7f19a47cb805 - std[d016f499f7096d82]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[bdf94cba6429e3e9]::run_compiler::{closure#0}>::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>>::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>> 81: 0x7f19a47cb632 - <::spawn_unchecked_, rustc_driver_impl[bdf94cba6429e3e9]::run_compiler::{closure#0}>::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>>::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[9ad5ca1534623343]::result::Result<(), rustc_span[68562dd5edd39f62]::ErrorGuaranteed>>::{closure#1} as core[9ad5ca1534623343]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 82: 0x7f19a581c3e5 - as core::ops::function::FnOnce>::call_once::ha1018986c04ed39c at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/alloc/src/boxed.rs:2020:9 83: 0x7f19a581c3e5 - as core::ops::function::FnOnce>::call_once::h785b54a9e46f4626 at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/alloc/src/boxed.rs:2020:9 84: 0x7f19a581c3e5 - std::sys::pal::unix::thread::Thread::new::thread_start::h3c9c1af568b2e82b at /rustc/8401645716b26a8b4c6974dc0680e55e81e9e8a1/library/std/src/sys/pal/unix/thread.rs:108:17 85: 0x7f199f4a955a - 86: 0x7f199f526a3c - 87: 0x0 - error: the compiler unexpectedly panicked. this is a bug. 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.78.0-nightly (840164571 2024-03-09) running on x86_64-unknown-linux-gnu query stack during panic: #0 [mir_built] building MIR for `::fmt` #1 [check_unsafety] unsafety-checking `::fmt` #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 10 previous errors Some errors have detailed explanations: E0204, E0277, E0308, E0369, E0601. For more information about an error, try `rustc --explain E0204`. ```

matthiaskrgr commented 4 months ago

120847 cc @oli-obk

original file was compiler/rustc_hir/src/target.rs

compiler-errors commented 4 months ago

Minimal:

#![feature(unsized_fn_params)]

#[derive(Copy, Clone)]
struct Target(str);

fn w(t: &Target) {
    x(*t);
}

fn x(t: Target) {}