From a8623d17445ba141cfb1a4dea6b4195acf3ad616 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sat, 18 Apr 2020 02:00:14 +0900 Subject: [PATCH] fixup! Update docs related to const-eval --- src/const-eval.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/const-eval.md b/src/const-eval.md index 0f5fdc675e..45a8345dbe 100644 --- a/src/const-eval.md +++ b/src/const-eval.md @@ -24,17 +24,21 @@ Constant evaluation can be done by calling the `const_eval_*` queries of `TyCtxt The `const_eval_*` queries use a [`ParamEnv`](./param_env.html) of environment in which the constant is evaluated (e.g. the function within which the constant is used) -and a `GlobalId`. The `GlobalId` is made up of an `Instance` referring to a constant +and a [`GlobalId`]. The `GlobalId` is made up of an `Instance` referring to a constant or static or of an `Instance` of a function and an index into the function's `Promoted` table. Constant evaluation returns a [`ConstEvalResult`] with either the error, or the simplest representation of the constant. "simplest" meaning if it is representable as an -integer or fat pointer, it will directly yield the value (via `ConstValue::Scalar` or -`ConstValue::Slice`), instead of referring to the [`miri`](./miri.html) virtual -memory allocation (via `ConstValue::ByRef`). This means that the `const_eval_*` +integer or fat pointer, it will directly yield the value (via [`ConstValue::Scalar`] +or [`ConstValue::Slice`]), instead of referring to the [`miri`](./miri.html) virtual +memory allocation (via [`ConstValue::ByRef`]). This means that the `const_eval_*` functions cannot be used to create miri-pointers to the evaluated constant or static. If you need that, you need to directly work with the functions in [`src/librustc_mir/const_eval.rs`]. +[`GlobalId`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/struct.GlobalId.html +[`ConstValue::Scalar`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Scalar +[`ConstValue::Slice`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.Slice +[`ConstValue::ByRef`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/value/enum.ConstValue.html#variant.ByRef [`ConstEvalResult`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/interpret/error/type.ConstEvalResult.html [`src/librustc_mir/const_eval.rs`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/const_eval/index.html