blob: 13fd8b19fdc6866917fceb037b71141581e828fe [file]
// Protocol Buffers - Google's data interchange format
// Copyright 2026 Google LLC. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
//! Enums from `optimize_for = LITE_RUNTIME` files, and every enum when the lite
//! runtime is forced, omit their value names: they don't implement `EnumValueNames`
//! (nor have inherent `name()`/`from_name()`), so code that needs the names
//! doesn't compile with them.
#[cfg(not(bzl))]
mod protos;
#[cfg(not(bzl))]
use protos::*;
use enums_rust_proto::TestEnumWithNumericNames;
use googletest::prelude::*;
use lite_enums_rust_proto::LiteTestEnum;
use protobuf::EnumValueNames;
use std::marker::PhantomData;
/// `Probe::<E>::HAS_NAMES` is whether `E: EnumValueNames`: the inherent constant
/// applies when its bound holds, and the trait's constant otherwise.
struct Probe<E>(PhantomData<E>);
trait WithoutNames {
const HAS_NAMES: bool = false;
}
impl<E> WithoutNames for Probe<E> {}
impl<E: EnumValueNames> Probe<E> {
const HAS_NAMES: bool = true;
}
#[gtest]
fn test_optimize_for_lite_enum_has_no_names() {
expect_false!(Probe::<LiteTestEnum>::HAS_NAMES);
}
#[gtest]
fn test_enum_has_names() {
expect_true!(Probe::<TestEnumWithNumericNames>::HAS_NAMES);
}