about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-06-19 08:56:02 +0200
committerGitHub <noreply@github.com>2020-06-19 08:56:02 +0200
commit5e7eec2eaa8b25d8a607a9ced3ef4df01aab3787 (patch)
treea4ab90836968694f335adcc5582e2b98edc570cc /src/test
parent99be102a6d18ec05178a0f55ece6c65f65e38c48 (diff)
parent10c8d2afb8b90e03e2d1563df021146150338c45 (diff)
downloadrust-5e7eec2eaa8b25d8a607a9ced3ef4df01aab3787.tar.gz
rust-5e7eec2eaa8b25d8a607a9ced3ef4df01aab3787.zip
Rollup merge of #72497 - RalfJung:tag-term, r=oli-obk
tag/niche terminology cleanup

The term "discriminant" was used in two ways throughout the compiler:
* every enum variant has a corresponding discriminant, that can be given explicitly with `Variant = N`.
* that discriminant is then encoded in memory to store which variant is active -- but this encoded form of the discriminant was also often called "discriminant", even though it is conceptually quite different (e.g., it can be smaller in size, or even use niche-filling).

After discussion with @eddyb, this renames the second term to "tag". The way the tag is encoded can be either `TagEncoding::Direct` (formerly `DiscriminantKind::Tag`) or `TagEncoding::Niche` (formerly `DiscrimianntKind::Niche`).

This finally resolves some long-standing confusion I had about the handling of variant indices and discriminants, which surfaced in https://github.com/rust-lang/rust/pull/72419.

(There is also a `DiscriminantKind` type in libcore, it remains unaffected. I think this corresponds to the discriminant, not the tag, so that seems all right.)

r? @eddyb
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/consts/const-eval/double_check2.stderr2
-rw-r--r--src/test/ui/consts/const-eval/ub-enum.stderr4
-rw-r--r--src/test/ui/layout/debug.stderr12
3 files changed, 9 insertions, 9 deletions
diff --git a/src/test/ui/consts/const-eval/double_check2.stderr b/src/test/ui/consts/const-eval/double_check2.stderr
index 81fa5c0df13..93dd9a53ec9 100644
--- a/src/test/ui/consts/const-eval/double_check2.stderr
+++ b/src/test/ui/consts/const-eval/double_check2.stderr
@@ -5,7 +5,7 @@ LL | / static FOO: (&Foo, &Bar) = unsafe {(
 LL | |     Union { u8: &BAR }.foo,
 LL | |     Union { u8: &BAR }.bar,
 LL | | )};
-   | |___^ type validation failed: encountered 0x05 at .1.<deref>, but expected a valid enum discriminant
+   | |___^ type validation failed: encountered 0x05 at .1.<deref>, but expected a valid enum tag
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
 
diff --git a/src/test/ui/consts/const-eval/ub-enum.stderr b/src/test/ui/consts/const-eval/ub-enum.stderr
index e49fd3e0b97..1f7593c6db9 100644
--- a/src/test/ui/consts/const-eval/ub-enum.stderr
+++ b/src/test/ui/consts/const-eval/ub-enum.stderr
@@ -2,7 +2,7 @@ error[E0080]: it is undefined behavior to use this value
   --> $DIR/ub-enum.rs:24:1
    |
 LL | const BAD_ENUM: Enum = unsafe { mem::transmute(1usize) };
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000001, but expected a valid enum discriminant
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000001, but expected a valid enum tag
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
 
@@ -26,7 +26,7 @@ error[E0080]: it is undefined behavior to use this value
   --> $DIR/ub-enum.rs:42:1
    |
 LL | const BAD_ENUM2: Enum2 = unsafe { mem::transmute(0usize) };
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000000, but expected a valid enum discriminant
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 0x00000000, but expected a valid enum tag
    |
    = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior.
 
diff --git a/src/test/ui/layout/debug.stderr b/src/test/ui/layout/debug.stderr
index cd8ebdffb73..1a371c6b170 100644
--- a/src/test/ui/layout/debug.stderr
+++ b/src/test/ui/layout/debug.stderr
@@ -10,15 +10,15 @@ error: layout_of(E) = Layout {
         ],
     },
     variants: Multiple {
-        discr: Scalar {
+        tag: Scalar {
             value: Int(
                 I32,
                 false,
             ),
             valid_range: 0..=0,
         },
-        discr_kind: Tag,
-        discr_index: 0,
+        tag_encoding: Direct,
+        tag_field: 0,
         variants: [
             Layout {
                 fields: Arbitrary {
@@ -202,15 +202,15 @@ error: layout_of(std::result::Result<i32, i32>) = Layout {
         ],
     },
     variants: Multiple {
-        discr: Scalar {
+        tag: Scalar {
             value: Int(
                 I32,
                 false,
             ),
             valid_range: 0..=1,
         },
-        discr_kind: Tag,
-        discr_index: 0,
+        tag_encoding: Direct,
+        tag_field: 0,
         variants: [
             Layout {
                 fields: Arbitrary {