Skip to content

Commit

Permalink
fixes for ICEs and unexpected errors
Browse files Browse the repository at this point in the history
  • Loading branch information
fee1-dead committed Feb 26, 2024
1 parent d42b128 commit bd1c55a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
28 changes: 23 additions & 5 deletions compiler/rustc_hir_analysis/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use rustc_hir::{def::DefKind, LangItem};
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
use rustc_span::sym;
use rustc_span::{def_id::DefId, Span};

/// Collects together a list of type bounds. These lists of bounds occur in many places
Expand Down Expand Up @@ -62,17 +63,34 @@ impl<'tcx> Bounds<'tcx> {
Some(tcx.expected_host_effect_param_for_body(defining_def_id))
}

(_, ty::BoundConstness::NotConst) => None,
(_, ty::BoundConstness::NotConst) => {
tcx.has_attr(trait_ref.def_id(), sym::const_trait).then_some(tcx.consts.true_)
}

// if the defining_def_id is a trait, we wire it differently than others by equating the effects.
(
kind @ (DefKind::Trait | DefKind::Impl { of_trait: true }),
kind @ (DefKind::Trait | DefKind::Impl { of_trait: true } | DefKind::AssocTy),
ty::BoundConstness::ConstIfConst,
) => {
let trait_we_are_in = if let DefKind::Trait = kind {
ty::TraitRef::identity(tcx, defining_def_id)
let parent_def_id = if kind == DefKind::AssocTy {
let did = tcx.parent(defining_def_id);
if !matches!(
tcx.def_kind(did),
DefKind::Trait | DefKind::Impl { of_trait: true }
) {
tcx.dcx().span_delayed_bug(span, "invalid `~const` encountered");
return;
}
did
} else {
tcx.impl_trait_ref(defining_def_id).unwrap().instantiate_identity()
defining_def_id
};
let trait_we_are_in = match tcx.def_kind(parent_def_id) {
DefKind::Trait => ty::TraitRef::identity(tcx, parent_def_id),
DefKind::Impl { of_trait: true } => {
tcx.impl_trait_ref(parent_def_id).unwrap().instantiate_identity()
}
_ => unreachable!(),
};
// create a new projection type `<T as TraitForBound>::Effects`
let Some(assoc) = tcx.associated_type_for_effects(trait_ref.def_id()) else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ pub(super) fn check_specialization_validity<'tcx>(
let result = opt_result.unwrap_or(Ok(()));

if let Err(parent_impl) = result {
if !tcx.is_impl_trait_in_trait(impl_item) {
if !tcx.is_impl_trait_in_trait(impl_item) && !tcx.is_effects_desugared_assoc_ty(impl_item) {
report_forbidden_specialization(tcx, impl_item, parent_impl);
} else {
tcx.dcx().delayed_bug(format!("parent item: {parent_impl:?} not marked as default"));
Expand Down

0 comments on commit bd1c55a

Please sign in to comment.