Use diagnostic items to check for Send, UnwindSafe and RefUnwindSafe traits

This commit is contained in:
Roxane Fruytier 2021-06-29 14:17:25 -04:00 committed by Roxane
parent 3e569dd2df
commit 06afafd492
3 changed files with 9 additions and 7 deletions

View File

@ -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();

View File

@ -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`");
}

View File

@ -133,7 +133,7 @@ pub fn panic_any<M: 'static + Any + Send>(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",