From 1df0a0ba0f04e15d74307088dd3c952dd61f2183 Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Fri, 8 Mar 2013 12:41:40 -0800 Subject: [PATCH] Const dereference works now, so allow it. --- src/librustc/middle/check_const.rs | 4 ++-- src/test/run-pass/const-deref.rs | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/test/run-pass/const-deref.rs diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 9d7a041ca09..7d228f76871 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -91,8 +91,8 @@ pub fn check_expr(sess: Session, v: visit::vt) { if is_const { match e.node { - expr_unary(box(_), _) | expr_unary(uniq(_), _) | - expr_unary(deref, _) => { + expr_unary(deref, _) => { } + expr_unary(box(_), _) | expr_unary(uniq(_), _) => { sess.span_err(e.span, ~"disallowed operator in constant expression"); return; diff --git a/src/test/run-pass/const-deref.rs b/src/test/run-pass/const-deref.rs new file mode 100644 index 00000000000..71ae273aaa3 --- /dev/null +++ b/src/test/run-pass/const-deref.rs @@ -0,0 +1,20 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +const C: &'static int = &1000; +const D: int = *C; +struct S(&'static int); +const E: &'static S = &S(C); +const F: int = ***E; + +pub fn main() { + fail_unless!(D == 1000); + fail_unless!(F == 1000); +}