Implement Arc/Rc raw pointer conversions for ?Sized by murarth · Pull Request #44073 · rust-lang/rust (original) (raw)
@alexcrichton: I've run into an issue implementing offset_of as an asm!-like macro. When attempting to evaluate ExprKind::OffsetOf as a constant expression (here), a lifetime error arises, apparently from the use of a TyCtxt<'a, 'tcx, 'tcx> (note the double 'tcx) by LayoutCx.
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
--> src/librustc_mir/build/expr/as_constant.rs:35:15
|
35 | = expr;
| ^^^^
|
note: first, the lifetime cannot outlive the lifetime 'tcx as defined on the impl at 22:1...
--> src/librustc_mir/build/expr/as_constant.rs:22:1
|
22 | / impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
23 | | /// Compile `expr`, yielding a compile-time constant. Assumes that
24 | | /// `expr` is a valid compile-time constant!
25 | | pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
... |
70 | | }
71 | | }
| |_^
note: ...so that expression is assignable (expected hair::Expr<'_>, found hair::Expr<'tcx>)
--> src/librustc_mir/build/expr/as_constant.rs:35:15
|
35 | = expr;
| ^^^^
note: but, the lifetime must be valid for the lifetime 'gcx as defined on the impl at 22:1...
--> src/librustc_mir/build/expr/as_constant.rs:22:1
|
22 | / impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
23 | | /// Compile `expr`, yielding a compile-time constant. Assumes that
24 | | /// `expr` is a valid compile-time constant!
25 | | pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
... |
70 | | }
71 | | }
| |_^
note: ...so that types are compatible (expected &build::Builder<'_, '_, '_>, found &build::Builder<'a, 'gcx, 'tcx>)
--> src/librustc_mir/build/expr/as_constant.rs:42:32
|
42 | let hir = self.hir();
| ^^^
Trying to resolve this by adding a 'gcx parameter to LayoutCx sets off a cascade of new 'gcx parameters, eventually running into another lifetime error that I'm having trouble resolving, in librustc/infer/mod.rs (here):
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
--> src/librustc/infer/mod.rs:501:14
|
501 | self.infer_ctxt().enter(|infcx| {
| ^^^^^^^^^^
|
note: first, the lifetime cannot outlive the lifetime 'a as defined on the impl at 473:1...
--> src/librustc/infer/mod.rs:473:1
|
473 | / impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
474 | | /// Currently, higher-ranked type bounds inhibit normalization. Therefore,
475 | | /// each time we erase them in translation, we need to normalize
476 | | /// the contents.
... |
526 | | }
527 | | }
| |_^
note: ...so that types are compatible (expected ty::context::TyCtxt<'_, '_, '_>, found ty::context::TyCtxt<'a, 'gcx, 'tcx>)
--> src/librustc/infer/mod.rs:501:14
|
501 | self.infer_ctxt().enter(|infcx| {
| ^^^^^^^^^^
note: but, the lifetime must be valid for the lifetime 'tcx as defined on the impl at 473:1...
--> src/librustc/infer/mod.rs:473:1
|
473 | / impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
474 | | /// Currently, higher-ranked type bounds inhibit normalization. Therefore,
475 | | /// each time we erase them in translation, we need to normalize
476 | | /// the contents.
... |
526 | | }
527 | | }
| |_^
note: ...so that expression is assignable (expected &infer::InferCtxt<'_, '_, 'tcx>, found &infer::InferCtxt<'_, '_, '_>)
--> src/librustc/infer/mod.rs:502:35
|
502 | value.trans_normalize(&infcx, param_env)
| ^^^^^^