Implement the unsafe-fields RFC.
Co-Authored-By: Jacob Pratt <jacob@jhpratt.dev>
This commit is contained in:
parent
75703c1a78
commit
9022bb2d6f
38 changed files with 793 additions and 85 deletions
|
@ -15,6 +15,7 @@ use rustc_data_structures::sync::{Lock, Lrc, OnceLock};
|
|||
use rustc_data_structures::unhash::UnhashMap;
|
||||
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, DeriveProcMacro};
|
||||
use rustc_hir::Safety;
|
||||
use rustc_hir::def::Res;
|
||||
use rustc_hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::{DefPath, DefPathData};
|
||||
|
@ -1101,6 +1102,7 @@ impl<'a> CrateMetadataRef<'a> {
|
|||
did,
|
||||
name: self.item_name(did.index),
|
||||
vis: self.get_visibility(did.index),
|
||||
safety: self.get_safety(did.index),
|
||||
})
|
||||
.collect(),
|
||||
adt_kind,
|
||||
|
@ -1162,6 +1164,10 @@ impl<'a> CrateMetadataRef<'a> {
|
|||
.map_id(|index| self.local_def_id(index))
|
||||
}
|
||||
|
||||
fn get_safety(self, id: DefIndex) -> Safety {
|
||||
self.root.tables.safety.get(self, id).unwrap_or_else(|| self.missing("safety", id))
|
||||
}
|
||||
|
||||
fn get_trait_item_def_id(self, id: DefIndex) -> Option<DefId> {
|
||||
self.root.tables.trait_item_def_id.get(self, id).map(|d| d.decode_from_cdata(self))
|
||||
}
|
||||
|
|
|
@ -1599,6 +1599,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
f.did.index
|
||||
}));
|
||||
|
||||
for field in &variant.fields {
|
||||
self.tables.safety.set_some(field.did.index, field.safety);
|
||||
}
|
||||
|
||||
if let Some((CtorKind::Fn, ctor_def_id)) = variant.ctor {
|
||||
let fn_sig = tcx.fn_sig(ctor_def_id);
|
||||
// FIXME only encode signature for ctor_def_id
|
||||
|
|
|
@ -411,6 +411,7 @@ define_tables! {
|
|||
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
|
||||
def_kind: Table<DefIndex, DefKind>,
|
||||
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
|
||||
safety: Table<DefIndex, hir::Safety>,
|
||||
def_span: Table<DefIndex, LazyValue<Span>>,
|
||||
def_ident_span: Table<DefIndex, LazyValue<Span>>,
|
||||
lookup_stability: Table<DefIndex, LazyValue<attr::Stability>>,
|
||||
|
|
|
@ -198,6 +198,13 @@ fixed_size_enum! {
|
|||
}
|
||||
}
|
||||
|
||||
fixed_size_enum! {
|
||||
hir::Safety {
|
||||
( Unsafe )
|
||||
( Safe )
|
||||
}
|
||||
}
|
||||
|
||||
fixed_size_enum! {
|
||||
ty::Asyncness {
|
||||
( Yes )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue