Skip to content

Commit

Permalink
Rollup merge of #86726 - sexxi-goose:use-diagnostic-item-for-rfc2229-…
Browse files Browse the repository at this point in the history
…migration, r=nikomatsakis

Use diagnostic items instead of lang items for rfc2229 migrations

This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in #84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations.

r? ```@nikomatsakis```
  • Loading branch information
GuillaumeGomez committed Jul 8, 2021
2 parents d9297ae + cc3af70 commit d12b168
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 20 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 0 additions & 3 deletions compiler/rustc_passes/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,6 @@ impl LanguageItemCollector<'tcx> {
| LangItem::Unpin
| LangItem::Termination
| LangItem::Try
| LangItem::Send
| LangItem::UnwindSafe
| LangItem::RefUnwindSafe
=> Some(0),

// Not a trait
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ symbols! {
receiver,
recursion_limit,
reexport_test_harness_main,
ref_unwind_safe,
ref_unwind_safe_trait,
reference,
reflect,
reg,
Expand Down Expand Up @@ -1073,7 +1073,6 @@ symbols! {
self_in_typedefs,
self_struct_ctor,
semitransparent,
send,
send_trait,
shl,
shl_assign,
Expand Down Expand Up @@ -1299,7 +1298,7 @@ symbols! {
unused_qualifications,
unwind,
unwind_attributes,
unwind_safe,
unwind_safe_trait,
unwrap,
unwrap_or,
use_extern_macros,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -688,15 +688,17 @@ 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 blacklist: Vec<_> =
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized, LangItem::Send]
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();

never_suggest_borrow.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();
Expand Down Expand Up @@ -798,15 +800,15 @@ 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 {
return try_borrowing(
ty::TraitRef::new(trait_ref.def_id, mut_substs),
trait_ref,
true,
&blacklist[..],
&never_suggest_borrow[..],
);
}
} else {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_typeck/src/check/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,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`");
}
Expand All @@ -686,15 +686,15 @@ 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`");
}

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`");
}
Expand Down
1 change: 0 additions & 1 deletion library/core/src/marker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +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")]
#[lang = "send"]
#[rustc_on_unimplemented(
message = "`{Self}` cannot be sent between threads safely",
label = "`{Self}` cannot be sent between threads safely"
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
#[cfg_attr(not(test), lang = "unwind_safe")]
#[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"
Expand All @@ -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")]
#[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",
Expand Down

0 comments on commit d12b168

Please sign in to comment.