rust-lang / rust

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

ice: effects: `parent also has host effect param?` #113378

Closed matthiaskrgr closed 10 months ago

matthiaskrgr commented 1 year ago

Code

#![feature(const_trait_impl)]
#![feature(effects)]

trait Value {}

impl<T> const Value for T {
    const fn value() -> u32 {
        0
    }
}

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (e4cd16100 2023-07-05)
binary: rustc
commit-hash: e4cd1610067501fa4d347eba7b18f77137dbbf48
commit-date: 2023-07-05
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.5

Error output

error[E0379]: functions in traits cannot be declared const
 --> treereduce.out:7:5
  |
7 |     const  fn value() -> u32 {
  |     ^^^^^ functions in traits cannot be const

error[E0407]: method `value` is not a member of trait `Value`
 --> treereduce.out:7:5
  |
7 | /     const  fn value() -> u32 {
8 | |         0
9 | |     }
  | |_____^ not a member of trait `Value`

error[E0601]: `main` function not found in crate `treereduce`
  --> treereduce.out:10:2
   |
10 | }
   |  ^ consider adding a `main` function to `treereduce.out`

error: const `impl` for trait `Value` which is not marked with `#[const_trait]`
 --> treereduce.out:6:15
  |
4 | trait Value {}
  | - help: mark `Value` as const: `#[const_trait]`
5 |
6 | impl<T> const Value for T {
  |               ^^^^^
  |
  = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const`
  = note: adding a non-const method body in the future would be a breaking change
Backtrace

``` error: internal compiler error: compiler/rustc_hir_analysis/src/collect/generics_of.rs:319:21: parent also has host effect param? index: 1, def: DefId(0:6 ~ treereduce[e3bb]::{impl#0}::value) thread 'rustc' panicked at 'Box', /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/compiler/rustc_errors/src/lib.rs:1651:9 stack backtrace: 0: 0x7f3658763a81 - std::backtrace_rs::backtrace::libunwind::trace::hd0180fafc3f67189 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f3658763a81 - std::backtrace_rs::backtrace::trace_unsynchronized::h5f5f542cfcd3ea93 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f3658763a81 - std::sys_common::backtrace::_print_fmt::h58fe9485d729332b at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f3658763a81 - ::fmt::h892fa574703406ce at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f36587c9d8f - core::fmt::rt::Argument::fmt::h9323d9ac1296ca86 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/core/src/fmt/rt.rs:138:9 5: 0x7f36587c9d8f - core::fmt::write::h7b3311fc7bec7011 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/core/src/fmt/mod.rs:1094:21 6: 0x7f36587564c7 - std::io::Write::write_fmt::hf0bd33b3cf0f8fc8 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/io/mod.rs:1714:15 7: 0x7f3658763895 - std::sys_common::backtrace::_print::h05e7ce29169ad453 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f3658763895 - std::sys_common::backtrace::print::h259bd490e3a5f495 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f3658766673 - std::panicking::default_hook::{{closure}}::h60419100c25d1f9e at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/panicking.rs:269:22 10: 0x7f3658766404 - std::panicking::default_hook::h5458ac0b23f9b258 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/panicking.rs:288:9 11: 0x7f365ba3634b - rustc_driver_impl[e2bfb106dcd1f64f]::install_ice_hook::{closure#0} 12: 0x7f3658766e9e - as core::ops::function::Fn>::call::h4fc06bcacf328e1a at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/alloc/src/boxed.rs:2024:9 13: 0x7f3658766e9e - std::panicking::rust_panic_with_hook::hc4b8011c5070ed88 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/panicking.rs:709:13 14: 0x7f365bff5291 - std[c4949d010b2b12f5]::panicking::begin_panic::::{closure#0} 15: 0x7f365bff36e6 - std[c4949d010b2b12f5]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f365bff35a6 - std[c4949d010b2b12f5]::panicking::begin_panic:: 17: 0x7f365bf558b4 - ::bug:: 18: 0x7f365bf55736 - ::bug:: 19: 0x7f365bf652fc - rustc_middle[36f410a133de2eee]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f365bf64a0a - rustc_middle[36f410a133de2eee]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f365bf649da - rustc_middle[36f410a133de2eee]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f365a16610d - rustc_middle[36f410a133de2eee]::util::bug::bug_fmt 23: 0x7f365a3742a6 - rustc_hir_analysis[efec7ea34622ed25]::collect::generics_of::generics_of 24: 0x7f365a370c58 - rustc_query_impl[b274d6131f7b1f90]::plumbing::__rust_begin_short_backtrace::> 25: 0x7f365a370bf0 - >::call_once 26: 0x7f3659a6ad65 - rustc_query_system[d3399df1ed0f61e2]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[b274d6131f7b1f90]::plumbing::QueryCtxt, false> 27: 0x7f365b3b6ed3 - rustc_query_impl[b274d6131f7b1f90]::query_impl::generics_of::get_query_non_incr::__rust_end_short_backtrace 28: 0x7f365a0d5e5b - ::visit_impl_item 29: 0x7f365a0d4e0e - ::visit_item_likes_in_module:: 30: 0x7f365a0d4c8c - rustc_hir_analysis[efec7ea34622ed25]::collect::collect_mod_item_types 31: 0x7f365a69fb4c - rustc_query_impl[b274d6131f7b1f90]::plumbing::__rust_begin_short_backtrace::> 32: 0x7f365a69fb2e - >::call_once 33: 0x7f365a18a7df - rustc_query_system[d3399df1ed0f61e2]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[b274d6131f7b1f90]::plumbing::QueryCtxt, false> 34: 0x7f365b37f974 - rustc_query_impl[b274d6131f7b1f90]::query_impl::collect_mod_item_types::get_query_non_incr::__rust_end_short_backtrace 35: 0x7f365ae79147 - ::for_each_module:: 36: 0x7f365ae78d82 - ::track_errors:: 37: 0x7f365ae77561 - rustc_hir_analysis[efec7ea34622ed25]::check_crate 38: 0x7f365ae6e64a - rustc_interface[b03e5b36acd0a493]::passes::analysis 39: 0x7f365aef958a - rustc_query_impl[b274d6131f7b1f90]::plumbing::__rust_begin_short_backtrace::> 40: 0x7f365aef9579 - >::call_once 41: 0x7f365b092e88 - rustc_query_system[d3399df1ed0f61e2]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[b274d6131f7b1f90]::plumbing::QueryCtxt, false> 42: 0x7f365b092c59 - rustc_query_impl[b274d6131f7b1f90]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 43: 0x7f365ac62545 - ::enter::> 44: 0x7f365ac61b72 - ::enter::, rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>> 45: 0x7f365ac58885 - rustc_span[ffa356b4eef30eb1]::set_source_map::, rustc_interface[b03e5b36acd0a493]::interface::run_compiler, rustc_driver_impl[e2bfb106dcd1f64f]::run_compiler::{closure#1}>::{closure#0}::{closure#0}> 46: 0x7f365ac582f6 - >::set::, rustc_driver_impl[e2bfb106dcd1f64f]::run_compiler::{closure#1}>::{closure#0}, core[1877eeee917502d9]::result::Result<(), rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>> 47: 0x7f365ac578bc - std[c4949d010b2b12f5]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[e2bfb106dcd1f64f]::run_compiler::{closure#1}>::{closure#0}, core[1877eeee917502d9]::result::Result<(), rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1877eeee917502d9]::result::Result<(), rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>> 48: 0x7f365ac57685 - <::spawn_unchecked_, rustc_driver_impl[e2bfb106dcd1f64f]::run_compiler::{closure#1}>::{closure#0}, core[1877eeee917502d9]::result::Result<(), rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[1877eeee917502d9]::result::Result<(), rustc_span[ffa356b4eef30eb1]::ErrorGuaranteed>>::{closure#1} as core[1877eeee917502d9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 49: 0x7f3658771315 - as core::ops::function::FnOnce>::call_once::ha34cb32f4acd27b7 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/alloc/src/boxed.rs:2010:9 50: 0x7f3658771315 - as core::ops::function::FnOnce>::call_once::h309fb4796a356ecf at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/alloc/src/boxed.rs:2010:9 51: 0x7f3658771315 - std::sys::unix::thread::Thread::new::thread_start::h947cced02a86e329 at /rustc/e4cd1610067501fa4d347eba7b18f77137dbbf48/library/std/src/sys/unix/thread.rs:108:17 52: 0x7f365850444b - 53: 0x7f3658587e40 - 54: 0x0 - 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.72.0-nightly (e4cd16100 2023-07-05) running on x86_64-unknown-linux-gnu query stack during panic: #0 [generics_of] computing generics of `::value` #1 [collect_mod_item_types] collecting item types in top-level module #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 5 previous errors Some errors have detailed explanations: E0379, E0407, E0601. For more information about an error, try `rustc --explain E0379`. ```

YakoYakoYokuYoku commented 1 year ago

Also hit this with...

#![feature(const_trait_impl, effects, rustc_attrs)]

#[const_trait]
pub trait Stone {
    type Recorded: Copy;

    fn get_record<#[rustc_host] const host: bool = true>(&self) -> Self::Recorded;
}

pub struct Wall<T: Stone>(T::Recorded);

pub struct Brick;

impl const Stone for Brick {
    type Recorded = i32;

    fn get_record(&self) -> i32 {
        0
    }
}

impl<T: ~const Stone> Wall<T> {
    const fn new(value: T) -> Self {
        Self(value.get_record())
    }
}

fn main() {
    let _ = Wall::new(Brick);
}

Error output...

   Compiling playground v0.0.1 (/playground)
warning: the feature `rustc_attrs` is internal to the compiler or standard library
 --> src/main.rs:1:39
  |
1 | #![feature(const_trait_impl, effects, rustc_attrs)]
  |                                       ^^^^^^^^^^^
  |
  = note: using it is strongly discouraged
  = note: `#[warn(internal_features)]` on by default

error: internal compiler error: compiler/rustc_hir_analysis/src/collect/generics_of.rs:320:21: parent also has host effect param? index: 1, def: DefId(0:5 ~ playground[bb69]::Stone::get_record)

thread 'rustc' panicked at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/compiler/rustc_errors/src/lib.rs:1659:9:
Box<dyn Any>
stack backtrace:
   ... see backtrace ...

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 attach the file at `/playground/rustc-ice-2023-10-21T16_54_00-17.txt` to your bug report

note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [generics_of] computing generics of `Stone::get_record`
#1 [collect_mod_item_types] collecting item types in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
warning: `playground` (bin "playground") generated 1 warning
error: could not compile `playground` (bin "playground"); 1 warning emitted
Backtrace

``` 0: 0x7f1ea4a3b17c - std::backtrace_rs::backtrace::libunwind::trace::he8dc9e634c3d5b69 at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f1ea4a3b17c - std::backtrace_rs::backtrace::trace_unsynchronized::hcc1fc094cc2c1843 at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f1ea4a3b17c - std::sys_common::backtrace::_print_fmt::he6c8e9059e21630d at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/sys_common/backtrace.rs:67:5 3: 0x7f1ea4a3b17c - ::fmt::h145361bce15f4a6a at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f1ea4a9d400 - core::fmt::rt::Argument::fmt::hb890552c7d6e8c2b at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/core/src/fmt/rt.rs:142:9 5: 0x7f1ea4a9d400 - core::fmt::write::h97d71643815ece8a at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/core/src/fmt/mod.rs:1117:17 6: 0x7f1ea4a2f09f - std::io::Write::write_fmt::h9145d12d2fb312aa at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/io/mod.rs:1762:15 7: 0x7f1ea4a3af64 - std::sys_common::backtrace::_print::h34d8c7ca46068513 at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/sys_common/backtrace.rs:47:5 8: 0x7f1ea4a3af64 - std::sys_common::backtrace::print::h69de4357a88b4f9d at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/sys_common/backtrace.rs:34:9 9: 0x7f1ea4a3dbf7 - std::panicking::default_hook::{{closure}}::hbf7d8b588847f0d6 10: 0x7f1ea4a3d95f - std::panicking::default_hook::h797e21049b5f2e1d at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/panicking.rs:292:9 11: 0x7f1ea75777a0 - std[df43e54be7296dae]::panicking::update_hook::>::{closure#0} 12: 0x7f1ea4a3e338 - as core::ops::function::Fn>::call::h49df07f7cb25728d at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/alloc/src/boxed.rs:2021:9 13: 0x7f1ea4a3e338 - std::panicking::rust_panic_with_hook::h4b1939882c095f9c at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/panicking.rs:735:13 14: 0x7f1ea7933c54 - std[df43e54be7296dae]::panicking::begin_panic::::{closure#0} 15: 0x7f1ea792b676 - std[df43e54be7296dae]::sys_common::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7f1ea7926236 - std[df43e54be7296dae]::panicking::begin_panic:: 17: 0x7f1ea790ec34 - ::bug:: 18: 0x7f1ea790e9f4 - ::bug:: 19: 0x7f1ea79ad2dd - rustc_middle[f16a63e6dbe53fea]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7f1ea79941ea - rustc_middle[f16a63e6dbe53fea]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7f1ea79940a8 - rustc_middle[f16a63e6dbe53fea]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7f1ea5aaf410 - rustc_middle[f16a63e6dbe53fea]::util::bug::bug_fmt 23: 0x7f1ea6bda0a2 - rustc_hir_analysis[8c6a7b4af31adcee]::collect::generics_of::generics_of 24: 0x7f1ea89209ec - rustc_query_impl[ad97e9652dfc28d8]::plumbing::__rust_begin_short_backtrace::> 25: 0x7f1ea8736685 - rustc_query_system[74c97372728b1147]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ad97e9652dfc28d8]::plumbing::QueryCtxt, false> 26: 0x7f1ea86d241b - rustc_query_impl[ad97e9652dfc28d8]::query_impl::generics_of::get_query_non_incr::__rust_end_short_backtrace 27: 0x7f1ea89d8686 - ::visit_trait_item 28: 0x7f1ea8b16cad - rustc_hir_analysis[8c6a7b4af31adcee]::collect::collect_mod_item_types 29: 0x7f1ea8b16b7d - rustc_query_impl[ad97e9652dfc28d8]::plumbing::__rust_begin_short_backtrace::> 30: 0x7f1ea8c209b4 - rustc_query_system[74c97372728b1147]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ad97e9652dfc28d8]::plumbing::QueryCtxt, false> 31: 0x7f1ea8c20483 - rustc_query_impl[ad97e9652dfc28d8]::query_impl::collect_mod_item_types::get_query_non_incr::__rust_end_short_backtrace 32: 0x7f1ea89ac3eb - rustc_hir_analysis[8c6a7b4af31adcee]::check_crate 33: 0x7f1ea8cf8c5f - rustc_interface[af334b81148fb8cb]::passes::analysis 34: 0x7f1ea8cf8661 - rustc_query_impl[ad97e9652dfc28d8]::plumbing::__rust_begin_short_backtrace::> 35: 0x7f1ea91dade6 - rustc_query_system[74c97372728b1147]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[ad97e9652dfc28d8]::plumbing::QueryCtxt, false> 36: 0x7f1ea91dac15 - rustc_query_impl[ad97e9652dfc28d8]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace 37: 0x7f1ea93f9caa - std[df43e54be7296dae]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[2bf85641168174bb]::run_compiler::{closure#1}>::{closure#0}, core[af478687de187ad3]::result::Result<(), rustc_span[bab404b0fd46984d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[af478687de187ad3]::result::Result<(), rustc_span[bab404b0fd46984d]::ErrorGuaranteed>> 38: 0x7f1ea93f8fb3 - <::spawn_unchecked_, rustc_driver_impl[2bf85641168174bb]::run_compiler::{closure#1}>::{closure#0}, core[af478687de187ad3]::result::Result<(), rustc_span[bab404b0fd46984d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[af478687de187ad3]::result::Result<(), rustc_span[bab404b0fd46984d]::ErrorGuaranteed>>::{closure#1} as core[af478687de187ad3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 39: 0x7f1ea4a49105 - as core::ops::function::FnOnce>::call_once::hac2e24a72c9237b1 at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/alloc/src/boxed.rs:2007:9 40: 0x7f1ea4a49105 - as core::ops::function::FnOnce>::call_once::h0a4ea247e7a2feab at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/alloc/src/boxed.rs:2007:9 41: 0x7f1ea4a49105 - std::sys::unix::thread::Thread::new::thread_start::ha157bf15852ae2a4 at /rustc/249624b5043013d18c00f0401ca431c1a6baa8cd/library/std/src/sys/unix/thread.rs:108:17 42: 0x7f1ea4939609 - start_thread 43: 0x7f1ea485c133 - clone 44: 0x0 - ```