diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-05 15:04:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-05 15:04:20 +0100 |
| commit | 214b2a126bc6654bf60108aea2e8dce94b096b4b (patch) | |
| tree | bdbc040e1f0e9b6c1a27784539118281fbcf5e3c /compiler/rustc_trait_selection/src | |
| parent | cafc4582e66c478b6b297ae85b225c788106015e (diff) | |
| parent | 1777f431ad3afa1c19ceed8b11b211dbe18b558c (diff) | |
Rollup merge of #90529 - b-naber:reborrows-consts, r=lcnr
Skip reborrows in AbstractConstBuilder Fixes https://github.com/rust-lang/rust/issues/90455 Temporary fix to prevent confusing diagnostics that refer to implicit borrows and derefs until we allow borrows and derefs on constant expressions. r? `@oli-obk`
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/const_evaluatable.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs index 6b5d37c0f43..0ea3a18ca34 100644 --- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs +++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs @@ -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, |
