use declarative macro for #[derive(TryFromU32)]
This commit is contained in:
@@ -6,7 +6,6 @@ use rustc_abi::Align;
|
||||
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
|
||||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_index::IndexVec;
|
||||
use rustc_macros::TryFromU32;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::RemapFileNameExt;
|
||||
use rustc_session::config::RemapPathScopeComponents;
|
||||
@@ -16,7 +15,7 @@ use tracing::debug;
|
||||
use crate::common::CodegenCx;
|
||||
use crate::coverageinfo::llvm_cov;
|
||||
use crate::coverageinfo::mapgen::covfun::prepare_covfun_record;
|
||||
use crate::llvm;
|
||||
use crate::{TryFromU32, llvm};
|
||||
|
||||
mod covfun;
|
||||
mod spans;
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#![feature(if_let_guard)]
|
||||
#![feature(impl_trait_in_assoc_type)]
|
||||
#![feature(iter_intersperse)]
|
||||
#![feature(macro_derive)]
|
||||
#![feature(rustdoc_internals)]
|
||||
#![feature(slice_as_array)]
|
||||
#![feature(try_blocks)]
|
||||
@@ -65,6 +66,7 @@ mod errors;
|
||||
mod intrinsic;
|
||||
mod llvm;
|
||||
mod llvm_util;
|
||||
mod macros;
|
||||
mod mono_item;
|
||||
mod type_;
|
||||
mod type_of;
|
||||
@@ -74,6 +76,8 @@ mod value;
|
||||
|
||||
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
|
||||
|
||||
pub(crate) use macros::TryFromU32;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LlvmCodegenBackend(());
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ use std::ptr;
|
||||
|
||||
use bitflags::bitflags;
|
||||
use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};
|
||||
use rustc_macros::TryFromU32;
|
||||
|
||||
use super::RustString;
|
||||
use super::debuginfo::{
|
||||
@@ -27,8 +26,8 @@ use super::debuginfo::{
|
||||
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
|
||||
DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
|
||||
};
|
||||
use crate::llvm;
|
||||
use crate::llvm::MetadataKindId;
|
||||
use crate::{TryFromU32, llvm};
|
||||
|
||||
/// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`,
|
||||
/// which has a different ABI from Rust or C++ `bool`.
|
||||
|
||||
22
compiler/rustc_codegen_llvm/src/macros.rs
Normal file
22
compiler/rustc_codegen_llvm/src/macros.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
macro_rules! TryFromU32 {
|
||||
derive() (
|
||||
$(#[$meta:meta])*
|
||||
$vis:vis enum $Type:ident {
|
||||
$(
|
||||
$(#[$varmeta:meta])*
|
||||
$Variant:ident $(= $discr:expr)?
|
||||
),* $(,)?
|
||||
}
|
||||
) => {
|
||||
impl ::core::convert::TryFrom<u32> for $Type {
|
||||
type Error = u32;
|
||||
#[allow(deprecated)] // Don't warn about deprecated variants.
|
||||
fn try_from(value: u32) -> ::core::result::Result<$Type, Self::Error> {
|
||||
$( if value == const { $Type::$Variant as u32 } { return Ok($Type::$Variant) } )*
|
||||
Err(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) use TryFromU32;
|
||||
Reference in New Issue
Block a user