Skip to content

Commit

Permalink
make Cell & SyncUnsafeCell lang items instead of diagnostic items
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigorenkoPV committed Aug 23, 2024
1 parent a44d4f0 commit fc365d5
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ language_item_table! {
Index, sym::index, index_trait, Target::Trait, GenericRequirement::Exact(1);
IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1);


Cell, sym::cell, cell_type, Target::Struct, GenericRequirement::None;
UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None;
SyncUnsafeCell, sym::sync_unsafe_cell, sync_unsafe_cell_type, Target::Struct, GenericRequirement::None;
VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None;

Deref, sym::deref, deref_trait, Target::Trait, GenericRequirement::Exact(0);
Expand Down
11 changes: 7 additions & 4 deletions compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,10 +1261,13 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
ty::Adt(def, args) => {
if matches!(
tcx.as_lang_item(def.did()),
Some(LangItem::UnsafeCell | LangItem::ManuallyDrop | LangItem::MaybeUninit)
) || matches!(
tcx.get_diagnostic_name(def.did()),
Some(sym::Cell | sym::SyncUnsafeCell)
Some(
LangItem::Cell
| LangItem::UnsafeCell
| LangItem::SyncUnsafeCell
| LangItem::ManuallyDrop
| LangItem::MaybeUninit
)
) {
// These are the types from `std` that guarantee that
// they have the same layout as `T`.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ symbols! {
CallOnceFuture,
CallRefFuture,
Capture,
Cell,
Center,
Cleanup,
Clone,
Expand Down Expand Up @@ -322,7 +321,6 @@ symbols! {
SubdiagMessage,
Subdiagnostic,
Sync,
SyncUnsafeCell,
T,
Target,
ToOwned,
Expand Down Expand Up @@ -531,6 +529,7 @@ symbols! {
ceilf16,
ceilf32,
ceilf64,
cell,
cfg,
cfg_accessible,
cfg_attr,
Expand Down Expand Up @@ -1861,6 +1860,7 @@ symbols! {
surface_async_drop_in_place,
sym,
sync,
sync_unsafe_cell,
synthetic,
t32,
target,
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ pub use once::OnceCell;
/// ```
///
/// See the [module-level documentation](self) for more.
#[cfg_attr(not(test), rustc_diagnostic_item = "Cell")]
#[cfg_attr(not(bootstrap), lang = "cell")]
#[stable(feature = "rust1", since = "1.0.0")]
#[repr(transparent)]
pub struct Cell<T: ?Sized> {
Expand Down Expand Up @@ -2296,7 +2296,7 @@ impl<T> UnsafeCell<*mut T> {
/// making this type just as unsafe to use.
///
/// See [`UnsafeCell`] for details.
#[cfg_attr(not(test), rustc_diagnostic_item = "SyncUnsafeCell")]
#[cfg_attr(not(bootstrap), lang = "sync_unsafe_cell")]
#[unstable(feature = "sync_unsafe_cell", issue = "95439")]
#[repr(transparent)]
pub struct SyncUnsafeCell<T: ?Sized> {
Expand Down

0 comments on commit fc365d5

Please sign in to comment.