Skip to content

ICE: delayed bugs were created - failed region resolution while normalizing ParamEnv #136661

Closed

Description

@steffahn

Code

#![allow(unused)]

trait Supertrait<T> {}

trait Other {
    fn method(&self) {}
}

impl WithAssoc for &'static () {
    type As = ();
}

trait WithAssoc {
    type As;
}

trait Trait<P: WithAssoc>: Supertrait<P::As> {
    fn method(&self) {}
}

fn hrtb<T: for<'a> Trait<&'a ()>>() {}

(playground)

Meta

tested stable 1.84.1 and nightly a9730c3b5 2025-02-051

Error output

   Compiling playground v0.0.1 (/playground)
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: failed region resolution while normalizing ParamEnv { caller_bounds: [Binder { value: TraitPredicate(<T as Trait<&'a ()>>, polarity:Positive), bound_vars: [Region(BrNamed(DefId(0:16 ~ playground[53aa]::hrtb::'a), 'a))] }, Binder { value: TraitPredicate(<T as Supertrait<<&'a () as WithAssoc>::As>>, polarity:Positive), bound_vars: [Region(BrNamed(DefId(0:16 ~ playground[53aa]::hrtb::'a), 'a))] }, Binder { value: TraitPredicate(<T as std::marker::Sized>, polarity:Positive), bound_vars: [] }] }: [ConcreteFailure(Subtype(TypeTrace { cause: ObligationCause { span: src/lib.rs:21:1: 21:36 (#0), body_id: DefId(0:14 ~ playground[53aa]::hrtb), code: MatchImpl(ObligationCause { span: src/lib.rs:21:1: 21:36 (#0), body_id: DefId(0:14 ~ playground[53aa]::hrtb), code: Misc }, DefId(0:7 ~ playground[53aa]::{impl#0})) }, values: TraitRefs(ExpectedFound { expected: <&'a () as WithAssoc>, found: <&'static () as WithAssoc> }) }), 'static, !1_0.Named(DefId(0:16 ~ playground[53aa]::hrtb::'a), "'a"))]
  --> src/lib.rs:21:1
   |
21 | fn hrtb<T: for<'a> Trait<&'a ()>>() {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at compiler/rustc_trait_selection/src/traits/mod.rs:293:19 - disabled backtrace
  --> src/lib.rs:21:1
   |
21 | fn hrtb<T: for<'a> Trait<&'a ()>>() {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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: please attach the file at `/playground/rustc-ice-2025-02-06T21_30_27-21.txt` to your bug report

note: compiler flags: --crate-type lib -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:
end of query stack
error: could not compile `playground` (lib)
Backtrace

note: delayed at compiler/rustc_trait_selection/src/traits/mod.rs:293:19
         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, alloc::string::String>
         4: rustc_trait_selection::traits::do_normalize_predicates
         5: rustc_trait_selection::traits::normalize_param_env_or_error
         6: rustc_ty_utils::ty::param_env
         7: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::param_env::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 8]>>
         8: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::DynamicConfig<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
         9: rustc_query_impl::query_impl::param_env::get_query_incr::__rust_end_short_backtrace
        10: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
        11: rustc_hir_analysis::check::wfcheck::check_item_fn
        12: rustc_hir_analysis::check::wfcheck::check_well_formed
        13: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        14: 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; 1]>, rustc_query_system::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        15: rustc_query_impl::query_impl::check_well_formed::get_query_incr::__rust_end_short_backtrace
        16: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
        17: rustc_query_impl::plumbing::__rust_begin_short_backtrace::<rustc_query_impl::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle::query::erase::Erased<[u8; 1]>>
        18: 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; 1]>>, false, false, false>, rustc_query_impl::plumbing::QueryCtxt, true>
        19: rustc_query_impl::query_impl::check_mod_type_wf::get_query_incr::__rust_end_short_backtrace
        20: rustc_hir_analysis::check_crate
        21: rustc_interface::passes::run_required_analyses
        22: rustc_interface::passes::analysis
        23: 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]>>
        24: 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, true>
        25: rustc_query_impl::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
        26: 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}
        27: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
        28: 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}, ()>
        29: <<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}
        30: std::sys::pal::unix::thread::Thread::new::thread_start
        31: start_thread
                   at ./nptl/pthread_create.c:447:8
        32: clone3
                   at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:78:0
  --> src/main.rs:21:1
   |
21 | fn hrtb<T: for<'a> Trait<&'a ()>>() {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Footnotes

  1. and also cf8986d which hasn't quite reached nightly yet ↩

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Feb 6, 2025
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 6, 2025
  3. added
    fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Feb 6, 2025
  4. compiler-errors commented on Feb 6, 2025

    @compiler-errors
    Contributor

    This has to do with the fact that we don't check the well-formedness of the trait goal T: for<'a> Trait<&'a ()> since it has higher-ranked regions. We currently opt out of checking a lot of things with higher-ranked regions due to a lack of higher-ranked implied bounds.

    To be specific:

    fn hrtb<T: for<'a> Trait<&'a ()>>() {}

    ... should additionally require that for<'a> &'a (): WithAssoc holds. That would be an error, since we know that the goal only holds when 'a = 'static. But we don't check it.

    I don't expect this to get solved any time soon. The new trait solver side-steps this ICE, but it doesn't "fix" the issue necessarily as fn hrtb ideally should error.

  5. matthiaskrgr commented on Feb 6, 2025

    @matthiaskrgr
    Member

    this seems to crash since nightly-2022-07-16 , before:

    error: implementation of `WithAssoc` is not general enough
      --> /tmp/crash.rs:21:1
       |
    21 | fn hrtb<T: for<'a> Trait<&'a ()>>() {}
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `WithAssoc` is not general enough
       |
       = note: `&'0 ()` must implement `WithAssoc`, for any lifetime `'0`...
       = note: ...but `WithAssoc` is actually implemented for the type `&'static ()`
    
    error: aborting due to previous error
    

    commit[0] 2022-07-14: Auto merge of #99252 - lqd:win-dwarf5, r=eddyb
    commit[1] 2022-07-14: Auto merge of #96544 - m-ysk:feature/issue-96358, r=cjgillot
    commit[2] 2022-07-15: Auto merge of #98203 - kckeiks:gather-body-owners-in-hir-item-queries, r=cjgillot
    commit[3] 2022-07-15: Auto merge of #97406 - aliemjay:verify-bounds-fix-master, r=oli-obk
    commit[4] 2022-07-15: Auto merge of #99267 - Dylan-DPC:rollup-d8l7y1o, r=Dylan-DPC
    commit[5] 2022-07-15: Auto merge of #99013 - RalfJung:dont-poison-my-places, r=oli-obk
    commit[6] 2022-07-15: Auto merge of #99278 - Dylan-DPC:rollup-fcln6st, r=Dylan-DPC
    commit[7] 2022-07-15: Auto merge of #99046 - nnethercote:final-derive-output-improvements, r=Mark-Simulacrum
    commit[8] 2022-07-15: Auto merge of #99015 - lcnr:fn-ctxt-no-more, r=compiler-errors

  6. added
    S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.
    on Mar 9, 2025
  7. added 2 commits that reference this issue on Jul 6, 2026
    5085223
    a7fac4d
  8. added a commit that references this issue on Jul 6, 2026
    5d29849
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions