Skip to content

ICE: trait object trait bounds reference Self #135918

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

Closed
matthiaskrgr opened this issue Jan 23, 2025 · 2 comments · Fixed by #135971
Closed

ICE: trait object trait bounds reference Self #135918

matthiaskrgr opened this issue Jan 23, 2025 · 2 comments · Fixed by #135971
Labels
A-dyn-trait Area: trait objects, vtable layout 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

trait FromResidual<R = <Self as Try>::Residual> {}

trait Try {
    type Residual;
}

fn w<U>() {
    let b: &dyn FromResidual = &();
}

fn main() {}

original:

trait FromResidual<R = <Self as Try>::Residual> {
    fn y(self) -> isize;
}

trait Try {
    type Residual;
}

fn w<U>() {
    let b: &dyn FromResidual = &();
    //~^ ERROR: the trait `FromResidual` is not dyn compatible
    //~| ERROR: the trait `FromResidual` is not dyn compatible
}

fn main() {}

Version information

rustc 1.86.0-nightly (3cd8fcbf8 2025-01-23)
binary: rustc
commit-hash: 3cd8fcbf87bd28a1f31be000ca906fb66f4d451d
commit-date: 2025-01-23
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

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

Program output

warning: trait `FromResidual` is never used
 --> /tmp/icemaker_global_tempdir.48NMtvPAjGxe/rustc_testrunner_tmpdir_reporting.LRiH8Fwh0jxX/mvce.rs:1:7
  |
1 | trait FromResidual<R = <Self as Try>::Residual> {}
  |       ^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: trait `Try` is never used
 --> /tmp/icemaker_global_tempdir.48NMtvPAjGxe/rustc_testrunner_tmpdir_reporting.LRiH8Fwh0jxX/mvce.rs:3:7
  |
3 | trait Try {
  |       ^^^

warning: function `w` is never used
 --> /tmp/icemaker_global_tempdir.48NMtvPAjGxe/rustc_testrunner_tmpdir_reporting.LRiH8Fwh0jxX/mvce.rs:7:4
  |
7 | fn w<U>() {
  |    ^

warning: 3 warnings emitted

note: no errors encountered even though delayed bugs were created

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

error: internal compiler error: trait object trait bounds reference `Self`
 --> /tmp/icemaker_global_tempdir.48NMtvPAjGxe/rustc_testrunner_tmpdir_reporting.LRiH8Fwh0jxX/mvce.rs:8:17
  |
8 |     let b: &dyn FromResidual = &();
  |                 ^^^^^^^^^^^^
  |
note: delayed at compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs:245:51
         0: <rustc_errors::DiagCtxtInner>::emit_diagnostic
         1: <rustc_errors::DiagCtxtHandle>::emit_diagnostic
         2: <rustc_span::ErrorGuaranteed as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
         3: <rustc_errors::DiagCtxtHandle>::span_delayed_bug::<rustc_span::span_encoding::Span, &str>
         4: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_trait_object_ty
         5: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty
         6: <dyn rustc_hir_analysis::hir_ty_lowering::HirTyLowerer>::lower_ty
         7: <rustc_hir_typeck::gather_locals::GatherLocalsVisitor as rustc_hir::intravisit::Visitor>::visit_local
         8: <rustc_hir_typeck::gather_locals::GatherLocalsVisitor as rustc_hir::intravisit::Visitor>::visit_expr
         9: rustc_hir_typeck::check::check_fn
        10: rustc_hir_typeck::typeck_with_inspect::{closure#0}
        11: 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]>>
        12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_data_structures::vec_cache::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        13: rustc_query_impl::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
        14: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_hir_analysis::check_crate::{closure#4}>::{closure#0}
        15: rustc_hir_analysis::check_crate
        16: rustc_interface::passes::run_required_analyses
        17: rustc_interface::passes::analysis
        18: 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; 0]>>
        19: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::SingleCache<rustc_middle::query::erase::Erased<[u8; 0]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, false>
        20: rustc_query_impl::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
        21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
        22: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        23: std::sys::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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
        24: <<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<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
        25: std::sys::pal::unix::thread::Thread::new::thread_start
        26: <unknown>
        27: <unknown>
 --> /tmp/icemaker_global_tempdir.48NMtvPAjGxe/rustc_testrunner_tmpdir_reporting.LRiH8Fwh0jxX/mvce.rs:8:17
  |
8 |     let b: &dyn FromResidual = &();
  |                 ^^^^^^^^^^^^

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 make sure that you have updated to the latest nightly

note: rustc 1.86.0-nightly (3cd8fcbf8 2025-01-23) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack

@matthiaskrgr matthiaskrgr 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 Jan 23, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jan 23, 2025
@matthiaskrgr
Copy link
Member Author

regression in #133830 cc @compiler-errors

@matthiaskrgr
Copy link
Member Author

trait A<C = <Self as D>::E> {}

trait D {
    type E;
}

fn f() {
    let B: dyn A = todo!();
}

fn main() {}

@fmease fmease added A-dyn-trait Area: trait objects, vtable layout and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 23, 2025
@bors bors closed this as completed in 9ffe558 Jan 25, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 25, 2025
Rollup merge of rust-lang#135971 - compiler-errors:self-projection, r=fmease

Properly report error when object type param default references self

I accidentally broke this error for cases where a type parameter references `Self` via a projection (i.e. `trait Foo<Arg = Self::Bar> {}`). This PR fixes that, and also makes the error a bit easier to understand.

Fixes rust-lang#135918
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-dyn-trait Area: trait objects, vtable layout 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants