diff options
| author | kennytm <kennytm@gmail.com> | 2018-02-05 01:27:36 +0800 |
|---|---|---|
| committer | kennytm <kennytm@gmail.com> | 2018-02-05 01:27:36 +0800 |
| commit | e17ebdf344401c265ade3b02bb68df0d0485d71a (patch) | |
| tree | 69ae9abfb6aa69f17d7ed5bc4904c185b41c3f9d /src/librustc_const_eval | |
| parent | 66d6c855bda49035cdf825625dbe423a2e1a2a6b (diff) | |
| parent | 196fad0d00bddd11074b5da32af2393abaac9a26 (diff) | |
Rollup merge of #47892 - Badel2:const_type_id_of, r=oli-obk
Turn `type_id` into a constant intrinsic https://github.com/rust-lang/rust/issues/27745 The method `get_type_id` in `Any` is intended to support reflection. It's currently unstable in favor of using an associated constant instead. This PR makes the `type_id` intrinsic a constant intrinsic, the same as `size_of` and `align_of`, allowing `TypeId::of` to be a `const fn`, which will allow using an associated constant in `Any`.
Diffstat (limited to 'src/librustc_const_eval')
| -rw-r--r-- | src/librustc_const_eval/eval.rs | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/librustc_const_eval/eval.rs b/src/librustc_const_eval/eval.rs index 1d2813e4f67..8e4ec93c14b 100644 --- a/src/librustc_const_eval/eval.rs +++ b/src/librustc_const_eval/eval.rs @@ -327,6 +327,10 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>, return Ok(mk_const(Integral(Usize(ConstUsize::new(align, tcx.sess.target.usize_ty).unwrap())))); } + "type_id" => { + let type_id = tcx.type_id_hash(substs.type_at(0)); + return Ok(mk_const(Integral(U64(type_id)))); + } _ => signal!(e, TypeckError) } } |
