1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! See docs in build/expr/mod.rs
17 impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
18 /// Compile `expr`, yielding a compile-time constant. Assumes that
19 /// `expr` is a valid compile-time constant!
20 pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
21 where M: Mirror<'tcx, Output=Expr<'tcx>>
23 let expr = self.hir.mirror(expr);
24 self.expr_as_constant(expr)
27 fn expr_as_constant(&mut self, expr: Expr<'tcx>) -> Constant<'tcx> {
29 let Expr { ty, temp_lifetime: _, temp_lifetime_was_shrunk: _, span, kind }
32 ExprKind::Scope { extent: _, value } =>
33 this.as_constant(value),
34 ExprKind::Literal { literal } =>
35 Constant { span: span, ty: ty, literal: literal },
39 "expression is not a valid constant {:?}",