Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move the Error trait into core (without fn backtrace) #90328

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,14 @@ language_item_table! {
F64, sym::f64, f64_impl, Target::Impl, GenericRequirement::None;
F32Runtime, sym::f32_runtime, f32_runtime_impl, Target::Impl, GenericRequirement::None;
F64Runtime, sym::f64_runtime, f64_runtime_impl, Target::Impl, GenericRequirement::None;

ErrorImpl, sym::error_impl, error_impl, Target::Impl, GenericRequirement::None;
ErrorAlloc, sym::error_alloc, error_alloc_impl, Target::Impl, GenericRequirement::None;
ErrorSend, sym::errorsend, errorsend_impl, Target::Impl, GenericRequirement::None;
ErrorSendAlloc, sym::errorsend_alloc, errorsend_alloc_impl, Target::Impl, GenericRequirement::None;
ErrorSendSync, sym::errorsendsync, errorsendsync_impl, Target::Impl, GenericRequirement::None;
ErrorSendSyncAlloc, sym::errorsendsync_alloc, errorsendsync_alloc_impl, Target::Impl, GenericRequirement::None;

Error, sym::error, error_trait, Target::Trait, GenericRequirement::None;
Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").
Expand All @@ -211,6 +218,7 @@ language_item_table! {
Copy, sym::copy, copy_trait, Target::Trait, GenericRequirement::Exact(0);
Clone, sym::clone, clone_trait, Target::Trait, GenericRequirement::None;
Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0);
Send, sym::send, send_trait, Target::Trait, GenericRequirement::Exact(0);
DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None;
/// The associated item of the [`DiscriminantKind`] trait.
Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None;
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,14 @@ symbols! {
env,
eq,
ermsb_target_feature,
error,
error_alloc,
error_impl,
errorsend,
errorsend_alloc,
errorsendsync,
errorsendsync_alloc,
errorstatic,
exact_div,
except,
exchange_malloc,
Expand Down Expand Up @@ -1177,6 +1185,7 @@ symbols! {
self_in_typedefs,
self_struct_ctor,
semitransparent,
send,
shl,
shl_assign,
should_panic,
Expand Down
47 changes: 45 additions & 2 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
let lang_items = self.tcx.lang_items();

match *self_ty.value.value.kind() {
ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
ty::Dynamic(data, ..) if let Some(p) = data.principal_def_id() => {
// Subtle: we can't use `instantiate_query_response` here: using it will
// commit to all of the type equalities assumed by inference going through
// autoderef (see the `method-probe-no-guessing` test).
Expand All @@ -639,7 +639,50 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.instantiate_canonical_with_fresh_inference_vars(self.span, self_ty);

self.assemble_inherent_candidates_from_object(generalized_self_ty);
self.assemble_inherent_impl_candidates_for_type(p.def_id());

let error_def_id = self.tcx.require_lang_item(hir::LangItem::Error, None);

if p != error_def_id {
self.assemble_inherent_impl_candidates_for_type(p);
} else {
let send_def_id = self.tcx.require_lang_item(hir::LangItem::Send, None);
let sync_def_id = self.tcx.require_lang_item(hir::LangItem::Sync, None);

let (mut is_send, mut is_sync) = (false, false);
let bounds = data.auto_traits();

for bound in bounds {
if bound == send_def_id {
is_send = true;
} else if bound == sync_def_id {
is_sync = true;
} else {
panic!("unexpected bound: {:?}", bound);
}
}

match (is_send, is_sync) {
(false, false) => {
let lang_def_id = lang_items.error_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
let lang_def_id = lang_items.error_alloc_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
(true, false) => {
let lang_def_id = lang_items.errorsend_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
let lang_def_id = lang_items.errorsend_alloc_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
(true, true) => {
let lang_def_id = lang_items.errorsendsync_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
let lang_def_id = lang_items.errorsendsync_alloc_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
(false, true) => panic!("unexpected combination of marker traits"),
}
}
}
ty::Adt(def, _) => {
self.assemble_inherent_impl_candidates_for_type(def.did);
Expand Down
54 changes: 52 additions & 2 deletions compiler/rustc_typeck/src/coherence/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,58 @@ impl<'tcx> ItemLikeVisitor<'_> for InherentCollect<'tcx> {
ty::Foreign(did) => {
self.check_def_id(item, did);
}
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
self.check_def_id(item, data.principal_def_id().unwrap());
ty::Dynamic(data, ..) if let Some(p) = data.principal_def_id() => {
let error_def_id = self.tcx.require_lang_item(hir::LangItem::Error, None);

if p != error_def_id {
self.check_def_id(item, p);
} else {
let send_def_id = self.tcx.require_lang_item(hir::LangItem::Send, None);
let sync_def_id = self.tcx.require_lang_item(hir::LangItem::Sync, None);
let (mut is_send, mut is_sync) = (false, false);
let bounds = data.auto_traits();

for bound in bounds {
if bound == send_def_id {
is_send = true;
} else if bound == sync_def_id {
is_sync = true;
} else {
panic!("unexpected bound: {:?}", bound);
}
}

match (is_send, is_sync) {
(false, false) => self.check_primitive_impl(
item.def_id,
lang_items.error_impl(),
lang_items.error_alloc_impl(),
"error_alloc_impl",
"dyn error",
item.span,
assoc_items,
),
(true, false) => self.check_primitive_impl(
item.def_id,
lang_items.errorsend_impl(),
lang_items.errorsend_alloc_impl(),
"errorsend_alloc_impl",
"dyn error",
item.span,
assoc_items,
),
(true, true) => self.check_primitive_impl(
item.def_id,
lang_items.errorsendsync_impl(),
lang_items.errorsendsync_alloc_impl(),
"errorsendsync_alloc_impl",
"dyn error",
item.span,
assoc_items,
),
(false, true) => panic!("unexpected combination of marker traits"),
}
}
}
ty::Dynamic(..) => {
struct_span_err!(
yaahc marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading