]> git.lizzy.rs Git - rust.git/commitdiff
Replace "rc"/"arc" lang items with Rc/Arc diagnostic items.
authorEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 8 Apr 2020 01:26:48 +0000 (04:26 +0300)
committerEduard-Mihai Burtescu <edy.burt@gmail.com>
Wed, 8 Apr 2020 07:47:41 +0000 (10:47 +0300)
17 files changed:
src/liballoc/rc.rs
src/liballoc/sync.rs
src/librustc_error_codes/error_codes/E0152.md
src/librustc_error_codes/error_codes/E0718.md
src/librustc_hir/lang_items.rs
src/librustc_middle/ty/context.rs
src/librustc_middle/ty/mod.rs
src/librustc_middle/ty/sty.rs
src/librustc_mir/borrow_check/diagnostics/mod.rs
src/librustc_mir/borrow_check/diagnostics/move_errors.rs
src/librustc_mir/borrow_check/diagnostics/mutability_errors.rs
src/librustc_span/symbol.rs
src/librustc_typeck/check/expr.rs
src/test/ui/error-codes/E0152.rs
src/test/ui/error-codes/E0152.stderr
src/test/ui/error-codes/E0718.rs
src/test/ui/error-codes/E0718.stderr

index 9db997e864170f2d9028668c1c72de150508e6a3..abc4056cf5695746d93fa37e992972146ab9781f 100644 (file)
@@ -279,7 +279,8 @@ struct RcBox<T: ?Sized> {
 /// type `T`.
 ///
 /// [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")]
 pub struct Rc<T: ?Sized> {
     ptr: NonNull<RcBox<T>>,
index 1cfb26eb35a113097a6d7200251c99763f520b74..b1b22e46a7c2fd0766b9e5ee671a9e11d3641010 100644 (file)
@@ -207,7 +207,8 @@ macro_rules! acquire {
 /// counting in general.
 ///
 /// [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")]
 pub struct Arc<T: ?Sized> {
     ptr: NonNull<ArcInner<T>>,
index 602dcb6e2c5b754fe6023a07c2f570145d5df02f..120c96b421104b4d2de741fc9e8f691c0db492ec 100644 (file)
@@ -5,8 +5,8 @@ Erroneous code example:
 ```compile_fail,E0152
 #![feature(lang_items)]
 
-#[lang = "arc"]
-struct Foo; // error: duplicate lang item found: `arc`
+#[lang = "owned_box"]
+struct Foo; // error: duplicate lang item found: `owned_box`
 ```
 
 Lang items are already implemented in the standard library. Unless you are
index 8548ff0c150118cbc86b72e63959503ffb13f1e3..e7ae51ca58835b12ca488205978f56b914c21fd7 100644 (file)
@@ -6,6 +6,6 @@ Examples of erroneous code:
 ```compile_fail,E0718
 #![feature(lang_items)]
 
-#[lang = "arc"]
+#[lang = "owned_box"]
 static X: u32 = 42;
 ```
index 89457009a8bfa4d32dbe533e91b99e44947a1a7d..5a3a9cabeb450d252c211f525da4363e47a04e4a 100644 (file)
@@ -254,7 +254,4 @@ pub fn extract(attrs: &[ast::Attribute]) -> Option<(Symbol, Span)> {
     AlignOffsetLangItem,         "align_offset",       align_offset_fn,         Target::Fn;
 
     TerminationTraitLangItem,    "termination",        termination,             Target::Trait;
-
-    Arc,                         "arc",                arc,                     Target::Struct;
-    Rc,                          "rc",                 rc,                      Target::Struct;
 }
index 95d0c758d08dea9b0035e012cc5f5518b5d85467..076134b8e9462c630cb61459331d40d084ff277a 100644 (file)
@@ -2213,6 +2213,12 @@ pub fn mk_lang_item(self, ty: Ty<'tcx>, item: lang_items::LangItem) -> Option<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]
     pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
         let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
index 1870856150f50a4342cb15c228ab5c3677d7728a..3683ea3288feb10909c1260b72dc12939db67f7d 100644 (file)
@@ -1856,14 +1856,9 @@ pub struct AdtFlags: u32 {
         const IS_BOX              = 1 << 6;
         /// Indicates whether the type is `ManuallyDrop`.
         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]`.
         /// (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;
     }
 }
 
@@ -2248,12 +2243,6 @@ fn new(
         if Some(did) == tcx.lang_items().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 }
     }
@@ -2332,16 +2321,6 @@ pub fn is_phantom_data(&self) -> bool {
         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>.
     #[inline]
     pub fn is_box(&self) -> bool {
index f09327886872ceb4ba4c5e196fcc7ed867e09803..fbd5049b0fbcb6789abeaa64ae463f736e04fa90 100644 (file)
@@ -1865,24 +1865,6 @@ pub fn is_any_ptr(&self) -> bool {
         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]
     pub fn is_box(&self) -> bool {
         match self.kind {
index 619ae0ff8faa1468972e73efb00285224ce2b358..404cc0c74679fb16591c6739598f8c10b04b16c3 100644 (file)
@@ -11,7 +11,7 @@
 };
 use rustc_middle::ty::print::Print;
 use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt};
-use rustc_span::Span;
+use rustc_span::{symbol::sym, Span};
 use rustc_target::abi::VariantIdx;
 
 use super::borrow_set::BorrowData;
@@ -632,20 +632,20 @@ pub(super) enum 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 {
             BorrowedContentSource::DerefRawPointer => "a raw pointer".to_string(),
             BorrowedContentSource::DerefSharedRef => "a shared reference".to_string(),
             BorrowedContentSource::DerefMutableRef => "a mutable reference".to_string(),
-            BorrowedContentSource::OverloadedDeref(ty) => {
-                if ty.is_rc() {
+            BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
+                ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
                     "an `Rc`".to_string()
-                } else if ty.is_arc() {
+                }
+                ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
                     "an `Arc`".to_string()
-                } else {
-                    format!("dereference of `{}`", ty)
                 }
-            }
+                _ => format!("dereference of `{}`", ty),
+            },
             BorrowedContentSource::OverloadedIndex(ty) => format!("index of `{}`", ty),
         }
     }
@@ -662,22 +662,22 @@ pub(super) fn describe_for_named_place(&self) -> Option<&'static str> {
         }
     }
 
-    pub(super) fn describe_for_immutable_place(&self) -> String {
+    pub(super) fn describe_for_immutable_place(&self, tcx: TyCtxt<'_>) -> String {
         match *self {
             BorrowedContentSource::DerefRawPointer => "a `*const` pointer".to_string(),
             BorrowedContentSource::DerefSharedRef => "a `&` reference".to_string(),
             BorrowedContentSource::DerefMutableRef => {
                 bug!("describe_for_immutable_place: DerefMutableRef isn't immutable")
             }
-            BorrowedContentSource::OverloadedDeref(ty) => {
-                if ty.is_rc() {
+            BorrowedContentSource::OverloadedDeref(ty) => match ty.kind {
+                ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Rc, def.did) => {
                     "an `Rc`".to_string()
-                } else if ty.is_arc() {
+                }
+                ty::Adt(def, _) if tcx.is_diagnostic_item(sym::Arc, def.did) => {
                     "an `Arc`".to_string()
-                } else {
-                    format!("a dereference of `{}`", ty)
                 }
-            }
+                _ => format!("a dereference of `{}`", ty),
+            },
             BorrowedContentSource::OverloadedIndex(ty) => format!("an index of `{}`", ty),
         }
     }
index d32533b6ce9a1a35ac98414e83a7c8c0f8892e05..1fbecb75dff531b3787bd5bbbeb2d1086177500e 100644 (file)
@@ -377,7 +377,10 @@ fn report_cannot_move_from_borrowed_content(
                         span,
                         &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),
+                    ),
                 }
             }
         };
index 35edd3d803db93460d2693205c94800c56110a10..635c299cf81364c0a5f82a5e2d3e96d17a20851d 100644 (file)
@@ -120,7 +120,7 @@ pub(crate) fn report_mutability_error(
                         local: the_place_err.local,
                         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);
                     if let Some(desc) = access_place_desc {
                         item_msg = format!("`{}`", desc);
index 54b404e1161b9313d9d1799ba5121e7ecaf6b8e2..6845cb3b9a35258477360e67c5c64b84134856f7 100644 (file)
         any,
         arbitrary_enum_discriminant,
         arbitrary_self_types,
+        Arc,
         Arguments,
         ArgumentV1,
         arm_target_feature,
         raw_dylib,
         raw_identifiers,
         raw_ref_op,
+        Rc,
         Ready,
         reason,
         recursion_limit,
index 9c57ffaf055acae2db713be6709fb57a30135c09..57e2349bb2e803f037d66cc6e98d22399636f7db 100644 (file)
@@ -902,8 +902,8 @@ fn report_extended_method_error(
         error: MethodError<'tcx>,
     ) {
         let rcvr = &args[0];
-        let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, rcvr_t, lang_item| {
-            if let Some(new_rcvr_t) = self.tcx.mk_lang_item(rcvr_t, lang_item) {
+        let try_alt_rcvr = |err: &mut DiagnosticBuilder<'_>, new_rcvr_t| {
+            if let Some(new_rcvr_t) = new_rcvr_t {
                 if let Ok(pick) = self.lookup_probe(
                     span,
                     segment.ident,
@@ -931,10 +931,10 @@ fn report_extended_method_error(
                 // Try alternative arbitrary self types that could fulfill this call.
                 // FIXME: probe for all types that *could* be arbitrary self-types, not
                 // just this whitelist.
-                try_alt_rcvr(&mut err, rcvr_t, lang_items::OwnedBoxLangItem);
-                try_alt_rcvr(&mut err, rcvr_t, lang_items::PinTypeLangItem);
-                try_alt_rcvr(&mut err, rcvr_t, lang_items::Arc);
-                try_alt_rcvr(&mut err, rcvr_t, lang_items::Rc);
+                try_alt_rcvr(&mut err, self.tcx.mk_lang_item(rcvr_t, lang_items::OwnedBoxLangItem));
+                try_alt_rcvr(&mut err, self.tcx.mk_lang_item(rcvr_t, lang_items::PinTypeLangItem));
+                try_alt_rcvr(&mut err, self.tcx.mk_diagnostic_item(rcvr_t, sym::Arc));
+                try_alt_rcvr(&mut err, self.tcx.mk_diagnostic_item(rcvr_t, sym::Rc));
             }
             err.emit();
         }
index dcaf9208835438b0f94f46980236bd224f376117..94467b9bddeb0a900d314e889cef8bbb652dec99 100644 (file)
@@ -1,6 +1,6 @@
 #![feature(lang_items)]
 
-#[lang = "arc"]
+#[lang = "owned_box"]
 struct Foo; //~ ERROR E0152
 
 fn main() {
index 29981991ee02b7cab6c264edac67ba9cbda4ffcf..fbaa276ce1093cad78379e3e96a033cf9421cd76 100644 (file)
@@ -1,4 +1,4 @@
-error[E0152]: found duplicate lang item `arc`
+error[E0152]: found duplicate lang item `owned_box`
   --> $DIR/E0152.rs:4:1
    |
 LL | struct Foo;
index 82ab2d4af1ba82f73dcd2c342c09601197c94283..909cae0ba25a210d2380acc48118a6c92058c5de 100644 (file)
@@ -1,7 +1,7 @@
 #![feature(lang_items)]
 
-// Arc is expected to be a struct, so this will error.
-#[lang = "arc"] //~ ERROR language item must be applied to a struct
+// Box is expected to be a struct, so this will error.
+#[lang = "owned_box"] //~ ERROR language item must be applied to a struct
 static X: u32 = 42;
 
 fn main() {}
index 412c856ce065a72bc028f1b20a20c12c9be8ae05..30378dd167457dcd3cb74aaf3f2fd868733d3077 100644 (file)
@@ -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
    |
-LL | #[lang = "arc"]
-   | ^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
+LL | #[lang = "owned_box"]
+   | ^^^^^^^^^^^^^^^^^^^^^ attribute should be applied to a struct, not a static item
 
 error: aborting due to previous error