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: expected type .. but found Lifetime.. #120792

Closed
matthiaskrgr opened this issue Feb 8, 2024 · 1 comment · Fixed by #128171
Closed

ice: expected type .. but found Lifetime.. #120792

matthiaskrgr opened this issue Feb 8, 2024 · 1 comment · Fixed by #128171
Labels
-Zpolymorphize Unstable option: Polymorphization. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

type WithLifetime<T> = impl Equals<>;
fn _defining_use<T>() -> WithLifetime<T> {}

trait Convert<'a> {
    
    fn convert<'b, T: ?Sized>(, x: &'a T) -> &'b T;
}



fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
    WithLifetime::<&'a ()>::convert_helper::<(), T>(&(), x)
}

trait Equals {
    
    fn convert_helper<'a, 'b, W: , T: ?Sized>(
        ,
        ,
    ) -> &'b T;
}

impl<S> Equals for S {
    
    fn convert_helper<'foo, 'b, W: Convert<'a, >, T: ?Sized>(
        proof: &'b Self,
        x: &'a T,
    ) -> &'b T {
        W::convert(proof, x)
    }
}


original code

original:

#![feature(type_alias_impl_trait)]

type WithLifetime<T> = impl Equals<SelfType = ()>;
fn _defining_use<T>() -> WithLifetime<T> {}

trait Convert<'a> {
    type Witness;
    fn convert<'b, T: ?Sized>(_proof: &'b Self::Witness, x: &'a T) -> &'b T;
}

impl<'a> Convert<'a> for () {
    type Witness = WithLifetime<&'a ()>;

    fn convert<'b, T: ?Sized>(_proof: &'b WithLifetime<&'a ()>, x: &'a T) -> &'b T {
        // compiler used to think it gets to assume 'a: 'b here because
        // of the `&'b WithLifetime<&'a ()>` argument
        x
        //~^ ERROR lifetime may not live long enough
    }
}

fn extend_lifetime<'a, 'b, T: ?Sized>(x: &'a T) -> &'b T {
    WithLifetime::<&'a ()>::convert_helper::<(), T>(&(), x)
}

trait Equals {
    type SelfType;
    fn convert_helper<'a, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
        proof: &'b Self::SelfType,
        x: &'a T,
    ) -> &'b T;
}

impl<S> Equals for S {
    type SelfType = Self;
    fn convert_helper<'foo, 'b, W: Convert<'a, Witness = Self>, T: ?Sized>(
        proof: &'b Self,
        x: &'a T,
    ) -> &'b T {
        W::convert(proof, x)
    }
}

fn main() {
    let r;
    {
        let x = String::from("Hello World?");
        r = extend_lifetime(&x);
    }
    println!("{}", r);
}

Version information

rustc 1.78.0-nightly (af88f7db5 2024-02-08)
binary: rustc
commit-hash: af88f7db51f6f2a1472f9279d7c7e7c822afff77
commit-date: 2024-02-08
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zpolymorphize=on -Zinline-mir=yes

Program output

error: expected argument name, found `,`
 --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:8:31
  |
8 |     fn convert<'b, T: ?Sized>(, x: &'a T) -> &'b T;
  |                               ^ expected argument name

error: expected argument name, found `,`
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:20:9
   |
20 |         ,
   |         ^ expected argument name

error: expected argument name, found `,`
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:21:9
   |
21 |         ,
   |         ^ expected argument name

error[E0261]: use of undeclared lifetime name `'a`
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:27:44
   |
27 |     fn convert_helper<'foo, 'b, W: Convert<'a, >, T: ?Sized>(
   |                                            ^^ 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
   |
27 |     fn convert_helper<'foo, 'b, W: for<'a> Convert<'a, >, T: ?Sized>(
   |                                    +++++++
help: consider introducing lifetime `'a` here
   |
27 |     fn convert_helper<'a, 'foo, 'b, W: Convert<'a, >, T: ?Sized>(
   |                       +++
help: consider introducing lifetime `'a` here
   |
25 | impl<'a, S> Equals for S {
   |      +++

error[E0261]: use of undeclared lifetime name `'a`
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:29:13
   |
29 |         x: &'a T,
   |             ^^ undeclared lifetime
   |
help: consider introducing lifetime `'a` here
   |
27 |     fn convert_helper<'a, 'foo, 'b, W: Convert<'a, >, T: ?Sized>(
   |                       +++
help: consider introducing lifetime `'a` here
   |
25 | impl<'a, S> Equals for S {
   |      +++

error[E0658]: `impl Trait` in type aliases is unstable
 --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:3:24
  |
3 | type WithLifetime<T> = impl Equals<>;
  |                        ^^^^^^^^^^^^^
  |
  = note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
  = help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
  = note: this compiler was built on 2024-02-08; consider upgrading it if it is out of date

warning: anonymous parameters are deprecated and will be removed in the next edition
 --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:8:30
  |
8 |     fn convert<'b, T: ?Sized>(, x: &'a T) -> &'b T;
  |                              ^ help: try naming the parameter or explicitly ignoring it: `_: (`
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
  = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>
  = note: `#[warn(anonymous_parameters)]` on by default

warning: anonymous parameters are deprecated and will be removed in the next edition
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:19:46
   |
19 |     fn convert_helper<'a, 'b, W: , T: ?Sized>(
   |                                              ^ help: try naming the parameter or explicitly ignoring it: `_: (`
   |
   = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
   = note: for more information, see issue #41686 <https://github.com/rust-lang/rust/issues/41686>

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:33:2
   |
33 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs`

error[E0195]: lifetime parameters or bounds on method `convert_helper` do not match the trait declaration
  --> /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:27:22
   |
19 |     fn convert_helper<'a, 'b, W: , T: ?Sized>(
   |                      ------------------------ lifetimes in impl do not match this method in trait
...
27 |     fn convert_helper<'foo, 'b, W: Convert<'a, >, T: ?Sized>(
   |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:915:9: expected type for `W/#1` (W/#1/1) but found Lifetime(ReErased) when substituting, args=[(), ReErased, (), T/#1]

thread 'rustc' panicked at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/compiler/rustc_errors/src/lib.rs:922:30:
Box<dyn Any>
stack backtrace:
   0:     0x7faf1c58bdd6 - std::backtrace_rs::backtrace::libunwind::trace::hf92ca961e56825b0
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7faf1c58bdd6 - std::backtrace_rs::backtrace::trace_unsynchronized::h23f341cc1a6c507f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7faf1c58bdd6 - std::sys_common::backtrace::_print_fmt::ha5a5ba44893edc7f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7faf1c58bdd6 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h667e6ba5a1d3724e
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7faf1c5de830 - core::fmt::rt::Argument::fmt::h06c91f49bef095fb
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/rt.rs:142:9
   5:     0x7faf1c5de830 - core::fmt::write::h8e4b31b0aa81d13f
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/core/src/fmt/mod.rs:1120:17
   6:     0x7faf1c57f64f - std::io::Write::write_fmt::h4c479f5c53dfe78c
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/io/mod.rs:1854:15
   7:     0x7faf1c58bbb4 - std::sys_common::backtrace::_print::he414f5864df55ed1
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7faf1c58bbb4 - std::sys_common::backtrace::print::h939e58bdcc61d57d
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7faf1c58e947 - std::panicking::default_hook::{{closure}}::h244e48e05cd664b2
  10:     0x7faf1c58e6a9 - std::panicking::default_hook::hf842080c39497dac
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:292:9
  11:     0x7faf1f3454ac - std[f801e042bca9681]::panicking::update_hook::<alloc[1377227f5558ef79]::boxed::Box<rustc_driver_impl[65af58b05c4f91ef]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7faf1c58f096 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hee9c09a26ce84f59
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2029:9
  13:     0x7faf1c58f096 - std::panicking::rust_panic_with_hook::h83c20f9191a2a712
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/panicking.rs:785:13
  14:     0x7faf1f376f04 - std[f801e042bca9681]::panicking::begin_panic::<rustc_errors[89ec94d63507ad05]::ExplicitBug>::{closure#0}
  15:     0x7faf1f3735f6 - std[f801e042bca9681]::sys_common::backtrace::__rust_end_short_backtrace::<std[f801e042bca9681]::panicking::begin_panic<rustc_errors[89ec94d63507ad05]::ExplicitBug>::{closure#0}, !>
  16:     0x7faf1f36ea66 - std[f801e042bca9681]::panicking::begin_panic::<rustc_errors[89ec94d63507ad05]::ExplicitBug>
  17:     0x7faf1f382b61 - <rustc_errors[89ec94d63507ad05]::diagnostic_builder::BugAbort as rustc_errors[89ec94d63507ad05]::diagnostic_builder::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7faf1f7369be - <rustc_errors[89ec94d63507ad05]::DiagCtxt>::bug::<alloc[1377227f5558ef79]::string::String>
  19:     0x7faf1f7d23db - rustc_middle[2cc1c6e52ad3d43f]::util::bug::opt_span_bug_fmt::<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}
  20:     0x7faf1f7b990a - rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_opt::<rustc_middle[2cc1c6e52ad3d43f]::util::bug::opt_span_bug_fmt<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7faf1f7b9788 - rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_context_opt::<rustc_middle[2cc1c6e52ad3d43f]::ty::context::tls::with_opt<rustc_middle[2cc1c6e52ad3d43f]::util::bug::opt_span_bug_fmt<rustc_span[467c297c964200f6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7faf1d767db0 - rustc_middle[2cc1c6e52ad3d43f]::util::bug::bug_fmt
  23:     0x7faf1f7c7712 - <rustc_middle[2cc1c6e52ad3d43f]::ty::generic_args::ArgFolder>::type_param_expected
  24:     0x7faf20607464 - <rustc_middle[2cc1c6e52ad3d43f]::ty::generic_args::ArgFolder as rustc_type_ir[7a3f94f8b621150f]::fold::TypeFolder<rustc_middle[2cc1c6e52ad3d43f]::ty::context::TyCtxt>>::fold_ty
  25:     0x7faf2131ef4c - rustc_mir_transform[f04df7d082cb6ded]::inline::cycle::mir_callgraph_reachable::process
  26:     0x7faf2131e2ee - rustc_mir_transform[f04df7d082cb6ded]::inline::cycle::mir_callgraph_reachable
  27:     0x7faf2131e1e9 - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_callgraph_reachable::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>
  28:     0x7faf2131e1ab - <rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_callgraph_reachable::dynamic_query::{closure#2} as core[30be359c16b30868]::ops::function::FnOnce<(rustc_middle[2cc1c6e52ad3d43f]::ty::context::TyCtxt, (rustc_middle[2cc1c6e52ad3d43f]::ty::instance::Instance, rustc_span[467c297c964200f6]::def_id::LocalDefId))>>::call_once
  29:     0x7faf2131db1d - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::DefaultCache<(rustc_middle[2cc1c6e52ad3d43f]::ty::instance::Instance, rustc_span[467c297c964200f6]::def_id::LocalDefId), rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  30:     0x7faf2131d85e - rustc_query_impl[5ca841c3c79670ea]::query_impl::mir_callgraph_reachable::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7faf210b57fb - <rustc_mir_transform[f04df7d082cb6ded]::inline::Inliner>::try_inlining
  32:     0x7faf210b1b86 - <rustc_mir_transform[f04df7d082cb6ded]::inline::Inliner>::process_blocks
  33:     0x7faf20806363 - <rustc_mir_transform[f04df7d082cb6ded]::inline::Inline as rustc_middle[2cc1c6e52ad3d43f]::mir::MirPass>::run_pass
  34:     0x7faf206123e6 - rustc_mir_transform[f04df7d082cb6ded]::pass_manager::run_passes_inner
  35:     0x7faf209afecd - rustc_mir_transform[f04df7d082cb6ded]::optimized_mir
  36:     0x7faf20674735 - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>
  37:     0x7faf20674d21 - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::DefIdCache<rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  38:     0x7faf2067455e - rustc_query_impl[5ca841c3c79670ea]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  39:     0x7faf2084199b - rustc_middle[2cc1c6e52ad3d43f]::query::plumbing::query_get_at::<rustc_query_system[125a8aa150dcabe3]::query::caches::DefIdCache<rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 8usize]>>>
  40:     0x7faf20fd91af - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::unused_generic_params::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 4usize]>>
  41:     0x7faf20fd8973 - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::DefaultCache<rustc_middle[2cc1c6e52ad3d43f]::ty::instance::InstanceDef, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  42:     0x7faf20fd865c - rustc_query_impl[5ca841c3c79670ea]::query_impl::unused_generic_params::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7faf20fd45da - rustc_interface[c2746bee48761670]::passes::analysis
  44:     0x7faf20fd3bdf - rustc_query_impl[5ca841c3c79670ea]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>
  45:     0x7faf212a17b2 - rustc_query_system[125a8aa150dcabe3]::query::plumbing::try_execute_query::<rustc_query_impl[5ca841c3c79670ea]::DynamicConfig<rustc_query_system[125a8aa150dcabe3]::query::caches::SingleCache<rustc_middle[2cc1c6e52ad3d43f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5ca841c3c79670ea]::plumbing::QueryCtxt, false>
  46:     0x7faf212a1515 - rustc_query_impl[5ca841c3c79670ea]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  47:     0x7faf212e2436 - rustc_interface[c2746bee48761670]::interface::run_compiler::<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}
  48:     0x7faf20f60248 - std[f801e042bca9681]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>
  49:     0x7faf20f60077 - <<std[f801e042bca9681]::thread::Builder>::spawn_unchecked_<rustc_interface[c2746bee48761670]::util::run_in_thread_with_globals<rustc_interface[c2746bee48761670]::util::run_in_thread_pool_with_globals<rustc_interface[c2746bee48761670]::interface::run_compiler<core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>, rustc_driver_impl[65af58b05c4f91ef]::run_compiler::{closure#0}>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[30be359c16b30868]::result::Result<(), rustc_span[467c297c964200f6]::ErrorGuaranteed>>::{closure#1} as core[30be359c16b30868]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0x7faf1c598735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h99757397e7c4fa77
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  51:     0x7faf1c598735 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e0e3d311e6447da
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/alloc/src/boxed.rs:2015:9
  52:     0x7faf1c598735 - std::sys::pal::unix::thread::Thread::new::thread_start::h0eb0f22e3002fa19
                               at /rustc/af88f7db51f6f2a1472f9279d7c7e7c822afff77/library/std/src/sys/pal/unix/thread.rs:108:17
  53:     0x7faf1c3839eb - <unknown>
  54:     0x7faf1c4077cc - <unknown>
  55:                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: rustc 1.78.0-nightly (af88f7db5 2024-02-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z polymorphize=on -Z inline-mir=yes -Z dump-mir-dir=dir

query stack during panic:
#0 [mir_callgraph_reachable] computing if `<impl at /tmp/icemaker_global_tempdir.smWWDFyFinWB/rustc_testrunner_tmpdir_reporting.PwzVr2WO2dCz/mvce.rs:25:1: 25:21>::convert_helper::<'_, ()>` (transitively) calls `extend_lifetime`
#1 [optimized_mir] optimizing MIR for `extend_lifetime`
#2 [unused_generic_params] determining which generic parameters are unused by `extend_lifetime`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 9 previous errors; 2 warnings emitted

Some errors have detailed explanations: E0195, E0261, E0601, E0658.
For more information about an error, try `rustc --explain E0195`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Feb 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 8, 2024
@oli-obk oli-obk added requires-nightly This issue requires a nightly compiler in some way. -Zpolymorphize Unstable option: Polymorphization. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 8, 2024
@matthiaskrgr
Copy link
Member Author

auto-reduced (treereduce-rust):

impl Trait<()> for () {
    fn foo<'a, K>(self, _: (), _: K) {
        todo!();
    }
}

trait Foo<T> {}

impl<F, T> Foo<T> for F {
    fn main() {
        ().foo((), ());
    }
}

trait Trait<T> {
    fn foo<'a, K>(self, _: T, _: K)
    where
        T: 'a,
        K: 'a;
}

original:

trait Bar<T> {
    fn foo<'a, K>(self, _: T, _: K) where K: 'a, K: 'main;
}

impl Trait<()> for () {
    fn foo<'a, K>(self, _: (), _: K) where { //~ ERROR E0195
        todo!();
    }
}

struct State;

trait Foo<T> {
    fn foo<'a>(&self, state: &'a State) -> &'a T
    where
        T: 'a;
}

impl<F, T> Foo<T> for F
where
    F: Fn(&State) -> &T,
{
    fn main() {
    ().foo((), ());
}
}

trait Trait<T> {
    fn foo<'a, K>(self, _: T, _: K) where T: 'a, K: 'a;
}

impl Bar for () {
    fn foo<'a: 'a>(&'a self) {} //~ ERROR E0195
}

fn main() {
    self(state);
}

Version information

rustc 1.79.0-nightly (8b2459c1f 2024-04-09)
binary: rustc
commit-hash: 8b2459c1f21187f9792d99310171a15e64feb9cf
commit-date: 2024-04-09
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.3

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zpolymorphize=on -Zinline-mir=yes

Program output

error[E0407]: method `main` is not a member of trait `Foo`
  --> /tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs:10:5
   |
10 | /     fn main() {
11 | |         ().foo((), ());
12 | |     }
   | |_____^ not a member of trait `Foo`

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs:20:2
   |
20 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs`

error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
  --> /tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs:2:11
   |
2  |     fn foo<'a, K>(self, _: (), _: K) {
   |           ^^^^^^^ lifetimes do not match method in trait
...
16 |     fn foo<'a, K>(self, _: T, _: K)
   |           ------- lifetimes in impl do not match this method in trait
17 |     where
18 |         T: 'a,
   |            -- this bound might be missing in the impl
19 |         K: 'a;
   |            -- this bound might be missing in the impl

error: internal compiler error: compiler/rustc_middle/src/ty/generic_args.rs:904:9: expected type for `K/#0` (K/#0/0) but found Lifetime('{erased}) when instantiating, args=['{erased}, ()]

thread 'rustc' panicked at compiler/rustc_middle/src/ty/generic_args.rs:904:9:
Box<dyn Any>
stack backtrace:
   0:     0x77b08cce7885 - std::backtrace_rs::backtrace::libunwind::trace::hdbe9796987ceb0c3
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x77b08cce7885 - std::backtrace_rs::backtrace::trace_unsynchronized::h2e6c5a328606b599
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x77b08cce7885 - std::sys_common::backtrace::_print_fmt::hcd61867f45f7a64e
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x77b08cce7885 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he7a3bc3921692656
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x77b08cd36abb - core::fmt::rt::Argument::fmt::h95836dbf862f7d1b
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/core/src/fmt/rt.rs:142:9
   5:     0x77b08cd36abb - core::fmt::write::hffa81a05ea2c737d
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/core/src/fmt/mod.rs:1153:17
   6:     0x77b08ccdc3ff - std::io::Write::write_fmt::ha28139dc2458ce78
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/io/mod.rs:1843:15
   7:     0x77b08cce765e - std::sys_common::backtrace::_print::hadc6ec3a0cb53db2
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x77b08cce765e - std::sys_common::backtrace::print::h9cc206a8a46a519b
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x77b08ccea159 - std::panicking::default_hook::{{closure}}::h72365f66652b6097
  10:     0x77b08cce9e75 - std::panicking::default_hook::h296340dc5ed32378
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/panicking.rs:291:9
  11:     0x77b08966367e - std[2474eec217f17911]::panicking::update_hook::<alloc[f48ecbf8778ab0f6]::boxed::Box<rustc_driver_impl[1fb95cb326290392]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x77b08ccea85c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h4df439e5fb4fe29f
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/alloc/src/boxed.rs:2032:9
  13:     0x77b08ccea85c - std::panicking::rust_panic_with_hook::hb888ecdc252dbf69
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/panicking.rs:792:13
  14:     0x77b089693544 - std[2474eec217f17911]::panicking::begin_panic::<rustc_errors[891d7395ead1ce18]::ExplicitBug>::{closure#0}
  15:     0x77b089690466 - std[2474eec217f17911]::sys_common::backtrace::__rust_end_short_backtrace::<std[2474eec217f17911]::panicking::begin_panic<rustc_errors[891d7395ead1ce18]::ExplicitBug>::{closure#0}, !>
  16:     0x77b089690146 - std[2474eec217f17911]::panicking::begin_panic::<rustc_errors[891d7395ead1ce18]::ExplicitBug>
  17:     0x77b08969d441 - <rustc_errors[891d7395ead1ce18]::diagnostic::BugAbort as rustc_errors[891d7395ead1ce18]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x77b089b3ff8c - rustc_middle[c40ba118dc41381f]::util::bug::opt_span_bug_fmt::<rustc_span[7fcb37ac6fbeabc]::span_encoding::Span>::{closure#0}
  19:     0x77b089b273ca - rustc_middle[c40ba118dc41381f]::ty::context::tls::with_opt::<rustc_middle[c40ba118dc41381f]::util::bug::opt_span_bug_fmt<rustc_span[7fcb37ac6fbeabc]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x77b089b2724b - rustc_middle[c40ba118dc41381f]::ty::context::tls::with_context_opt::<rustc_middle[c40ba118dc41381f]::ty::context::tls::with_opt<rustc_middle[c40ba118dc41381f]::util::bug::opt_span_bug_fmt<rustc_span[7fcb37ac6fbeabc]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x77b087753960 - rustc_middle[c40ba118dc41381f]::util::bug::bug_fmt
  22:     0x77b089b31b72 - <rustc_middle[c40ba118dc41381f]::ty::generic_args::ArgFolder>::type_param_expected
  23:     0x77b08aa0af59 - <rustc_middle[c40ba118dc41381f]::ty::generic_args::ArgFolder as rustc_type_ir[359712355f3f4dcc]::fold::TypeFolder<rustc_middle[c40ba118dc41381f]::ty::context::TyCtxt>>::fold_ty
  24:     0x77b08b029c51 - <rustc_mir_transform[86f15631b6fc49c9]::inline::Inliner>::try_inlining
  25:     0x77b08b0475d0 - <rustc_mir_transform[86f15631b6fc49c9]::inline::Inliner>::process_blocks
  26:     0x77b08b0214b9 - <rustc_mir_transform[86f15631b6fc49c9]::inline::Inline as rustc_middle[c40ba118dc41381f]::mir::MirPass>::run_pass
  27:     0x77b08aa0190d - rustc_mir_transform[86f15631b6fc49c9]::pass_manager::run_passes_inner
  28:     0x77b08b0316b1 - rustc_mir_transform[86f15631b6fc49c9]::optimized_mir
  29:     0x77b08b03089b - rustc_query_impl[441f0dd3998ce1f3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[441f0dd3998ce1f3]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 8usize]>>
  30:     0x77b08abb8021 - rustc_query_system[34c3e53911c1ab13]::query::plumbing::try_execute_query::<rustc_query_impl[441f0dd3998ce1f3]::DynamicConfig<rustc_query_system[34c3e53911c1ab13]::query::caches::DefIdCache<rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[441f0dd3998ce1f3]::plumbing::QueryCtxt, false>
  31:     0x77b08abb7762 - rustc_query_impl[441f0dd3998ce1f3]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  32:     0x77b08ad4bcb6 - rustc_middle[c40ba118dc41381f]::query::plumbing::query_get_at::<rustc_query_system[34c3e53911c1ab13]::query::caches::DefIdCache<rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 8usize]>>>
  33:     0x77b08b305887 - rustc_query_impl[441f0dd3998ce1f3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[441f0dd3998ce1f3]::query_impl::unused_generic_params::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 4usize]>>
  34:     0x77b08b305059 - rustc_query_system[34c3e53911c1ab13]::query::plumbing::try_execute_query::<rustc_query_impl[441f0dd3998ce1f3]::DynamicConfig<rustc_query_system[34c3e53911c1ab13]::query::caches::DefaultCache<rustc_middle[c40ba118dc41381f]::ty::instance::InstanceDef, rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[441f0dd3998ce1f3]::plumbing::QueryCtxt, false>
  35:     0x77b08b304d4e - rustc_query_impl[441f0dd3998ce1f3]::query_impl::unused_generic_params::get_query_non_incr::__rust_end_short_backtrace
  36:     0x77b08b300880 - rustc_interface[bf8f900257cf37fb]::passes::analysis
  37:     0x77b08b2ff595 - rustc_query_impl[441f0dd3998ce1f3]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[441f0dd3998ce1f3]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 1usize]>>
  38:     0x77b08b858e65 - rustc_query_system[34c3e53911c1ab13]::query::plumbing::try_execute_query::<rustc_query_impl[441f0dd3998ce1f3]::DynamicConfig<rustc_query_system[34c3e53911c1ab13]::query::caches::SingleCache<rustc_middle[c40ba118dc41381f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[441f0dd3998ce1f3]::plumbing::QueryCtxt, false>
  39:     0x77b08b858bc9 - rustc_query_impl[441f0dd3998ce1f3]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  40:     0x77b08b6ee814 - rustc_interface[bf8f900257cf37fb]::interface::run_compiler::<core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>, rustc_driver_impl[1fb95cb326290392]::run_compiler::{closure#0}>::{closure#0}
  41:     0x77b08b7c0e1d - std[2474eec217f17911]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bf8f900257cf37fb]::util::run_in_thread_with_globals<rustc_interface[bf8f900257cf37fb]::util::run_in_thread_pool_with_globals<rustc_interface[bf8f900257cf37fb]::interface::run_compiler<core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>, rustc_driver_impl[1fb95cb326290392]::run_compiler::{closure#0}>::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>
  42:     0x77b08b7c0c2a - <<std[2474eec217f17911]::thread::Builder>::spawn_unchecked_<rustc_interface[bf8f900257cf37fb]::util::run_in_thread_with_globals<rustc_interface[bf8f900257cf37fb]::util::run_in_thread_pool_with_globals<rustc_interface[bf8f900257cf37fb]::interface::run_compiler<core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>, rustc_driver_impl[1fb95cb326290392]::run_compiler::{closure#0}>::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[21d3ad91760ee510]::result::Result<(), rustc_span[7fcb37ac6fbeabc]::ErrorGuaranteed>>::{closure#1} as core[21d3ad91760ee510]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  43:     0x77b08ccf428b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd1b00ae2ddfcdaf0
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/alloc/src/boxed.rs:2018:9
  44:     0x77b08ccf428b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9b7565e262650825
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/alloc/src/boxed.rs:2018:9
  45:     0x77b08ccf428b - std::sys::pal::unix::thread::Thread::new::thread_start::h7f0b25bf4ebb2e1b
                               at /rustc/8b2459c1f21187f9792d99310171a15e64feb9cf/library/std/src/sys/pal/unix/thread.rs:108:17
  46:     0x77b0864a955a - <unknown>
  47:     0x77b086526a3c - <unknown>
  48:                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: rustc 1.79.0-nightly (8b2459c1f 2024-04-09) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z polymorphize=on -Z inline-mir=yes -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at /tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs:9:1: 9:24>::main`
#1 [unused_generic_params] determining which generic parameters are unused by `<impl at /tmp/icemaker_global_tempdir.3Q51z5KKvcCT/rustc_testrunner_tmpdir_reporting.fhYfT0a7niEy/mvce.rs:9:1: 9:24>::main`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0195, E0407, E0601.
For more information about an error, try `rustc --explain E0195`.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 18, 2024
@bors bors closed this as completed in 5a853d0 Jul 25, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 25, 2024
Rollup merge of rust-lang#128171 - compiler-errors:arg-compat, r=oli-obk

Make sure that args are compatible in `resolve_associated_item`

Implements a similar check to the one that we have in projection for GATs (rust-lang#102488, rust-lang#123240), where we check that the args of an impl item are compatible before returning it. This is done in `resolve_assoc_item`, which is backing `Instance::resolve`, so this is conceptually generalizing the check from GATs to methods/assoc consts. This is important to make sure that the inliner will only visit and substitute MIR bodies that are compatible w/ their trait definitions.

This shouldn't happen in codegen, but there are a few ways to get the inliner to be invoked (via calls to `optimized_mir`) before codegen, namely polymorphization and CTFE.

Fixes rust-lang#121957
Fixes rust-lang#120792
Fixes rust-lang#120793
Fixes rust-lang#121063
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zpolymorphize Unstable option: Polymorphization. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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
Development

Successfully merging a pull request may close this issue.

3 participants