Rollup merge of #70913 - eddyb:rc-arc-diagnostic-items, r=matthewjasper
Replace "rc"/"arc" lang items with Rc/Arc diagnostic items. `Rc`/`Arc` should have no special semantics, so it seems appropriate for them to not be lang items. r? @matthewjasper
This commit is contained in:
commit
74e93bb8e6
|
@ -279,7 +279,8 @@ struct RcBox<T: ?Sized> {
|
||||||
/// type `T`.
|
/// type `T`.
|
||||||
///
|
///
|
||||||
/// [get_mut]: #method.get_mut
|
/// [get_mut]: #method.get_mut
|
||||||
#[cfg_attr(not(test), lang = "rc")]
|
#[cfg_attr(all(bootstrap, not(test)), lang = "rc")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Rc")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Rc<T: ?Sized> {
|
pub struct Rc<T: ?Sized> {
|
||||||
ptr: NonNull<RcBox<T>>,
|
ptr: NonNull<RcBox<T>>,
|
||||||
|
|
|
@ -207,7 +207,8 @@ macro_rules! acquire {
|
||||||
/// counting in general.
|
/// counting in general.
|
||||||
///
|
///
|
||||||
/// [rc_examples]: ../../std/rc/index.html#examples
|
/// [rc_examples]: ../../std/rc/index.html#examples
|
||||||
#[cfg_attr(not(test), lang = "arc")]
|
#[cfg_attr(all(bootstrap, not(test)), lang = "arc")]
|
||||||
|
#[cfg_attr(not(test), rustc_diagnostic_item = "Arc")]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
pub struct Arc<T: ?Sized> {
|
pub struct Arc<T: ?Sized> {
|
||||||
ptr: NonNull<ArcInner<T>>,
|
ptr: NonNull<ArcInner<T>>,
|
||||||
|
|
|
@ -5,8 +5,8 @@ Erroneous code example:
|
||||||
```compile_fail,E0152
|
```compile_fail,E0152
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
|
|
||||||
#[lang = "arc"]
|
#[lang = "owned_box"]
|
||||||
struct Foo; // error: duplicate lang item found: `arc`
|
struct Foo; // error: duplicate lang item found: `owned_box`
|
||||||
```
|
```
|
||||||
|
|
||||||
Lang items are already implemented in the standard library. Unless you are
|
Lang items are already implemented in the standard library. Unless you are
|
||||||
|
|
|
@ -6,6 +6,6 @@ Examples of erroneous code:
|
||||||
```compile_fail,E0718
|
```compile_fail,E0718
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
|
|
||||||
#[lang = "arc"]
|
#[lang = "owned_box"]
|
||||||
static X: u32 = 42;
|
static X: u32 = 42;
|
||||||
```
|
```
|
||||||
|
|
|
@ -254,7 +254,4 @@ language_item_table! {
|
||||||
AlignOffsetLangItem, "align_offset", align_offset_fn, Target::Fn;
|
AlignOffsetLangItem, "align_offset", align_offset_fn, Target::Fn;
|
||||||
|
|
||||||
TerminationTraitLangItem, "termination", termination, Target::Trait;
|
TerminationTraitLangItem, "termination", termination, Target::Trait;
|
||||||
|
|
||||||
Arc, "arc", arc, Target::Struct;
|
|
||||||
Rc, "rc", rc, Target::Struct;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2209,6 +2209,12 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
Some(self.mk_generic_adt(def_id, ty))
|
Some(self.mk_generic_adt(def_id, ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn mk_diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option<Ty<'tcx>> {
|
||||||
|
let def_id = self.get_diagnostic_item(name)?;
|
||||||
|
Some(self.mk_generic_adt(def_id, ty))
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
|
||||||
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
|
let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
|
||||||
|
|
|
@ -1829,14 +1829,9 @@ bitflags! {
|
||||||
const IS_BOX = 1 << 6;
|
const IS_BOX = 1 << 6;
|
||||||
/// Indicates whether the type is `ManuallyDrop`.
|
/// Indicates whether the type is `ManuallyDrop`.
|
||||||
const IS_MANUALLY_DROP = 1 << 7;
|
const IS_MANUALLY_DROP = 1 << 7;
|
||||||
// FIXME(matthewjasper) replace these with diagnostic items
|
|
||||||
/// Indicates whether the type is an `Arc`.
|
|
||||||
const IS_ARC = 1 << 8;
|
|
||||||
/// Indicates whether the type is an `Rc`.
|
|
||||||
const IS_RC = 1 << 9;
|
|
||||||
/// Indicates whether the variant list of this ADT is `#[non_exhaustive]`.
|
/// Indicates whether the variant list of this ADT is `#[non_exhaustive]`.
|
||||||
/// (i.e., this flag is never set unless this ADT is an enum).
|
/// (i.e., this flag is never set unless this ADT is an enum).
|
||||||
const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 10;
|
const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2221,12 +2216,6 @@ impl<'tcx> AdtDef {
|
||||||
if Some(did) == tcx.lang_items().manually_drop() {
|
if Some(did) == tcx.lang_items().manually_drop() {
|
||||||
flags |= AdtFlags::IS_MANUALLY_DROP;
|
flags |= AdtFlags::IS_MANUALLY_DROP;
|
||||||
}
|
}
|
||||||
if Some(did) == tcx.lang_items().arc() {
|
|
||||||
flags |= AdtFlags::IS_ARC;
|
|
||||||
}
|
|
||||||
if Some(did) == tcx.lang_items().rc() {
|
|
||||||
flags |= AdtFlags::IS_RC;
|
|
||||||
}
|
|
||||||
|
|
||||||
AdtDef { did, variants, flags, repr }
|
AdtDef { did, variants, flags, repr }
|
||||||
}
|
}
|
||||||
|
@ -2305,16 +2294,6 @@ impl<'tcx> AdtDef {
|
||||||
self.flags.contains(AdtFlags::IS_PHANTOM_DATA)
|
self.flags.contains(AdtFlags::IS_PHANTOM_DATA)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this is `Arc<T>`.
|
|
||||||
pub fn is_arc(&self) -> bool {
|
|
||||||
self.flags.contains(AdtFlags::IS_ARC)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this is `Rc<T>`.
|
|
||||||
pub fn is_rc(&self) -> bool {
|
|
||||||
self.flags.contains(AdtFlags::IS_RC)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this is Box<T>.
|
/// Returns `true` if this is Box<T>.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_box(&self) -> bool {
|
pub fn is_box(&self) -> bool {
|
||||||
|
|
|
@ -1864,24 +1864,6 @@ impl<'tcx> TyS<'tcx> {
|
||||||
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
|
self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns `true` if this type is an `Arc<T>`.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_arc(&self) -> bool {
|
|
||||||
match self.kind {
|
|
||||||
Adt(def, _) => def.is_arc(),
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns `true` if this type is an `Rc<T>`.
|
|
||||||
#[inline]
|
|
||||||
pub fn is_rc(&self) -> bool {
|
|
||||||
match self.kind {
|
|
||||||
Adt(def, _) => def.is_rc(),
|
|
||||||
_ => false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn is_box(&self) -> bool {
|
pub fn is_box(&self) -> bool {
|
||||||
match self.kind {
|
match self.kind {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use rustc_middle::mir::{
|
||||||
};
|
};
|
||||||
use rustc_middle::ty::print::Print;
|
use rustc_middle::ty::print::Print;
|
||||||
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
|
use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
|
||||||
use rustc_span::Span;
|
use rustc_span::{symbol::sym, Span};
|
||||||
use rustc_target::abi::VariantIdx;
|
use rustc_target::abi::VariantIdx;
|
||||||
|
|
||||||
use super::borrow_set::BorrowData;
|
use super::borrow_set::BorrowData;
|
||||||
|
@ -632,20 +632,20 @@ pub(super) enum BorrowedContentSource<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BorrowedContentSource<'tcx> {
|
impl BorrowedContentSource<'tcx> {
|
||||||
pub(super) fn describe_for_unnamed_place(&self) -> String {
|
pub(super) fn describe_for_unnamed_place(&self, tcx: TyCtxt<'_>) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(),
|
BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(),
|
||||||
BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(),
|
BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(),
|
||||||
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
|
BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
|
||||||
BorrowedContentSource::OverloadedDeref(ty) => {
|
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
|
||||||
if ty.is_rc() {
|
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
|
||||||
"an `Rc`".to_string()
|
"an `Rc`".to_string()
|
||||||
} else if ty.is_arc() {
|
|
||||||
"an `Arc`".to_string()
|
|
||||||
} else {
|
|
||||||
format!("dereference of `{}`", ty)
|
|
||||||
}
|
}
|
||||||
}
|
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
|
||||||
|
"an `Arc`".to_string()
|
||||||
|
}
|
||||||
|
_ => format!("dereference of `{}`", ty),
|
||||||
|
},
|
||||||
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
|
BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -662,22 +662,22 @@ impl BorrowedContentSource<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn describe_for_immutable_place(&self) -> String {
|
pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> String {
|
||||||
match *self {
|
match *self {
|
||||||
BorrowedContentSource::DerefRawPointer => "a `*const` pointer".to_string(),
|
BorrowedContentSource::DerefRawPointer => "a `*const` pointer".to_string(),
|
||||||
BorrowedContentSource::DerefSharedRef => "a `&` reference".to_string(),
|
BorrowedContentSource::DerefSharedRef => "a `&` reference".to_string(),
|
||||||
BorrowedContentSource::DerefMutableRef => {
|
BorrowedContentSource::DerefMutableRef => {
|
||||||
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
|
bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
|
||||||
}
|
}
|
||||||
BorrowedContentSource::OverloadedDeref(ty) => {
|
BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
|
||||||
if ty.is_rc() {
|
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
|
||||||
"an `Rc`".to_string()
|
"an `Rc`".to_string()
|
||||||
} else if ty.is_arc() {
|
|
||||||
"an `Arc`".to_string()
|
|
||||||
} else {
|
|
||||||
format!("a dereference of `{}`", ty)
|
|
||||||
}
|
}
|
||||||
}
|
ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
|
||||||
|
"an `Arc`".to_string()
|
||||||
|
}
|
||||||
|
_ => format!("a dereference of `{}`", ty),
|
||||||
|
},
|
||||||
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
|
BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,7 +377,10 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
span,
|
span,
|
||||||
&format!("`{}` which is behind a {}", place_desc, source_desc),
|
&format!("`{}` which is behind a {}", place_desc, source_desc),
|
||||||
),
|
),
|
||||||
(_, _) => self.cannot_move_out_of(span, &source.describe_for_unnamed_place()),
|
(_, _) => self.cannot_move_out_of(
|
||||||
|
span,
|
||||||
|
&source.describe_for_unnamed_place(self.infcx.tcx),
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
local: the_place_err.local,
|
local: the_place_err.local,
|
||||||
projection: proj_base,
|
projection: proj_base,
|
||||||
});
|
});
|
||||||
let pointer_type = source.describe_for_immutable_place();
|
let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);
|
||||||
opt_source = Some(source);
|
opt_source = Some(source);
|
||||||
if let Some(desc) = access_place_desc {
|
if let Some(desc) = access_place_desc {
|
||||||
item_msg = format!("`{}`", desc);
|
item_msg = format!("`{}`", desc);
|
||||||
|
|
|
@ -144,6 +144,7 @@ symbols! {
|
||||||
any,
|
any,
|
||||||
arbitrary_enum_discriminant,
|
arbitrary_enum_discriminant,
|
||||||
arbitrary_self_types,
|
arbitrary_self_types,
|
||||||
|
Arc,
|
||||||
Arguments,
|
Arguments,
|
||||||
ArgumentV1,
|
ArgumentV1,
|
||||||
arm_target_feature,
|
arm_target_feature,
|
||||||
|
@ -582,6 +583,7 @@ symbols! {
|
||||||
raw_dylib,
|
raw_dylib,
|
||||||
raw_identifiers,
|
raw_identifiers,
|
||||||
raw_ref_op,
|
raw_ref_op,
|
||||||
|
Rc,
|
||||||
Ready,
|
Ready,
|
||||||
reason,
|
reason,
|
||||||
recursion_limit,
|
recursion_limit,
|
||||||
|
|
|
@ -902,8 +902,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
error: MethodError<'tcx>,
|
error: MethodError<'tcx>,
|
||||||
) {
|
) {
|
||||||
let rcvr = &args[0];
|
let rcvr = &args[0];
|
||||||
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, rcvr_t, lang_item| {
|
let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, new_rcvr_t| {
|
||||||
if let Some(new_rcvr_t) = self.tcx.mk_lang_item(rcvr_t, lang_item) {
|
if let Some(new_rcvr_t) = new_rcvr_t {
|
||||||
if let Ok(pick) = self.lookup_probe(
|
if let Ok(pick) = self.lookup_probe(
|
||||||
span,
|
span,
|
||||||
segment.ident,
|
segment.ident,
|
||||||
|
@ -931,10 +931,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// Try alternative arbitrary self types that could fulfill this call.
|
// Try alternative arbitrary self types that could fulfill this call.
|
||||||
// FIXME: probe for all types that *could* be arbitrary self-types, not
|
// FIXME: probe for all types that *could* be arbitrary self-types, not
|
||||||
// just this whitelist.
|
// just this whitelist.
|
||||||
try_alt_rcvr(&mut err, rcvr_t, lang_items::OwnedBoxLangItem);
|
try_alt_rcvr(&mut err, self.tcx.mk_lang_item(rcvr_t, lang_items::OwnedBoxLangItem));
|
||||||
try_alt_rcvr(&mut err, rcvr_t, lang_items::PinTypeLangItem);
|
try_alt_rcvr(&mut err, self.tcx.mk_lang_item(rcvr_t, lang_items::PinTypeLangItem));
|
||||||
try_alt_rcvr(&mut err, rcvr_t, lang_items::Arc);
|
try_alt_rcvr(&mut err, self.tcx.mk_diagnostic_item(rcvr_t, sym::Arc));
|
||||||
try_alt_rcvr(&mut err, rcvr_t, lang_items::Rc);
|
try_alt_rcvr(&mut err, self.tcx.mk_diagnostic_item(rcvr_t, sym::Rc));
|
||||||
}
|
}
|
||||||
err.emit();
|
err.emit();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
|
|
||||||
#[lang = "arc"]
|
#[lang = "owned_box"]
|
||||||
struct Foo; //~ ERROR E0152
|
struct Foo; //~ ERROR E0152
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
error[E0152]: found duplicate lang item `arc`
|
error[E0152]: found duplicate lang item `owned_box`
|
||||||
--> $DIR/E0152.rs:4:1
|
--> $DIR/E0152.rs:4:1
|
||||||
|
|
|
|
||||||
LL | struct Foo;
|
LL | struct Foo;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
#![feature(lang_items)]
|
#![feature(lang_items)]
|
||||||
|
|
||||||
// Arc is expected to be a struct, so this will error.
|
// Box is expected to be a struct, so this will error.
|
||||||
#[lang = "arc"] //~ ERROR language item must be applied to a struct
|
#[lang = "owned_box"] //~ ERROR language item must be applied to a struct
|
||||||
static X: u32 = 42;
|
static X: u32 = 42;
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
error[E0718]: `arc` language item must be applied to a struct
|
error[E0718]: `owned_box` language item must be applied to a struct
|
||||||
--> $DIR/E0718.rs:4:1
|
--> $DIR/E0718.rs:4:1
|
||||||
|
|
|
|
||||||
LL | #[lang = "arc"]
|
LL | #[lang = "owned_box"]
|
||||||
| ^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
|
| ^^^^^^^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue