Skip to content

Commit d12b168

Browse files
Rollup merge of rust-lang#86726 - sexxi-goose:use-diagnostic-item-for-rfc2229-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 rust-lang#84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations. r? ```@nikomatsakis```
2 parents d9297ae + cc3af70 commit d12b168

File tree

7 files changed

+14
-20
lines changed

7 files changed

+14
-20
lines changed

compiler/rustc_hir/src/lang_items.rs

-3
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,4 @@ language_item_table! {
348348
Range, sym::Range, range_struct, Target::Struct;
349349
RangeToInclusive, sym::RangeToInclusive, range_to_inclusive_struct, Target::Struct;
350350
RangeTo, sym::RangeTo, range_to_struct, Target::Struct;
351-
Send, sym::send, send_trait, Target::Trait;
352-
UnwindSafe, sym::unwind_safe, unwind_safe_trait, Target::Trait;
353-
RefUnwindSafe, sym::ref_unwind_safe, ref_unwind_safe_trait, Target::Trait;
354351
}

compiler/rustc_passes/src/lang_items.rs

-3
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,6 @@ impl LanguageItemCollector<'tcx> {
257257
| LangItem::Unpin
258258
| LangItem::Termination
259259
| LangItem::Try
260-
| LangItem::Send
261-
| LangItem::UnwindSafe
262-
| LangItem::RefUnwindSafe
263260
=> Some(0),
264261

265262
// Not a trait

compiler/rustc_span/src/symbol.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,7 @@ symbols! {
947947
receiver,
948948
recursion_limit,
949949
reexport_test_harness_main,
950-
ref_unwind_safe,
950+
ref_unwind_safe_trait,
951951
reference,
952952
reflect,
953953
reg,
@@ -1073,7 +1073,6 @@ symbols! {
10731073
self_in_typedefs,
10741074
self_struct_ctor,
10751075
semitransparent,
1076-
send,
10771076
send_trait,
10781077
shl,
10791078
shl_assign,
@@ -1299,7 +1298,7 @@ symbols! {
12991298
unused_qualifications,
13001299
unwind,
13011300
unwind_attributes,
1302-
unwind_safe,
1301+
unwind_safe_trait,
13031302
unwrap,
13041303
unwrap_or,
13051304
use_extern_macros,

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

+7-5
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,17 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
688688
return false;
689689
}
690690

691-
// Blacklist traits for which it would be nonsensical to suggest borrowing.
691+
// List of traits for which it would be nonsensical to suggest borrowing.
692692
// For instance, immutable references are always Copy, so suggesting to
693693
// borrow would always succeed, but it's probably not what the user wanted.
694-
let blacklist: Vec<_> =
695-
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized, LangItem::Send]
694+
let mut never_suggest_borrow: Vec<_> =
695+
[LangItem::Copy, LangItem::Clone, LangItem::Unpin, LangItem::Sized]
696696
.iter()
697697
.filter_map(|lang_item| self.tcx.lang_items().require(*lang_item).ok())
698698
.collect();
699699

700+
never_suggest_borrow.push(self.tcx.get_diagnostic_item(sym::send_trait).unwrap());
701+
700702
let span = obligation.cause.span;
701703
let param_env = obligation.param_env;
702704
let trait_ref = trait_ref.skip_binder();
@@ -798,15 +800,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
798800
ty::TraitRef::new(trait_ref.def_id, imm_substs),
799801
trait_ref,
800802
false,
801-
&blacklist[..],
803+
&never_suggest_borrow[..],
802804
) {
803805
return true;
804806
} else {
805807
return try_borrowing(
806808
ty::TraitRef::new(trait_ref.def_id, mut_substs),
807809
trait_ref,
808810
true,
809-
&blacklist[..],
811+
&never_suggest_borrow[..],
810812
);
811813
}
812814
} else {

compiler/rustc_typeck/src/check/upvar.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
670670
if self.need_2229_migrations_for_trait(
671671
min_captures,
672672
var_hir_id,
673-
tcx.lang_items().send_trait(),
673+
tcx.get_diagnostic_item(sym::send_trait),
674674
) {
675675
auto_trait_reasons.insert("`Send`");
676676
}
@@ -686,15 +686,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
686686
if self.need_2229_migrations_for_trait(
687687
min_captures,
688688
var_hir_id,
689-
tcx.lang_items().unwind_safe_trait(),
689+
tcx.get_diagnostic_item(sym::unwind_safe_trait),
690690
) {
691691
auto_trait_reasons.insert("`UnwindSafe`");
692692
}
693693

694694
if self.need_2229_migrations_for_trait(
695695
min_captures,
696696
var_hir_id,
697-
tcx.lang_items().ref_unwind_safe_trait(),
697+
tcx.get_diagnostic_item(sym::ref_unwind_safe_trait),
698698
) {
699699
auto_trait_reasons.insert("`RefUnwindSafe`");
700700
}

library/core/src/marker.rs

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use crate::hash::Hasher;
3131
/// [ub]: ../../reference/behavior-considered-undefined.html
3232
#[stable(feature = "rust1", since = "1.0.0")]
3333
#[cfg_attr(not(test), rustc_diagnostic_item = "send_trait")]
34-
#[lang = "send"]
3534
#[rustc_on_unimplemented(
3635
message = "`{Self}` cannot be sent between threads safely",
3736
label = "`{Self}` cannot be sent between threads safely"

library/std/src/panic.rs

+2-2
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-
#[cfg_attr(not(test), lang = "unwind_safe")]
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-
#[cfg_attr(not(test), lang = "ref_unwind_safe")]
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)