Open
Description
auto-reduced (treereduce-rust):
pub struct InvariantRef<'a, T: ?Sized>(&'a T);
impl<'a, T: ?Sized> InvariantRef<'a, T> {
pub const fn new(r: &'a T) -> Self {}
}
fn get_invariant_ref<'a>() -> InvariantRef<'static, _> {
const { InvariantRef::<'a, ()>::new(&()) }
}
original:
//@ run-pass
use std::marker::PhantomData;
// rust-lang/rust#78174: ICE: "cannot convert ReErased to a region vid"
fn issue_78174() {
let foo = const { "foo" };
assert_eq!(foo, "foo");
}
pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
impl<'a, T: ?Sized> InvariantRef<'a, T> {
pub const fn new(r: &'a T) -> Self {
InvariantRef(r, PhantomData)
}
}
fn get_invariant_ref<'a>() -> InvariantRef<'static, _> {
const { InvariantRef::<'a, ()>::new(&()) }
}
fn get_invariant_ref2<'a>() -> InvariantRef<'a, ()> {
// Try some type inference
const { InvariantRef::new(&()) }
}
fn main() {
issue_78174();
get_invariant_ref();
get_invariant_ref2();
}
Version information
rustc 1.86.0-nightly (cd805f09f 2025-01-21)
binary: rustc
commit-hash: cd805f09ffbfa3896c8f50a619de9b67e1d9f3c3
commit-date: 2025-01-21
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7
Possibly related line of code:
rust/compiler/rustc_borrowck/src/universal_regions.rs
Lines 882 to 894 in cd805f0
Command:
/home/matthias/.rustup/toolchains/master/bin/rustc
Program output
error[E0601]: `main` function not found in crate `mvce`
--> /tmp/icemaker_global_tempdir.sXnYG42JCCJ4/rustc_testrunner_tmpdir_reporting.qVKGb9NYPlaR/mvce.rs:9:2
|
9 | }
| ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.sXnYG42JCCJ4/rustc_testrunner_tmpdir_reporting.qVKGb9NYPlaR/mvce.rs`
error[E0121]: the placeholder `_` is not allowed within types on item signatures for return types
--> /tmp/icemaker_global_tempdir.sXnYG42JCCJ4/rustc_testrunner_tmpdir_reporting.qVKGb9NYPlaR/mvce.rs:7:53
|
7 | fn get_invariant_ref<'a>() -> InvariantRef<'static, _> {
| ----------------------^-
| | |
| | not allowed in type signatures
| help: replace with the correct return type: `InvariantRef<'_, ()>`
error[E0308]: mismatched types
--> /tmp/icemaker_global_tempdir.sXnYG42JCCJ4/rustc_testrunner_tmpdir_reporting.qVKGb9NYPlaR/mvce.rs:4:35
|
4 | pub const fn new(r: &'a T) -> Self {}
| --- ^^^^ expected `InvariantRef<'_, T>`, found `()`
| |
| implicitly returns `()` as its body has no tail or `return` expression
|
= note: expected struct `InvariantRef<'a, T>`
found unit type `()`
error: internal compiler error: compiler/rustc_borrowck/src/universal_regions.rs:888:36: cannot convert `ReLateParam(DefId(0:12 ~ mvce[18ee]::get_invariant_ref), BrNamed(DefId(0:13 ~ mvce[18ee]::get_invariant_ref::'a), 'a))` to a region vid
thread 'rustc' panicked at compiler/rustc_borrowck/src/universal_regions.rs:888:36:
Box<dyn Any>
stack backtrace:
0: 0x703ddf2fabfa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he8f87afa3ba953c7
1: 0x703ddfa12de6 - core::fmt::write::hd1a70dafa054ef6e
2: 0x703de0932191 - std::io::Write::write_fmt::hb7487c14cde15a5b
3: 0x703ddf2faa52 - std::sys::backtrace::BacktraceLock::print::hccabcb6160db5eae
4: 0x703ddf2fced2 - std::panicking::default_hook::{{closure}}::h8c6502dfd308289c
5: 0x703ddf2fcd5a - std::panicking::default_hook::hb4c1963f11244643
6: 0x703dde459a8b - std[59f0843774866faa]::panicking::update_hook::<alloc[ba5425907d200e29]::boxed::Box<rustc_driver_impl[d01b6faf608d79fd]::install_ice_hook::{closure#1}>>::{closure#0}
7: 0x703ddf2fda13 - std::panicking::rust_panic_with_hook::hc3d8183c3b9ea233
8: 0x703dde4948a1 - std[59f0843774866faa]::panicking::begin_panic::<rustc_errors[33b093a44d219c0d]::ExplicitBug>::{closure#0}
9: 0x703dde4897a6 - std[59f0843774866faa]::sys::backtrace::__rust_end_short_backtrace::<std[59f0843774866faa]::panicking::begin_panic<rustc_errors[33b093a44d219c0d]::ExplicitBug>::{closure#0}, !>
10: 0x703dde4862b9 - std[59f0843774866faa]::panicking::begin_panic::<rustc_errors[33b093a44d219c0d]::ExplicitBug>
11: 0x703dde49e7d1 - <rustc_errors[33b093a44d219c0d]::diagnostic::BugAbort as rustc_errors[33b093a44d219c0d]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x703ddea800e3 - rustc_middle[d9c304bb3c99a636]::util::bug::opt_span_bug_fmt::<rustc_span[79f25feaa0a05865]::span_encoding::Span>::{closure#0}
13: 0x703ddea658da - rustc_middle[d9c304bb3c99a636]::ty::context::tls::with_opt::<rustc_middle[d9c304bb3c99a636]::util::bug::opt_span_bug_fmt<rustc_span[79f25feaa0a05865]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x703ddea6576b - rustc_middle[d9c304bb3c99a636]::ty::context::tls::with_context_opt::<rustc_middle[d9c304bb3c99a636]::ty::context::tls::with_opt<rustc_middle[d9c304bb3c99a636]::util::bug::opt_span_bug_fmt<rustc_span[79f25feaa0a05865]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x703ddcbd4270 - rustc_middle[d9c304bb3c99a636]::util::bug::bug_fmt
16: 0x703de03b2479 - <rustc_borrowck[418e11b174dea340]::type_check::constraint_conversion::ConstraintConversion>::convert
17: 0x703de03b158e - <rustc_borrowck[418e11b174dea340]::type_check::TypeChecker>::prove_closure_bounds
18: 0x703ddfc6e6ca - <rustc_borrowck[418e11b174dea340]::type_check::TypeChecker>::typeck_mir
19: 0x703de0ab7e93 - rustc_borrowck[418e11b174dea340]::type_check::type_check
20: 0x703ddfb0777e - rustc_borrowck[418e11b174dea340]::nll::compute_regions
21: 0x703de0adbb87 - rustc_borrowck[418e11b174dea340]::do_mir_borrowck
22: 0x703de0acebaf - rustc_query_impl[51e2c968ef770bf4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51e2c968ef770bf4]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d9c304bb3c99a636]::query::erase::Erased<[u8; 8usize]>>
23: 0x703ddfddbc0e - rustc_query_system[62ef735fec9db900]::query::plumbing::try_execute_query::<rustc_query_impl[51e2c968ef770bf4]::DynamicConfig<rustc_data_structures[ab2428ff1810be63]::vec_cache::VecCache<rustc_span[79f25feaa0a05865]::def_id::LocalDefId, rustc_middle[d9c304bb3c99a636]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[62ef735fec9db900]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[51e2c968ef770bf4]::plumbing::QueryCtxt, false>
24: 0x703ddfddb70d - rustc_query_impl[51e2c968ef770bf4]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
25: 0x703ddfdd4900 - rustc_interface[511fe094a4999c01]::passes::run_required_analyses
26: 0x703de092d99e - rustc_interface[511fe094a4999c01]::passes::analysis
27: 0x703de092d96f - rustc_query_impl[51e2c968ef770bf4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[51e2c968ef770bf4]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d9c304bb3c99a636]::query::erase::Erased<[u8; 0usize]>>
28: 0x703de0a083d5 - rustc_query_system[62ef735fec9db900]::query::plumbing::try_execute_query::<rustc_query_impl[51e2c968ef770bf4]::DynamicConfig<rustc_query_system[62ef735fec9db900]::query::caches::SingleCache<rustc_middle[d9c304bb3c99a636]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[51e2c968ef770bf4]::plumbing::QueryCtxt, false>
29: 0x703de0a0810e - rustc_query_impl[51e2c968ef770bf4]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
30: 0x703de09a1169 - rustc_interface[511fe094a4999c01]::passes::create_and_enter_global_ctxt::<core[ee856ee324d81d9a]::option::Option<rustc_interface[511fe094a4999c01]::queries::Linker>, rustc_driver_impl[d01b6faf608d79fd]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
31: 0x703de09ef950 - rustc_interface[511fe094a4999c01]::interface::run_compiler::<(), rustc_driver_impl[d01b6faf608d79fd]::run_compiler::{closure#0}>::{closure#1}
32: 0x703de0940076 - std[59f0843774866faa]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[511fe094a4999c01]::util::run_in_thread_with_globals<rustc_interface[511fe094a4999c01]::util::run_in_thread_pool_with_globals<rustc_interface[511fe094a4999c01]::interface::run_compiler<(), rustc_driver_impl[d01b6faf608d79fd]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
33: 0x703de093fd59 - <<std[59f0843774866faa]::thread::Builder>::spawn_unchecked_<rustc_interface[511fe094a4999c01]::util::run_in_thread_with_globals<rustc_interface[511fe094a4999c01]::util::run_in_thread_pool_with_globals<rustc_interface[511fe094a4999c01]::interface::run_compiler<(), rustc_driver_impl[d01b6faf608d79fd]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[ee856ee324d81d9a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
34: 0x703de093f4ef - std::sys::pal::unix::thread::Thread::new::thread_start::h66685cea0b34fc94
35: 0x703ddaca339d - <unknown>
36: 0x703ddad2849c - <unknown>
37: 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: please make sure that you have updated to the latest nightly
note: rustc 1.86.0-nightly (cd805f09f 2025-01-21) running on x86_64-unknown-linux-gnu
query stack during panic:
#0 [mir_borrowck] borrow-checking `get_invariant_ref`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0121, E0308, E0601.
For more information about an error, try `rustc --explain E0121`.