Rollup merge of #110563 - bryangarza:refactor-trait-selection-error-reporting, r=compiler-errors
Break up long function in trait selection error reporting + clean up nearby code - Move blocks of code into their own functions - Replace a few function argument types with their type aliases - Create "AppendConstMessage" enum to replace a nested `Option`.
This commit is contained in:
commit
5f33a8c026
@ -300,8 +300,7 @@ pub(super) fn obligation_for_method(
|
|||||||
trait_def_id: DefId,
|
trait_def_id: DefId,
|
||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
opt_input_types: Option<&[Ty<'tcx>]>,
|
opt_input_types: Option<&[Ty<'tcx>]>,
|
||||||
) -> (traits::Obligation<'tcx, ty::Predicate<'tcx>>, &'tcx ty::List<ty::subst::GenericArg<'tcx>>)
|
) -> (traits::PredicateObligation<'tcx>, &'tcx ty::List<ty::subst::GenericArg<'tcx>>) {
|
||||||
{
|
|
||||||
// Construct a trait-reference `self_ty : Trait<input_tys>`
|
// Construct a trait-reference `self_ty : Trait<input_tys>`
|
||||||
let substs = InternalSubsts::for_item(self.tcx, trait_def_id, |param, _| {
|
let substs = InternalSubsts::for_item(self.tcx, trait_def_id, |param, _| {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
|
@ -123,7 +123,7 @@ pub struct FulfillmentError<'tcx> {
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum FulfillmentErrorCode<'tcx> {
|
pub enum FulfillmentErrorCode<'tcx> {
|
||||||
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
|
/// Inherently impossible to fulfill; this trait is implemented if and only if it is already implemented.
|
||||||
CodeCycle(Vec<Obligation<'tcx, ty::Predicate<'tcx>>>),
|
CodeCycle(Vec<PredicateObligation<'tcx>>),
|
||||||
CodeSelectionError(SelectionError<'tcx>),
|
CodeSelectionError(SelectionError<'tcx>),
|
||||||
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
|
CodeProjectionError(MismatchedProjectionTypes<'tcx>),
|
||||||
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
|
CodeSubtypeError(ExpectedFound<Ty<'tcx>>, TypeError<'tcx>), // always comes from a SubtypePredicate
|
||||||
|
@ -591,7 +591,7 @@ fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'_>) ->
|
|||||||
fn evaluate_nested_obligations(
|
fn evaluate_nested_obligations(
|
||||||
&self,
|
&self,
|
||||||
ty: Ty<'_>,
|
ty: Ty<'_>,
|
||||||
nested: impl Iterator<Item = Obligation<'tcx, ty::Predicate<'tcx>>>,
|
nested: impl Iterator<Item = PredicateObligation<'tcx>>,
|
||||||
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
|
computed_preds: &mut FxIndexSet<ty::Predicate<'tcx>>,
|
||||||
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
|
fresh_preds: &mut FxHashSet<ty::Predicate<'tcx>>,
|
||||||
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
|
predicates: &mut VecDeque<ty::PolyTraitPredicate<'tcx>>,
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -327,7 +327,7 @@ pub struct OnUnimplementedDirective {
|
|||||||
pub label: Option<OnUnimplementedFormatString>,
|
pub label: Option<OnUnimplementedFormatString>,
|
||||||
pub note: Option<OnUnimplementedFormatString>,
|
pub note: Option<OnUnimplementedFormatString>,
|
||||||
pub parent_label: Option<OnUnimplementedFormatString>,
|
pub parent_label: Option<OnUnimplementedFormatString>,
|
||||||
pub append_const_msg: Option<Option<Symbol>>,
|
pub append_const_msg: Option<AppendConstMessage>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For the `#[rustc_on_unimplemented]` attribute
|
/// For the `#[rustc_on_unimplemented]` attribute
|
||||||
@ -337,11 +337,21 @@ pub struct OnUnimplementedNote {
|
|||||||
pub label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub note: Option<String>,
|
pub note: Option<String>,
|
||||||
pub parent_label: Option<String>,
|
pub parent_label: Option<String>,
|
||||||
/// Append a message for `~const Trait` errors. `None` means not requested and
|
// If none, should fall back to a generic message
|
||||||
/// should fallback to a generic message, `Some(None)` suggests using the default
|
pub append_const_msg: Option<AppendConstMessage>,
|
||||||
/// appended message, `Some(Some(s))` suggests use the `s` message instead of the
|
}
|
||||||
/// default one..
|
|
||||||
pub append_const_msg: Option<Option<Symbol>>,
|
/// Append a message for `~const Trait` errors.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||||
|
pub enum AppendConstMessage {
|
||||||
|
Default,
|
||||||
|
Custom(Symbol),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for AppendConstMessage {
|
||||||
|
fn default() -> Self {
|
||||||
|
AppendConstMessage::Default
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> OnUnimplementedDirective {
|
impl<'tcx> OnUnimplementedDirective {
|
||||||
@ -419,10 +429,10 @@ fn parse(
|
|||||||
}
|
}
|
||||||
} else if item.has_name(sym::append_const_msg) && append_const_msg.is_none() {
|
} else if item.has_name(sym::append_const_msg) && append_const_msg.is_none() {
|
||||||
if let Some(msg) = item.value_str() {
|
if let Some(msg) = item.value_str() {
|
||||||
append_const_msg = Some(Some(msg));
|
append_const_msg = Some(AppendConstMessage::Custom(msg));
|
||||||
continue;
|
continue;
|
||||||
} else if item.is_word() {
|
} else if item.is_word() {
|
||||||
append_const_msg = Some(None);
|
append_const_msg = Some(AppendConstMessage::Default);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -386,7 +386,7 @@ fn probe_assoc_types_at_expr(
|
|||||||
fn maybe_suggest_convert_to_slice(
|
fn maybe_suggest_convert_to_slice(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
candidate_impls: &[ImplCandidate<'tcx>],
|
candidate_impls: &[ImplCandidate<'tcx>],
|
||||||
span: Span,
|
span: Span,
|
||||||
);
|
);
|
||||||
@ -3848,7 +3848,7 @@ fn probe_assoc_types_at_expr(
|
|||||||
fn maybe_suggest_convert_to_slice(
|
fn maybe_suggest_convert_to_slice(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
trait_ref: ty::Binder<'tcx, ty::TraitRef<'tcx>>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
candidate_impls: &[ImplCandidate<'tcx>],
|
candidate_impls: &[ImplCandidate<'tcx>],
|
||||||
span: Span,
|
span: Span,
|
||||||
) {
|
) {
|
||||||
|
Loading…
Reference in New Issue
Block a user