From 3e569dd2dff023378debce3b98e19bf3ef8c6904 Mon Sep 17 00:00:00 2001 From: Roxane Fruytier Date: Tue, 29 Jun 2021 14:15:58 -0400 Subject: [PATCH 1/3] Remove lang items Send, UnwindSafe and RefUnwindSafe --- compiler/rustc_hir/src/lang_items.rs | 3 --- compiler/rustc_passes/src/lang_items.rs | 3 --- compiler/rustc_span/src/symbol.rs | 5 ++--- library/core/src/marker.rs | 3 +++ library/std/src/panic.rs | 4 ++-- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index bab685006eafc..28ae08030e630 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -348,7 +348,4 @@ language_item_table! { Range, sym::Range, range_struct, Target::Struct; RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct; RangeTo, sym::RangeTo, range_to_struct, Target::Struct; - Send, sym::send, send_trait, Target::Trait; - UnwindSafe, sym::unwind_safe, unwind_safe_trait, Target::Trait; - RefUnwindSafe, sym::ref_unwind_safe, ref_unwind_safe_trait, Target::Trait; } diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index 118fcca4508ea..f57f5fd56d284 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -257,9 +257,6 @@ impl LanguageItemCollector<'tcx> { | LangItem::Unpin | LangItem::Termination | LangItem::Try - | LangItem::Send - | LangItem::UnwindSafe - | LangItem::RefUnwindSafe => Some(0), // Not a trait diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index be4f12c6d1cb8..38e19dcb678aa 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -947,7 +947,7 @@ symbols! { receiver, recursion_limit, reexport_test_harness_main, - ref_unwind_safe, + ref_unwind_safe_trait, reference, reflect, reg, @@ -1073,7 +1073,6 @@ symbols! { self_in_typedefs, self_struct_ctor, semitransparent, - send, send_trait, shl, shl_assign, @@ -1299,7 +1298,7 @@ symbols! { unused_qualifications, unwind, unwind_attributes, - unwind_safe, + unwind_safe_trait, unwrap, unwrap_or, use_extern_macros, diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 271565693d66e..d00fb2284b884 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -31,7 +31,10 @@ use crate::hash::Hasher; /// [ub]: ../../reference/behavior-considered-undefined.html #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "send_trait")] +<<<<<<< HEAD #[lang = "send"] +======= +>>>>>>> Remove lang items Send, UnwindSafe and RefUnwindSafe #[rustc_on_unimplemented( message = "`{Self}` cannot be sent between threads safely", label = "`{Self}` cannot be sent between threads safely" diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index ee069eefd4541..7931c4c0a5fca 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -133,7 +133,7 @@ pub fn panic_any(msg: M) -> ! { /// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be /// implemented for any closed over variables passed to `catch_unwind`. #[stable(feature = "catch_unwind", since = "1.9.0")] -#[cfg_attr(not(test), lang = "unwind_safe")] +#[rustc_diagnostic_item = "unwind_safe_trait"] #[rustc_on_unimplemented( message = "the type `{Self}` may not be safely transferred across an unwind boundary", label = "`{Self}` may not be safely transferred across an unwind boundary" @@ -149,7 +149,7 @@ pub auto trait UnwindSafe {} /// This is a "helper marker trait" used to provide impl blocks for the /// [`UnwindSafe`] trait, for more information see that documentation. #[stable(feature = "catch_unwind", since = "1.9.0")] -#[cfg_attr(not(test), lang = "ref_unwind_safe")] +#[rustc_diagnostic_item = "ref_unwind_safe_trait"] #[rustc_on_unimplemented( message = "the type `{Self}` may contain interior mutability and a reference may not be safely \ transferrable across a catch_unwind boundary", From 06afafd492c151d0521240bbee94a595a4e006e5 Mon Sep 17 00:00:00 2001 From: Roxane Fruytier Date: Tue, 29 Jun 2021 14:17:25 -0400 Subject: [PATCH 2/3] Use diagnostic items to check for Send, UnwindSafe and RefUnwindSafe traits --- .../src/traits/error_reporting/suggestions.rs | 6 ++++-- compiler/rustc_typeck/src/check/upvar.rs | 6 +++--- library/std/src/panic.rs | 4 ++-- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 5c35b515f3d02..13c14d26b70f4 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -690,12 +690,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { // Blacklist traits for which it would be nonsensical to suggest borrowing. // For instance, immutable references are always Copy, so suggesting to // borrow would always succeed, but it's probably not what the user wanted. - let blacklist: Vec<_> = - [LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized, LangItem::Send] + let mut blacklist: Vec<_> = + [LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized] .iter() .filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok()) .collect(); + blacklist.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap()); + let span = obligation.cause.span; let param_env = obligation.param_env; let trait_ref = trait_ref.skip_binder(); diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 7b5b14ae6c831..197c4e3b319ab 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -663,7 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.need_2229_migrations_for_trait( min_captures, var_hir_id, - tcx.lang_items().send_trait(), + tcx.get_diagnostic_item(sym::send_trait), ) { auto_trait_reasons.insert("`Send`"); } @@ -679,7 +679,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.need_2229_migrations_for_trait( min_captures, var_hir_id, - tcx.lang_items().unwind_safe_trait(), + tcx.get_diagnostic_item(sym::unwind_safe_trait), ) { auto_trait_reasons.insert("`UnwindSafe`"); } @@ -687,7 +687,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if self.need_2229_migrations_for_trait( min_captures, var_hir_id, - tcx.lang_items().ref_unwind_safe_trait(), + tcx.get_diagnostic_item(sym::ref_unwind_safe_trait), ) { auto_trait_reasons.insert("`RefUnwindSafe`"); } diff --git a/library/std/src/panic.rs b/library/std/src/panic.rs index 7931c4c0a5fca..7bc987db8814b 100644 --- a/library/std/src/panic.rs +++ b/library/std/src/panic.rs @@ -133,7 +133,7 @@ pub fn panic_any(msg: M) -> ! { /// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be /// implemented for any closed over variables passed to `catch_unwind`. #[stable(feature = "catch_unwind", since = "1.9.0")] -#[rustc_diagnostic_item = "unwind_safe_trait"] +#[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")] #[rustc_on_unimplemented( message = "the type `{Self}` may not be safely transferred across an unwind boundary", label = "`{Self}` may not be safely transferred across an unwind boundary" @@ -149,7 +149,7 @@ pub auto trait UnwindSafe {} /// This is a "helper marker trait" used to provide impl blocks for the /// [`UnwindSafe`] trait, for more information see that documentation. #[stable(feature = "catch_unwind", since = "1.9.0")] -#[rustc_diagnostic_item = "ref_unwind_safe_trait"] +#[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")] #[rustc_on_unimplemented( message = "the type `{Self}` may contain interior mutability and a reference may not be safely \ transferrable across a catch_unwind boundary", From cc3af7091caeaf91851f2999dea3225d0d5d39b0 Mon Sep 17 00:00:00 2001 From: Roxane Date: Tue, 29 Jun 2021 20:26:37 -0400 Subject: [PATCH 3/3] Rename variable --- .../src/traits/error_reporting/suggestions.rs | 10 +++++----- library/core/src/marker.rs | 4 ---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 13c14d26b70f4..b85d2a50f0579 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -687,16 +687,16 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { return false; } - // Blacklist traits for which it would be nonsensical to suggest borrowing. + // List of traits for which it would be nonsensical to suggest borrowing. // For instance, immutable references are always Copy, so suggesting to // borrow would always succeed, but it's probably not what the user wanted. - let mut blacklist: Vec<_> = + let mut never_suggest_borrow: Vec<_> = [LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized] .iter() .filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok()) .collect(); - blacklist.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap()); + never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap()); let span = obligation.cause.span; let param_env = obligation.param_env; @@ -799,7 +799,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ty::TraitRef::new(trait_ref.def_id, imm_substs), trait_ref, false, - &blacklist[..], + &never_suggest_borrow[..], ) { return true; } else { @@ -807,7 +807,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> { ty::TraitRef::new(trait_ref.def_id, mut_substs), trait_ref, true, - &blacklist[..], + &never_suggest_borrow[..], ); } } else { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index d00fb2284b884..fb957348bebd3 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -31,10 +31,6 @@ use crate::hash::Hasher; /// [ub]: ../../reference/behavior-considered-undefined.html #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "send_trait")] -<<<<<<< HEAD -#[lang = "send"] -======= ->>>>>>> Remove lang items Send, UnwindSafe and RefUnwindSafe #[rustc_on_unimplemented( message = "`{Self}` cannot be sent between threads safely", label = "`{Self}` cannot be sent between threads safely"