Skip to content

Commit 06afafd

Browse files
committed
Use diagnostic items to check for Send, UnwindSafe and RefUnwindSafe traits
1 parent 3e569dd commit 06afafd

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,12 +690,14 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
690690
// Blacklist traits for which it would be nonsensical to suggest borrowing.
691691
// For instance, immutable references are always Copy, so suggesting to
692692
// borrow would always succeed, but it's probably not what the user wanted.
693-
let blacklist: Vec<_> =
694-
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized, LangItem::Send]
693+
let mut blacklist: Vec<_> =
694+
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized]
695695
.iter()
696696
.filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok())
697697
.collect();
698698

699+
blacklist.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap());
700+
699701
let span = obligation.cause.span;
700702
let param_env = obligation.param_env;
701703
let trait_ref = trait_ref.skip_binder();

compiler/rustc_typeck/src/check/upvar.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
663663
if self.need_2229_migrations_for_trait(
664664
min_captures,
665665
var_hir_id,
666-
tcx.lang_items().send_trait(),
666+
tcx.get_diagnostic_item(sym::send_trait),
667667
) {
668668
auto_trait_reasons.insert("`Send`");
669669
}
@@ -679,15 +679,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
679679
if self.need_2229_migrations_for_trait(
680680
min_captures,
681681
var_hir_id,
682-
tcx.lang_items().unwind_safe_trait(),
682+
tcx.get_diagnostic_item(sym::unwind_safe_trait),
683683
) {
684684
auto_trait_reasons.insert("`UnwindSafe`");
685685
}
686686

687687
if self.need_2229_migrations_for_trait(
688688
min_captures,
689689
var_hir_id,
690-
tcx.lang_items().ref_unwind_safe_trait(),
690+
tcx.get_diagnostic_item(sym::ref_unwind_safe_trait),
691691
) {
692692
auto_trait_reasons.insert("`RefUnwindSafe`");
693693
}

library/std/src/panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn panic_any<M: 'static + Any + Send>(msg: M) -> ! {
133133
/// [`AssertUnwindSafe`] wrapper struct can be used to force this trait to be
134134
/// implemented for any closed over variables passed to `catch_unwind`.
135135
#[stable(feature = "catch_unwind", since = "1.9.0")]
136-
#[rustc_diagnostic_item = "unwind_safe_trait"]
136+
#[cfg_attr(not(test), rustc_diagnostic_item = "unwind_safe_trait")]
137137
#[rustc_on_unimplemented(
138138
message = "the type `{Self}` may not be safely transferred across an unwind boundary",
139139
label = "`{Self}` may not be safely transferred across an unwind boundary"
@@ -149,7 +149,7 @@ pub auto trait UnwindSafe {}
149149
/// This is a "helper marker trait" used to provide impl blocks for the
150150
/// [`UnwindSafe`] trait, for more information see that documentation.
151151
#[stable(feature = "catch_unwind", since = "1.9.0")]
152-
#[rustc_diagnostic_item = "ref_unwind_safe_trait"]
152+
#[cfg_attr(not(test), rustc_diagnostic_item = "ref_unwind_safe_trait")]
153153
#[rustc_on_unimplemented(
154154
message = "the type `{Self}` may contain interior mutability and a reference may not be safely \
155155
transferrable across a catch_unwind boundary",

0 commit comments

Comments
 (0)