Skip to content

Commit 8ff50fe

Browse files
committed
skip reborrows during AbstractConst building
1 parent 9520925 commit 8ff50fe

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,25 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
399399
let arg = self.recurse_build(source)?;
400400
self.nodes.push(Node::Cast(abstract_const::CastKind::As, arg, node.ty))
401401
}
402-
402+
ExprKind::Borrow{ arg, ..} => {
403+
let arg_node = &self.body.exprs[*arg];
404+
405+
// Skip reborrows for now until we allow Deref/Borrow/AddressOf
406+
// expressions.
407+
// FIXME(generic_const_exprs): Verify/explain why this is sound
408+
if let ExprKind::Deref {arg} = arg_node.kind {
409+
self.recurse_build(arg)?
410+
} else {
411+
self.maybe_supported_error(
412+
node.span,
413+
"borrowing is not supported in generic constants",
414+
)?
415+
}
416+
}
403417
// FIXME(generic_const_exprs): We may want to support these.
404-
ExprKind::AddressOf { .. }
405-
| ExprKind::Borrow { .. }
406-
| ExprKind::Deref { .. } => self.maybe_supported_error(
418+
ExprKind::AddressOf { .. } | ExprKind::Deref {..}=> self.maybe_supported_error(
407419
node.span,
408-
"dereferencing is not supported in generic constants",
420+
"dereferencing or taking the address is not supported in generic constants",
409421
)?,
410422
ExprKind::Repeat { .. } | ExprKind::Array { .. } => self.maybe_supported_error(
411423
node.span,

0 commit comments

Comments
 (0)