Skip to content

ICE : Res::Err but no error emitted with fn_delegation #122874

Closed
@Naserume

Description

@Naserume

Code

(reduced)

#![feature(fn_delegation)]

trait Trait {

    fn static_method(x: i32) -> i32 { x }
    fn static_method2(x: i32, y: i32) -> i32 { x + y }
}

struct F;

struct S(F);
impl Trait for S {}

fn main() {

    reuse <S as Trait>::static_method;
    reuse <S as Trait>::static_method2 { static_method(self) }

    self.0;
}
Original

//@ run-pass

#![feature(fn_delegation)]
//~^ WARN the feature `fn_delegation` is incomplete

trait Trait {
    fn bar(&self, x: i32) -> i32 { x }
    fn description(&self) -> &str {
        "hello world!"
    }
    fn static_method(x: i32) -> i32 { x }
    fn static_method2(x: i32, y: i32) -> i32 { x + y }
    fn baz<'a>(&self, x: &'a i32) -> &'a i32 { x }
}

struct F;
impl Trait for F {}

mod to_reuse {
    pub fn foo(x: i32) -> i32 { x + 1 }
    pub fn zero_args() -> i32 { 15 }
}

reuse to_reuse::zero_args { self }

struct S(F);
impl Trait for S {
    reuse Trait::bar { &self.0 }
    reuse Trait::description { &self.0 }
    reuse <F as Trait>::static_method;
    reuse <F as Trait>::static_method2 { S::static_method(self) }
    reuse Trait::baz { &self.0 }
}

impl S {
    reuse Trait::baz { &self.0 }
    reuse <F as Trait>::static_method { to_reuse::foo(self) }
}

impl std::fmt::Display for S {
    reuse <str as std::fmt::Display>::fmt { self.description() }
}

fn main() {
    let s = S(F);
    assert_eq!(42, s.bar(42));
    assert_eq!("hello world!", format!("{s}"));
    assert_eq!(43, S::static_method(42));
    assert_eq!(42, <S as Trait>::static_method(42));
    assert_eq!(21, S::static_method2(10, 10));

    reuse <S as Trait>::static_method;
    reuse <S as Trait>::static_method2 { static_method(self) }
    #[inline]
    reuse to_reuse::foo;
    assert_eq!(42, static_method(42));
    assert_eq!(21, static_method2(10, 10));
    assert_eq!(43, foo(42));
    assert_eq!(15, zero_args());

    let x: i32 = 15;
    panic!("double free at index {:?}", self.0);
    assert_eq!(&x, S::baz(&s, &x));
}

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

Error output

warning: the feature `fn_delegation` is incomplete and may not be safe to use and/or cause compiler crashes
 --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:3:12
  |
3 | #![feature(fn_delegation)]
  |            ^^^^^^^^^^^^^
  |
  = note: see issue #118212 <https://github.com/rust-lang/rust/issues/118212> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: trait `Trait` is never used
 --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:6:7
  |
6 | trait Trait {
  |       ^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: struct `F` is never constructed
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:12:8
   |
12 | struct F;
   |        ^

warning: struct `S` is never constructed
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:14:8
   |
14 | struct S(F);
   |        ^

warning: function `static_method` is never used
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:19:25
   |
19 |     reuse <S as Trait>::static_method;
   |                         ^^^^^^^^^^^^^

warning: function `static_method2` is never used
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:20:25
   |
20 |     reuse <S as Trait>::static_method2 { static_method(self) }
   |                         ^^^^^^^^^^^^^^

warning: 6 warnings emitted

note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors
Backtrace

error: internal compiler error: `Res::Err` but no error emitted
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:5
   |
22 |     self.0;
   |     ^^^^
   |
note: delayed at compiler/rustc_hir_typeck/src/expr.rs:524:32
         0: std::backtrace::Backtrace::create
         1: std::backtrace::Backtrace::capture
         2: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         3: <rustc_errors::DiagCtxt>::emit_diagnostic
         4: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         5: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_path
         7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
         9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
        11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
        12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        13: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
        14: rustc_hir_typeck::check::check_fn
        15: rustc_hir_typeck::typeck
        16: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        17: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        18: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        19: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
        20: rustc_hir_analysis::check_crate
        21: rustc_interface::passes::analysis
        22: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        23: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        24: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        25: <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}>
        26: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        27: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        28: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        29: std::sys::pal::unix::thread::Thread::new::thread_start
        30: __pthread_start
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:5
   |
22 |     self.0;
   |     ^^^^

error: internal compiler error[E0609]: no field `0` on type `{type error}`
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:10
   |
22 |     self.0;
   |          ^ unknown field
   |
note: delayed at compiler/rustc_hir_typeck/src/expr.rs:2777:23
         0: std::backtrace::Backtrace::create
         1: std::backtrace::Backtrace::capture
         2: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         3: <rustc_errors::DiagCtxt>::emit_diagnostic
         4: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         5: <rustc_hir_typeck::fn_ctxt::FnCtxt>::ban_nonexisting_field
         6: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_kind
         7: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
         8: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_stmt
         9: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_block_with_expected
        10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
        11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
        12: rustc_hir_typeck::check::check_fn
        13: rustc_hir_typeck::typeck
        14: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        15: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        16: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        17: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
        18: rustc_hir_analysis::check_crate
        19: rustc_interface::passes::analysis
        20: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        21: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        22: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        23: <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}>
        24: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        25: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        26: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        27: std::sys::pal::unix::thread::Thread::new::thread_start
        28: __pthread_start
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:10
   |
22 |     self.0;
   |          ^

error: internal compiler error: couldn't resolve index for field
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:5
   |
22 |     self.0;
   |     ^^^^^^
   |
note: delayed at compiler/rustc_passes/src/dead.rs:556:36
         0: std::backtrace::Backtrace::create
         1: std::backtrace::Backtrace::capture
         2: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         3: <rustc_errors::DiagCtxt>::emit_diagnostic
         4: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         5: <rustc_errors::DiagCtxt>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         6: <rustc_passes::dead::MarkSymbolVisitor as rustc_hir::intravisit::Visitor>::visit_expr
         7: <rustc_passes::dead::MarkSymbolVisitor as rustc_hir::intravisit::Visitor>::visit_expr
         8: rustc_hir::intravisit::walk_item::<rustc_passes::dead::MarkSymbolVisitor>
         9: <rustc_passes::dead::MarkSymbolVisitor>::mark_live_symbols
        10: rustc_passes::dead::live_symbols_and_ignored_derived_traits
        11: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::live_symbols_and_ignored_derived_traits::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
        12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        13: rustc_query_impl::query_impl::live_symbols_and_ignored_derived_traits::get_query_non_incr::__rust_end_short_backtrace
        14: rustc_passes::dead::check_mod_deathness
        15: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_deathness::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 0]>>
        16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalModDefId, rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        17: rustc_query_impl::query_impl::check_mod_deathness::get_query_non_incr::__rust_end_short_backtrace
        18: rustc_interface::passes::analysis
        19: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        21: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        22: <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}>
        23: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}
        24: std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
        25: <<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        26: std::sys::pal::unix::thread::Thread::new::thread_start
        27: __pthread_start
  --> 33B7EA3C786ACECC5120C5E71F2ABA806F951277F5D1A778A0BABD76796A0D08.rs:22:5
   |
22 |     self.0;
   |     ^^^^^^

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/sal/Downloads/240321_bugs/rustc-ice-2024-03-22T12_41_11-87747.txt` to your bug report

query stack during panic:
end of query stack

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.F-fn_delegation`#![feature(fn_delegation)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️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.requires-incomplete-featuresThis issue requires the use of incomplete features.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions