]> git.lizzy.rs Git - rust.git/blob - tests/ui/inline-const/const-expr-lifetime.rs
Rollup merge of #106670 - albertlarsan68:check-docs-in-pr-ci, r=Mark-Simulacrum
[rust.git] / tests / ui / inline-const / const-expr-lifetime.rs
1 // run-pass
2
3 #![feature(const_mut_refs)]
4 #![feature(inline_const)]
5
6 use std::marker::PhantomData;
7
8 // rust-lang/rust#78174: ICE: "cannot convert ReErased to a region vid"
9 fn issue_78174() {
10     let foo = const { "foo" };
11     assert_eq!(foo, "foo");
12 }
13
14 pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>);
15
16 impl<'a, T: ?Sized> InvariantRef<'a, T> {
17     pub const fn new(r: &'a T) -> Self {
18         InvariantRef(r, PhantomData)
19     }
20 }
21
22 fn get_invariant_ref<'a>() -> InvariantRef<'a, ()> {
23     const { InvariantRef::<'a, ()>::new(&()) }
24 }
25
26 fn get_invariant_ref2<'a>() -> InvariantRef<'a, ()> {
27     // Try some type inference
28     const { InvariantRef::new(&()) }
29 }
30
31 fn main() {
32     issue_78174();
33     get_invariant_ref();
34     get_invariant_ref2();
35 }