Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #91555

Merged
merged 10 commits into from
Dec 5, 2021
Prev Previous commit
Next Next commit
skip reborrows during AbstractConst building
  • Loading branch information
b-naber committed Dec 5, 2021
commit 8ff50fe2736d8d33e2c51105cbabf023eff93218
22 changes: 17 additions & 5 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 399,25 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
let arg = self.recurse_build(source)?;
self.nodes.push(Node::Cast(abstract_const::CastKind::As, arg, node.ty))
}

ExprKind::Borrow{ arg, ..} => {
let arg_node = &self.body.exprs[*arg];

// Skip reborrows for now until we allow Deref/Borrow/AddressOf
// expressions.
// FIXME(generic_const_exprs): Verify/explain why this is sound
if let ExprKind::Deref {arg} = arg_node.kind {
self.recurse_build(arg)?
} else {
self.maybe_supported_error(
node.span,
"borrowing is not supported in generic constants",
)?
}
}
// FIXME(generic_const_exprs): We may want to support these.
ExprKind::AddressOf { .. }
| ExprKind::Borrow { .. }
| ExprKind::Deref { .. } => self.maybe_supported_error(
ExprKind::AddressOf { .. } | ExprKind::Deref {..}=> self.maybe_supported_error(
node.span,
"dereferencing is not supported in generic constants",
"dereferencing or taking the address is not supported in generic constants",
)?,
ExprKind::Repeat { .. } | ExprKind::Array { .. } => self.maybe_supported_error(
node.span,
Expand Down