Skip to content

leak_check in rustc_const_eval::util::relate_types - #155883

Open
lcnr wants to merge 1 commit into
rust-lang:mainfrom
lcnr:relate_types-leak-check
Open

leak_check in rustc_const_eval::util::relate_types#155883
lcnr wants to merge 1 commit into
rust-lang:mainfrom
lcnr:relate_types-leak-check

Conversation

@lcnr

@lcnr lcnr commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

fixes #155477. we should really figure out an API where people don't have to manually call leak_check for their code to be correct. I don't really know what that API should be for now, but the status quo sucks xx

same issue was recently fixed when checking that the return type of fn main implements Termination in #151377

r? BoxyUwU

@rustbot

rustbot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 27, 2026
@rustbot

rustbot commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

impl Trait for F1 {
type Assoc = i64;
}
#[expect(coherence_leak_check)]

@RalfJung RalfJung Apr 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do...?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it expects the coherence_leak_check lint. That lint is in a horrible state but fixing the lint doesn't seem too useful given that this thing is currently still in flux and updating it properly is non-trivial 😅

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, your fix makes this code emit a lint (#56105). That doesn't seem to make much sense but 🤷 sure whatever.

Comment thread tests/ui/transmute/equal-up-to-leak-check.rs Outdated
@lcnr
lcnr force-pushed the relate_types-leak-check branch from de223eb to 715e75d Compare April 27, 2026 15:35
@RalfJung

Copy link
Copy Markdown
Member

r=me based on the tests passing. Up to you if you want to get a review from someone who actually knows what all these type system queries do. ;)

ocx.evaluate_obligations_error_on_ambiguity().is_empty()

if ocx.evaluate_obligations_error_on_ambiguity().is_empty() {
infcx.leak_check(ty::UniverseIndex::ROOT, None).is_ok()

@RalfJung RalfJung Apr 27, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
infcx.leak_check(ty::UniverseIndex::ROOT, None).is_ok()
// Ensure there are no pending lifetime constraints. This is needed to avoid issues like
// <https://github.com/rust-lang/rust/issues/155477>.
infcx.leak_check(ty::UniverseIndex::ROOT, None).is_ok()

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@lcnr

lcnr commented Apr 28, 2026

Copy link
Copy Markdown
Contributor Author

looks like this exposes a place where validation uses equality instead of subtyping? don't have the time to look into that rn, but prolly just need to change the variance/used function at the place where this ICEs

@BoxyUwU

BoxyUwU commented May 1, 2026

Copy link
Copy Markdown
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 1, 2026
@rustbot

rustbot commented May 1, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-bors

This comment has been minimized.

@lcnr

lcnr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

affected test with just rustc src/main.rs -Zvalidate-mir

fn foo(_: &str) {}
fn main() {
    let lhs = foo as fn(&'static str);
    let rhs = foo as for<'a> fn(&'a str);
    let _ = lhs == rhs;
}

@lcnr

lcnr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

looking at the MIR https://gist.github.com/lcnr/0b3dde206b3c47989e30a9bbcfbdc3cf we just equate Eq(move _5, move _6) with let _5: fn(&str); and let _6: for<'a> fn(&'a str).

MIR validation then checks whether _5 and _6 are equal

@lcnr
lcnr force-pushed the relate_types-leak-check branch from 715e75d to d475155 Compare August 25, 2026 10:01
@rustbot

rustbot commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@lcnr

lcnr commented Aug 25, 2026

Copy link
Copy Markdown
Contributor Author

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-miri failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
tests/pass/shims/x86/rounding-error.rs ... ok
tests/pass/shims/x86/intrinsics-x86-gfni.rs ... ok

FAILED TEST: tests/pass/issues/issue-91636.rs
command: MIRI_ENV_VAR_TEST="0" MIRI_TEMP="/tmp/miri-uitest-5ItnDT" RUST_BACKTRACE="1" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/miri" "--error-format=json" "-Dwarnings" "-Dunused" "-Ainternal_features" "-Zui-testing" "--sysroot=/checkout/obj/build/x86_64-unknown-linux-gnu/miri-sysroot" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/tmp/miri_ui/0/tests/pass/issues" "tests/pass/issues/issue-91636.rs" "--edition" "2021"

error: test got exit status: 101, but expected 0
 = note: the compiler panicked

error: no output was expected
Execute `./miri test --bless` to update `tests/pass/issues/issue-91636.stderr` to the actual output
+++ <stderr output>
##[error]error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:82:25: broken MIR in Item(DefId(0:10 ~ issue_91636[2625]::main)) (after phase change to runtime-optimized) at bb2[10]:
                                Cannot Eq compare incompatible types fn(&str) and for<'a> fn(&'a str)
  --> tests/pass/issues/issue-91636.rs:22:13
   |
LL |     assert!(inner == func2.inner);
   |             ^^^^^^^^^^^^^^^^^^^^


thread 'rustc' (28889) panicked at compiler/rustc_mir_transform/src/validate.rs:82:25:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_mir_transform::validate::CfgChecker>::fail::<alloc::string::String>
   8: <rustc_mir_transform::validate::Validator as rustc_mir_transform::pass_manager::MirPass>::run_pass
   9: rustc_mir_transform::pass_manager::run_passes_inner
  10: rustc_mir_transform::run_optimization_passes
  11: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
  12: <rustc_middle::ty::context::TyCtxt>::instance_mir
  13: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>>::load_mir
  14: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>>::init_fn_call
  15: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine> as miri::concurrency::scheduler::EvalContextExt>::run_threads
  16: miri::eval::eval_entry
  17: <miri::MiriCompilerCalls as rustc_driver_impl::Callbacks>::after_analysis
  18: std::panicking::catch_unwind::<core::option::Option<rustc_interface::queries::Linker>, core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}::{closure#0}>>
  19: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  20: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}>
  21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>
  22: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}::{closure#0}>>
  23: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
  24: rustc_span::create_session_globals_then::<(), 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#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---
           6: std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
               at /checkout/library/std/src/panic.rs:359:14: 359:40
           7: std::rt::lang_start_internal::{closure#0}
               at /checkout/library/std/src/rt.rs:175:24: 175:49
           8: std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /checkout/library/std/src/panicking.rs:574:43: 574:46
           9: std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>
               at /checkout/library/std/src/panicking.rs:542:19: 542:77
           10: std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /checkout/library/std/src/panic.rs:359:14: 359:40
           11: std::rt::lang_start_internal
               at /checkout/library/std/src/rt.rs:171:5: 193:7
           12: std::rt::lang_start::<()>
               at /checkout/library/std/src/rt.rs:205:5: 210:6

error: aborting due to 1 previous error



full stderr:
##[error]error: internal compiler error: compiler/rustc_mir_transform/src/validate.rs:82:25: broken MIR in Item(DefId(0:10 ~ issue_91636[2625]::main)) (after phase change to runtime-optimized) at bb2[10]:
                                Cannot Eq compare incompatible types fn(&str) and for<'a> fn(&'a str)
  --> tests/pass/issues/issue-91636.rs:22:13
   |
LL |     assert!(inner == func2.inner);
   |             ^^^^^^^^^^^^^^^^^^^^


thread 'rustc' (28889) panicked at compiler/rustc_mir_transform/src/validate.rs:82:25:
Box<dyn Any>
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: <rustc_errors::DiagCtxtHandle>::span_bug::<rustc_span::span_encoding::Span, alloc::string::String>
   3: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   5: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   6: rustc_middle::util::bug::span_bug_fmt::<rustc_span::span_encoding::Span>
   7: <rustc_mir_transform::validate::CfgChecker>::fail::<alloc::string::String>
   8: <rustc_mir_transform::validate::Validator as rustc_mir_transform::pass_manager::MirPass>::run_pass
   9: rustc_mir_transform::pass_manager::run_passes_inner
  10: rustc_mir_transform::run_optimization_passes
  11: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
  12: <rustc_middle::ty::context::TyCtxt>::instance_mir
  13: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>>::load_mir
  14: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine>>::init_fn_call
  15: <rustc_const_eval::interpret::eval_context::InterpCx<miri::machine::MiriMachine> as miri::concurrency::scheduler::EvalContextExt>::run_threads
  16: miri::eval::eval_entry
  17: <miri::MiriCompilerCalls as rustc_driver_impl::Callbacks>::after_analysis
  18: std::panicking::catch_unwind::<core::option::Option<rustc_interface::queries::Linker>, core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}::{closure#0}>>
  19: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
  20: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>::{closure#2}>
  21: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}>
  22: std::panicking::catch_unwind::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}::{closure#0}>>
  23: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#2}
  24: rustc_span::create_session_globals_then::<(), 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#2}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
---
           6: std::panic::catch_unwind::<&dyn std::ops::Fn() -> i32 + std::marker::Sync + std::panic::RefUnwindSafe, i32>
               at /checkout/library/std/src/panic.rs:359:14: 359:40
           7: std::rt::lang_start_internal::{closure#0}
               at /checkout/library/std/src/rt.rs:175:24: 175:49
           8: std::panicking::catch_unwind::do_call::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /checkout/library/std/src/panicking.rs:574:43: 574:46
           9: std::panicking::catch_unwind::<isize, {closure@std::rt::lang_start_internal::{closure#0}}>
               at /checkout/library/std/src/panicking.rs:542:19: 542:77
           10: std::panic::catch_unwind::<{closure@std::rt::lang_start_internal::{closure#0}}, isize>
               at /checkout/library/std/src/panic.rs:359:14: 359:40
           11: std::rt::lang_start_internal
               at /checkout/library/std/src/rt.rs:171:5: 193:7
           12: std::rt::lang_start::<()>
               at /checkout/library/std/src/rt.rs:205:5: 210:6
---

Location:
   /cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ui_test-0.30.7/src/lib.rs:365

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
error: test failed, to rerun pass `--test ui`

Caused by:
  process didn't exit successfully: `/checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/release/build/miri/7ba553d1ba36e81d/out/ui-7ba553d1ba36e81d` (exit status: 1)
Command `/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo test --target x86_64-unknown-linux-gnu -Zbinary-dep-depinfo -j 4 -Zroot-dir=/checkout -Zembed-metadata=no --locked --color=always --profile=release --manifest-path /checkout/src/tools/miri/Cargo.toml -- [workdir=/checkout]` failed with exit code 1
Created at: src/bootstrap/src/core/build_steps/tool.rs:208:21
Executed at: src/bootstrap/src/core/build_steps/test.rs:791:19

Command has failed. Rerun with -v to see more details.
Bootstrap failed while executing `test --stage 2 miri cargo-miri`
Currently active steps:
test::Miri { target: x86_64-unknown-linux-gnu } at src/bootstrap/src/core/build_steps/test.rs:717
Build completed unsuccessfully in 0:35:44
  local time: Tue Aug 25 10:41:42 UTC 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: Miri/consteval assertion failure due to transmuting types with HRTB

5 participants